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 6c73221dd4 forward: limit the forwarding range of broadcast packets
6c73221dd4 is described below
commit 6c73221dd439ec586faba1f457141cb434ad2a52
Author: zhanghongyu <[email protected]>
AuthorDate: Tue Apr 18 18:25:42 2023 +0800
forward: limit the forwarding range of broadcast packets
Signed-off-by: zhanghongyu <[email protected]>
---
net/ipforward/ipv4_forward.c | 11 ++++++++++-
net/ipforward/ipv6_forward.c | 11 ++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/net/ipforward/ipv4_forward.c b/net/ipforward/ipv4_forward.c
index 1bc3b9c322..7fc7e2d61b 100644
--- a/net/ipforward/ipv4_forward.c
+++ b/net/ipforward/ipv4_forward.c
@@ -343,7 +343,16 @@ int ipv4_forward_callback(FAR struct net_driver_s *fwddev,
FAR void *arg)
FAR struct ipv4_hdr_s *ipv4;
int ret;
- DEBUGASSERT(fwddev != NULL && dev != NULL && dev->d_buf != NULL);
+ DEBUGASSERT(fwddev != NULL);
+
+ /* Only IFF_UP device and non-loopback device need forward packet */
+
+ if (!IFF_IS_UP(fwddev->d_flags) || fwddev->d_lltype == NET_LL_LOOPBACK)
+ {
+ return OK;
+ }
+
+ DEBUGASSERT(dev != NULL && dev->d_buf != NULL);
/* Check if we are forwarding on the same device that we received the
* packet from.
diff --git a/net/ipforward/ipv6_forward.c b/net/ipforward/ipv6_forward.c
index 527f476ce6..0787a7593e 100644
--- a/net/ipforward/ipv6_forward.c
+++ b/net/ipforward/ipv6_forward.c
@@ -470,7 +470,16 @@ int ipv6_forward_callback(FAR struct net_driver_s *fwddev,
FAR void *arg)
FAR struct ipv6_hdr_s *ipv6;
int ret;
- DEBUGASSERT(fwddev != NULL && dev != NULL && dev->d_buf != NULL);
+ DEBUGASSERT(fwddev != NULL);
+
+ /* Only IFF_UP device and non-loopback device need forward packet */
+
+ if (!IFF_IS_UP(fwddev->d_flags) || fwddev->d_lltype == NET_LL_LOOPBACK)
+ {
+ return OK;
+ }
+
+ DEBUGASSERT(dev != NULL && dev->d_buf != NULL);
/* Check if we are forwarding on the same device that we received the
* packet from.