From 82d67b201ace06be75f1869df9544b2efcf1cf4f Mon Sep 17 00:00:00 2001 From: chao an Date: Sat, 3 Dec 2022 21:38:16 +0800 Subject: [PATCH] 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 --- net/arp/arp_arpin.c | 60 ++++++++++++++++++++++++++++++++++++++--- net/devif/devif_poll.c | 2 -- net/netdev/netdev_iob.c | 1 + net/pkt/pkt_input.c | 15 ++++++++++- net/udp/udp_recvfrom.c | 2 -- 5 files changed, 71 insertions(+), 9 deletions(-) diff --git a/net/arp/arp_arpin.c b/net/arp/arp_arpin.c index 02d341fba07..c7f3042a7b8 100644 --- a/net/arp/arp_arpin.c +++ b/net/arp/arp_arpin.c @@ -52,15 +52,16 @@ #include #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 */ diff --git a/net/devif/devif_poll.c b/net/devif/devif_poll.c index fef4e48bcf5..fed11e7ba25 100644 --- a/net/devif/devif_poll.c +++ b/net/devif/devif_poll.c @@ -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; } diff --git a/net/netdev/netdev_iob.c b/net/netdev/netdev_iob.c index 1ed32a0d2fb..0c5921a70ea 100644 --- a/net/netdev/netdev_iob.c +++ b/net/netdev/netdev_iob.c @@ -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; } } diff --git a/net/pkt/pkt_input.c b/net/pkt/pkt_input.c index f825360a6a2..c04e9a45616 100644 --- a/net/pkt/pkt_input.c +++ b/net/pkt/pkt_input.c @@ -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); diff --git a/net/udp/udp_recvfrom.c b/net/udp/udp_recvfrom.c index 972dc439400..e6d880d01d7 100644 --- a/net/udp/udp_recvfrom.c +++ b/net/udp/udp_recvfrom.c @@ -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; } }