You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/10/21 08:57:41 UTC

[incubator-nuttx] branch master updated: arch/sim: fix MTU mismatch on TAP device in host route mode

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 4ac44bc8b5 arch/sim: fix MTU mismatch on TAP device in host route mode
4ac44bc8b5 is described below

commit 4ac44bc8b5febd8ef3ab809a439bcf705567bb17
Author: Zhe Weng <we...@xiaomi.com>
AuthorDate: Thu Oct 20 19:01:02 2022 +0800

    arch/sim: fix MTU mismatch on TAP device in host route mode
    
    In host route mode (bridge mode disabled), the d_pktsize of TAP device is not initialized and will be set to CONFIG_NET_ETH_PKTSIZE in netdev_register, while the MTU on host side keeps at 1500. Input packets larger than CONFIG_NET_ETH_PKTSIZE will be dropped because 'IP packet shorter than length in IP header'.
    This patch fix this issue by reading MTU from host side and set as d_pktsize, just the same as what is done in bridge mode.
    
    Signed-off-by: Zhe Weng <we...@xiaomi.com>
---
 arch/sim/src/sim/posix/up_tapdev.c | 10 +++++-----
 arch/sim/src/sim/up_netdriver.c    |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/sim/src/sim/posix/up_tapdev.c b/arch/sim/src/sim/posix/up_tapdev.c
index 2be0568b76..ce518006da 100644
--- a/arch/sim/src/sim/posix/up_tapdev.c
+++ b/arch/sim/src/sim/posix/up_tapdev.c
@@ -189,10 +189,7 @@ void tapdev_init(int devidx, void *priv,
   struct ifreq ifr;
   int tapdevfd;
   int ret;
-
-#ifdef CONFIG_SIM_NET_BRIDGE
   int sockfd;
-#endif
 
   /* Open the tap device */
 
@@ -219,7 +216,6 @@ void tapdev_init(int devidx, void *priv,
 
   strncpy(gdevname[devidx], ifr.ifr_name, IFNAMSIZ);
 
-#ifdef CONFIG_SIM_NET_BRIDGE
   /* Get a socket with which to manipulate the tap device; the remaining
    * ioctl calls unfortunately won't work on the tap device fd.
    */
@@ -232,6 +228,7 @@ void tapdev_init(int devidx, void *priv,
       return;
     }
 
+#ifdef CONFIG_SIM_NET_BRIDGE
   /* Assign the tap device to a bridge */
 
   memset(&ifr, 0, sizeof(ifr));
@@ -248,6 +245,10 @@ void tapdev_init(int devidx, void *priv,
       close(tapdevfd);
       return;
     }
+#else
+  memset(&ifr, 0, sizeof(ifr));
+  strncpy(ifr.ifr_name, gdevname[devidx], IFNAMSIZ);
+#endif
 
   ret = ioctl(sockfd, SIOCGIFMTU, &ifr);
   close(sockfd);
@@ -262,7 +263,6 @@ void tapdev_init(int devidx, void *priv,
     {
       netdriver_setmtu(devidx, ifr.ifr_mtu);
     }
-#endif
 
   gtapdevfd[devidx] = tapdevfd;
   g_priv[devidx] = priv;
diff --git a/arch/sim/src/sim/up_netdriver.c b/arch/sim/src/sim/up_netdriver.c
index 93c294d5d1..af9d1437d8 100644
--- a/arch/sim/src/sim/up_netdriver.c
+++ b/arch/sim/src/sim/up_netdriver.c
@@ -441,7 +441,7 @@ void netdriver_setmacaddr(int devidx, unsigned char *macaddr)
 
 void netdriver_setmtu(int devidx, int mtu)
 {
-  g_sim_dev[devidx].d_pktsize = mtu;
+  g_sim_dev[devidx].d_pktsize = mtu + ETH_HDRLEN;
 }
 
 void netdriver_loop(void)