net/netdev: Add netdev_iob_clone helper

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
Zhe Weng
2024-03-27 18:52:54 +08:00
committed by Xiang Xiao
parent e87de19322
commit 2a342d2424
4 changed files with 56 additions and 22 deletions
+38
View File
@@ -153,3 +153,41 @@ void netdev_iob_release(FAR struct net_driver_s *dev)
dev->d_buf = NULL;
}
/****************************************************************************
* Name: netdev_iob_clone
*
* Description:
* Backup the current iob buffer for a given NIC by cloning it.
*
* Assumptions:
* The caller has locked the network.
*
****************************************************************************/
FAR struct iob_s *netdev_iob_clone(FAR struct net_driver_s *dev,
bool throttled)
{
FAR struct iob_s *iob;
int ret;
iob = iob_tryalloc(throttled);
if (iob == NULL)
{
nwarn("WARNING: IOB alloc failed for dev %s!\n", dev->d_ifname);
return NULL;
}
iob_reserve(iob, CONFIG_NET_LL_GUARDSIZE);
ret = iob_clone_partial(dev->d_iob, dev->d_iob->io_pktlen, 0,
iob, 0, throttled, false);
if (ret < 0)
{
iob_free_chain(iob);
nwarn("WARNING: IOB clone failed for dev %s, ret=%d!\n",
dev->d_ifname, ret);
return NULL;
}
return iob;
}