This is an automated email from the ASF dual-hosted git repository.

xiaoxiang 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 688f0e9117 net: Only call arp_send for PF_INET and icmpv6_neighbor for 
PF_INET6
688f0e9117 is described below

commit 688f0e911730554bf8335f795a4ace175a889d2f
Author: Zhe Weng <weng...@xiaomi.com>
AuthorDate: Fri Jan 5 15:35:06 2024 +0800

    net: Only call arp_send for PF_INET and icmpv6_neighbor for PF_INET6
    
    If we only enable one of `CONFIG_NET_ARP_SEND` and
    `CONFIG_NET_ICMPv6_NEIGHBOR`, both IPv4 and IPv6 traffic will send
    ARP or NDP, which causes problem.
    
    Example:
    `CONFIG_NET_ARP_SEND=n`
    `CONFIG_NET_ICMPv6_NEIGHBOR=y`
    
    Wrong:
    IPv4 traffic (`PF_INET`) goes into `icmpv6_neighbor`, which
    definitely causes problem.
    
    Correct:
    IPv4 traffic doesn't call anything, IPv6 traffic calls `icmpv6_neighbor`
    
    Signed-off-by: Zhe Weng <weng...@xiaomi.com>
---
 net/tcp/tcp_conn.c              | 8 ++++----
 net/tcp/tcp_send_buffered.c     | 6 +-----
 net/tcp/tcp_send_unbuffered.c   | 6 +-----
 net/tcp/tcp_sendfile.c          | 9 +++------
 net/udp/udp_sendto_buffered.c   | 6 +-----
 net/udp/udp_sendto_unbuffered.c | 8 ++------
 6 files changed, 12 insertions(+), 31 deletions(-)

diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c
index 8b721a2edf..4d8a3eec9e 100644
--- a/net/tcp/tcp_conn.c
+++ b/net/tcp/tcp_conn.c
@@ -1319,7 +1319,7 @@ int tcp_bind(FAR struct tcp_conn_s *conn, FAR const 
struct sockaddr *addr)
 int tcp_connect(FAR struct tcp_conn_s *conn, FAR const struct sockaddr *addr)
 {
   int port;
-  int ret;
+  int ret = OK;
 
   /* The connection is expected to be in the TCP_ALLOCATED state.. i.e.,
    * allocated via up_tcpalloc(), but not yet put into the active connections
@@ -1468,7 +1468,7 @@ int tcp_connect(FAR struct tcp_conn_s *conn, FAR const 
struct sockaddr *addr)
 
 #if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
 #ifdef CONFIG_NET_ARP_SEND
-#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
+#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
   if (conn->domain == PF_INET)
 #endif
     {
@@ -1479,8 +1479,8 @@ int tcp_connect(FAR struct tcp_conn_s *conn, FAR const 
struct sockaddr *addr)
 #endif /* CONFIG_NET_ARP_SEND */
 
 #ifdef CONFIG_NET_ICMPv6_NEIGHBOR
-#ifdef CONFIG_NET_ARP_SEND
-  else
+#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
+  if (conn->domain == PF_INET6)
 #endif
     {
       /* Make sure that the IP address mapping is in the Neighbor Table */
diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c
index 874b8d5c0e..8024827d23 100644
--- a/net/tcp/tcp_send_buffered.c
+++ b/net/tcp/tcp_send_buffered.c
@@ -1304,9 +1304,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR 
const void *buf,
 
 #if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
 #ifdef CONFIG_NET_ARP_SEND
-#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
   if (psock->s_domain == PF_INET)
-#endif
     {
       /* Make sure that the IP address mapping is in the ARP table */
 
@@ -1315,9 +1313,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR 
const void *buf,
 #endif /* CONFIG_NET_ARP_SEND */
 
 #ifdef CONFIG_NET_ICMPv6_NEIGHBOR
-#ifdef CONFIG_NET_ARP_SEND
-  else
-#endif
+  if (psock->s_domain == PF_INET6)
     {
       /* Make sure that the IP address mapping is in the Neighbor Table */
 
diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c
index c01c3c5a26..4b4f9882b1 100644
--- a/net/tcp/tcp_send_unbuffered.c
+++ b/net/tcp/tcp_send_unbuffered.c
@@ -508,9 +508,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
 
 #if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
 #ifdef CONFIG_NET_ARP_SEND
-#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
   if (psock->s_domain == PF_INET)
-#endif
     {
       /* Make sure that the IP address mapping is in the ARP table */
 
@@ -519,9 +517,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
 #endif /* CONFIG_NET_ARP_SEND */
 
 #ifdef CONFIG_NET_ICMPv6_NEIGHBOR
-#ifdef CONFIG_NET_ARP_SEND
-  else
-#endif
+  if (psock->s_domain == PF_INET6)
     {
       /* Make sure that the IP address mapping is in the Neighbor Table */
 
diff --git a/net/tcp/tcp_sendfile.c b/net/tcp/tcp_sendfile.c
index 0cbac05fb1..6f27a806b2 100644
--- a/net/tcp/tcp_sendfile.c
+++ b/net/tcp/tcp_sendfile.c
@@ -417,7 +417,7 @@ ssize_t tcp_sendfile(FAR struct socket *psock, FAR struct 
file *infile,
   FAR struct tcp_conn_s *conn;
   struct sendfile_s state;
   off_t startpos;
-  int ret;
+  int ret = OK;
 
   conn = psock->s_conn;
   DEBUGASSERT(conn != NULL);
@@ -434,19 +434,16 @@ ssize_t tcp_sendfile(FAR struct socket *psock, FAR struct 
file *infile,
 
 #if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
 #ifdef CONFIG_NET_ARP_SEND
-#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
   if (psock->s_domain == PF_INET)
-#endif
     {
       /* Make sure that the IP address mapping is in the ARP table */
 
       ret = arp_send(conn->u.ipv4.raddr);
     }
 #endif /* CONFIG_NET_ARP_SEND */
+
 #ifdef CONFIG_NET_ICMPv6_NEIGHBOR
-#ifdef CONFIG_NET_ARP_SEND
-  else
-#endif
+  if (psock->s_domain == PF_INET6)
     {
       /* Make sure that the IP address mapping is in the Neighbor Table */
 
diff --git a/net/udp/udp_sendto_buffered.c b/net/udp/udp_sendto_buffered.c
index 764531867f..2e3cde8e21 100644
--- a/net/udp/udp_sendto_buffered.c
+++ b/net/udp/udp_sendto_buffered.c
@@ -593,9 +593,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR 
const void *buf,
    * the ARP table.
    */
 
-#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
   if (psock->s_domain == PF_INET)
-#endif
     {
       in_addr_t destipaddr;
 
@@ -632,9 +630,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR 
const void *buf,
    * the neighbor table.
    */
 
-#ifdef CONFIG_NET_ARP_SEND
-  else
-#endif
+  if (psock->s_domain == PF_INET6)
     {
       FAR const uint16_t *destipaddr;
 
diff --git a/net/udp/udp_sendto_unbuffered.c b/net/udp/udp_sendto_unbuffered.c
index 6e93c22a6d..b45625b7a3 100644
--- a/net/udp/udp_sendto_unbuffered.c
+++ b/net/udp/udp_sendto_unbuffered.c
@@ -267,7 +267,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR 
const void *buf,
 {
   FAR struct udp_conn_s *conn;
   struct sendto_s state;
-  int ret;
+  int ret = OK;
 
   /* Verify that the sockfd corresponds to valid, allocated socket */
 
@@ -314,9 +314,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR 
const void *buf,
    * the ARP table.
    */
 
-#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
   if (psock->s_domain == PF_INET)
-#endif
     {
       in_addr_t destipaddr;
 
@@ -353,9 +351,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR 
const void *buf,
    * the neighbor table.
    */
 
-#ifdef CONFIG_NET_ARP_SEND
-  else
-#endif
+  if (psock->s_domain == PF_INET6)
     {
       FAR const uint16_t *destipaddr;
 

Reply via email to