You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/05/14 13:55:07 UTC

[incubator-nuttx] branch master updated (03f462c -> a586886)

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

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


    from 03f462c  net/sockopt: fix nxstyle warning
     new 9cc2f50  netdev/register: configurable net packet size
     new 8bce416  sim/tapdev: follow the tunnel MTU size
     new a586886  net: remove unnecessary spaces

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 arch/sim/src/sim/up_internal.h  |  1 +
 arch/sim/src/sim/up_netdriver.c | 37 ++++++++++++++++++------
 arch/sim/src/sim/up_tapdev.c    | 28 +++++++++++++++----
 net/netdev/netdev_register.c    | 62 +++++++++++++++++++++++++----------------
 net/tcp/tcp_accept.c            |  2 +-
 net/udp/udp_recvfrom.c          | 17 ++++++-----
 6 files changed, 102 insertions(+), 45 deletions(-)


[incubator-nuttx] 02/03: sim/tapdev: follow the tunnel MTU size

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8bce416c25f26c4c284121ceaab8b84dcc1393de
Author: chao.an <an...@xiaomi.com>
AuthorDate: Thu May 14 16:24:21 2020 +0800

    sim/tapdev: follow the tunnel MTU size
    
    Change-Id: Ia32255517650d95ea3a675ee9fe5b69e923fb51a
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 arch/sim/src/sim/up_internal.h  |  1 +
 arch/sim/src/sim/up_netdriver.c | 37 +++++++++++++++++++++++++++++--------
 arch/sim/src/sim/up_tapdev.c    | 28 +++++++++++++++++++++++-----
 3 files changed, 53 insertions(+), 13 deletions(-)

diff --git a/arch/sim/src/sim/up_internal.h b/arch/sim/src/sim/up_internal.h
index 9c80960..7208e31 100644
--- a/arch/sim/src/sim/up_internal.h
+++ b/arch/sim/src/sim/up_internal.h
@@ -373,6 +373,7 @@ void vpnkit_ifdown(void);
 #ifdef CONFIG_SIM_NETDEV
 int netdriver_init(void);
 void netdriver_setmacaddr(unsigned char *macaddr);
+void netdriver_setmtu(int mtu);
 void netdriver_loop(void);
 #endif
 
diff --git a/arch/sim/src/sim/up_netdriver.c b/arch/sim/src/sim/up_netdriver.c
index e5df8f6..ee8f0c3 100644
--- a/arch/sim/src/sim/up_netdriver.c
+++ b/arch/sim/src/sim/up_netdriver.c
@@ -48,6 +48,7 @@
 #include <debug.h>
 #include <string.h>
 
+#include <nuttx/kmalloc.h>
 #include <nuttx/wqueue.h>
 #include <nuttx/net/net.h>
 #include <nuttx/net/netdev.h>
@@ -69,10 +70,6 @@ static struct work_s g_timer_work;
 static struct work_s g_avail_work;
 static struct work_s g_recv_work;
 
-/* A single packet buffer is used */
-
-static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
-
 /* Ethernet peripheral state */
 
 static struct net_driver_s g_sim_dev;
@@ -126,10 +123,12 @@ static void netdriver_recv_work(FAR void *arg)
 
   net_lock();
 
