net/netdev: Avoid hardcoded guardsize when using d_iob

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
Zhe Weng 2023-01-06 11:46:36 +08:00 committed by Xiang Xiao
parent 632ed0d3a4
commit 1cf3147626
15 changed files with 23 additions and 38 deletions

View File

@ -103,8 +103,7 @@ static void netdriver_send(struct net_driver_s *dev)
{
int devidx = (intptr_t)dev->d_private;
#ifdef SIM_NETDEV_IOB_OFFLOAD
uint8_t *buf = &dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE -
NET_LL_HDRLEN(dev)];
uint8_t *buf = NETLLBUF;
#else
uint8_t *buf = dev->d_buf;
#endif

View File

@ -161,8 +161,8 @@
* headers
*/
#define IPBUF(hl) ((FAR void *)\
&dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE + (hl)])
#define IPBUF(hl) ((FAR void *)(IOB_DATA(dev->d_iob) + (hl)))
#define NETLLBUF (IPBUF(0) - NET_LL_HDRLEN(dev))
#define IPv4BUF ((FAR struct ipv4_hdr_s *)IPBUF(0))
#define IPv6BUF ((FAR struct ipv6_hdr_s *)IPBUF(0))

View File

@ -84,10 +84,8 @@
/* This is a helper pointer for accessing the contents of the IP header */
#define ARPBUF ((FAR struct arp_hdr_s *)\
&dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE])
#define ARPIPBUF ((FAR struct arp_iphdr_s *)\
&dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE])
#define ARPBUF ((FAR struct arp_hdr_s *)IPBUF(0))
#define ARPIPBUF ((FAR struct arp_iphdr_s *)IPBUF(0))
/****************************************************************************
* Public Types

View File

@ -195,8 +195,7 @@ void arp_input(FAR struct net_driver_s *dev)
/* Set the device buffer to l2 */
dev->d_buf = &dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE -
NET_LL_HDRLEN(dev)];
dev->d_buf = NETLLBUF;
arp_in(dev);
dev->d_buf = buf;

View File

@ -228,8 +228,7 @@ int can_input(FAR struct net_driver_s *dev)
/* Set the device buffer to l2 */
dev->d_buf = &dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE -
NET_LL_HDRLEN(dev)];
dev->d_buf = NETLLBUF;
ret = can_in(dev);
dev->d_buf = buf;

View File

@ -237,9 +237,7 @@
* headers
*/
#define ETHBUF ((FAR struct eth_hdr_s *)\
&dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE - \
NET_LL_HDRLEN(dev)])
#define ETHBUF ((FAR struct eth_hdr_s *)NETLLBUF)
/****************************************************************************
* Public Type Definitions

View File

@ -109,8 +109,7 @@ void devif_iob_send(FAR struct net_driver_s *dev, FAR struct iob_s *iob,
dev->d_iob = iob;
dev->d_sndlen = len;
dev->d_buf = &iob->io_data[CONFIG_NET_LL_GUARDSIZE -
NET_LL_HDRLEN(dev)];
dev->d_buf = NETLLBUF;
}
#ifdef CONFIG_NET_TCP_WRBUFFER_DUMP

View File

@ -1009,8 +1009,7 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback)
/* Copy l2 header (arp out) */
memcpy(buf, dev->d_iob->io_data +
(CONFIG_NET_LL_GUARDSIZE - llhdrlen), llhdrlen);
memcpy(buf, IPBUF(-llhdrlen), llhdrlen);
/* Restore flat buffer pointer */

View File

@ -497,8 +497,7 @@ int ipv4_input(FAR struct net_driver_s *dev)
/* Set the device buffer to l2 */
dev->d_buf = &dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE -
NET_LL_HDRLEN(dev)];
dev->d_buf = NETLLBUF;
ret = ipv4_in(dev);
dev->d_buf = buf;

View File

@ -621,8 +621,7 @@ int ipv6_input(FAR struct net_driver_s *dev)
/* Set the device buffer to l2 */
dev->d_buf = &dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE -
NET_LL_HDRLEN(dev)];
dev->d_buf = NETLLBUF;
ret = ipv6_in(dev);
dev->d_buf = buf;

View File

@ -167,8 +167,7 @@ void ipfwd_dropstats(FAR struct forward_s *fwd)
if (fwd->f_domain == PF_INET)
#endif
{
ipv4_dropstats((FAR struct ipv4_hdr_s *)
&fwd->f_iob->io_data[CONFIG_NET_LL_GUARDSIZE]);
ipv4_dropstats((FAR struct ipv4_hdr_s *)IOB_DATA(fwd->f_iob));
}
#endif
#ifdef CONFIG_NET_IPv6
@ -176,8 +175,7 @@ void ipfwd_dropstats(FAR struct forward_s *fwd)
else
#endif
{
ipv6_dropstats((FAR struct ipv6_hdr_s *)
&fwd->f_iob->io_data[CONFIG_NET_LL_GUARDSIZE]);
ipv6_dropstats((FAR struct ipv6_hdr_s *)IOB_DATA(fwd->f_iob));
}
#endif
}

View File

@ -67,8 +67,8 @@ int netdev_input(FAR struct net_driver_s *dev,
devif_poll_callback_t callback, bool reply)
{
uint16_t llhdrlen = NET_LL_HDRLEN(dev);
unsigned int offset = CONFIG_NET_LL_GUARDSIZE - llhdrlen;
FAR uint8_t *buf = dev->d_buf;
unsigned int offset;
unsigned int l3l4len;
int ret;
@ -82,6 +82,7 @@ int netdev_input(FAR struct net_driver_s *dev,
/* Copy l2 header to gruard area */
offset = dev->d_iob->io_offset - llhdrlen;
memcpy(dev->d_iob->io_data + offset, buf, llhdrlen);
/* Copy l3/l4 data to iob entry */

View File

@ -73,15 +73,14 @@ int netdev_iob_prepare(FAR struct net_driver_s *dev, bool throttled,
return -ENOMEM;
}
/* Set the device buffer to l2 */
dev->d_buf = &dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE -
NET_LL_HDRLEN(dev)];
/* Update l2 gruard size */
iob_reserve(dev->d_iob, CONFIG_NET_LL_GUARDSIZE);
/* Set the device buffer to l2 */
dev->d_buf = NETLLBUF;
return OK;
}
@ -106,8 +105,7 @@ void netdev_iob_replace(FAR struct net_driver_s *dev, FAR struct iob_s *iob)
/* Set new buffer */
dev->d_iob = iob;
dev->d_buf = &dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE -
NET_LL_HDRLEN(dev)];
dev->d_buf = NETLLBUF;
dev->d_len = iob->io_pktlen;
}

View File

@ -146,8 +146,7 @@ int pkt_input(FAR struct net_driver_s *dev)
/* Set the device buffer to l2 */
dev->d_buf = &dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE -
NET_LL_HDRLEN(dev)];
dev->d_buf = NETLLBUF;
ret = pkt_in(dev);
dev->d_buf = buf;

View File

@ -63,7 +63,7 @@
#include "utils/utils.h"
#include "tcp/tcp.h"
#define IPDATA(hl) (dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE + (hl)])
#define IPDATA(hl) (*(FAR uint8_t *)IPBUF(hl))
/****************************************************************************
* Private Functions