فهرست منبع

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)
pinacolada1610 7 ماه پیش
والد
کامیت
1e362f2ba5
1فایلهای تغییر یافته به همراه9 افزوده شده و 3 حذف شده
  1. 9 3
      src/core/tcp_main.c

+ 9 - 3
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)) {