Created
December 12, 2023 09:47
-
-
Save fredldotme/6c8a3f33551f4e55a85f1e59b16ea1ff to your computer and use it in GitHub Desktop.
Sofia-SIP patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 775bad6fad033edfdc69c6e816a8a7c4d8ffbcf6 Mon Sep 17 00:00:00 2001 | |
From: Alfred Neumayer <dev.beidl@gmail.com> | |
Date: Tue, 12 Dec 2023 10:37:03 +0100 | |
Subject: [PATCH] libsofia-sip-ua: Reuse port on all transport types | |
Enable reuse of previously allocated ports before binding sockets. | |
--- | |
libsofia-sip-ua/su/su.c | 2 +- | |
libsofia-sip-ua/tport/tport_type_tls.c | 5 +++++ | |
libsofia-sip-ua/tport/tport_type_udp.c | 4 ++++ | |
3 files changed, 10 insertions(+), 1 deletion(-) | |
diff --git a/libsofia-sip-ua/su/su.c b/libsofia-sip-ua/su/su.c | |
index dd148de..fbbde0d 100644 | |
--- a/libsofia-sip-ua/su/su.c | |
+++ b/libsofia-sip-ua/su/su.c | |
@@ -391,7 +391,7 @@ int su_getsocktype(su_socket_t s) | |
int su_setreuseaddr(su_socket_t s, int reuse) | |
{ | |
- return setsockopt(s, SOL_SOCKET, SO_REUSEADDR, | |
+ return setsockopt(s, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, | |
(void *)&reuse, (socklen_t)sizeof(reuse)); | |
} | |
diff --git a/libsofia-sip-ua/tport/tport_type_tls.c b/libsofia-sip-ua/tport/tport_type_tls.c | |
index 24f5d1b..9962c9a 100644 | |
--- a/libsofia-sip-ua/tport/tport_type_tls.c | |
+++ b/libsofia-sip-ua/tport/tport_type_tls.c | |
@@ -647,6 +647,11 @@ tport_t *tport_tls_connect(tport_primary_t *pri, | |
__func__, (void *)self, su_strerror(su_errno()))); | |
} else { | |
susa.su_port = 0; | |
+ | |
+#if defined(__linux__) | |
+ su_setreuseaddr(s, 1); | |
+#endif | |
+ | |
if (bind(s, &susa.su_sa, susalen) < 0) { | |
SU_DEBUG_3(("%s(%p): bind(local-ip): %s\n", | |
__func__, (void *)self, su_strerror(su_errno()))); | |
diff --git a/libsofia-sip-ua/tport/tport_type_udp.c b/libsofia-sip-ua/tport/tport_type_udp.c | |
index 8d0f2de..6dd4ed6 100644 | |
--- a/libsofia-sip-ua/tport/tport_type_udp.c | |
+++ b/libsofia-sip-ua/tport/tport_type_udp.c | |
@@ -139,6 +139,10 @@ int tport_udp_init_primary(tport_primary_t *pri, | |
pri->pri_primary->tp_socket = s; | |
+#if defined(__linux__) | |
+ su_setreuseaddr(s, 1); | |
+#endif | |
+ | |
if (tport_bind_socket(s, ai, return_culprit) < 0) | |
return -1; | |
-- | |
2.43.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment