From 2f3e23738041879a3c201f7e83f7cccf1d96ae89 Mon Sep 17 00:00:00 2001 From: Zhe Weng Date: Thu, 8 Dec 2022 17:06:54 +0800 Subject: [PATCH] net/ipfwd: limit number of ipforward struct to be less than number of IOB If ipforward consumes all the IOB, devif_poll will not poll any more. Without polling, ipforward will not release any IOB, then all the network stack may fail with no IOB available. Signed-off-by: Zhe Weng --- net/devif/devif_poll.c | 1 + net/ipforward/Kconfig | 4 ++++ net/ipforward/ipforward.h | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/net/devif/devif_poll.c b/net/devif/devif_poll.c index 4b4d42a4a15..28baba33d1b 100644 --- a/net/devif/devif_poll.c +++ b/net/devif/devif_poll.c @@ -925,6 +925,7 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback) if (netdev_iob_prepare(dev, false, 0) != OK) { + nwarn("WARNING: IOB Prepare failed for dev %s!\n", dev->d_ifname); bstop = true; break; } diff --git a/net/ipforward/Kconfig b/net/ipforward/Kconfig index cc18dee4ce7..3be48eac759 100644 --- a/net/ipforward/Kconfig +++ b/net/ipforward/Kconfig @@ -36,3 +36,7 @@ config NET_IPFORWARD_NSTRUCT packets that may be waiting to be forwarded from one network device to another. CONFIG_IOB_NBUFFERS also limits the forward because the payload of the packet (up to the MSS) is retain in IOBs. + + WARNING: DO NOT set this setting to a value greater than or equal to + CONFIG_IOB_NBUFFERS, otherwise it may consume all the IOB and let + netdev fail to work. diff --git a/net/ipforward/ipforward.h b/net/ipforward/ipforward.h index 30b8a9d973e..29087c03aaf 100644 --- a/net/ipforward/ipforward.h +++ b/net/ipforward/ipforward.h @@ -27,6 +27,7 @@ #include +#include #include #undef HAVE_FWDALLOC @@ -42,6 +43,9 @@ # define CONFIG_NET_IPFORWARD_NSTRUCT 4 #endif +static_assert(CONFIG_IOB_NBUFFERS > CONFIG_NET_IPFORWARD_NSTRUCT, + "IP forward may consume all the IOB and break netdev logic"); + /* Allocate a new IP forwarding data callback */ #define ipfwd_callback_alloc(dev) devif_callback_alloc(dev, \