From 09b95cb62f566362f458a7d8681b4ebe20fd84bd Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Tue, 16 Aug 2022 18:31:06 +0200 Subject: [PATCH] protocol/lldp: accept unknown TLVs on known orgs Fix #532 --- NEWS | 1 + src/daemon/protocols/lldp.c | 17 +++++++++++------ tests/integration/test_custom.py | 7 ++++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index c36aa292..ee9c8851 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ lldpd (1.0.15) * Changes + Add configure command to override system capabilities. Contributed by Ignacio Sanchez Navarro. (#526) + + An unrecognized ORG TLV is now considered as a custom one. (#536) * Fix: + Really don't send VLANs when there are too many (#520) + Ignore temporary IPv6 addresses (#521) diff --git a/src/daemon/protocols/lldp.c b/src/daemon/protocols/lldp.c index 81397aaf..032f28e7 100644 --- a/src/daemon/protocols/lldp.c +++ b/src/daemon/protocols/lldp.c @@ -669,6 +669,7 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, u_int8_t addr_str_length, addr_str_buffer[32]; u_int8_t addr_family, addr_length, *addr_ptr, iface_subtype; u_int32_t iface_number, iface; + int unrecognized; #ifdef ENABLE_CUSTOM struct lldpd_custom *custom = NULL; #endif @@ -897,10 +898,11 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, case LLDP_TLV_ORG: CHECK_TLV_SIZE(1 + (int)sizeof(orgid), "Organisational"); PEEK_BYTES(orgid, sizeof(orgid)); + unrecognized = 0; tlv_subtype = PEEK_UINT8; if (memcmp(dot1, orgid, sizeof(orgid)) == 0) { #ifndef ENABLE_DOT1 - hardware->h_rx_unrecognized_cnt++; + unrecognized = 1; #else /* Dot1 */ switch (tlv_subtype) { @@ -986,12 +988,12 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, break; default: /* Unknown Dot1 TLV, ignore it */ - hardware->h_rx_unrecognized_cnt++; + unrecognized = 1; } #endif } else if (memcmp(dot3, orgid, sizeof(orgid)) == 0) { #ifndef ENABLE_DOT3 - hardware->h_rx_unrecognized_cnt++; + unrecognized = 1; #else /* Dot3 */ switch (tlv_subtype) { @@ -1077,13 +1079,13 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, break; default: /* Unknown Dot3 TLV, ignore it */ - hardware->h_rx_unrecognized_cnt++; + unrecognized = 1; } #endif } else if (memcmp(med, orgid, sizeof(orgid)) == 0) { /* LLDP-MED */ #ifndef ENABLE_LLDPMED - hardware->h_rx_unrecognized_cnt++; + unrecognized = 1; #else u_int32_t policy; unsigned loctype; @@ -1277,11 +1279,14 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, } else if (memcmp(dcbx, orgid, sizeof(orgid)) == 0) { log_debug("lldp", "unsupported DCBX tlv received on %s - ignore", hardware->h_ifname); - hardware->h_rx_unrecognized_cnt++; + unrecognized = 1; } else { log_debug("lldp", "unknown org tlv [%02x:%02x:%02x] received on %s", orgid[0], orgid[1], orgid[2], hardware->h_ifname); + unrecognized = 1; + } + if (unrecognized) { hardware->h_rx_unrecognized_cnt++; #ifdef ENABLE_CUSTOM custom = (struct lldpd_custom*)calloc(1, sizeof(struct lldpd_custom)); diff --git a/tests/integration/test_custom.py b/tests/integration/test_custom.py index a2d6dc79..f01f0ea1 100644 --- a/tests/integration/test_custom.py +++ b/tests/integration/test_custom.py @@ -49,7 +49,12 @@ import time (["oui 33,44,55 subtype 44 oui-info 45,45,45,45,45", "add oui 33,44,55 subtype 55 oui-info 65,65,65,65,65", "-"], - {})]) + {}), + (["oui 00,80,c2 subtype 18 oui-info 45,45,45,45,45"], + {'unknown-tlv.oui': '00,80,C2', + 'unknown-tlv.subtype': '18', + 'unknown-tlv.len': '5', + 'unknown-tlv': '45,45,45,45,45'})]) def test_custom_tlv(lldpd1, lldpd, lldpcli, namespaces, commands, expected): with namespaces(2): -- 2.39.5