From: Vincent Bernat Date: Thu, 4 Feb 2016 19:25:59 +0000 (+0100) Subject: interfaces: fix alias handling X-Git-Tag: 0.9.1~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a403df6662cd506fbf7fee8a46ebbf209142ffd7;p=thirdparty%2Flldpd.git interfaces: fix alias handling And try to add some simple tests for them. The manual page says that if an alias is provided, the default is to use the alias as description and port name as port ID. We try to respect that. The tests are not as complete as they could be because the MSAP changes due to the port ID change and this makes tests more complex. --- diff --git a/NEWS b/NEWS index 558871af..09481141 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,9 @@ lldpd (0.9.1) + Rework packaging for OS X to make it work with El Capitan. To simplify a bit, it is not possible anymore to build fat binaries. Latest version of OS X supporting 32bit was 10.6. + * Fix: + + By default, when using port alias as description, use port name + as port ID. lldpd (0.9.0) * Change: diff --git a/src/client/conf-lldp.c b/src/client/conf-lldp.c index 10cf5dd4..275a4855 100644 --- a/src/client/conf-lldp.c +++ b/src/client/conf-lldp.c @@ -426,7 +426,7 @@ register_commands_configure_lldp(struct cmd_node *configure, NULL, NULL, NULL); for (lldpctl_map_t *b_map = - lldpctl_key_get_map(lldpctl_k_config_lldp_portid_type); + lldpctl_key_get_map(lldpctl_k_config_lldp_portid_type); b_map->string; b_map++) { if (!strcmp(b_map->string, "ifname")) { commands_new( diff --git a/src/daemon/interfaces.c b/src/daemon/interfaces.c index ec817213..009a5784 100644 --- a/src/daemon/interfaces.c +++ b/src/daemon/interfaces.c @@ -499,43 +499,44 @@ interfaces_helper_port_name_desc(struct lldpd *cfg, { struct lldpd_port *port = &hardware->h_lport; - if (port->p_id_subtype == LLDP_PORTID_SUBTYPE_LOCAL) - return; - /* We need to set the portid to what the client configured. This can be done from the CLI. */ - switch (cfg->g_config.c_lldp_portid_type) { - case LLDP_PORTID_SUBTYPE_IFNAME: - log_debug("interfaces", "use ifname for %s", - hardware->h_ifname); - port->p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME; - port->p_id_len = strlen(hardware->h_ifname); - free(port->p_id); - if ((port->p_id = calloc(1, port->p_id_len)) == NULL) - fatal("interfaces", NULL); - memcpy(port->p_id, hardware->h_ifname, port->p_id_len); - break; - case LLDP_PORTID_SUBTYPE_LLADDR: - /* fall through so we use the mac address */ - default: - log_debug("interfaces", "use MAC address for %s", - hardware->h_ifname); - port->p_id_subtype = LLDP_PORTID_SUBTYPE_LLADDR; - free(port->p_id); - if ((port->p_id = calloc(1, ETHER_ADDR_LEN)) == NULL) - fatal("interfaces", NULL); - memcpy(port->p_id, hardware->h_lladdr, ETHER_ADDR_LEN); - port->p_id_len = ETHER_ADDR_LEN; - } + int has_alias = (iface->alias != NULL && strlen(iface->alias) != 0); + int portid_type = cfg->g_config.c_lldp_portid_type; + if (portid_type == LLDP_PORTID_SUBTYPE_IFNAME || + (portid_type == LLDP_PORTID_SUBTYPE_UNKNOWN && has_alias) || + (portid_type == LLDP_PORTID_SUBTYPE_LOCAL && has_alias)) { + if (portid_type != LLDP_PORTID_SUBTYPE_LOCAL) { + log_debug("interfaces", "use ifname for %s", + hardware->h_ifname); + port->p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME; + port->p_id_len = strlen(hardware->h_ifname); + free(port->p_id); + if ((port->p_id = calloc(1, port->p_id_len)) == NULL) + fatal("interfaces", NULL); + memcpy(port->p_id, hardware->h_ifname, port->p_id_len); + } - if (iface->alias != NULL && strlen(iface->alias) != 0) { /* use the actual alias in the port description */ log_debug("interfaces", "using alias in description for %s", hardware->h_ifname); free(port->p_descr); - port->p_descr = strdup(iface->alias); + if (has_alias) { + port->p_descr = strdup(iface->alias); + } } else { + if (portid_type != LLDP_PORTID_SUBTYPE_LOCAL) { + log_debug("interfaces", "use MAC address for %s", + hardware->h_ifname); + port->p_id_subtype = LLDP_PORTID_SUBTYPE_LLADDR; + free(port->p_id); + if ((port->p_id = calloc(1, ETHER_ADDR_LEN)) == NULL) + fatal("interfaces", NULL); + memcpy(port->p_id, hardware->h_lladdr, ETHER_ADDR_LEN); + port->p_id_len = ETHER_ADDR_LEN; + } + /* use the ifname in the port description until alias is set */ log_debug("interfaces", "using ifname in description for %s", hardware->h_ifname); diff --git a/tests/R1.expected b/tests/R1.expected index fc346a90..bb05a239 100644 --- a/tests/R1.expected +++ b/tests/R1.expected @@ -76,8 +76,8 @@ Interface: iface2, via: LLDP, RID: 1, Time: 0 day Capability: Wlan, off Capability: Station, on Port: - PortID: mac 50:54:0e:ec:6e:77 - PortDescr: iface2 + PortID: ifname iface2 + PortDescr: SecondInterface LLDP-MED: Device Type: Media Endpoint (Class II) Capability: Capabilities @@ -199,8 +199,8 @@ Interface: iface2, via: LLDP, RID: 1, Time: 0 day Capability: Wlan, off Capability: Station, on Port: - PortID: mac 50:54:0e:ec:6e:77 - PortDescr: iface2 + PortID: ifname iface2 + PortDescr: SecondInterface VLAN: 450 iface2.450 VLAN: 451 iface2.451 VLAN: 452 iface2.452 @@ -236,8 +236,8 @@ Interface: iface2, via: LLDP, RID: 1, Time: 0 day Capability: Wlan, off Capability: Station, on Port: - PortID: mac 50:54:0e:ec:6e:77 - PortDescr: iface2 + PortID: ifname iface2 + PortDescr: SecondInterface VLAN: 450 iface2.450 VLAN: 452 iface2.452 LLDP-MED: @@ -415,8 +415,8 @@ Interface: iface2, via: LLDP, RID: 1, Time: 0 day Capability: Wlan, off Capability: Station, off Port: - PortID: mac 50:54:0e:ec:6e:77 - PortDescr: iface2 + PortID: ifname iface2 + PortDescr: SecondInterface MDI Power: supported: yes, enabled: yes, pair control: yes Device type: PSE Power pairs: spare @@ -463,8 +463,8 @@ Interface: iface2, via: LLDP, RID: 1, Time: 0 day Capability: Wlan, off Capability: Station, off Port: - PortID: mac 50:54:0e:ec:6e:77 - PortDescr: iface2 + PortID: ifname iface2 + PortDescr: SecondInterface MDI Power: supported: yes, enabled: yes, pair control: yes Device type: PSE Power pairs: spare diff --git a/tests/integration-tests.in b/tests/integration-tests.in index 6838ef02..54d28b30 100755 --- a/tests/integration-tests.in +++ b/tests/integration-tests.in @@ -272,6 +272,8 @@ process_commands() { } start_tests() { + # Set the environment + run R2 ip link set dev iface2 alias "SecondInterface" # Start lldpd on each VM run R1 ./libtool execute src/daemon/lldpd -M 1 -L \$PWD/src/client/lldpcli run R2 ./libtool execute src/daemon/lldpd -M 2 -L \$PWD/src/client/lldpcli