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/nuttx-apps.git

commit ae7c168bf601bcf8cc98d8c31f14b7c50e2dec25
Author: Zhe Weng <[email protected]>
AuthorDate: Tue Jan 7 18:02:39 2025 +0800

    nshlib: Add vconfig command
    
    Add vconfig command
    
    Signed-off-by: gaohedong <[email protected]>
---
 nshlib/Kconfig       |  4 ++++
 nshlib/nsh.h         |  3 +++
 nshlib/nsh_command.c |  4 ++++
 nshlib/nsh_netcmds.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 58 insertions(+)

diff --git a/nshlib/Kconfig b/nshlib/Kconfig
index 7fd49bbc7..b9a510383 100644
--- a/nshlib/Kconfig
+++ b/nshlib/Kconfig
@@ -423,6 +423,10 @@ config NSH_DISABLE_IFCONFIG
        bool "Disable ifconfig"
        default DEFAULT_SMALL || !FS_PROCFS || FS_PROCFS_EXCLUDE_NET
 
+config NSH_DISABLE_VCONFIG
+       bool "Disable vconfig"
+       default DEFAULT_SMALL || !FS_PROCFS || FS_PROCFS_EXCLUDE_NET
+
 config NSH_DISABLE_IFUPDOWN
        bool "Disable ifup/down"
        default DEFAULT_SMALL || !FS_PROCFS || FS_PROCFS_EXCLUDE_NET
diff --git a/nshlib/nsh.h b/nshlib/nsh.h
index 8d037f517..9c2c1d5ed 100644
--- a/nshlib/nsh.h
+++ b/nshlib/nsh.h
@@ -1093,6 +1093,9 @@ int cmd_irqinfo(FAR struct nsh_vtbl_s *vtbl, int argc, 
FAR char **argv);
 #  ifndef CONFIG_NSH_DISABLE_IFCONFIG
   int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
 #  endif
+#  ifndef CONFIG_NSH_DISABLE_VCONFIG
+  int cmd_vconfig(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
+#  endif
 #  ifndef CONFIG_NSH_DISABLE_IFUPDOWN
   int cmd_ifup(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
   int cmd_ifdown(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c
index 629949753..1474b824c 100644
--- a/nshlib/nsh_command.c
+++ b/nshlib/nsh_command.c
@@ -286,6 +286,10 @@ static const struct cmdmap_s g_cmdmap[] =
     "[dr|gw|gateway <dr-address>] [netmask <net-mask>|prefixlen <len>] "
     "[dns <dns-address>] [hw <hw-mac>]"),
 #  endif
+#  if defined(CONFIG_NET_VLAN) && !defined(CONFIG_NSH_DISABLE_VCONFIG)
+  CMD_MAP("vconfig", cmd_vconfig, 3, 4,
+    "[add iface-name vlan-id]|[rem vlan-name]"),
+#  endif
 #  ifndef CONFIG_NSH_DISABLE_IFUPDOWN
   CMD_MAP("ifdown",   cmd_ifdown,   2, 2, "<interface>"),
   CMD_MAP("ifup",     cmd_ifup,     2, 2, "<interface>"),
diff --git a/nshlib/nsh_netcmds.c b/nshlib/nsh_netcmds.c
index 1b2c8efd7..233231a95 100644
--- a/nshlib/nsh_netcmds.c
+++ b/nshlib/nsh_netcmds.c
@@ -1097,6 +1097,53 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, 
FAR char **argv)
 }
 #endif
 
+/****************************************************************************
+ * Name: cmd_vconfig
+ ****************************************************************************/
+
+#if defined(CONFIG_NET_VLAN) && !defined(CONFIG_NSH_DISABLE_VCONFIG)
+int cmd_vconfig(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
+{
+  DEBUGASSERT(argc >= 2);
+
+  if (!strcmp(argv[1], "add"))
+    {
+      if (argc != 4)
+        {
+          nsh_error(vtbl, g_fmtargrequired, argv[0]);
+          return ERROR;
+        }
+
+      if (netlib_add_vlan(argv[2], atoi(argv[3])) < 0)
+        {
+          perror("Failed to add VLAN");
+          return ERROR;
+        }
+    }
+  else if (!strcmp(argv[1], "rem") || !strcmp(argv[1], "del"))
+    {
+      if (argc != 3)
+        {
+          nsh_error(vtbl, g_fmtargrequired, argv[0]);
+          return ERROR;
+        }
+
+      if (netlib_del_vlan(argv[2]) < 0)
+        {
+          perror("Failed to remove VLAN");
+          return ERROR;
+        }
+    }
+  else
+    {
+      nsh_error(vtbl, g_fmtarginvalid, argv[1]);
+      return ERROR;
+    }
+
+  return OK;
+}
+#endif
+
 /****************************************************************************
  * Name: cmd_nslookup
  ****************************************************************************/

Reply via email to