diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index bc153235d95..3c9d9a31853 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -895,6 +895,20 @@ int netdev_lladdrsize(FAR struct net_driver_s *dev); int netdev_iob_prepare(FAR struct net_driver_s *dev, bool throttled, unsigned int timeout); +/**************************************************************************** + * Name: netdev_iob_replace + * + * Description: + * Replace buffer resources for a given NIC + * + * Assumptions: + * The caller has locked the network and new iob is prepared with + * l2 gruard size as offset. + * + ****************************************************************************/ + +void netdev_iob_replace(FAR struct net_driver_s *dev, FAR struct iob_s *iob); + /**************************************************************************** * Name: netdev_iob_clear * diff --git a/net/devif/devif_forward.c b/net/devif/devif_forward.c index fa05ac10ab7..6ea5146a5ef 100644 --- a/net/devif/devif_forward.c +++ b/net/devif/devif_forward.c @@ -60,24 +60,14 @@ void devif_forward(FAR struct forward_s *fwd) { - unsigned int offset; - int ret; - DEBUGASSERT(fwd != NULL && fwd->f_iob != NULL && fwd->f_dev != NULL); - offset = NET_LL_HDRLEN(fwd->f_dev); - /* Copy the IOB chain that contains the L3L3 headers and any data payload */ + /* Move the IOB chain that contains the L3 header and any data payload */ - DEBUGASSERT(offset + fwd->f_iob->io_pktlen <= NETDEV_PKTSIZE(fwd->f_dev)); - ret = iob_copyout(&fwd->f_dev->d_buf[offset], fwd->f_iob, - fwd->f_iob->io_pktlen, 0); - - DEBUGASSERT(ret == fwd->f_iob->io_pktlen); + netdev_iob_replace(fwd->f_dev, fwd->f_iob); fwd->f_dev->d_sndlen = 0; - fwd->f_dev->d_len = fwd->f_iob->io_pktlen; - - UNUSED(ret); + fwd->f_iob = NULL; } #endif /* CONFIG_NET_IPFORWARD */ diff --git a/net/netdev/netdev_iob.c b/net/netdev/netdev_iob.c index 0c5921a70ea..c13482cda35 100644 --- a/net/netdev/netdev_iob.c +++ b/net/netdev/netdev_iob.c @@ -84,6 +84,32 @@ int netdev_iob_prepare(FAR struct net_driver_s *dev, bool throttled, return OK; } +/**************************************************************************** + * Name: netdev_iob_replace + * + * Description: + * Replace buffer resources for a given NIC + * + * Assumptions: + * The caller has locked the network and new iob is prepared with + * l2 gruard size as offset. + * + ****************************************************************************/ + +void netdev_iob_replace(FAR struct net_driver_s *dev, FAR struct iob_s *iob) +{ + /* Release previous buffer */ + + netdev_iob_release(dev); + + /* Set new buffer */ + + dev->d_iob = iob; + dev->d_buf = &dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE - + NET_LL_HDRLEN(dev)]; + dev->d_len = iob->io_pktlen; +} + /**************************************************************************** * Name: netdev_iob_clear *