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;
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;
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);
+ }
}
}
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"