]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
interfaces: fix setting of local value for port ID
authorVincent Bernat <vincent@bernat.im>
Thu, 9 Jun 2016 16:07:00 +0000 (18:07 +0200)
committerVincent Bernat <vincent@bernat.im>
Thu, 9 Jun 2016 16:07:00 +0000 (18:07 +0200)
This was broken in a403df6662cd506fbf7fee8a46ebbf209142ffd7 (0.9.1). Add
some integration tests to ensure it works as expected.

Fix #183.

NEWS
src/daemon/client.c
src/daemon/interfaces.c
src/lldpd-structs.h
tests/integration/test_basic.py

diff --git a/NEWS b/NEWS
index 1cbcad2445140c7b3fbf297725b3eb6546e3d3d8..bdbafddbf91fd02c8f5a075ce81192bf2dd0600e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@ lldpd (0.9.4)
   * Change:
     + Make lldpd accepts a `-p` option to specify the PID file.
     + lldpcli will now display chassis TTL when detailed view is enabled.
+  * Fix:
+    + Fix setting of local value for port ID.
 
 lldpd (0.9.3)
   * Change:
index 42612402837307bdf67c1790fc151b87bdd1bf05..34d403e2e77e86a79a65e55c43e2079c9854b027 100644 (file)
@@ -327,11 +327,13 @@ _client_handle_set_port(struct lldpd *cfg,
                port->p_id = strdup(set->local_id);
                port->p_id_len = strlen(set->local_id);
                port->p_id_subtype = LLDP_PORTID_SUBTYPE_LOCAL;
+               port->p_descr_force = 0;
        }
        if (set->local_descr) {
                log_debug("rpc", "requested change to Port Description");
                free(port->p_descr);
                port->p_descr = strdup(set->local_descr);
+               port->p_descr_force = 1;
        }
        switch (set->rxtx) {
        case LLDPD_RXTX_TXONLY:
index bc3e41a56520a56bf1afd04821be2d47e92b06ce..cefbec4d3cde87bfadfea4c9ca8981a83e3822b5 100644 (file)
@@ -517,8 +517,8 @@ interfaces_helper_port_name_desc(struct lldpd *cfg,
        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) {
+           (port->p_id_subtype == LLDP_PORTID_SUBTYPE_LOCAL && has_alias)) {
+               if (port->p_id_subtype != LLDP_PORTID_SUBTYPE_LOCAL) {
                        log_debug("interfaces", "use ifname for %s",
                            hardware->h_ifname);
                        port->p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME;
@@ -529,19 +529,21 @@ interfaces_helper_port_name_desc(struct lldpd *cfg,
                        memcpy(port->p_id, hardware->h_ifname, port->p_id_len);
                }
 
-               /* use the actual alias in the port description */
-               log_debug("interfaces", "using alias in description for %s",
-                         hardware->h_ifname);
-               free(port->p_descr);
-               if (has_alias) {
-                       port->p_descr = strdup(iface->alias);
-               } else {
-                       /* We don't have anything else to put here and for CDP
-                        * with need something non-NULL */
-                       port->p_descr = strdup(hardware->h_ifname);
+               if (port->p_descr_force == 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);
+                       if (has_alias) {
+                               port->p_descr = strdup(iface->alias);
+                       } else {
+                               /* We don't have anything else to put here and for CDP
+                                * with need something non-NULL */
+                               port->p_descr = strdup(hardware->h_ifname);
+                       }
                }
        } else {
-               if (portid_type != LLDP_PORTID_SUBTYPE_LOCAL) {
+               if (port->p_id_subtype != LLDP_PORTID_SUBTYPE_LOCAL) {
                        log_debug("interfaces", "use MAC address for %s",
                            hardware->h_ifname);
                        port->p_id_subtype = LLDP_PORTID_SUBTYPE_LLADDR;
@@ -552,11 +554,13 @@ interfaces_helper_port_name_desc(struct lldpd *cfg,
                        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);
-               free(port->p_descr);
-               port->p_descr = strdup(hardware->h_ifname);
+               if (port->p_descr_force == 0) {
+                       /* use the ifname in the port description until alias is set */
+                       log_debug("interfaces", "using ifname in description for %s",
+                           hardware->h_ifname);
+                       free(port->p_descr);
+                       port->p_descr = strdup(hardware->h_ifname);
+               }
        }
 }
 
index 0260ae7ab1d155cd051c2f52297ba92b13b49ac2..4c65db31338aa8d7cde48a405ad87129ea6c726c 100644 (file)
@@ -259,6 +259,7 @@ struct lldpd_port {
        char                    *p_id;
        int                      p_id_len;
        char                    *p_descr;
+       int                      p_descr_force; /* Description has been forced by user */
        u_int16_t                p_mfs;
 
 #ifdef ENABLE_DOT3
index f0043d8540befe4c2248cd1ac45592d5926d4d19..84a81e2096d0c2a2c75358ebeef1dd9320c4c83f 100644 (file)
@@ -88,3 +88,77 @@ def test_management_address(lldpd1, lldpd, lldpcli, links, namespaces):
     with namespaces(1):
         out = lldpcli("-f", "keyvalue", "show", "neighbors")
         assert out["lldp.eth0.chassis.mgmt-ip"] == "172.25.21.47"
+
+
+def test_portid_subtype_ifname(lldpd1, lldpd, lldpcli, namespaces):
+    with namespaces(2):
+        lldpd()
+        result = lldpcli("configure", "lldp", "portidsubtype", "ifname")
+        time.sleep(3)
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.port.ifname"] == "eth1"
+        assert out["lldp.eth0.port.descr"] == "eth1"
+
+
+def test_portid_subtype_with_alias(lldpd1, lldpd, lldpcli, links, namespaces):
+    with namespaces(2):
+        ipr = pyroute2.IPRoute()
+        idx = ipr.link_lookup(ifname="eth1")[0]
+        ipr.link('set', index=idx, ifalias="alias of eth1")
+        lldpd()
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.port.ifname"] == "eth1"
+        assert out["lldp.eth0.port.descr"] == "alias of eth1"
+
+
+def test_portid_subtype_macaddress(lldpd1, lldpd, lldpcli, links, namespaces):
+    with namespaces(2):
+        ipr = pyroute2.IPRoute()
+        idx = ipr.link_lookup(ifname="eth1")[0]
+        ipr.link('set', index=idx, ifalias="alias of eth1")
+        lldpd()
+        result = lldpcli("configure", "lldp", "portidsubtype", "macaddress")
+        time.sleep(3)
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.port.mac"] == "00:00:00:00:00:02"
+        assert out["lldp.eth0.port.descr"] == "eth1"
+
+
+def test_portid_subtype_local(lldpd1, lldpd, lldpcli, namespaces):
+    with namespaces(2):
+        lldpd()
+        result = lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
+        time.sleep(3)
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.port.local"] == "localname"
+        assert out["lldp.eth0.port.descr"] == "eth1"
+
+
+def test_portid_subtype_local_with_description(lldpd1, lldpd, lldpcli, namespaces):
+    with namespaces(2):
+        lldpd()
+        result = lldpcli("configure", "lldp", "portidsubtype", "local", "localname", "description", "localdescription")
+        time.sleep(3)
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.port.local"] == "localname"
+        assert out["lldp.eth0.port.descr"] == "localdescription"
+
+
+def test_portid_subtype_local_with_alias(lldpd1, lldpd, lldpcli, namespaces):
+    with namespaces(2):
+        ipr = pyroute2.IPRoute()
+        idx = ipr.link_lookup(ifname="eth1")[0]
+        ipr.link('set', index=idx, ifalias="alias of eth1")
+        lldpd()
+        lldpd()
+        result = lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
+        time.sleep(3)
+    with namespaces(1):
+        out = lldpcli("-f", "keyvalue", "show", "neighbors")
+        assert out["lldp.eth0.port.local"] == "localname"
+        assert out["lldp.eth0.port.descr"] == "alias of eth1"