Module: kamailio Branch: master Commit: 0cb6e35d581398d2c5a7086a0d98b113fbb16138 URL: https://github.com/kamailio/kamailio/commit/0cb6e35d581398d2c5a7086a0d98b113...
Author: pinacolada1610 starinchikova@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2025-01-29T08:15:47+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.
---
Modified: src/core/tcp_main.c
---
Diff: https://github.com/kamailio/kamailio/commit/0cb6e35d581398d2c5a7086a0d98b113... Patch: https://github.com/kamailio/kamailio/commit/0cb6e35d581398d2c5a7086a0d98b113...
---
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)) {