drivers/net/tun.c: Fixes a problem reported by Masayuki Ishikwawa: Recently I noticed that ARP response packet is corrupted when I tried to run bluekitchen with the latest tun.c in TAP mode. If I revert commit 8193c28e91, then it works again.

This commit is contained in:
Xiang Xiao
2018-12-30 17:54:03 -06:00
committed by Gregory Nutt
parent c4dfb76b0d
commit fc9964f6b6
+53 -18
View File
@@ -619,6 +619,33 @@ static void tun_net_receive_tap(FAR struct tun_device_s *priv)
arp_ipin(&priv->dev); arp_ipin(&priv->dev);
ipv4_input(&priv->dev); ipv4_input(&priv->dev);
/* If the above function invocation resulted in data that should be
* sent out on the network, the field d_len will set to a value > 0.
*/
if (priv->dev.d_len > 0)
{
/* Update the Ethernet header with the correct MAC address */
#ifdef CONFIG_NET_IPv6
if (IFF_IS_IPv4(priv->dev.d_flags))
#endif
{
arp_out(&priv->dev);
}
#ifdef CONFIG_NET_IPv6
else
{
neighbor_out(&priv->dev);
}
#endif
/* And send the packet */
priv->write_d_len = priv->dev.d_len;
tun_fd_transmit(priv);
}
} }
else else
#endif #endif
@@ -631,21 +658,6 @@ static void tun_net_receive_tap(FAR struct tun_device_s *priv)
/* Give the IPv6 packet to the network layer. */ /* Give the IPv6 packet to the network layer. */
ipv6_input(&priv->dev); ipv6_input(&priv->dev);
}
else
#endif
#ifdef CONFIG_NET_ARP
if (BUF->type == htons(ETHTYPE_ARP))
{
arp_arpin(&priv->dev);
NETDEV_RXARP(&priv->dev);
}
else
#endif
{
NETDEV_RXDROPPED(&priv->dev);
priv->dev.d_len = 0;
}
/* If the above function invocation resulted in data that should be /* If the above function invocation resulted in data that should be
* sent out on the network, the field d_len will set to a value > 0. * sent out on the network, the field d_len will set to a value > 0.
@@ -660,19 +672,42 @@ static void tun_net_receive_tap(FAR struct tun_device_s *priv)
{ {
arp_out(&priv->dev); arp_out(&priv->dev);
} }
else
#endif #endif
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
if (IFF_IS_IPv6(priv->dev.d_flags))
{ {
neighbor_out(&priv->dev); neighbor_out(&priv->dev);
} }
#endif #endif
/* And send the packet */
priv->write_d_len = priv->dev.d_len; priv->write_d_len = priv->dev.d_len;
tun_fd_transmit(priv); tun_fd_transmit(priv);
} }
}
else
#endif
#ifdef CONFIG_NET_ARP
if (BUF->type == htons(ETHTYPE_ARP))
{
arp_arpin(&priv->dev);
NETDEV_RXARP(&priv->dev);
/* If the above function invocation resulted in data that should be
* sent out on the network, the field d_len will set to a value > 0.
*/
if (priv->dev.d_len > 0)
{
priv->write_d_len = priv->dev.d_len;
tun_fd_transmit(priv);
}
}
else
#endif
{
NETDEV_RXDROPPED(&priv->dev);
}
} }
#endif #endif