Commit ab7cb867 authored by Alessandro Rubini's avatar Alessandro Rubini

shell: implement vlan command

This allows a run-time change of the active vlan, if CONFIG_VLAN is
active at build time.  The pfilter rules are being rewritten every
time the vlan is changed (and we have one VLAN only for the CPU).

   wrc# vlan set 0
   0 ("0") out of range
   Command "vlan": error -22
   wrc# vlan set pippo
   0 ("pippo") out of range
   Command "vlan": error -22

   wrc# vlan
   current vlan: 10 (0xa)

   wrc# vlan set 20
   current vlan: 20 (0x14)
   wrc# ip set 192.168.20.2
   IP-address: 192.168.20.2 (static assignment)

      (and the node now replies to ping on vlan 20)

   wrc# vlan set 10
   current vlan: 10 (0xa)
   wrc# ip set 192.168.10.2
   IP-address: 192.168.10.2 (static assignment)

      (and the node now replies to ping on vlan 10)
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 33fcb1c0
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2016 GSI (www.gsi.de)
* Author: Alessandro Rubini <a.rubini@gsi.de>
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <wrc.h>
#include <string.h>
#include <errno.h>
#include <shell.h>
#include <endpoint.h>
static int cmd_vlan(const char *args[])
{
int i;
if (!args[0] || !strcasecmp(args[0], "get")) {
/* nothing... */
} else if (!strcasecmp(args[0], "set") && args[1]) {
fromdec(args[1], &i);
if (i < 1 || i > 4095) {
pp_printf("%i (\"%s\") out of range\n", i, args[1]);
return -EINVAL;
}
wrc_vlan_number = i;
pfilter_init_default();
} else {
return -EINVAL;
}
pp_printf("current vlan: %i (0x%x)\n",
wrc_vlan_number, wrc_vlan_number);
return 0;
}
DEFINE_WRC_COMMAND(vlan) = {
.name = "vlan",
.exec = cmd_vlan,
};
...@@ -22,3 +22,4 @@ obj-$(CONFIG_CMD_CONFIG) += shell/cmd_config.o ...@@ -22,3 +22,4 @@ obj-$(CONFIG_CMD_CONFIG) += shell/cmd_config.o
obj-$(CONFIG_CMD_SLEEP) += shell/cmd_sleep.o obj-$(CONFIG_CMD_SLEEP) += shell/cmd_sleep.o
obj-$(CONFIG_CMD_LL) += shell/cmd_ll.o obj-$(CONFIG_CMD_LL) += shell/cmd_ll.o
obj-$(CONFIG_FLASH_INIT) += shell/cmd_init.o obj-$(CONFIG_FLASH_INIT) += shell/cmd_init.o
obj-$(CONFIG_VLAN) += shell/cmd_vlan.o
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment