Skip to content

Commit

Permalink
tun: fix the access address is incorrect
Browse files Browse the repository at this point in the history
correct eth_hdr address and reset d_iob to NULL after netdev_iob_prepare

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
  • Loading branch information
zhhyu7 authored and pkarashchenko committed Mar 15, 2023
1 parent af21bb4 commit 9a28cd2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions drivers/net/tun.c
Expand Up @@ -105,7 +105,7 @@
*/

#ifdef CONFIG_NET_ETHERNET
# define BUF ((FAR struct eth_hdr_s *)priv->dev.d_buf)
# define ETHBUF ((FAR struct eth_hdr_s *)NETLLBUF)
#endif

/****************************************************************************
Expand Down Expand Up @@ -452,6 +452,8 @@ static void tun_net_receive(FAR struct tun_device_s *priv)
#ifdef CONFIG_NET_ETHERNET
static void tun_net_receive_tap(FAR struct tun_device_s *priv)
{
FAR struct net_driver_s *dev = &priv->dev;

/* Copy the data data from the hardware to priv->dev.d_buf. Set amount of
* data in priv->dev.d_len
*/
Expand All @@ -467,7 +469,7 @@ static void tun_net_receive_tap(FAR struct tun_device_s *priv)
/* We only accept IP packets of the configured type and ARP packets */

#if defined(CONFIG_NET_IPv4)
if (BUF->type == HTONS(ETHTYPE_IP))
if (ETHBUF->type == HTONS(ETHTYPE_IP))
{
ninfo("IPv4 frame\n");
NETDEV_RXIPV4(&priv->dev);
Expand All @@ -479,7 +481,7 @@ static void tun_net_receive_tap(FAR struct tun_device_s *priv)
else
#endif
#ifdef CONFIG_NET_IPv6
if (BUF->type == HTONS(ETHTYPE_IP6))
if (ETHBUF->type == HTONS(ETHTYPE_IP6))
{
ninfo("IPv6 frame\n");
NETDEV_RXIPV6(&priv->dev);
Expand All @@ -491,7 +493,7 @@ static void tun_net_receive_tap(FAR struct tun_device_s *priv)
else
#endif
#ifdef CONFIG_NET_ARP
if (BUF->type == HTONS(ETHTYPE_ARP))
if (ETHBUF->type == HTONS(ETHTYPE_ARP))
{
arp_input(&priv->dev);
NETDEV_RXARP(&priv->dev);
Expand Down Expand Up @@ -986,6 +988,7 @@ static ssize_t tun_write(FAR struct file *filep, FAR const char *buffer,
{
net_lock();
ret = netdev_iob_prepare(&priv->dev, false, 0);
priv->dev.d_buf = NULL;
if (ret < 0)
{
nwritten = (nwritten == 0) ? ret : nwritten;
Expand Down

0 comments on commit 9a28cd2

Please sign in to comment.