mirror of
https://github.com/apache/nuttx.git
synced 2026-05-18 00:34:10 +08:00
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:
@@ -182,15 +182,8 @@ static void netpkt_put(FAR struct net_driver_s *dev, FAR netpkt_t *pkt,
|
||||
|
||||
DEBUGASSERT(dev && pkt);
|
||||
|
||||
/* TODO: Using netdev_iob_release instead of netdev_iob_replace now,
|
||||
* because netdev_iob_replace sets d_len = L3_LEN and d_buf,
|
||||
* but we don't want these changes.
|
||||
*/
|
||||
|
||||
atomic_fetch_add(&upper->lower->quota[type], 1);
|
||||
netdev_iob_release(dev);
|
||||
dev->d_iob = pkt;
|
||||
dev->d_len = netpkt_getdatalen(upper->lower, pkt);
|
||||
netdev_iob_replace_l2(dev, pkt);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -344,7 +337,7 @@ static int netdev_upper_tx(FAR struct net_driver_s *dev)
|
||||
{
|
||||
/* Put the packet back to the device */
|
||||
|
||||
netdev_iob_replace(dev, iob_remove_queue(&upper->txq));
|
||||
netdev_iob_replace_l2(dev, iob_remove_queue(&upper->txq));
|
||||
return netdev_upper_txpoll(dev);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1160,10 +1160,10 @@ void netdev_iob_prepare_dynamic(FAR struct net_driver_s *dev, uint16_t size);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netdev_iob_replace
|
||||
* Name: netdev_iob_replace / netdev_iob_replace_l2
|
||||
*
|
||||
* Description:
|
||||
* Replace buffer resources for a given NIC
|
||||
* Replace IOB for a given NIC, used by net stack (l3-4) / net driver (l2).
|
||||
*
|
||||
* Assumptions:
|
||||
* The caller has locked the network and new iob is prepared with
|
||||
@@ -1172,6 +1172,8 @@ void netdev_iob_prepare_dynamic(FAR struct net_driver_s *dev, uint16_t size);
|
||||
****************************************************************************/
|
||||
|
||||
void netdev_iob_replace(FAR struct net_driver_s *dev, FAR struct iob_s *iob);
|
||||
void netdev_iob_replace_l2(FAR struct net_driver_s *dev,
|
||||
FAR struct iob_s *iob);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netdev_iob_clear
|
||||
|
||||
+28
-1
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user