This is an automated email from the ASF dual-hosted git repository.
archer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new da74a5e368 net/tcp/tcp_conn.c: optimize the port conflict detection
rules for tcp_listener(). fixed potential conflict between implicit binding and
port conflict detection.
da74a5e368 is described below
commit da74a5e3680bf1dde769c4407043a4d55296c13f
Author: nuttxs <[email protected]>
AuthorDate: Sun Apr 20 14:49:56 2025 +0800
net/tcp/tcp_conn.c: optimize the port conflict detection rules
for tcp_listener(). fixed potential conflict between implicit
binding and port conflict detection.
Implicit binding automatically allocates an interface address during
connection,but port conflict detection occurs before binding/connecting.
This can cause issues when creating multiple TCP connections in succession.
If the first connection uses a random port via implicit binding, subsequent
connections might reuse the same port under current filtering rules,
leading to connect() failures.
Signed-off-by: nuttxs <[email protected]>
---
net/tcp/tcp_conn.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c
index 19c1fd97cc..153f92b348 100644
--- a/net/tcp/tcp_conn.c
+++ b/net/tcp/tcp_conn.c
@@ -143,7 +143,8 @@ static FAR struct tcp_conn_s *
#endif /* CONFIG_NET_IPv6 */
{
if (net_ipv4addr_cmp(conn->u.ipv4.laddr, ipaddr->ipv4) ||
- net_ipv4addr_cmp(conn->u.ipv4.laddr, INADDR_ANY))
+ net_ipv4addr_cmp(conn->u.ipv4.laddr, INADDR_ANY) ||
+ net_ipv4addr_cmp(ipaddr->ipv4, INADDR_ANY))
{
/* The port number is in use, return the connection */
@@ -158,7 +159,8 @@ static FAR struct tcp_conn_s *
#endif /* CONFIG_NET_IPv4 */
{
if (net_ipv6addr_cmp(conn->u.ipv6.laddr, ipaddr->ipv6) ||
- net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_unspecaddr))
+ net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_unspecaddr) ||
+ net_ipv6addr_cmp(ipaddr->ipv6, g_ipv6_unspecaddr))
{
/* The port number is in use, return the connection */