net/offload: add offload support for pkt/arp

1. add offload support for pkt/arp
2. Reset the d_buf to NULL if d_iob has released

Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
chao an 2022-12-03 21:38:16 +08:00 committed by Xiang Xiao
parent 0dafa5f921
commit 82d67b201a
5 changed files with 71 additions and 9 deletions

View File

@ -52,15 +52,16 @@
#include <nuttx/net/arp.h>
#include "arp/arp.h"
#include "devif/devif.h"
#ifdef CONFIG_NET_ARP
/****************************************************************************
* Public Functions
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: arp_arpin
* Name: arp_input
*
* Description:
* This function should be called by the Ethernet device driver when an
@ -83,7 +84,7 @@
*
****************************************************************************/
void arp_arpin(FAR struct net_driver_s *dev)
static int arp_input(FAR struct net_driver_s *dev)
{
FAR struct arp_hdr_s *arp = ARPBUF;
in_addr_t ipaddr;
@ -92,7 +93,7 @@ void arp_arpin(FAR struct net_driver_s *dev)
{
nerr("ERROR: Packet Too small\n");
dev->d_len = 0;
return;
return -EINVAL;
}
dev->d_len = 0;
@ -153,6 +154,57 @@ void arp_arpin(FAR struct net_driver_s *dev)
}
break;
}
return OK;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: arp_arpin
*
* Description:
* This function should be called by the Ethernet device driver when an
* ARP packet has been received. The function will act differently
* depending on the ARP packet type: if it is a reply for a request
* that we previously sent out, the ARP cache will be filled in with
* the values from the ARP reply. If the incoming ARP packet is an ARP
* request for our IP address, an ARP reply packet is created and put
* into the d_buf buffer.
*
* On entry, this function expects that an ARP packet with a prepended
* Ethernet header is present in the d_buf buffer and that the length of
* the packet is set in the d_len field.
*
* When the function returns, the value of the field d_len indicates
* whether the device driver should send out the ARP reply packet or not.
* If d_len is zero, no packet should be sent; If d_len is non-zero, it
* contains the length of the outbound packet that is present in the
* d_buf buffer.
*
****************************************************************************/
void arp_arpin(FAR struct net_driver_s *dev)
{
FAR uint8_t *buf;
if (dev->d_iob != NULL)
{
buf = dev->d_buf;
/* Set the device buffer to l2 */
dev->d_buf = &dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE -
NET_LL_HDRLEN(dev)];
arp_input(dev);
dev->d_buf = buf;
return;
}
netdev_input(dev, arp_input, true);
}
#endif /* CONFIG_NET_ARP */

View File

@ -833,8 +833,6 @@ static int devif_iob_poll(FAR struct net_driver_s *dev,
netdev_iob_release(dev);
dev->d_buf = NULL;
return bstop;
}

View File

@ -124,5 +124,6 @@ void netdev_iob_release(FAR struct net_driver_s *dev)
{
iob_free_chain(dev->d_iob);
dev->d_iob = NULL;
dev->d_buf = NULL;
}
}

View File

@ -137,9 +137,22 @@ static int pkt_in(FAR struct net_driver_s *dev)
int pkt_input(FAR struct net_driver_s *dev)
{
FAR uint8_t *buf;
int ret;
if (dev->d_iob != NULL)
{
return pkt_in(dev);
buf = dev->d_buf;
/* Set the device buffer to l2 */
dev->d_buf = &dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE -
NET_LL_HDRLEN(dev)];
ret = pkt_in(dev);
dev->d_buf = buf;
return ret;
}
return netdev_input(dev, pkt_in, false);

View File

@ -447,8 +447,6 @@ static uint16_t udp_eventhandler(FAR struct net_driver_s *dev,
/* Indicate no data in the buffer */
netdev_iob_release(dev);
dev->d_buf = NULL;
}
}