]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
interfaces: fix alias handling
authorVincent Bernat <vincent@bernat.im>
Thu, 4 Feb 2016 19:25:59 +0000 (20:25 +0100)
committerVincent Bernat <vincent@bernat.im>
Thu, 4 Feb 2016 20:12:50 +0000 (21:12 +0100)
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.

NEWS
src/client/conf-lldp.c
src/daemon/interfaces.c
tests/R1.expected
tests/integration-tests.in

diff --git a/NEWS b/NEWS
index 558871afb03c298bfeea1397e51cc62cb4fe1adf..09481141a3fef48fac35d3cc51014d404055a3f9 100644 (file)
--- 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:
index 10cf5dd4852ad356c9e712419662416b1a9c412a..275a485518b38d8478521a15f977f6ee5e2c4a85 100644 (file)
@@ -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(
index ec817213eb9b17555d08f302f702ac3266782c07..009a578472731cd318872acff3da1874754886d0 100644 (file)
@@ -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);
index fc346a90551a64fae05ad102f30aaeabece8d744..bb05a239d3748b57c323e79a8070db0405b5fc7d 100644 (file)
@@ -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
index 6838ef02a060cfe34bdfcd59a37fa4d291a3e5f6..54d28b30dbee33edc4a43e1c9cbd659f2f5ac958 100755 (executable)
@@ -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