diff --git a/drivers/net/tun.c b/drivers/net/tun.c index a8b76290c4..d14fb7ed28 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -429,52 +429,58 @@ static void tun_net_receive(FAR struct tun_device_s *priv) #if defined(CONFIG_NET_IPv4) ninfo("IPv4 frame\n"); NETDEV_RXIPV4(&priv->dev); -################################################################################# -@@ -429,20 +431,27 @@ static void tun_receive(FAR struct tun_device_s *priv) - /* Give the IPv4 packet to the network layer */ + /* Give the IPv4 packet to the network layer. ipv4_input will return + * an error if it is unable to dispatch the packet at this time. + */ - ret = ipv4_input(&priv->dev); + ret = ipv4_input(&priv->dev); + if (ret == OK) + { + /* 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 (ret == OK) + if (priv->dev.d_len > 0) { - /* 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 - { - tun_pollnotify(priv, POLLOUT); - } + priv->write_d_len = priv->dev.d_len; + tun_fd_transmit(priv); } else { - priv->dev.d_len = 0; tun_pollnotify(priv, POLLOUT); } } + else + { + priv->dev.d_len = 0; + tun_pollnotify(priv, POLLOUT); + } #elif defined(CONFIG_NET_IPv6) ninfo("Iv6 frame\n"); NETDEV_RXIPV6(&priv->dev); - /* Give the IPv6 packet to the network layer */ - - ipv6_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. + /* Give the IPv6 packet to the network layer. ipv6_input will return + * an error if it is unable to dispatch the packet at this time. */ - if (priv->dev.d_len > 0) + ret = ipv6_input(&priv->dev); + if (ret == OK) { - priv->write_d_len = priv->dev.d_len; - tun_fd_transmit(priv); + /* 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 + { + tun_pollnotify(priv, POLLOUT); + } } else {