forked from nuttx/nuttx-update
net/netdev: add devif_loopback_out() to check the loopback case where a packet is being sent to itself. Modify the net driver to call this function in this case. This function will simply re-inject the packet back into the network and the network driver will not put anything on the wire.
This commit is contained in:
parent
f74ddd2a04
commit
0074afa0ac
33 changed files with 639 additions and 366 deletions
|
@ -1046,19 +1046,22 @@ static int c5471_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
c5471_transmit(priv);
|
||||
|
||||
/* Check if the ESM has let go of the RX descriptor giving us access
|
||||
* rights to submit another Ethernet frame.
|
||||
*/
|
||||
|
||||
if ((EIM_TXDESC_OWN_HOST & getreg32(priv->c_rxcpudesc)) != 0)
|
||||
if (!devif_loopback_out(&priv->c_dev))
|
||||
{
|
||||
/* No, then return non-zero to terminate the poll */
|
||||
/* Send the packet */
|
||||
|
||||
return 1;
|
||||
c5471_transmit(priv);
|
||||
|
||||
/* Check if the ESM has let go of the RX descriptor giving us access
|
||||
* rights to submit another Ethernet frame.
|
||||
*/
|
||||
|
||||
if ((EIM_TXDESC_OWN_HOST & getreg32(priv->c_rxcpudesc)) != 0)
|
||||
{
|
||||
/* No, then return non-zero to terminate the poll */
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -600,20 +600,23 @@ static int imxrt_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
imxrt_transmit(priv);
|
||||
priv->dev.d_buf =
|
||||
(uint8_t*)imxrt_swap32((uint32_t)priv->txdesc[priv->txhead].data);
|
||||
|
||||
/* Check if there is room in the device to hold another packet. If not,
|
||||
* return a non-zero value to terminate the poll.
|
||||
*/
|
||||
|
||||
if (imxrt_txringfull(priv))
|
||||
if (!devif_loopback_out(&priv->dev))
|
||||
{
|
||||
return -EBUSY;
|
||||
}
|
||||
/* Send the packet */
|
||||
|
||||
imxrt_transmit(priv);
|
||||
priv->dev.d_buf =
|
||||
(uint8_t*)imxrt_swap32((uint32_t)priv->txdesc[priv->txhead].data);
|
||||
|
||||
/* Check if there is room in the device to hold another packet. If not,
|
||||
* return a non-zero value to terminate the poll.
|
||||
*/
|
||||
|
||||
if (imxrt_txringfull(priv))
|
||||
{
|
||||
return -EBUSY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If zero is returned, the polling will continue until all connections have
|
||||
|
|
|
@ -571,19 +571,22 @@ static int kinetis_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
kinetis_transmit(priv);
|
||||
priv->dev.d_buf =
|
||||
(uint8_t*)kinesis_swap32((uint32_t)priv->txdesc[priv->txhead].data);
|
||||
|
||||
/* Check if there is room in the device to hold another packet. If not,
|
||||
* return a non-zero value to terminate the poll.
|
||||
*/
|
||||
|
||||
if (kinetis_txringfull(priv))
|
||||
if (!devif_loopback_out(&priv->dev))
|
||||
{
|
||||
return -EBUSY;
|
||||
/* Send the packet */
|
||||
|
||||
kinetis_transmit(priv);
|
||||
priv->dev.d_buf =
|
||||
(uint8_t*)kinesis_swap32((uint32_t)priv->txdesc[priv->txhead].data);
|
||||
|
||||
/* Check if there is room in the device to hold another packet. If not,
|
||||
* return a non-zero value to terminate the poll.
|
||||
*/
|
||||
|
||||
if (kinetis_txringfull(priv))
|
||||
{
|
||||
return -EBUSY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -716,17 +716,20 @@ static int lpc17_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send this packet. In this context, we know that there is space for
|
||||
* at least one more packet in the descriptor list.
|
||||
*/
|
||||
if (!devif_loopback_out(&priv->lp_dev))
|
||||
{
|
||||
/* Send this packet. In this context, we know that there is space for
|
||||
* at least one more packet in the descriptor list.
|
||||
*/
|
||||
|
||||
lpc17_transmit(priv);
|
||||
lpc17_transmit(priv);
|
||||
|
||||
/* Check if there is room in the device to hold another packet. If not,
|
||||
* return any non-zero value to terminate the poll.
|
||||
*/
|
||||
/* Check if there is room in the device to hold another packet. If not,
|
||||
* return any non-zero value to terminate the poll.
|
||||
*/
|
||||
|
||||
ret = lpc17_txdesc(priv);
|
||||
ret = lpc17_txdesc(priv);
|
||||
}
|
||||
}
|
||||
|
||||
/* If zero is returned, the polling will continue until all connections have
|
||||
|
|
|
@ -1165,44 +1165,47 @@ static int lpc43_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
lpc43_transmit(priv);
|
||||
DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL);
|
||||
|
||||
/* Check if the next TX descriptor is owned by the Ethernet DMA or CPU. We
|
||||
* cannot perform the TX poll if we are unable to accept another packet for
|
||||
* transmission.
|
||||
*
|
||||
* In a race condition, ETH_TDES0_OWN may be cleared BUT still not available
|
||||
* because lpc43_freeframe() has not yet run. If lpc43_freeframe() has run,
|
||||
* the buffer1 pointer (tdes2) will be nullified (and inflight should be <
|
||||
* CONFIG_LPC43_ETH_NTXDESC).
|
||||
*/
|
||||
|
||||
if ((priv->txhead->tdes0 & ETH_TDES0_OWN) != 0 ||
|
||||
priv->txhead->tdes2 != 0)
|
||||
if (!devif_loopback_out(&priv->dev))
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
/* Send the packet */
|
||||
|
||||
lpc43_transmit(priv);
|
||||
DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL);
|
||||
|
||||
/* Check if the next TX descriptor is owned by the Ethernet DMA or CPU. We
|
||||
* cannot perform the TX poll if we are unable to accept another packet for
|
||||
* transmission.
|
||||
*
|
||||
* In a race condition, ETH_TDES0_OWN may be cleared BUT still not available
|
||||
* because lpc43_freeframe() has not yet run. If lpc43_freeframe() has run,
|
||||
* the buffer1 pointer (tdes2) will be nullified (and inflight should be <
|
||||
* CONFIG_LPC43_ETH_NTXDESC).
|
||||
*/
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
if ((priv->txhead->tdes0 & ETH_TDES0_OWN) != 0 ||
|
||||
priv->txhead->tdes2 != 0)
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
*/
|
||||
|
||||
/* We have the descriptor, we can continue the poll. Allocate a new
|
||||
* buffer for the poll.
|
||||
*/
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
dev->d_buf = lpc43_allocbuffer(priv);
|
||||
/* We have the descriptor, we can continue the poll. Allocate a new
|
||||
* buffer for the poll.
|
||||
*/
|
||||
|
||||
/* We can't continue the poll if we have no buffers */
|
||||
dev->d_buf = lpc43_allocbuffer(priv);
|
||||
|
||||
if (dev->d_buf == NULL)
|
||||
{
|
||||
/* Terminate the poll. */
|
||||
/* We can't continue the poll if we have no buffers */
|
||||
|
||||
return -ENOMEM;
|
||||
if (dev->d_buf == NULL)
|
||||
{
|
||||
/* Terminate the poll. */
|
||||
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -790,49 +790,52 @@ static int lpc54_eth_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
chan = lpc54_eth_getring(priv);
|
||||
txring = &priv->eth_txring[chan];
|
||||
|
||||
(txring->tr_buffers)[txring->tr_supply] =
|
||||
(uint32_t *)priv->eth_dev.d_buf;
|
||||
|
||||
lpc54_eth_transmit(priv, chan);
|
||||
|
||||
txring0 = &priv->eth_txring[0];
|
||||
#ifdef CONFIG_LPC54_ETH_MULTIQUEUE
|
||||
txring1 = &priv->eth_txring[1];
|
||||
|
||||
/* We cannot perform the Tx poll now if all of the Tx descriptors for
|
||||
* both channels are in-use.
|
||||
*/
|
||||
|
||||
if (txring0->tr_inuse >= txring0->tr_ndesc ||
|
||||
txring1->tr_inuse >= txring1->tr_ndesc)
|
||||
#else
|
||||
/* We cannot continue the Tx poll now if all of the Tx descriptors for
|
||||
* this channel 0 are in-use.
|
||||
*/
|
||||
|
||||
if (txring0->tr_inuse >= txring0->tr_ndesc)
|
||||
#endif
|
||||
if (!devif_loopback_out(&priv->eth_dev))
|
||||
{
|
||||
/* Stop the poll.. no more Tx descriptors */
|
||||
/* Send the packet */
|
||||
|
||||
return 1;
|
||||
}
|
||||
chan = lpc54_eth_getring(priv);
|
||||
txring = &priv->eth_txring[chan];
|
||||
|
||||
/* There is a free descriptor in the ring, allocate a new Tx buffer
|
||||
* to perform the poll.
|
||||
*/
|
||||
(txring->tr_buffers)[txring->tr_supply] =
|
||||
(uint32_t *)priv->eth_dev.d_buf;
|
||||
|
||||
priv->eth_dev.d_buf = (uint8_t *)lpc54_pktbuf_alloc(priv);
|
||||
if (priv->eth_dev.d_buf == NULL)
|
||||
{
|
||||
/* Stop the poll.. no more packet buffers */
|
||||
lpc54_eth_transmit(priv, chan);
|
||||
|
||||
return 1;
|
||||
txring0 = &priv->eth_txring[0];
|
||||
#ifdef CONFIG_LPC54_ETH_MULTIQUEUE
|
||||
txring1 = &priv->eth_txring[1];
|
||||
|
||||
/* We cannot perform the Tx poll now if all of the Tx descriptors for
|
||||
* both channels are in-use.
|
||||
*/
|
||||
|
||||
if (txring0->tr_inuse >= txring0->tr_ndesc ||
|
||||
txring1->tr_inuse >= txring1->tr_ndesc)
|
||||
#else
|
||||
/* We cannot continue the Tx poll now if all of the Tx descriptors for
|
||||
* this channel 0 are in-use.
|
||||
*/
|
||||
|
||||
if (txring0->tr_inuse >= txring0->tr_ndesc)
|
||||
#endif
|
||||
{
|
||||
/* Stop the poll.. no more Tx descriptors */
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* There is a free descriptor in the ring, allocate a new Tx buffer
|
||||
* to perform the poll.
|
||||
*/
|
||||
|
||||
priv->eth_dev.d_buf = (uint8_t *)lpc54_pktbuf_alloc(priv);
|
||||
if (priv->eth_dev.d_buf == NULL)
|
||||
{
|
||||
/* Stop the poll.. no more packet buffers */
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -889,21 +889,24 @@ static int sam_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
sam_transmit(priv);
|
||||
|
||||
/* Check if there are any free TX descriptors. We cannot perform
|
||||
* the TX poll if we do not have buffering for another packet.
|
||||
*/
|
||||
|
||||
if (sam_txfree(priv) == 0)
|
||||
if (!devif_loopback_out(&priv->dev))
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
/* Send the packet */
|
||||
|
||||
sam_transmit(priv);
|
||||
|
||||
/* Check if there are any free TX descriptors. We cannot perform
|
||||
* the TX poll if we do not have buffering for another packet.
|
||||
*/
|
||||
|
||||
return -EBUSY;
|
||||
if (sam_txfree(priv) == 0)
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
*/
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -898,21 +898,24 @@ static int sam_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
sam_transmit(priv);
|
||||
|
||||
/* Check if there are any free TX descriptors. We cannot perform
|
||||
* the TX poll if we do not have buffering for another packet.
|
||||
*/
|
||||
|
||||
if (sam_txfree(priv) == 0)
|
||||
if (!devif_loopback_out(&priv->dev))
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
/* Send the packet */
|
||||
|
||||
sam_transmit(priv);
|
||||
|
||||
/* Check if there are any free TX descriptors. We cannot perform
|
||||
* the TX poll if we do not have buffering for another packet.
|
||||
*/
|
||||
|
||||
return -EBUSY;
|
||||
if (sam_txfree(priv) == 0)
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
*/
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1233,21 +1233,24 @@ static int sam_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
sam_transmit(priv);
|
||||
|
||||
/* Check if there are any free TX descriptors. We cannot perform
|
||||
* the TX poll if we do not have buffering for another packet.
|
||||
*/
|
||||
|
||||
if (sam_txfree(priv) == 0)
|
||||
if (!devif_loopback_out(&priv->dev))
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
/* Send the packet */
|
||||
|
||||
sam_transmit(priv);
|
||||
|
||||
/* Check if there are any free TX descriptors. We cannot perform
|
||||
* the TX poll if we do not have buffering for another packet.
|
||||
*/
|
||||
|
||||
return -EBUSY;
|
||||
if (sam_txfree(priv) == 0)
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
*/
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -830,21 +830,24 @@ static int sam_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
sam_transmit(priv);
|
||||
|
||||
/* Check if there are any free TX descriptors. We cannot perform
|
||||
* the TX poll if we do not have buffering for another packet.
|
||||
*/
|
||||
|
||||
if (sam_txfree(priv) == 0)
|
||||
if (!devif_loopback_out(&priv->dev))
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
/* Send the packet */
|
||||
|
||||
sam_transmit(priv);
|
||||
|
||||
/* Check if there are any free TX descriptors. We cannot perform
|
||||
* the TX poll if we do not have buffering for another packet.
|
||||
*/
|
||||
|
||||
return -EBUSY;
|
||||
if (sam_txfree(priv) == 0)
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
*/
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1547,21 +1547,24 @@ static int sam_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
sam_transmit(priv, EMAC_QUEUE_0);
|
||||
|
||||
/* Check if there are any free TX descriptors. We cannot perform
|
||||
* the TX poll if we do not have buffering for another packet.
|
||||
*/
|
||||
|
||||
if (sam_txfree(priv, EMAC_QUEUE_0) == 0)
|
||||
if (!devif_loopback_out(&priv->dev))
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
/* Send the packet */
|
||||
|
||||
sam_transmit(priv, EMAC_QUEUE_0);
|
||||
|
||||
/* Check if there are any free TX descriptors. We cannot perform
|
||||
* the TX poll if we do not have buffering for another packet.
|
||||
*/
|
||||
|
||||
return -EBUSY;
|
||||
if (sam_txfree(priv, EMAC_QUEUE_0) == 0)
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
*/
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1271,44 +1271,47 @@ static int stm32_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
stm32_transmit(priv);
|
||||
DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL);
|
||||
|
||||
/* Check if the next TX descriptor is owned by the Ethernet DMA or CPU. We
|
||||
* cannot perform the TX poll if we are unable to accept another packet for
|
||||
* transmission.
|
||||
*
|
||||
* In a race condition, ETH_TDES0_OWN may be cleared BUT still not available
|
||||
* because stm32_freeframe() has not yet run. If stm32_freeframe() has run,
|
||||
* the buffer1 pointer (tdes2) will be nullified (and inflight should be <
|
||||
* CONFIG_STM32_ETH_NTXDESC).
|
||||
*/
|
||||
|
||||
if ((priv->txhead->tdes0 & ETH_TDES0_OWN) != 0 ||
|
||||
priv->txhead->tdes2 != 0)
|
||||
if (!devif_loopback_out(&priv->dev))
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
/* Send the packet */
|
||||
|
||||
stm32_transmit(priv);
|
||||
DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL);
|
||||
|
||||
/* Check if the next TX descriptor is owned by the Ethernet DMA or CPU. We
|
||||
* cannot perform the TX poll if we are unable to accept another packet for
|
||||
* transmission.
|
||||
*
|
||||
* In a race condition, ETH_TDES0_OWN may be cleared BUT still not available
|
||||
* because stm32_freeframe() has not yet run. If stm32_freeframe() has run,
|
||||
* the buffer1 pointer (tdes2) will be nullified (and inflight should be <
|
||||
* CONFIG_STM32_ETH_NTXDESC).
|
||||
*/
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
if ((priv->txhead->tdes0 & ETH_TDES0_OWN) != 0 ||
|
||||
priv->txhead->tdes2 != 0)
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
*/
|
||||
|
||||
/* We have the descriptor, we can continue the poll. Allocate a new
|
||||
* buffer for the poll.
|
||||
*/
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
dev->d_buf = stm32_allocbuffer(priv);
|
||||
/* We have the descriptor, we can continue the poll. Allocate a new
|
||||
* buffer for the poll.
|
||||
*/
|
||||
|
||||
/* We can't continue the poll if we have no buffers */
|
||||
dev->d_buf = stm32_allocbuffer(priv);
|
||||
|
||||
if (dev->d_buf == NULL)
|
||||
{
|
||||
/* Terminate the poll. */
|
||||
/* We can't continue the poll if we have no buffers */
|
||||
|
||||
return -ENOMEM;
|
||||
if (dev->d_buf == NULL)
|
||||
{
|
||||
/* Terminate the poll. */
|
||||
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1305,44 +1305,47 @@ static int stm32_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
stm32_transmit(priv);
|
||||
DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL);
|
||||
|
||||
/* Check if the next TX descriptor is owned by the Ethernet DMA or CPU. We
|
||||
* cannot perform the TX poll if we are unable to accept another packet for
|
||||
* transmission.
|
||||
*
|
||||
* In a race condition, ETH_TDES0_OWN may be cleared BUT still not available
|
||||
* because stm32_freeframe() has not yet run. If stm32_freeframe() has run,
|
||||
* the buffer1 pointer (tdes2) will be nullified (and inflight should be <
|
||||
* CONFIG_STM32F7_ETH_NTXDESC).
|
||||
*/
|
||||
|
||||
if ((priv->txhead->tdes0 & ETH_TDES0_OWN) != 0 ||
|
||||
priv->txhead->tdes2 != 0)
|
||||
if (!devif_loopback_out(&priv->dev))
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
/* Send the packet */
|
||||
|
||||
stm32_transmit(priv);
|
||||
DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL);
|
||||
|
||||
/* Check if the next TX descriptor is owned by the Ethernet DMA or CPU. We
|
||||
* cannot perform the TX poll if we are unable to accept another packet for
|
||||
* transmission.
|
||||
*
|
||||
* In a race condition, ETH_TDES0_OWN may be cleared BUT still not available
|
||||
* because stm32_freeframe() has not yet run. If stm32_freeframe() has run,
|
||||
* the buffer1 pointer (tdes2) will be nullified (and inflight should be <
|
||||
* CONFIG_STM32F7_ETH_NTXDESC).
|
||||
*/
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
if ((priv->txhead->tdes0 & ETH_TDES0_OWN) != 0 ||
|
||||
priv->txhead->tdes2 != 0)
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
*/
|
||||
|
||||
/* We have the descriptor, we can continue the poll. Allocate a new
|
||||
* buffer for the poll.
|
||||
*/
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
dev->d_buf = stm32_allocbuffer(priv);
|
||||
/* We have the descriptor, we can continue the poll. Allocate a new
|
||||
* buffer for the poll.
|
||||
*/
|
||||
|
||||
/* We can't continue the poll if we have no buffers */
|
||||
dev->d_buf = stm32_allocbuffer(priv);
|
||||
|
||||
if (dev->d_buf == NULL)
|
||||
{
|
||||
/* Terminate the poll. */
|
||||
/* We can't continue the poll if we have no buffers */
|
||||
|
||||
return -ENOMEM;
|
||||
if (dev->d_buf == NULL)
|
||||
{
|
||||
/* Terminate the poll. */
|
||||
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -644,11 +644,14 @@ static int tiva_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet. tiva_transmit() will return zero if the
|
||||
* packet was successfully handled.
|
||||
*/
|
||||
if (!devif_loopback_out(&priv->ld_dev))
|
||||
{
|
||||
/* Send the packet. tiva_transmit() will return zero if the
|
||||
* packet was successfully handled.
|
||||
*/
|
||||
|
||||
ret = tiva_transmit(priv);
|
||||
ret = tiva_transmit(priv);
|
||||
}
|
||||
}
|
||||
|
||||
/* If zero is returned, the polling will continue until all connections have
|
||||
|
|
|
@ -1273,44 +1273,47 @@ static int tiva_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
tiva_transmit(priv);
|
||||
DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL);
|
||||
|
||||
/* Check if the next TX descriptor is owned by the Ethernet DMA or CPU. We
|
||||
* cannot perform the TX poll if we are unable to accept another packet for
|
||||
* transmission.
|
||||
*
|
||||
* In a race condition, EMAC_TDES0_OWN may be cleared BUT still not available
|
||||
* because tiva_freeframe() has not yet run. If tiva_freeframe() has run,
|
||||
* the buffer1 pointer (tdes2) will be nullified (and inflight should be <
|
||||
* CONFIG_TIVA_EMAC_NTXDESC).
|
||||
*/
|
||||
|
||||
if ((priv->txhead->tdes0 & EMAC_TDES0_OWN) != 0 ||
|
||||
priv->txhead->tdes2 != 0)
|
||||
if (!devif_loopback_out(&priv->dev))
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
/* Send the packet */
|
||||
|
||||
tiva_transmit(priv);
|
||||
DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL);
|
||||
|
||||
/* Check if the next TX descriptor is owned by the Ethernet DMA or CPU. We
|
||||
* cannot perform the TX poll if we are unable to accept another packet for
|
||||
* transmission.
|
||||
*
|
||||
* In a race condition, EMAC_TDES0_OWN may be cleared BUT still not available
|
||||
* because tiva_freeframe() has not yet run. If tiva_freeframe() has run,
|
||||
* the buffer1 pointer (tdes2) will be nullified (and inflight should be <
|
||||
* CONFIG_TIVA_EMAC_NTXDESC).
|
||||
*/
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
if ((priv->txhead->tdes0 & EMAC_TDES0_OWN) != 0 ||
|
||||
priv->txhead->tdes2 != 0)
|
||||
{
|
||||
/* We have to terminate the poll if we have no more descriptors
|
||||
* available for another transfer.
|
||||
*/
|
||||
|
||||
/* We have the descriptor, we can continue the poll. Allocate a new
|
||||
* buffer for the poll.
|
||||
*/
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
dev->d_buf = tiva_allocbuffer(priv);
|
||||
/* We have the descriptor, we can continue the poll. Allocate a new
|
||||
* buffer for the poll.
|
||||
*/
|
||||
|
||||
/* We can't continue the poll if we have no buffers */
|
||||
dev->d_buf = tiva_allocbuffer(priv);
|
||||
|
||||
if (dev->d_buf == NULL)
|
||||
{
|
||||
/* Terminate the poll. */
|
||||
/* We can't continue the poll if we have no buffers */
|
||||
|
||||
return -ENOMEM;
|
||||
if (dev->d_buf == NULL)
|
||||
{
|
||||
/* Terminate the poll. */
|
||||
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -244,13 +244,16 @@ static int emac_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
if (!devif_loopback_out(&priv->d_dev))
|
||||
{
|
||||
/* Send the packet */
|
||||
|
||||
emac_transmit(priv);
|
||||
emac_transmit(priv);
|
||||
|
||||
/* Check if there is room in the device to hold another packet. If not,
|
||||
* return a non-zero value to terminate the poll.
|
||||
*/
|
||||
/* Check if there is room in the device to hold another packet. If not,
|
||||
* return a non-zero value to terminate the poll.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
/* If zero is returned, the polling will continue until all connections have
|
||||
|
|
|
@ -1149,31 +1149,34 @@ static int pic32mx_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send this packet. In this context, we know that there is space for
|
||||
* at least one more packet in the descriptor list.
|
||||
*/
|
||||
|
||||
pic32mx_transmit(priv);
|
||||
|
||||
/* Check if the next TX descriptor is available. If not, return a
|
||||
* non-zero value to terminate the poll.
|
||||
*/
|
||||
|
||||
if (pic32mx_txdesc(priv) == NULL)
|
||||
if (!devif_loopback_out(&priv->pd_dev))
|
||||
{
|
||||
/* There are no more TX descriptors/buffers available.. stop the poll */
|
||||
/* Send this packet. In this context, we know that there is space for
|
||||
* at least one more packet in the descriptor list.
|
||||
*/
|
||||
|
||||
return -EAGAIN;
|
||||
}
|
||||
pic32mx_transmit(priv);
|
||||
|
||||
/* Get the next Tx buffer needed in order to continue the poll */
|
||||
/* Check if the next TX descriptor is available. If not, return a
|
||||
* non-zero value to terminate the poll.
|
||||
*/
|
||||
|
||||
priv->pd_dev.d_buf = pic32mx_allocbuffer(priv);
|
||||
if (priv->pd_dev.d_buf == NULL)
|
||||
{
|
||||
/* We have no more buffers available for the nex Tx.. stop the poll */
|
||||
if (pic32mx_txdesc(priv) == NULL)
|
||||
{
|
||||
/* There are no more TX descriptors/buffers available.. stop the poll */
|
||||
|
||||
return -ENOMEM;
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
/* Get the next Tx buffer needed in order to continue the poll */
|
||||
|
||||
priv->pd_dev.d_buf = pic32mx_allocbuffer(priv);
|
||||
if (priv->pd_dev.d_buf == NULL)
|
||||
{
|
||||
/* We have no more buffers available for the nex Tx.. stop the poll */
|
||||
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1176,31 +1176,34 @@ static int pic32mz_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send this packet. In this context, we know that there is space for
|
||||
* at least one more packet in the descriptor list.
|
||||
*/
|
||||
|
||||
pic32mz_transmit(priv);
|
||||
|
||||
/* Check if the next TX descriptor is available. If not, return a
|
||||
* non-zero value to terminate the poll.
|
||||
*/
|
||||
|
||||
if (pic32mz_txdesc(priv) == NULL)
|
||||
if (!devif_loopback_out(&priv->pd_dev))
|
||||
{
|
||||
/* There are no more TX descriptors/buffers available.. stop the poll */
|
||||
/* Send this packet. In this context, we know that there is space for
|
||||
* at least one more packet in the descriptor list.
|
||||
*/
|
||||
|
||||
return -EAGAIN;
|
||||
}
|
||||
pic32mz_transmit(priv);
|
||||
|
||||
/* Get the next Tx buffer needed in order to continue the poll */
|
||||
/* Check if the next TX descriptor is available. If not, return a
|
||||
* non-zero value to terminate the poll.
|
||||
*/
|
||||
|
||||
priv->pd_dev.d_buf = pic32mz_allocbuffer(priv);
|
||||
if (priv->pd_dev.d_buf == NULL)
|
||||
{
|
||||
/* We have no more buffers available for the nex Tx.. stop the poll */
|
||||
if (pic32mz_txdesc(priv) == NULL)
|
||||
{
|
||||
/* There are no more TX descriptors/buffers available.. stop the poll */
|
||||
|
||||
return -ENOMEM;
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
/* Get the next Tx buffer needed in order to continue the poll */
|
||||
|
||||
priv->pd_dev.d_buf = pic32mz_allocbuffer(priv);
|
||||
if (priv->pd_dev.d_buf == NULL)
|
||||
{
|
||||
/* We have no more buffers available for the nex Tx.. stop the poll */
|
||||
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -334,13 +334,16 @@ static int misoc_net_txpoll(FAR struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
if (!devif_loopback_out(&priv->misoc_net_dev))
|
||||
{
|
||||
/* Send the packet */
|
||||
|
||||
misoc_net_transmit(priv);
|
||||
misoc_net_transmit(priv);
|
||||
|
||||
/* Check if there is room in the device to hold another packet. If not,
|
||||
* return a non-zero value to terminate the poll.
|
||||
*/
|
||||
/* Check if there is room in the device to hold another packet. If not,
|
||||
* return a non-zero value to terminate the poll.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
/* If zero is returned, the polling will continue until all connections have
|
||||
|
|
|
@ -151,9 +151,12 @@ static int sim_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
if (!devif_loopback_out(&g_sim_dev))
|
||||
{
|
||||
/* Send the packet */
|
||||
|
||||
netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len);
|
||||
netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len);
|
||||
}
|
||||
}
|
||||
|
||||
/* If zero is returned, the polling will continue until all connections have
|
||||
|
|
|
@ -1147,11 +1147,14 @@ static int ez80emac_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet. ez80emac_transmit() will return zero if the
|
||||
* packet was successfully handled.
|
||||
*/
|
||||
if (!devif_loopback_out(&priv->dev))
|
||||
{
|
||||
/* Send the packet. ez80emac_transmit() will return zero if the
|
||||
* packet was successfully handled.
|
||||
*/
|
||||
|
||||
ret = ez80emac_transmit(priv);
|
||||
ret = ez80emac_transmit(priv);
|
||||
}
|
||||
}
|
||||
|
||||
/* If zero is returned, the polling will continue until all connections have
|
||||
|
|
|
@ -819,19 +819,22 @@ static int dm9x_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
dm9x_transmit(priv);
|
||||
|
||||
/* Check if there is room in the DM90x0 to hold another packet. In 100M mode,
|
||||
* that can be 2 packets, otherwise it is a single packet.
|
||||
*/
|
||||
|
||||
if (priv->dm_ntxpending > 1 || !priv->dm_b100M)
|
||||
if (!devif_loopback_out(&priv->dm_dev))
|
||||
{
|
||||
/* Returning a non-zero value will terminate the poll operation */
|
||||
/* Send the packet */
|
||||
|
||||
return 1;
|
||||
dm9x_transmit(priv);
|
||||
|
||||
/* Check if there is room in the DM90x0 to hold another packet. In 100M mode,
|
||||
* that can be 2 packets, otherwise it is a single packet.
|
||||
*/
|
||||
|
||||
if (priv->dm_ntxpending > 1 || !priv->dm_b100M)
|
||||
{
|
||||
/* Returning a non-zero value will terminate the poll operation */
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1213,13 +1213,16 @@ static int enc_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
if (!devif_loopback_out(&priv->dev))
|
||||
{
|
||||
/* Send the packet */
|
||||
|
||||
enc_transmit(priv);
|
||||
enc_transmit(priv);
|
||||
|
||||
/* Stop the poll now because we can queue only one packet */
|
||||
/* Stop the poll now because we can queue only one packet */
|
||||
|
||||
return -EBUSY;
|
||||
return -EBUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/* If zero is returned, the polling will continue until all connections have
|
||||
|
|
|
@ -1194,9 +1194,12 @@ static int enc_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
if (!devif_loopback_out(&priv->dev))
|
||||
{
|
||||
/* Send the packet */
|
||||
|
||||
ret = enc_txenqueue(priv);
|
||||
ret = enc_txenqueue(priv);
|
||||
}
|
||||
}
|
||||
|
||||
/* If zero is returned, the polling will continue until all connections have
|
||||
|
|
|
@ -388,13 +388,16 @@ static int ftmac100_txpoll(struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
if (!devif_loopback_out(&priv->ft_dev))
|
||||
{
|
||||
/* Send the packet */
|
||||
|
||||
ftmac100_transmit(priv);
|
||||
ftmac100_transmit(priv);
|
||||
|
||||
/* Check if there is room in the device to hold another packet. If not,
|
||||
* return a non-zero value to terminate the poll.
|
||||
*/
|
||||
/* Check if there is room in the device to hold another packet. If not,
|
||||
* return a non-zero value to terminate the poll.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
/* If zero is returned, the polling will continue until all connections have
|
||||
|
|
|
@ -299,13 +299,21 @@ static int skel_txpoll(FAR struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
skel_transmit(priv);
|
||||
|
||||
/* Check if there is room in the device to hold another packet. If not,
|
||||
* return a non-zero value to terminate the poll.
|
||||
/* Check if the network is sending this packet to the IP address of
|
||||
* this device. If so, just loop the packet back into the network but
|
||||
* don't attmpt to put it on the wire.
|
||||
*/
|
||||
|
||||
if (!devif_loopback_out(&priv->sk_dev))
|
||||
{
|
||||
/* Send the packet */
|
||||
|
||||
skel_transmit(priv);
|
||||
|
||||
/* Check if there is room in the device to hold another packet. If not,
|
||||
* return a non-zero value to terminate the poll.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
/* If zero is returned, the polling will continue until all connections have
|
||||
|
|
|
@ -405,7 +405,10 @@ static int slip_txpoll(FAR struct net_driver_s *dev)
|
|||
|
||||
if (priv->dev.d_len > 0)
|
||||
{
|
||||
slip_transmit(priv);
|
||||
if (!devif_loopback_out(&priv->dev))
|
||||
{
|
||||
slip_transmit(priv);
|
||||
}
|
||||
}
|
||||
|
||||
/* If zero is returned, the polling will continue until all connections have
|
||||
|
|
|
@ -400,15 +400,18 @@ static int cdcecm_txpoll(FAR struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
if (!devif_loopback_out(&priv->dev))
|
||||
{
|
||||
/* Send the packet */
|
||||
|
||||
cdcecm_transmit(priv);
|
||||
cdcecm_transmit(priv);
|
||||
|
||||
/* Check if there is room in the device to hold another packet. If
|
||||
* not, return a non-zero value to terminate the poll.
|
||||
*/
|
||||
/* Check if there is room in the device to hold another packet. If
|
||||
* not, return a non-zero value to terminate the poll.
|
||||
*/
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* If zero is returned, the polling will continue until all connections
|
||||
|
|
|
@ -994,8 +994,10 @@ static int rndis_txpoll(FAR struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
ret = rndis_transmit(priv);
|
||||
|
||||
if (!devif_loopback_out(&priv->netdev))
|
||||
{
|
||||
ret = rndis_transmit(priv);
|
||||
}
|
||||
}
|
||||
|
||||
/* If zero is returned, the polling will continue until all connections have
|
||||
|
|
|
@ -473,16 +473,19 @@ static int bcmf_txpoll(FAR struct net_driver_s *dev)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* Send the packet */
|
||||
if (!devif_loopback_out(&priv->bc_dev))
|
||||
{
|
||||
/* Send the packet */
|
||||
|
||||
bcmf_transmit(priv, priv->cur_tx_frame);
|
||||
bcmf_transmit(priv, priv->cur_tx_frame);
|
||||
|
||||
/* TODO: Check if there is room in the device to hold another packet.
|
||||
* If not, return a non-zero value to terminate the poll.
|
||||
*/
|
||||
/* TODO: Check if there is room in the device to hold another packet.
|
||||
* If not, return a non-zero value to terminate the poll.
|
||||
*/
|
||||
|
||||
priv->cur_tx_frame = NULL;
|
||||
return 1;
|
||||
priv->cur_tx_frame = NULL;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* If zero is returned, the polling will continue until all connections have
|
||||
|
|
|
@ -568,6 +568,23 @@ int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback);
|
|||
void neighbor_out(FAR struct net_driver_s *dev);
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: devif_loopback_out
|
||||
*
|
||||
* Description:
|
||||
* This function should be called before sending out a packet. The function
|
||||
* checks the destination address of the packet to see whether the target of
|
||||
* packet is ourself and then consume the packet directly by calling input
|
||||
* process functions.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned if the packet don't loop back to ourself, otherwise
|
||||
* a no zero value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int devif_loopback_out(FAR struct net_driver_s *dev);
|
||||
|
||||
/****************************************************************************
|
||||
* Carrier detection
|
||||
*
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
# Network device interface source files
|
||||
|
||||
NET_CSRCS += devif_initialize.c devif_send.c devif_poll.c devif_callback.c
|
||||
NET_CSRCS += devif_loopbackout.c
|
||||
|
||||
# Device driver IP packet receipt interfaces
|
||||
|
||||
|
|
161
net/devif/devif_loopbackout.c
Normal file
161
net/devif/devif_loopbackout.c
Normal file
|
@ -0,0 +1,161 @@
|
|||
/****************************************************************************
|
||||
* net/devif/devif_loopbackout.c
|
||||
*
|
||||
* Copyright (C) 2018 Pinecone Inc. All rights reserved.
|
||||
* Author: Xiang Xiao <xiaoxiang@pinecone.net>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/net/ip.h>
|
||||
#include <nuttx/net/pkt.h>
|
||||
#include <nuttx/net/netdev.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* This is a helper pointer for accessing the contents of the ip header */
|
||||
|
||||
#define IPv4BUF ((FAR struct ipv4_hdr_s *)(dev->d_buf + dev->d_llhdrlen))
|
||||
#define IPv6BUF ((FAR struct ipv6_hdr_s *)(dev->d_buf + dev->d_llhdrlen))
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static bool is_loopback(FAR struct net_driver_s *dev)
|
||||
{
|
||||
if (dev->d_len > 0)
|
||||
{
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
if ((IPv4BUF->vhl & IP_VERSION_MASK) == IPv4_VERSION &&
|
||||
net_ipv4addr_hdrcmp(IPv4BUF->destipaddr, &dev->d_ipaddr))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
if ((IPv6BUF->vtc & IP_VERSION_MASK) == IPv6_VERSION &&
|
||||
net_ipv6addr_hdrcmp(IPv6BUF->destipaddr, dev->d_ipv6addr))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: devif_loopback_out
|
||||
*
|
||||
* Description:
|
||||
* This function should be called before sending out a packet. The function
|
||||
* checks the destination address of the packet to see whether the target of
|
||||
* packet is ourself and then consume the packet directly by calling input
|
||||
* process functions.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned if the packet don't loop back to ourself, otherwise
|
||||
* a no zero value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int devif_loopback_out(FAR struct net_driver_s *dev)
|
||||
{
|
||||
if (!is_loopback(dev))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Loop while if there is data "sent" to ourself.
|
||||
* Sending, of course, just means relaying back through the network.
|
||||
*/
|
||||
|
||||
do
|
||||
{
|
||||
NETDEV_TXPACKETS(dev);
|
||||
NETDEV_RXPACKETS(dev);
|
||||
|
||||
#ifdef CONFIG_NET_PKT
|
||||
/* When packet sockets are enabled, feed the frame into the packet tap */
|
||||
|
||||
pkt_input(dev);
|
||||
#endif
|
||||
|
||||
/* We only accept IP packets of the configured type */
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
if ((IPv4BUF->vhl & IP_VERSION_MASK) == IPv4_VERSION)
|
||||
{
|
||||
ninfo("IPv4 frame\n");
|
||||
|
||||
NETDEV_RXIPV4(dev);
|
||||
ipv4_input(dev);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
if ((IPv6BUF->vtc & IP_VERSION_MASK) == IPv6_VERSION)
|
||||
{
|
||||
ninfo("Iv6 frame\n");
|
||||
|
||||
NETDEV_RXIPV6(dev);
|
||||
ipv6_input(dev);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
NETDEV_RXDROPPED(dev);
|
||||
}
|
||||
|
||||
NETDEV_TXDONE(dev);
|
||||
|
||||
/* Add the data link header length for the next loop */
|
||||
|
||||
if (dev->d_len != 0)
|
||||
{
|
||||
dev->d_len += dev->d_llhdrlen;
|
||||
}
|
||||
}
|
||||
while (dev->d_len > 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in a new issue