This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 9c2bef421c04f63faa170cc0e2bdbd81da85c116 Author: Marco Casaroli <[email protected]> AuthorDate: Thu Nov 26 06:26:10 2026 +0100 net: Check for the ICMP stack before an ICMP reply. Three other callers of icmp_reply() and icmpv6_reply() checked the wrong option: - ipfrag.c sent the ICMPv6 Time Exceeded message under the check for the ICMP (IPv4) stack. A build with CONFIG_NET_IPFRAG, CONFIG_NET_IPv4, CONFIG_NET_IPv6 and CONFIG_NET_ICMP but without CONFIG_NET_ICMPv6 failed. Now each family replies only if its own stack is there, and a timeout of a family without the stack only frees the fragments. - ipv6_forward.c checked only CONFIG_NET_ICMPv6, so a build with CONFIG_NET_ICMPv6_NO_STACK failed. - udp_input.c checked only CONFIG_NET_ICMP and CONFIG_NET_ICMPv6, so a build with the UDP stack and CONFIG_NET_ICMP_NO_STACK or CONFIG_NET_ICMPv6_NO_STACK failed. Use NET_ICMP_HAVE_STACK and NET_ICMPv6_HAVE_STACK from icmp.h and icmpv6.h, as ipv4_input.c and ipv6_input.c do. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- net/ipfrag/ipfrag.c | 21 +++++++++++++++++---- net/netforward/ipv6_forward.c | 10 +++++----- net/udp/udp_input.c | 10 +++++----- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/net/ipfrag/ipfrag.c b/net/ipfrag/ipfrag.c index 4259d91cf6e..54c132de2c3 100644 --- a/net/ipfrag/ipfrag.c +++ b/net/ipfrag/ipfrag.c @@ -100,6 +100,18 @@ do \ #define LOOPBACK_IPFRAME_NOFRAGMENT 0 +/* A reassembly timeout sends ICMP Time Exceeded only if the ICMP stack of + * the family of the packet is there. + */ + +#if defined(NET_ICMP_HAVE_STACK) && defined(NET_ICMPv6_HAVE_STACK) +# define IPFRAG_CAN_REPLY(isipv4) true +#elif defined(NET_ICMP_HAVE_STACK) +# define IPFRAG_CAN_REPLY(isipv4) (isipv4) +#elif defined(NET_ICMPv6_HAVE_STACK) +# define IPFRAG_CAN_REPLY(isipv4) (!(isipv4)) +#endif + /**************************************************************************** * Private Data ****************************************************************************/ @@ -227,8 +239,9 @@ static void ip_fragin_timerwork(FAR void *arg) */ ninfo("Reassembly timeout occurs!"); -#if defined(CONFIG_NET_ICMP) && !defined(CONFIG_NET_ICMP_NO_STACK) - if ((node->verifyflag & IP_FRAGVERIFY_RECVDZEROFRAG) != 0) +#ifdef IPFRAG_CAN_REPLY + if ((node->verifyflag & IP_FRAGVERIFY_RECVDZEROFRAG) != 0 && + IPFRAG_CAN_REPLY(node->frags->isipv4)) { FAR struct net_driver_s *dev = node->dev; @@ -237,7 +250,7 @@ static void ip_fragin_timerwork(FAR void *arg) netdev_iob_replace(dev, node->frags->frag); node->frags->frag = NULL; -#ifdef CONFIG_NET_IPv4 +#if defined(CONFIG_NET_IPv4) && defined(NET_ICMP_HAVE_STACK) if (node->frags->isipv4) { icmp_reply(dev, ICMP_TIME_EXCEEDED, @@ -245,7 +258,7 @@ static void ip_fragin_timerwork(FAR void *arg) } #endif -#ifdef CONFIG_NET_IPv6 +#if defined(CONFIG_NET_IPv6) && defined(NET_ICMPv6_HAVE_STACK) if (!node->frags->isipv4) { icmpv6_reply(dev, ICMPv6_PACKET_TIME_EXCEEDED, diff --git a/net/netforward/ipv6_forward.c b/net/netforward/ipv6_forward.c index a6493aebb0e..3b960837148 100644 --- a/net/netforward/ipv6_forward.c +++ b/net/netforward/ipv6_forward.c @@ -609,11 +609,11 @@ int ipv6_forward(FAR struct net_driver_s *dev, FAR struct ipv6_hdr_s *ipv6) { FAR struct net_driver_s *fwddev; int ret; -#ifdef CONFIG_NET_ICMPv6 +#ifdef NET_ICMPv6_HAVE_STACK int icmpv6_reply_type; int icmpv6_reply_code; int icmpv6_reply_data; -#endif /* CONFIG_NET_ICMP */ +#endif /* NET_ICMPv6_HAVE_STACK */ /* Check if source device supports IP forwarding capability */ @@ -716,7 +716,7 @@ int ipv6_forward(FAR struct net_driver_s *dev, FAR struct ipv6_hdr_s *ipv6) drop: ipv6_dropstats(ipv6); -#ifdef CONFIG_NET_ICMPv6 +#ifdef NET_ICMPv6_HAVE_STACK /* Try reply ICMPv6 to the sender. */ switch (ret) @@ -753,7 +753,7 @@ drop: dev->d_len = 0; return ret; -#ifdef CONFIG_NET_ICMPv6 +#ifdef NET_ICMPv6_HAVE_STACK reply: # ifdef CONFIG_NET_NAT66 /* Before we reply ICMPv6, call NAT outbound to try to translate @@ -765,7 +765,7 @@ reply: icmpv6_reply(dev, icmpv6_reply_type, icmpv6_reply_code, icmpv6_reply_data); return OK; -#endif /* CONFIG_NET_ICMP */ +#endif /* NET_ICMPv6_HAVE_STACK */ } /**************************************************************************** diff --git a/net/udp/udp_input.c b/net/udp/udp_input.c index 2eb01f53aec..0b026828813 100644 --- a/net/udp/udp_input.c +++ b/net/udp/udp_input.c @@ -412,7 +412,7 @@ static int udp_input(FAR struct net_driver_s *dev, unsigned int iplen) * unless destination address was broadcast/multicast. */ -#if !defined(CONFIG_NET_ICMP) && !defined(CONFIG_NET_ICMPv6) +#if !defined(NET_ICMP_HAVE_STACK) && !defined(NET_ICMPv6_HAVE_STACK) dev->d_len = 0; #else # ifdef CONFIG_NET_IPv4 @@ -420,11 +420,11 @@ static int udp_input(FAR struct net_driver_s *dev, unsigned int iplen) if (IFF_IS_IPv4(dev->d_flags)) # endif { -# ifdef CONFIG_NET_ICMP +# ifdef NET_ICMP_HAVE_STACK icmp_reply(dev, ICMP_DEST_UNREACHABLE, ICMP_PORT_UNREACH); # else dev->d_len = 0; -# endif /* CONFIG_NET_ICMP */ +# endif /* NET_ICMP_HAVE_STACK */ } # endif /* CONFIG_NET_IPv4 */ # ifdef CONFIG_NET_IPv6 @@ -432,12 +432,12 @@ static int udp_input(FAR struct net_driver_s *dev, unsigned int iplen) else # endif { -# ifdef CONFIG_NET_ICMPv6 +# ifdef NET_ICMPv6_HAVE_STACK icmpv6_reply(dev, ICMPv6_DEST_UNREACHABLE, ICMPv6_PORT_UNREACH, 0); # else dev->d_len = 0; -# endif /* CONFIG_NET_ICMPv6 */ +# endif /* NET_ICMPv6_HAVE_STACK */ } # endif /* CONFIG_NET_IPv6*/ #endif
