net/netdev: Add netdev_iob_replace_l2 for netdev to avoid misuse

And fix wrong `d_len` for IOBs from `upper->txq` in TX.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
Zhe Weng
2025-01-14 17:02:57 +08:00
committed by Alan C. Assis
parent 3c0309e0ed
commit b2db3a6430
3 changed files with 34 additions and 12 deletions
+28 -1
View File
@@ -127,7 +127,8 @@ void netdev_iob_prepare_dynamic(FAR struct net_driver_s *dev, uint16_t size)
* Name: netdev_iob_replace
*
* Description:
* Replace buffer resources for a given NIC
* Replace buffer resources for a given NIC, used by net stack for L3/L4
* and set d_buf to l2 (for legacy drivers using d_buf).
*
* Assumptions:
* The caller has locked the network and new iob is prepared with
@@ -148,6 +149,32 @@ void netdev_iob_replace(FAR struct net_driver_s *dev, FAR struct iob_s *iob)
dev->d_len = iob->io_pktlen;
}
/****************************************************************************
* Name: netdev_iob_replace_l2
*
* Description:
* Replace buffer resources for a given NIC, used by L2 (net drivers) and
* set d_len to l2, keep d_buf as NULL.
*
* Assumptions:
* The caller has locked the network and new iob is prepared with
* l2 gruard size as offset.
*
****************************************************************************/
void netdev_iob_replace_l2(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_len = iob->io_pktlen + NET_LL_HDRLEN(dev);
}
/****************************************************************************
* Name: netdev_iob_clear
*