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

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


The following commit(s) were added to refs/heads/master by this push:
     new 45b54db1f netlib: let vconfig set the RX mode of a new VLAN device.
45b54db1f is described below

commit 45b54db1f3ff6dc93a6502f9546d9ea84658d53c
Author: wangjinjing1 <[email protected]>
AuthorDate: Wed Feb 4 16:50:06 2026 +0800

    netlib: let vconfig set the RX mode of a new VLAN device.
    
    netlib_add_vlan() filled in only three fields of struct vlan_ioctl_args
    and left rx_type and rx_priority with whatever the stack held.
    vlan_register() refuses an rx_type above NETDEV_RX_DEFAULT, so
    "vconfig add eth0 10" failed with EINVAL whenever the garbage value
    happened to be out of range: creating a VLAN device from nsh did not
    work.
    
    Pass both fields in, defaulting rx_type to NETDEV_RX_DEFAULT so the
    child inherits the RX mode of the real device, and let vconfig override
    them.
    
    netlib_add_vlan() takes two more arguments; nshlib is its only caller.
    
    Assisted-by: Kiro:claude-opus-4
    Signed-off-by: wangjinjing1 <[email protected]>
---
 include/netutils/netlib.h        |  3 ++-
 netutils/netlib/netlib_addvlan.c | 12 ++++++++----
 nshlib/nsh_command.c             |  5 +++--
 nshlib/nsh_netcmds.c             | 24 +++++++++++++++++++++---
 4 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/include/netutils/netlib.h b/include/netutils/netlib.h
index a4dace4de..5298d7c88 100644
--- a/include/netutils/netlib.h
+++ b/include/netutils/netlib.h
@@ -374,7 +374,8 @@ int netlib_setessid(FAR const char *ifname, FAR const char 
*essid);
 #endif
 
 #ifdef CONFIG_NET_VLAN
-int netlib_add_vlan(FAR const char *ifname, int vlanid, int prio);
+int netlib_add_vlan(FAR const char *ifname, int vlanid, int prio,
+                    uint8_t rx_type, uint8_t rx_priority);
 int netlib_del_vlan(FAR const char *vlanif);
 #endif
 
diff --git a/netutils/netlib/netlib_addvlan.c b/netutils/netlib/netlib_addvlan.c
index db1369578..7bee48b1e 100644
--- a/netutils/netlib/netlib_addvlan.c
+++ b/netutils/netlib/netlib_addvlan.c
@@ -49,21 +49,25 @@
  *
  ****************************************************************************/
 
-int netlib_add_vlan(FAR const char *ifname, int vlanid, int prio)
+int netlib_add_vlan(FAR const char *ifname, int vlanid, int prio,
+                    uint8_t rx_type, uint8_t rx_priority)
 {
   int ret = ERROR;
 
   if (ifname && vlanid > 0)
     {
       int sockfd = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL);
+
       if (sockfd >= 0)
         {
           struct vlan_ioctl_args ifv;
 
           strlcpy(ifv.device1, ifname, sizeof(ifv.device1));
-          ifv.u.VID    = vlanid;
-          ifv.vlan_qos = prio;
-          ifv.cmd      = ADD_VLAN_CMD;
+          ifv.u.VID       = vlanid;
+          ifv.vlan_qos    = prio;
+          ifv.cmd         = ADD_VLAN_CMD;
+          ifv.rx_type     = rx_type;
+          ifv.rx_priority = rx_priority;
 
           ret = ioctl(sockfd, SIOCSIFVLAN, &ifv);
           close(sockfd);
diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c
index df118520e..e24d0ab7f 100644
--- a/nshlib/nsh_command.c
+++ b/nshlib/nsh_command.c
@@ -305,8 +305,9 @@ static const struct cmdmap_s g_cmdmap[] =
     "[dns <dns-address>] [hw <hw-mac>] [up|down]"),
 #  endif
 #  if defined(CONFIG_NET_VLAN) && !defined(CONFIG_NSH_DISABLE_VCONFIG)
-  CMD_MAP("vconfig", cmd_vconfig, 3, 5,
-    "[add iface-name vlan-id [pcp]]|[rem vlan-name]"),
+  CMD_MAP("vconfig", cmd_vconfig, 3, 7,
+    "[add iface-name vlan-id [pcp [rx-type [rx-priority]]]]"
+    "|[rem vlan-name]"),
 #  endif
 #  ifndef CONFIG_NSH_DISABLE_IFUPDOWN
   CMD_MAP("ifdown",   cmd_ifdown,   2, 2, "<interface>"),
diff --git a/nshlib/nsh_netcmds.c b/nshlib/nsh_netcmds.c
index f368a5de7..8e3c5836d 100644
--- a/nshlib/nsh_netcmds.c
+++ b/nshlib/nsh_netcmds.c
@@ -63,6 +63,7 @@
 #include <nuttx/clock.h>
 #include <nuttx/net/net.h>
 #include <nuttx/net/netdev.h>
+#include <nuttx/net/netdev_lowerhalf.h>
 #include <nuttx/net/netstats.h>
 #include <nuttx/net/ip.h>
 #include <nuttx/net/icmp.h>
@@ -1129,19 +1130,36 @@ int cmd_vconfig(FAR struct nsh_vtbl_s *vtbl, int argc, 
FAR char **argv)
   if (!strcmp(argv[1], "add"))
     {
       int prio = 0;
+      uint8_t rx_type = NETDEV_RX_DEFAULT;
+      uint8_t rx_priority = 0;
 
-      if (argc != 4 && argc != 5)
+      /* "add <iface> <vid>" needs 4 arguments; pcp, rx-type and
+       * rx-priority are optional.
+       */
+
+      if (argc < 4 || argc > 7)
         {
           nsh_error(vtbl, g_fmtargrequired, argv[0]);
           return ERROR;
         }
 
-      if (argc == 5)
+      if (argc >= 5)
         {
           prio = atoi(argv[4]);
         }
 
-      if (netlib_add_vlan(argv[2], atoi(argv[3]), prio) < 0)
+      if (argc > 5)
+        {
+          rx_type = atoi(argv[5]);
+
+          if (argc == 7)
+            {
+              rx_priority = MIN(atoi(argv[6]), 255);
+            }
+        }
+
+      if (netlib_add_vlan(argv[2], atoi(argv[3]), prio, rx_type,
+                          rx_priority) < 0)
         {
           perror("Failed to add VLAN");
           return ERROR;

Reply via email to