Module: kamailio
Branch: 6.0
Commit: 1e362f2ba51c6ee9a9e005675a30202e42ceb3a7
URL: 
https://github.com/kamailio/kamailio/commit/1e362f2ba51c6ee9a9e005675a30202e42ceb3a7

Author: pinacolada1610 <starinchik...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2025-01-29T10:31:19+01:00

tcp: fix for local TCP/TLS socket matching with 'tcp_reuse_port' enabled

- Changed the logic for matching a listening TCP/TLS-socket in tcp_reuse_port 
scenario, now it considers local port as well.
With 'tcp_reuse_port' option enabled, the local port is meaningful and helps to 
differenciate between sockets on the same IP but different ports.

(cherry picked from commit 0cb6e35d581398d2c5a7086a0d98b113fbb16138)

---

Modified: src/core/tcp_main.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/1e362f2ba51c6ee9a9e005675a30202e42ceb3a7.diff
Patch: 
https://github.com/kamailio/kamailio/commit/1e362f2ba51c6ee9a9e005675a30202e42ceb3a7.patch

---

diff --git a/src/core/tcp_main.c b/src/core/tcp_main.c
index bc1327204e8..e0238fe090b 100644
--- a/src/core/tcp_main.c
+++ b/src/core/tcp_main.c
@@ -1332,6 +1332,7 @@ inline static int tcp_do_connect(union sockaddr_union 
*server,
        union sockaddr_union my_name;
        socklen_t my_name_len;
        struct ip_addr ip;
+       unsigned short port;
 #ifdef TCP_ASYNC
        int n;
 #endif /* TCP_ASYNC */
@@ -1437,14 +1438,19 @@ inline static int tcp_do_connect(union sockaddr_union 
*server,
        from = &my_name; /* update from with the real "from" address */
        su2ip_addr(&ip, &my_name);
 find_socket:
+#ifdef SO_REUSEPORT
+       port = cfg_get(tcp, tcp_cfg, reuse_port) ? su_getport(from) : 0;
+#else
+       port = 0;
+#endif
 #ifdef USE_TLS
        if(unlikely(type == PROTO_TLS)) {
-               *res_si = find_si(&ip, 0, PROTO_TLS);
+               *res_si = find_si(&ip, port, PROTO_TLS);
        } else {
-               *res_si = find_si(&ip, 0, PROTO_TCP);
+               *res_si = find_si(&ip, port, PROTO_TCP);
        }
 #else
-       *res_si = find_si(&ip, 0, PROTO_TCP);
+       *res_si = find_si(&ip, port, PROTO_TCP);
 #endif
 
        if(unlikely(*res_si == 0)) {

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to