From 8fc1e524ab87d95d4f7a303afc56986e989a1aee Mon Sep 17 00:00:00 2001 From: chao an Date: Mon, 5 Dec 2022 00:33:41 +0800 Subject: [PATCH] net/ip: return success if the packet was forwarded. The incoming packet should not be input to ip layer if the packet has been forwarded Signed-off-by: chao an --- net/devif/ipv4_input.c | 25 +++++++++++++++++++++++-- net/devif/ipv6_input.c | 10 ++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/net/devif/ipv4_input.c b/net/devif/ipv4_input.c index ee1961f74f..aaf854290b 100644 --- a/net/devif/ipv4_input.c +++ b/net/devif/ipv4_input.c @@ -255,8 +255,15 @@ static int ipv4_in(FAR struct net_driver_s *dev) /* Forward broadcast packets */ ipv4_forward_broadcast(dev, ipv4); + + /* Process the incoming packet if not forwardable */ + + if (dev->d_len > 0) #endif - ret = udp_ipv4_input(dev); + { + ret = udp_ipv4_input(dev); + } + goto done; } else @@ -276,8 +283,15 @@ static int ipv4_in(FAR struct net_driver_s *dev) /* Forward broadcast packets */ ipv4_forward_broadcast(dev, ipv4); + + /* Process the incoming packet if not forwardable */ + + if (dev->d_len > 0) #endif - ret = udp_ipv4_input(dev); + { + ret = udp_ipv4_input(dev); + } + goto done; } else @@ -298,6 +312,13 @@ static int ipv4_in(FAR struct net_driver_s *dev) /* Forward multicast packets */ ipv4_forward_broadcast(dev, ipv4); + + /* Return success if the packet was forwarded. */ + + if (dev->d_len == 0) + { + goto done; + } #endif } else diff --git a/net/devif/ipv6_input.c b/net/devif/ipv6_input.c index 914ff43872..7b7dfa4067 100644 --- a/net/devif/ipv6_input.c +++ b/net/devif/ipv6_input.c @@ -395,6 +395,16 @@ static int ipv6_in(FAR struct net_driver_s *dev) } } } + +#ifdef CONFIG_NET_IPFORWARD + /* Return success if the packet was forwarded. */ + + if (dev->d_len == 0) + { + goto done; + } +#endif + #ifdef CONFIG_NET_ICMPv6 /* In other cases, the device must be assigned a non-zero IP address