From aff85bf3b24809891859b73a0843e992ee3f158a Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sat, 17 Dec 2011 17:09:43 +0100 Subject: [PATCH] cdp: allow reception of native vlan --- CHANGELOG | 4 ++++ src/cdp.c | 27 +++++++++++++++++++++++++++ src/cdp.h | 3 ++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 1a1e9d01..a6816e3b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +lldpd (0.5.6) + * Features: + + Parse CDP native VLAN TLV. + lldpd (0.5.5) * Features: + Support for PPVID and PI Dot1 TLV, thanks to Shuah Khan. diff --git a/src/cdp.c b/src/cdp.c index af4e552c..f71a36f3 100644 --- a/src/cdp.c +++ b/src/cdp.c @@ -20,6 +20,7 @@ #if defined (ENABLE_CDP) || defined (ENABLE_FDP) +#include #include #include #include @@ -209,6 +210,9 @@ cdp_decode(struct lldpd *cfg, char *frame, int s, #endif u_int8_t *pos, *tlv, *pos_address, *pos_next_address; int length, len_eth, tlv_type, tlv_len, addresses_len, address_len; +#ifdef ENABLE_DOT1 + struct lldpd_vlan *vlan; +#endif if ((chassis = calloc(1, sizeof(struct lldpd_chassis))) == NULL) { LLOG_WARN("failed to allocate remote chassis"); @@ -418,6 +422,29 @@ cdp_decode(struct lldpd *cfg, char *frame, int s, platform_len = tlv_len; PEEK_SAVE(platform); break; +#ifdef ENABLE_DOT1 + case CDP_TLV_NATIVEVLAN: + CHECK_TLV_SIZE(2, "Native VLAN"); + if ((vlan = (struct lldpd_vlan *)calloc(1, + sizeof(struct lldpd_vlan))) == NULL) { + LLOG_WARN("unable to alloc vlan " + "structure for " + "tlv received on %s", + hardware->h_ifname); + goto malformed; + } + vlan->v_vid = port->p_pvid = PEEK_UINT16; + if (asprintf(&vlan->v_name, "VLAN #%d", vlan->v_vid) == -1) { + LLOG_WARN("unable to alloc VLAN name for " + "TLV received on %s", + hardware->h_ifname); + free(vlan); + goto malformed; + } + TAILQ_INSERT_TAIL(&port->p_vlans, + vlan, v_entries); + break; +#endif default: LLOG_DEBUG("unknown CDP/FDP TLV type (%d) received on %s", ntohs(tlv_type), hardware->h_ifname); diff --git a/src/cdp.h b/src/cdp.h index 1fe72c22..bae7f5e2 100644 --- a/src/cdp.h +++ b/src/cdp.h @@ -41,7 +41,8 @@ enum { CDP_TLV_PORT = 3, CDP_TLV_CAPABILITIES = 4, CDP_TLV_SOFTWARE = 5, - CDP_TLV_PLATFORM = 6 + CDP_TLV_PLATFORM = 6, + CDP_TLV_NATIVEVLAN = 10 }; #define CDP_ADDRESS_PROTO_IP 0xcc -- 2.39.5