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.