From 3041e813f00c7d29c5030479b834fcd1b30a23a0 Mon Sep 17 00:00:00 2001 From: Zhe Weng Date: Tue, 7 Jan 2025 18:02:39 +0800 Subject: [PATCH 1/2] nshlib: Add vconfig command Add vconfig command Signed-off-by: gaohedong --- 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 7fd49bbc727..b9a51038330 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 8d037f5176f..9c2c1d5edfa 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 2f05557cb30..d9deadd0cf1 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 ] [netmask |prefixlen ] " "[dns ] [hw ]"), # 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, ""), CMD_MAP("ifup", cmd_ifup, 2, 2, ""), diff --git a/nshlib/nsh_netcmds.c b/nshlib/nsh_netcmds.c index 1b2c8efd7f6..233231a9519 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 ****************************************************************************/ From ea580198f5445c2a52de2ccb7ca3e85273b273c9 Mon Sep 17 00:00:00 2001 From: Zhe Weng Date: Fri, 7 Feb 2025 14:46:46 +0800 Subject: [PATCH 2/2] vconfig: Support setting default PCP when creating VLAN Now we allow setting a default PCP when creating VLAN like: `vconfig add iface-name vlan-id [pcp]` e.g. `vconfig add eth0 10` will create eth0.10 with VID=10 and no PCP(0) `vconfig add eth0 10 3` will create eth0.10 with VID=10 and PCP=3 Signed-off-by: Zhe Weng --- include/netutils/netlib.h | 2 +- nshlib/nsh_command.c | 4 ++-- nshlib/nsh_netcmds.c | 11 +++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/netutils/netlib.h b/include/netutils/netlib.h index a751ed60b23..5be9747b2ee 100644 --- a/include/netutils/netlib.h +++ b/include/netutils/netlib.h @@ -330,7 +330,7 @@ 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 netlib_add_vlan(FAR const char *ifname, int vlanid, int prio); int netlib_del_vlan(FAR const char *vlanif); #endif diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c index d9deadd0cf1..333dbdf2cd4 100644 --- a/nshlib/nsh_command.c +++ b/nshlib/nsh_command.c @@ -287,8 +287,8 @@ static const struct cmdmap_s g_cmdmap[] = "[dns ] [hw ]"), # 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]"), + CMD_MAP("vconfig", cmd_vconfig, 3, 5, + "[add iface-name vlan-id [pcp]]|[rem vlan-name]"), # endif # ifndef CONFIG_NSH_DISABLE_IFUPDOWN CMD_MAP("ifdown", cmd_ifdown, 2, 2, ""), diff --git a/nshlib/nsh_netcmds.c b/nshlib/nsh_netcmds.c index 233231a9519..6010e10840e 100644 --- a/nshlib/nsh_netcmds.c +++ b/nshlib/nsh_netcmds.c @@ -1108,13 +1108,20 @@ int cmd_vconfig(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) if (!strcmp(argv[1], "add")) { - if (argc != 4) + int prio = 0; + + if (argc != 4 && argc != 5) { nsh_error(vtbl, g_fmtargrequired, argv[0]); return ERROR; } - if (netlib_add_vlan(argv[2], atoi(argv[3])) < 0) + if (argc == 5) + { + prio = atoi(argv[4]); + } + + if (netlib_add_vlan(argv[2], atoi(argv[3]), prio) < 0) { perror("Failed to add VLAN"); return ERROR;