diff options
author | Luiz Souza <luiz@netgate.com> | 2018-03-12 16:56:54 -0300 |
---|---|---|
committer | Luiz Souza <luiz@netgate.com> | 2018-03-12 12:16:41 -0500 |
commit | 67ff878b5e5dabfe5f9c7d93f77f18a87d2a995b (patch) | |
tree | 9aad88899f438d70ec2f9064c0d5fe445e8679d6 | |
parent | 7d8125bc3128984869fd1520d5387ef4d603720d (diff) | |
download | FreeBSD-src-67ff878b5e5dabfe5f9c7d93f77f18a87d2a995b.zip FreeBSD-src-67ff878b5e5dabfe5f9c7d93f77f18a87d2a995b.tar.gz |
Print and allow setting the switch port state.
The port state can be set to: disabled, learning, blocking and forwarding.
(cherry picked from commit 76dbc69beb1365281a904ba531acbcbc607b394e)
(cherry picked from commit 1a4022d9c69dfa01a9bd21805b4c26eb8b4161d9)
-rw-r--r-- | sbin/etherswitchcfg/etherswitchcfg.c | 36 | ||||
-rw-r--r-- | sys/dev/etherswitch/etherswitch.h | 11 |
2 files changed, 46 insertions, 1 deletions
diff --git a/sbin/etherswitchcfg/etherswitchcfg.c b/sbin/etherswitchcfg/etherswitchcfg.c index a8d8cce..3151e90 100644 --- a/sbin/etherswitchcfg/etherswitchcfg.c +++ b/sbin/etherswitchcfg/etherswitchcfg.c @@ -225,6 +225,34 @@ set_port_flag(struct cfg *cfg, char *argv[]) err(EX_OSERR, "ioctl(IOETHERSWITCHSETPORT)"); } +static int +set_port_state(struct cfg *cfg, char *argv[]) +{ + etherswitch_port_t p; + uint32_t state; + + if ((cfg->info.es_switch_caps & ETHERSWITCH_CAPS_PSTATE) == 0) { + printf("%s: setting the port state is not supported.\n", + cfg->controlfile); + return; + } + state = ETHERSWITCH_PSTATE_DISABLED; + if (strcasecmp(argv[0], "blocking") == 0) + state = ETHERSWITCH_PSTATE_BLOCKING; + else if (strcasecmp(argv[0], "learning") == 0) + state = ETHERSWITCH_PSTATE_LEARNING; + else if (strcasecmp(argv[0], "forwarding") == 0) + state = ETHERSWITCH_PSTATE_FORWARDING; + + bzero(&p, sizeof(p)); + p.es_port = cfg->unit; + if (ioctl(cfg->fd, IOETHERSWITCHGETPORT, &p) != 0) + err(EX_OSERR, "ioctl(IOETHERSWITCHGETPORT)"); + p.es_state = state; + if (ioctl(cfg->fd, IOETHERSWITCHSETPORT, &p) != 0) + err(EX_OSERR, "ioctl(IOETHERSWITCHSETPORT)"); +} + static void set_port_media(struct cfg *cfg, char *argv[]) { @@ -484,6 +512,10 @@ print_port(struct cfg *cfg, int port) printf("port%d:\n", port); if (cfg->conf.vlan_mode == ETHERSWITCH_VLAN_DOT1Q) printf("\tpvid: %d\n", p.es_pvid); + if (cfg->info.es_switch_caps & ETHERSWITCH_CAPS_PSTATE) { + printb("\tstate", p.es_state, ETHERSWITCH_PSTATE_BITS); + printf("\n"); + } printb("\tflags", p.es_flags, ETHERSWITCH_PORT_FLAGS_BITS); printf("\n"); printf("\tmedia: "); @@ -814,6 +846,10 @@ static struct cmds cmds[] = { { MODE_PORT, "-droptagged", 0, set_port_flag }, { MODE_PORT, "dropuntagged", 0, set_port_flag }, { MODE_PORT, "-dropuntagged", 0, set_port_flag }, + { MODE_PORT, "disabled", 0, set_port_state }, + { MODE_PORT, "blocking", 0, set_port_state }, + { MODE_PORT, "learning", 0, set_port_state }, + { MODE_PORT, "forwarding", 0, set_port_state }, { MODE_CONFIG, "vlan_mode", 1, set_vlan_mode }, { MODE_LAGGROUP, "members", 1, set_laggroup_members }, { MODE_VLANGROUP, "vlan", 1, set_vlangroup_vid }, diff --git a/sys/dev/etherswitch/etherswitch.h b/sys/dev/etherswitch/etherswitch.h index 81f1e65..4f78763 100644 --- a/sys/dev/etherswitch/etherswitch.h +++ b/sys/dev/etherswitch/etherswitch.h @@ -38,8 +38,9 @@ typedef struct etherswitch_phyreg etherswitch_phyreg_t; #define ETHERSWITCH_CAPS_PORTS_MASK (1 << 0) /* Ports mask */ #define ETHERSWITCH_CAPS_LAGG (1 << 1) /* LAGG support */ +#define ETHERSWITCH_CAPS_PSTATE (1 << 2) /* Port state */ #define ETHERSWITCH_CAPS_BITS \ -"\020\1PORTSMASK\2LAGG" +"\020\1PORTSMASK\2LAGG\3PSTATE" #define MAX_PORTS 1024 #define MAX_PORTS_UINT32 (MAX_PORTS / sizeof(uint32_t)) @@ -77,6 +78,13 @@ typedef struct etherswitch_conf etherswitch_conf_t; "\020\1CPUPORT\2STRIPTAG\3ADDTAG\4FIRSTLOCK\5DROPUNTAGGED\6QinQ\7INGRESS" \ "\10DROPTAGGED" +#define ETHERSWITCH_PSTATE_DISABLED (1 << 0) +#define ETHERSWITCH_PSTATE_BLOCKING (1 << 1) +#define ETHERSWITCH_PSTATE_LEARNING (1 << 2) +#define ETHERSWITCH_PSTATE_FORWARDING (1 << 3) +#define ETHERSWITCH_PSTATE_BITS \ +"\020\1DISABLED\2BLOCKING\3LEARNING\4FORWARDING" + #define ETHERSWITCH_PORT_MAX_LEDS 3 enum etherswitch_port_led { @@ -93,6 +101,7 @@ struct etherswitch_port { int es_pvid; int es_nleds; uint32_t es_flags; + uint32_t es_state; etherswitch_port_led_t es_led[ETHERSWITCH_PORT_MAX_LEDS]; union { struct ifreq es_uifr; |