From 75b3469d012e36628f374d0911fa0aad07539bdc Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Tue, 16 Dec 2008 17:34:02 +0100 Subject: [PATCH] Handle reception and display of PVID --- src/agent.c | 18 ++++++++++++++++++ src/lldp.c | 23 +++++++++++++++++------ src/lldpctl.c | 4 +++- src/lldpd.h | 3 ++- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/agent.c b/src/agent.c index 6a779700..86e425b8 100644 --- a/src/agent.c +++ b/src/agent.c @@ -326,6 +326,7 @@ header_tprvindexed_table(struct variable *vp, oid *name, size_t *length, #define LLDP_SNMP_LOCAL_DOT3_AGG_STATUS 9 #define LLDP_SNMP_LOCAL_DOT3_AGG_ID 10 #define LLDP_SNMP_LOCAL_DOT3_MFS 11 +#define LLDP_SNMP_LOCAL_DOT1_PVID 12 /* Remote ports */ #define LLDP_SNMP_REMOTE_CIDSUBTYPE 1 #define LLDP_SNMP_REMOTE_CID 2 @@ -343,6 +344,7 @@ header_tprvindexed_table(struct variable *vp, oid *name, size_t *length, #define LLDP_SNMP_REMOTE_DOT3_AGG_STATUS 14 #define LLDP_SNMP_REMOTE_DOT3_AGG_ID 15 #define LLDP_SNMP_REMOTE_DOT3_MFS 16 +#define LLDP_SNMP_REMOTE_DOT1_PVID 17 /* Local vlans */ #define LLDP_SNMP_LOCAL_DOT1_VLANNAME 1 /* Remote vlans */ @@ -862,6 +864,11 @@ agent_h_local_port(struct variable *vp, oid *name, size_t *length, case LLDP_SNMP_LOCAL_DOT3_MFS: long_ret = hardware->h_lport.p_mfs; return (u_char *)&long_ret; +#endif +#ifdef ENABLE_DOT1 + case LLDP_SNMP_LOCAL_DOT1_PVID: + long_ret = hardware->h_lport.p_pvid; /* Should always be 0 */ + return (u_char *)&long_ret; #endif default: break; @@ -976,6 +983,11 @@ agent_h_remote_port(struct variable *vp, oid *name, size_t *length, case LLDP_SNMP_REMOTE_DOT3_MFS: long_ret = hardware->h_rport->p_mfs; return (u_char *)&long_ret; +#endif +#ifdef ENABLE_DOT1 + case LLDP_SNMP_REMOTE_DOT1_PVID: + long_ret = hardware->h_rport->p_pvid; + return (u_char *)&long_ret; #endif default: break; @@ -1114,6 +1126,10 @@ static struct variable8 lldp_vars[] = { {1, 5, 4623, 1, 2, 3, 1, 2}}, {LLDP_SNMP_LOCAL_DOT3_MFS, ASN_INTEGER, RONLY, agent_h_local_port, 8, {1, 5, 4623, 1, 2, 4, 1, 1}}, +#endif +#ifdef ENABLE_DOT1 + {LLDP_SNMP_LOCAL_DOT1_PVID, ASN_INTEGER, RONLY, agent_h_local_port, 8, + {1, 5, 32962, 1, 2, 1, 1, 1}}, #endif /* Remote ports */ {LLDP_SNMP_REMOTE_CIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_remote_port, 5, {1, 4, 1, 1, 4}}, @@ -1142,6 +1158,8 @@ static struct variable8 lldp_vars[] = { {1, 5, 4623, 1, 3, 4, 1, 1}}, #endif #ifdef ENABLE_DOT1 + {LLDP_SNMP_REMOTE_DOT1_PVID, ASN_INTEGER, RONLY, agent_h_remote_port, 8, + {1, 5, 32962, 1, 3, 1, 1, 1}}, /* Local vlans */ {LLDP_SNMP_LOCAL_DOT1_VLANNAME, ASN_OCTET_STR, RONLY, agent_h_local_vlan, 8, {1, 5, 32962, 1, 2, 3, 1, 2}}, diff --git a/src/lldp.c b/src/lldp.c index 5d406ca6..d47d489b 100644 --- a/src/lldp.c +++ b/src/lldp.c @@ -410,6 +410,8 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, int size, type, subtype; /* TLV header */ char *b; int gotend = 0; + struct lldpd_vlan *vlan; + int vlan_len; if ((chassis = calloc(1, sizeof(struct lldpd_chassis))) == NULL) { LLOG_WARN("failed to allocate remote chassis"); @@ -572,11 +574,8 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, hardware->h_rx_unrecognized_cnt++; #else /* Dot1 */ - if ((*(u_int8_t*)(frame + f + 3)) == - LLDP_TLV_DOT1_VLANNAME) { - struct lldpd_vlan *vlan; - int vlan_len; - + switch (*(u_int8_t*)(frame + f + 3)) { + case LLDP_TLV_DOT1_VLANNAME: if ((size < 7) || (size < 7 + *(u_int8_t*)(frame + f + 6))) { LLOG_WARNX("too short vlan tlv " @@ -609,7 +608,19 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, TAILQ_INSERT_TAIL(&port->p_vlans, vlan, v_entries); f += size - 7; - } else { + break; + case LLDP_TLV_DOT1_PVID: + if (size < 6) { + LLOG_WARNX("too short pvid tlv " + "received on %s", + hardware->h_ifname); + goto malformed; + } + port->p_pvid = + ntohs(*(u_int16_t*)(frame + f + 4)); + f += size; + break; + default: /* Unknown Dot1 TLV, ignore it */ f += size; hardware->h_rx_unrecognized_cnt++; diff --git a/src/lldpctl.c b/src/lldpctl.c index 608637a6..5ce76710 100644 --- a/src/lldpctl.c +++ b/src/lldpctl.c @@ -756,7 +756,9 @@ display_vlans(struct lldpd_port *port) int i = 0; struct lldpd_vlan *vlan; TAILQ_FOREACH(vlan, &port->p_vlans, v_entries) - printf(" VLAN %4d: %-20s%c", vlan->v_vid, vlan->v_name, + printf(" %cVLAN %4d: %-20s%c", + (port->p_pvid == vlan->v_vid)?'*':' ', + vlan->v_vid, vlan->v_name, (i++ % 2) ? '\n' : ' '); if (i % 2) printf("\n"); diff --git a/src/lldpd.h b/src/lldpd.h index 3e437a55..36bc0b5a 100644 --- a/src/lldpd.h +++ b/src/lldpd.h @@ -160,7 +160,8 @@ struct lldpd_port { #endif #ifdef ENABLE_DOT1 -#define STRUCT_LLDPD_PORT_DOT1 "PP" +#define STRUCT_LLDPD_PORT_DOT1 "wPP" + u_int16_t p_pvid; TAILQ_HEAD(, lldpd_vlan) p_vlans; #else #define STRUCT_LLDPD_PORT_DOT1 "" -- 2.39.5