mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 05:45:20 +08:00
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:
+56
-4
@@ -52,15 +52,16 @@
|
|||||||
#include <nuttx/net/arp.h>
|
#include <nuttx/net/arp.h>
|
||||||
|
|
||||||
#include "arp/arp.h"
|
#include "arp/arp.h"
|
||||||
|
#include "devif/devif.h"
|
||||||
|
|
||||||
#ifdef CONFIG_NET_ARP
|
#ifdef CONFIG_NET_ARP
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: arp_arpin
|
* Name: arp_input
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function should be called by the Ethernet device driver when an
|
* 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;
|
FAR struct arp_hdr_s *arp = ARPBUF;
|
||||||
in_addr_t ipaddr;
|
in_addr_t ipaddr;
|
||||||
@@ -92,7 +93,7 @@ void arp_arpin(FAR struct net_driver_s *dev)
|
|||||||
{
|
{
|
||||||
nerr("ERROR: Packet Too small\n");
|
nerr("ERROR: Packet Too small\n");
|
||||||
dev->d_len = 0;
|
dev->d_len = 0;
|
||||||
return;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev->d_len = 0;
|
dev->d_len = 0;
|
||||||
@@ -153,6 +154,57 @@ void arp_arpin(FAR struct net_driver_s *dev)
|
|||||||
}
|
}
|
||||||
break;
|
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 */
|
#endif /* CONFIG_NET_ARP */
|
||||||
|
|||||||
@@ -833,8 +833,6 @@ static int devif_iob_poll(FAR struct net_driver_s *dev,
|
|||||||
|
|
||||||
netdev_iob_release(dev);
|
netdev_iob_release(dev);
|
||||||
|
|
||||||
dev->d_buf = NULL;
|
|
||||||
|
|
||||||
return bstop;
|
return bstop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,5 +124,6 @@ void netdev_iob_release(FAR struct net_driver_s *dev)
|
|||||||
{
|
{
|
||||||
iob_free_chain(dev->d_iob);
|
iob_free_chain(dev->d_iob);
|
||||||
dev->d_iob = NULL;
|
dev->d_iob = NULL;
|
||||||
|
dev->d_buf = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-1
@@ -137,9 +137,22 @@ static int pkt_in(FAR struct net_driver_s *dev)
|
|||||||
|
|
||||||
int pkt_input(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)
|
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);
|
return netdev_input(dev, pkt_in, false);
|
||||||
|
|||||||
@@ -447,8 +447,6 @@ static uint16_t udp_eventhandler(FAR struct net_driver_s *dev,
|
|||||||
/* Indicate no data in the buffer */
|
/* Indicate no data in the buffer */
|
||||||
|
|
||||||
netdev_iob_release(dev);
|
netdev_iob_release(dev);
|
||||||
|
|
||||||
dev->d_buf = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user