Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/netdev: Add netdev_iob_replace_l2 for netdev to avoid misuse #167

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions drivers/net/netdev_upperhalf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/****************************************************************************
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions include/nuttx/net/netdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* include/nuttx/net/netdev.h
*
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-FileCopyrightText: 2007, 2009, 2011-2018 Gregory Nutt. All rights reserved.
* SPDX-FileCopyrightText: 2007, 2009, 2011-2018 Gregory Nutt.
* All rights reserved.
* SPDX-FileCopyrightText: 2001-2003, Adam Dunkels. All rights reserved.
* SPDX-FileContributor: Gregory Nutt <[email protected]>
*
Expand Down Expand Up @@ -1148,10 +1149,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
Expand All @@ -1160,6 +1161,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
Expand Down
29 changes: 28 additions & 1 deletion net/netdev/netdev_iob.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*
Expand Down
Loading