diff options
author | Alexander Amelkin <alexander@amelkin.msk.ru> | 2018-11-11 11:57:12 +0300 |
---|---|---|
committer | Alexander Amelkin <alexander@amelkin.msk.ru> | 2018-11-11 11:57:12 +0300 |
commit | 6e2b688e241b3e1edb345a470b2f913b49ccafd4 (patch) | |
tree | 8507c4208e23a776f5e9727e2fb0f77e0cf72755 /lib | |
parent | 6c3d4b56c94761eb9416a70f87c3376163a489f1 (diff) | |
download | ipmitool-6e2b688e241b3e1edb345a470b2f913b49ccafd4.tar.gz |
lan: Fix processing disabled VLAN
Before this fix `ipmitool` would complain that VLAN ID
is out of range when trying to disable an already disabled VLAN
on a lan channel. With this fix it will properly report that
VLAN is already disabled.
Resolves ipmitool/ipmitool#55
Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ipmi_lanp.c | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/lib/ipmi_lanp.c b/lib/ipmi_lanp.c index 183234d..af5e612 100644 --- a/lib/ipmi_lanp.c +++ b/lib/ipmi_lanp.c @@ -1204,18 +1204,27 @@ ipmi_lan_set_vlan_id(struct ipmi_intf *intf, uint8_t chan, char *string) { struct lan_param *p; uint8_t data[2]; - int rc; + int rc = -1; - if (!string) { + if (!string) { /* request to disable VLAN */ lprintf(LOG_DEBUG, "Get current VLAN ID from BMC."); p = get_lan_param(intf, chan, IPMI_LANP_VLAN_ID); if (p && p->data && p->data_len > 1) { int id = ((p->data[1] & 0x0f) << 8) + p->data[0]; - if (id < 1 || id > 4094) { + if (IPMI_LANP_VLAN_DISABLE == id) { + printf("VLAN is already disabled for channel %" + PRIu8 "\n", chan); + rc = 0; + goto out; + } + if (IPMI_LANP_IS_VLAN_VALID(id)) { lprintf(LOG_ERR, - "Retrieved VLAN ID %i is out of range <1..4094>.", - id); - return (-1); + "Retrieved VLAN ID %i is out of " + "range <%d..%d>.", + id, + IPMI_LANP_VLAN_ID_MIN, + IPMI_LANP_VLAN_ID_MAX); + goto out; } data[0] = p->data[0]; data[1] = p->data[1] & 0x0F; @@ -1227,13 +1236,18 @@ ipmi_lan_set_vlan_id(struct ipmi_intf *intf, uint8_t chan, char *string) else { int id = 0; if (str2int(string, &id) != 0) { - lprintf(LOG_ERR, "Given VLAN ID '%s' is invalid.", string); - return (-1); + lprintf(LOG_ERR, + "Given VLAN ID '%s' is invalid.", + string); + goto out; } - if (id < 1 || id > 4094) { - lprintf(LOG_NOTICE, "VLAN ID must be between 1 and 4094."); - return (-1); + if (IPMI_LANP_IS_VLAN_VALID(id)) { + lprintf(LOG_NOTICE, + "VLAN ID must be between %d and %d.", + IPMI_LANP_VLAN_ID_MIN, + IPMI_LANP_VLAN_ID_MAX); + goto out; } else { data[0] = (uint8_t)id; @@ -1241,6 +1255,8 @@ ipmi_lan_set_vlan_id(struct ipmi_intf *intf, uint8_t chan, char *string) } } rc = set_lan_param(intf, chan, IPMI_LANP_VLAN_ID, data, 2); + +out: return rc; } |