-  /* netdev_read will return 0 on a timeout event and >0 on a data received event */
+  /* netdev_read will return 0 on a timeout event and > 0
+   * on a data received event
+   */
 
   dev->d_len = netdev_read((FAR unsigned char *)dev->d_buf,
-                           CONFIG_NET_ETH_PKTSIZE);
+                           dev->d_pktsize);
   if (dev->d_len > 0)
     {
       NETDEV_RXPACKETS(dev);
@@ -149,7 +148,9 @@ static void netdriver_recv_work(FAR void *arg)
           pkt_input(dev);
 #endif /* CONFIG_NET_PKT */
 
-          /* We only accept IP packets of the configured type and ARP packets */
+          /* We only accept IP packets of the configured type
+           * and ARP packets
+           */
 
 #ifdef CONFIG_NET_IPv4
           if (eth->type == HTONS(ETHTYPE_IP))
@@ -325,14 +326,29 @@ static int netdriver_txavail(FAR struct net_driver_s *dev)
 int netdriver_init(void)
 {
   FAR struct net_driver_s *dev = &g_sim_dev;
+  void *pktbuf;
+  int pktsize;
 
   /* Internal initialization */
 
   netdev_init();
 
+  /* Update the buffer size */
+
+  pktsize = dev->d_pktsize ? dev->d_pktsize :
+            (MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE);
+
+  /* Allocate packet buffer */
+
+  pktbuf = kmm_malloc(pktsize);
+  if (pktbuf == NULL)
+    {
+      return -ENOMEM;
+    }
+
   /* Set callbacks */
 
-  dev->d_buf     = g_pktbuf;         /* Single packet buffer */
+  dev->d_buf     = pktbuf;
   dev->d_ifup    = netdriver_ifup;
   dev->d_ifdown  = netdriver_ifdown;
   dev->d_txavail = netdriver_txavail;
@@ -347,6 +363,11 @@ void netdriver_setmacaddr(unsigned char *macaddr)
   memcpy(g_sim_dev.d_mac.ether.ether_addr_octet, macaddr, IFHWADDRLEN);
 }
 
+void netdriver_setmtu(int mtu)
+{
+  g_sim_dev.d_pktsize = mtu;
+}
+
 void netdriver_loop(void)
 {
   if (work_available(&g_recv_work) && netdev_avail())
diff --git a/arch/sim/src/sim/up_tapdev.c b/arch/sim/src/sim/up_tapdev.c
index 4ef2975..7b9e8e6 100644
--- a/arch/sim/src/sim/up_tapdev.c
+++ b/arch/sim/src/sim/up_tapdev.c
@@ -92,6 +92,7 @@ struct sel_arg_struct
  ****************************************************************************/
 
 void netdriver_setmacaddr(unsigned char *macaddr);
+void netdriver_setmtu(int mtu);
 
 /****************************************************************************
  * Private Data
@@ -219,15 +220,29 @@ void tapdev_init(void)
   ifr.ifr_ifindex = if_nametoindex(gdevname);
 
   ret = ioctl(sockfd, SIOCBRADDIF, &ifr);
-  close(sockfd);
   if (ret < 0)
     {
       printf("TAPDEV: ioctl failed (can't add interface %s to "
              "bridge %s): %d\r\n",
              gdevname, CONFIG_SIM_NET_BRIDGE_DEVICE, -ret);
+      close(sockfd);
+      close(tapdevfd);
+      return;
+    }
+
+  ret = ioctl(sockfd, SIOCGIFMTU, &ifr);
+  close(sockfd);
+  if (ret < 0)
+    {
+      printf("TAPDEV: ioctl failed (can't get MTU "
+             "from %s): %d\r\n", gdevname, -ret);
       close(tapdevfd);
       return;
-   }
+    }
+  else
+    {
+      netdriver_setmtu(ifr.ifr_mtu);
+    }
 #endif
 
   gtapdevfd = tapdevfd;
@@ -341,7 +356,8 @@ void tapdev_ifup(in_addr_t ifaddr)
   ret = ioctl(sockfd, SIOCGIFFLAGS, (unsigned long)&ifr);
   if (ret < 0)
     {
-      printf("TAPDEV: ioctl failed (can't get interface flags): %d\r\n", -ret);
+      printf("TAPDEV: ioctl failed "
+             "(can't get interface flags): %d\r\n", -ret);
       close(sockfd);
       return;
     }
@@ -350,7 +366,8 @@ void tapdev_ifup(in_addr_t ifaddr)
   ret = ioctl(sockfd, SIOCSIFFLAGS, (unsigned long)&ifr);
   if (ret < 0)
     {
-      printf("TAPDEV: ioctl failed (can't set interface flags): %d\r\n", -ret);
+      printf("TAPDEV: ioctl failed "
+             "(can't set interface flags): %d\r\n", -ret);
       close(sockfd);
       return;
     }
@@ -405,7 +422,8 @@ void tapdev_ifdown(void)
       ret = ioctl(sockfd, SIOCDELRT, (unsigned long)&ghostroute);
       if (ret < 0)
         {
-          printf("TAPDEV: ioctl failed (can't delete host route): %d\r\n", -ret);
+          printf("TAPDEV: ioctl failed "
+                 "(can't delete host route): %d\r\n", -ret);
         }
 
       close(sockfd);


[incubator-nuttx] 03/03: net: remove unnecessary spaces

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a5868864bc679eb18d78fe88c9281a5654aa6611
Author: chao.an <an...@xiaomi.com>
AuthorDate: Thu May 14 16:42:18 2020 +0800

    net: remove unnecessary spaces
    
    minor style fix
    
    Change-Id: I06b6fe48628440490090b89a39baf01481f79b79
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 net/tcp/tcp_accept.c   |  2 +-
 net/udp/udp_recvfrom.c | 17 ++++++++++-------
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/net/tcp/tcp_accept.c b/net/tcp/tcp_accept.c
index e69c89d..c3c4426 100644
--- a/net/tcp/tcp_accept.c
+++ b/net/tcp/tcp_accept.c
@@ -300,7 +300,7 @@ int psock_tcp_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
       conn->accept_private = NULL;
       conn->accept         = NULL;
 
-      nxsem_destroy(&state. acpt_sem);
+      nxsem_destroy(&state.acpt_sem);
 
       /* Check for a errors.  Errors are signalled by negative errno values
        * for the send length.
diff --git a/net/udp/udp_recvfrom.c b/net/udp/udp_recvfrom.c
index f2da4d2..2c19970 100644
--- a/net/udp/udp_recvfrom.c
+++ b/net/udp/udp_recvfrom.c
@@ -196,7 +196,8 @@ static inline void udp_newdata(FAR struct net_driver_s *dev,
 
 static inline void udp_readahead(struct udp_recvfrom_s *pstate)
 {
-  FAR struct udp_conn_s *conn = (FAR struct udp_conn_s *)pstate->ir_sock->s_conn;
+  FAR struct udp_conn_s *conn = (FAR struct udp_conn_s *)
+                                pstate->ir_sock->s_conn;
   FAR struct iob_s *iob;
   int recvlen;
 
@@ -572,8 +573,9 @@ static ssize_t udp_recvfrom_result(int result, struct udp_recvfrom_s *pstate)
       return pstate->ir_result;
     }
 
-  /* If net_timedwait failed, then we were probably reawakened by a signal. In
-   * this case, net_timedwait will have returned negated errno appropriately.
+  /* If net_timedwait failed, then we were probably reawakened by a signal.
+   * In this case, net_timedwait will have returned negated errno
+   * appropriately.
    */
 
   if (result < 0)
@@ -654,9 +656,10 @@ ssize_t psock_udp_recvfrom(FAR struct socket *psock, FAR void *buf,
         }
     }
 
-  /* It is okay to block if we need to.  If there is space to receive anything
-   * more, then we will wait to receive the data.  Otherwise return the number
-   * of bytes read from the read-ahead buffer (already in 'ret').
+  /* It is okay to block if we need to.  If there is space to receive
+   * anything more, then we will wait to receive the data. Otherwise
+   * return the number of bytes read from the read-ahead buffer
+   * (already in 'ret').
    *
    * NOTE: that udp_readahead() may set state.ir_recvlen == -1.
    */
@@ -686,7 +689,7 @@ ssize_t psock_udp_recvfrom(FAR struct socket *psock, FAR void *buf,
            * received.
            */
 
-          ret = net_timedwait(&state. ir_sem, _SO_TIMEOUT(psock->s_rcvtimeo));
+          ret = net_timedwait(&state.ir_sem, _SO_TIMEOUT(psock->s_rcvtimeo));
           if (ret == -ETIMEDOUT)
             {
               ret = -EAGAIN;


[incubator-nuttx] 01/03: netdev/register: configurable net packet size

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9cc2f50405e38b3ddd0b597c754fadf313384360
Author: chao.an <an...@xiaomi.com>
AuthorDate: Thu May 14 15:52:13 2020 +0800

    netdev/register: configurable net packet size
    
    Change-Id: I2af571a0273e67a06c1b4543eac3ded7cfdd8060
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 net/netdev/netdev_register.c | 62 +++++++++++++++++++++++++++-----------------
 1 file changed, 38 insertions(+), 24 deletions(-)

diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c
index 3b00ee6..15a5d1d 100644
--- a/net/netdev/netdev_register.c
+++ b/net/netdev/netdev_register.c
@@ -237,8 +237,8 @@ static int get_ifindex(void)
  *
  * Input Parameters:
  *   dev    - The device driver structure to be registered.
- *   lltype - Link level protocol used by the driver (Ethernet, SLIP, TUN, ...
- *              ...
+ *   lltype - Link level protocol used by the driver (Ethernet, SLIP, TUN,
+ *            ...)
  *
  * Returned Value:
  *   0:Success; negated errno on failure
@@ -253,6 +253,8 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
 {
   FAR char devfmt_str[IFNAMSIZ];
   FAR const char *devfmt;
+  uint16_t pktsize = 0;
+  uint8_t llhdrlen = 0;
   int devnum;
 #ifdef CONFIG_NETDEV_IFINDEX
   int ifindex;
@@ -268,63 +270,63 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
         {
 #ifdef CONFIG_NET_LOOPBACK
           case NET_LL_LOOPBACK:   /* Local loopback */
-            dev->d_llhdrlen = 0;
-            dev->d_pktsize  = NET_LO_PKTSIZE;
-            devfmt          = NETDEV_LO_FORMAT;
+            llhdrlen = 0;
+            pktsize  = NET_LO_PKTSIZE;
+            devfmt   = NETDEV_LO_FORMAT;
             break;
 #endif
 
 #ifdef CONFIG_NET_ETHERNET
           case NET_LL_ETHERNET:   /* Ethernet */
-            dev->d_llhdrlen = ETH_HDRLEN;
-            dev->d_pktsize  = CONFIG_NET_ETH_PKTSIZE;
-            devfmt          = NETDEV_ETH_FORMAT;
+            llhdrlen = ETH_HDRLEN;
+            pktsize  = CONFIG_NET_ETH_PKTSIZE;
+            devfmt   = NETDEV_ETH_FORMAT;
             break;
 #endif
 
 #ifdef CONFIG_DRIVERS_IEEE80211
           case NET_LL_IEEE80211:  /* IEEE 802.11 */
-            dev->d_llhdrlen = ETH_HDRLEN;
-            dev->d_pktsize  = CONFIG_NET_ETH_PKTSIZE;
-            devfmt          = NETDEV_WLAN_FORMAT;
+            llhdrlen = ETH_HDRLEN;
+            pktsize  = CONFIG_NET_ETH_PKTSIZE;
+            devfmt   = NETDEV_WLAN_FORMAT;
             break;
 #endif
 
 #ifdef CONFIG_NET_BLUETOOTH
-          case NET_LL_BLUETOOTH:  /* Bluetooth */
-            dev->d_llhdrlen = BLUETOOTH_MAX_HDRLEN; /* Determined at runtime */
+          case NET_LL_BLUETOOTH:              /* Bluetooth */
+            llhdrlen = BLUETOOTH_MAX_HDRLEN;  /* Determined at runtime */
 #ifdef CONFIG_NET_6LOWPAN
-            dev->d_pktsize  = CONFIG_NET_6LOWPAN_PKTSIZE;
+            pktsize  = CONFIG_NET_6LOWPAN_PKTSIZE;
 #endif
-            devfmt          = NETDEV_BNEP_FORMAT;
+            devfmt   = NETDEV_BNEP_FORMAT;
             break;
 #endif
 
 #if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154)
           case NET_LL_IEEE802154: /* IEEE 802.15.4 MAC */
           case NET_LL_PKTRADIO:   /* Non-IEEE 802.15.4 packet radio */
-            dev->d_llhdrlen = 0;  /* Determined at runtime */
+            llhdrlen = 0;         /* Determined at runtime */
 #ifdef CONFIG_NET_6LOWPAN
-            dev->d_pktsize  = CONFIG_NET_6LOWPAN_PKTSIZE;
+            pktsize  = CONFIG_NET_6LOWPAN_PKTSIZE;
 #endif
-            devfmt          = NETDEV_WPAN_FORMAT;
+            devfmt   = NETDEV_WPAN_FORMAT;
             break;
 #endif
 
 #ifdef CONFIG_NET_SLIP
           case NET_LL_SLIP:       /* Serial Line Internet Protocol (SLIP) */
-            dev->d_llhdrlen = 0;
-            dev->d_pktsize  = CONFIG_NET_SLIP_PKTSIZE;
-            devfmt          = NETDEV_SLIP_FORMAT;
+            llhdrlen = 0;
+            pktsize  = CONFIG_NET_SLIP_PKTSIZE;
+            devfmt   = NETDEV_SLIP_FORMAT;
             break;
 #endif
 
 #ifdef CONFIG_NET_TUN
           case NET_LL_TUN:        /* Virtual Network Device (TUN) */
-            dev->d_llhdrlen = 0;  /* This will be overwritten by tun_ioctl
+            llhdrlen = 0;         /* This will be overwritten by tun_ioctl
                                    * if used as a TAP (layer 2) device */
-            dev->d_pktsize  = CONFIG_NET_TUN_PKTSIZE;
-            devfmt          = NETDEV_TUN_FORMAT;
+            pktsize  = CONFIG_NET_TUN_PKTSIZE;
+            devfmt   = NETDEV_TUN_FORMAT;
             break;
 #endif
 
@@ -333,6 +335,18 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
             return -EINVAL;
         }
 
+      /* Update the package length */
+
+      if (dev->d_llhdrlen == 0)
+        {
+          dev->d_llhdrlen = llhdrlen;
+        }
+
+      if (dev->d_pktsize == 0)
+        {
+          dev->d_pktsize = pktsize;
+        }
+
       /* Remember the verified link type */
 
       dev->d_lltype = (uint8_t)lltype;