From a1347cd86b433177f39b36950e7e3fbc98367666 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 26 Nov 2008 19:21:06 +0100 Subject: [PATCH] Add a way to disable Dot1 and Dot3 --- configure.ac | 24 ++++++++++++++++++++++++ src/agent.c | 16 ++++++++++++++++ src/cdp.c | 4 ++++ src/client.c | 4 ++++ src/edp.c | 32 ++++++++++++++++++++++++++++++-- src/lldp.c | 41 +++++++++++++++++++++++++++++++++++------ src/lldpctl.c | 18 ++++++++++++++++++ src/lldpd.c | 29 +++++++++++++++++++++++++++-- src/lldpd.h | 28 ++++++++++++++++++++++++---- src/sonmp.c | 2 ++ 10 files changed, 184 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 806a83bc..c723c10f 100644 --- a/configure.ac +++ b/configure.ac @@ -148,4 +148,28 @@ else AC_MSG_RESULT(no) fi +#Dot1 +AC_ARG_ENABLE(dot1, AC_HELP_STRING([--enable-dot1], + [Enable LLDP Dot1 extension]), + [enable_dot1=$enableval],[enable_dot1=yes]) +AC_MSG_CHECKING(whether to enable Dot1) +if test x$enable_dot1 = xyes; then + AC_MSG_RESULT(yes) + AC_DEFINE([ENABLE_DOT1],, [Enable LLDP Dot1 extension]) +else + AC_MSG_RESULT(no) +fi + +#Dot3 +AC_ARG_ENABLE(dot3, AC_HELP_STRING([--enable-dot3], + [Enable LLDP Dot3 extension]), + [enable_dot3=$enableval],[enable_dot3=yes]) +AC_MSG_CHECKING(whether to enable Dot3) +if test x$enable_dot3 = xyes; then + AC_MSG_RESULT(yes) + AC_DEFINE([ENABLE_DOT3],, [Enable LLDP Dot3 extension]) +else + AC_MSG_RESULT(no) +fi + AC_OUTPUT diff --git a/src/agent.c b/src/agent.c index b400a9b3..512410cb 100644 --- a/src/agent.c +++ b/src/agent.c @@ -144,6 +144,7 @@ header_tprindexed_table(struct variable *vp, oid *name, size_t *length, return phardware; } +#ifdef ENABLE_DOT1 struct lldpd_vlan* header_pvindexed_table(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) @@ -249,6 +250,7 @@ header_tprvindexed_table(struct variable *vp, oid *name, size_t *length, return pvlan; } +#endif /* Scalars */ #define LLDP_SNMP_TXINTERVAL 1 @@ -588,7 +590,9 @@ static u_char* agent_h_local_port(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { +#ifdef ENABLE_DOT3 static uint8_t bit; +#endif struct lldpd_hardware *hardware; static unsigned long long_ret; @@ -606,6 +610,7 @@ agent_h_local_port(struct variable *vp, oid *name, size_t *length, case LLDP_SNMP_LOCAL_PORTDESC: *var_len = strlen(hardware->h_lport.p_descr); return (u_char *)hardware->h_lport.p_descr; +#ifdef ENABLE_DOT3 case LLDP_SNMP_LOCAL_DOT3_AUTONEG_SUPPORT: long_ret = 2 - hardware->h_lport.p_autoneg_support; return (u_char *)&long_ret; @@ -625,12 +630,14 @@ agent_h_local_port(struct variable *vp, oid *name, size_t *length, case LLDP_SNMP_LOCAL_DOT3_AGG_ID: long_ret = hardware->h_lport.p_aggregid; return (u_char *)&long_ret; +#endif default: break; } return NULL; } +#ifdef ENABLE_DOT1 static u_char* agent_h_local_vlan(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) @@ -670,6 +677,7 @@ agent_h_remote_vlan(struct variable *vp, oid *name, size_t *length, } return NULL; } +#endif static u_char* agent_h_remote_port(struct variable *vp, oid *name, size_t *length, @@ -713,6 +721,7 @@ agent_h_remote_port(struct variable *vp, oid *name, size_t *length, *var_len = 1; bit = swap_bits(hardware->h_rchassis->c_cap_enabled); return (u_char *)&bit; +#ifdef ENABLE_DOT3 case LLDP_SNMP_REMOTE_DOT3_AUTONEG_SUPPORT: long_ret = 2 - hardware->h_rport->p_autoneg_support; return (u_char *)&long_ret; @@ -732,6 +741,7 @@ agent_h_remote_port(struct variable *vp, oid *name, size_t *length, case LLDP_SNMP_REMOTE_DOT3_AGG_ID: long_ret = hardware->h_rport->p_aggregid; return (u_char *)&long_ret; +#endif default: break; } @@ -854,6 +864,7 @@ static struct variable8 lldp_vars[] = { {LLDP_SNMP_LOCAL_PIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_local_port, 5, {1, 3, 7, 1, 2}}, {LLDP_SNMP_LOCAL_PID, ASN_OCTET_STR, RONLY, agent_h_local_port, 5, {1, 3, 7, 1, 3}}, {LLDP_SNMP_LOCAL_PORTDESC, ASN_OCTET_STR, RONLY, agent_h_local_port, 5, {1, 3, 7, 1, 4}}, +#ifdef ENABLE_DOT3 {LLDP_SNMP_LOCAL_DOT3_AUTONEG_SUPPORT, ASN_INTEGER, RONLY, agent_h_local_port, 8, {1, 5, 4623, 1, 2, 1, 1, 1}}, {LLDP_SNMP_LOCAL_DOT3_AUTONEG_ENABLED, ASN_INTEGER, RONLY, agent_h_local_port, 8, @@ -866,6 +877,7 @@ static struct variable8 lldp_vars[] = { {1, 5, 4623, 1, 2, 3, 1, 1}}, {LLDP_SNMP_LOCAL_DOT3_AGG_ID, ASN_INTEGER, RONLY, agent_h_local_port, 8, {1, 5, 4623, 1, 2, 3, 1, 2}}, +#endif /* Remote ports */ {LLDP_SNMP_REMOTE_CIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_remote_port, 5, {1, 4, 1, 1, 4}}, {LLDP_SNMP_REMOTE_CID, ASN_OCTET_STR, RONLY, agent_h_remote_port, 5, {1, 4, 1, 1, 5}}, @@ -876,6 +888,7 @@ static struct variable8 lldp_vars[] = { {LLDP_SNMP_REMOTE_SYSDESC, ASN_OCTET_STR, RONLY, agent_h_remote_port, 5, {1, 4, 1, 1, 10}}, {LLDP_SNMP_REMOTE_SYSCAP_SUP, ASN_OCTET_STR, RONLY, agent_h_remote_port, 5, {1, 4, 1, 1, 11}}, {LLDP_SNMP_REMOTE_SYSCAP_ENA, ASN_OCTET_STR, RONLY, agent_h_remote_port, 5, {1, 4, 1, 1, 12}}, +#ifdef ENABLE_DOT3 {LLDP_SNMP_REMOTE_DOT3_AUTONEG_SUPPORT, ASN_INTEGER, RONLY, agent_h_remote_port, 8, {1, 5, 4623, 1, 3, 1, 1, 1}}, {LLDP_SNMP_REMOTE_DOT3_AUTONEG_ENABLED, ASN_INTEGER, RONLY, agent_h_remote_port, 8, @@ -888,12 +901,15 @@ static struct variable8 lldp_vars[] = { {1, 5, 4623, 1, 3, 3, 1, 1}}, {LLDP_SNMP_REMOTE_DOT3_AGG_ID, ASN_INTEGER, RONLY, agent_h_remote_port, 8, {1, 5, 4623, 1, 3, 3, 1, 2}}, +#endif +#ifdef ENABLE_DOT1 /* Local vlans */ {LLDP_SNMP_LOCAL_DOT1_VLANNAME, ASN_OCTET_STR, RONLY, agent_h_local_vlan, 8, {1, 5, 32962, 1, 2, 3, 1, 2}}, /* Remote vlans */ {LLDP_SNMP_REMOTE_DOT1_VLANNAME, ASN_OCTET_STR, RONLY, agent_h_remote_vlan, 8, {1, 5, 32962, 1, 3, 3, 1, 2}}, +#endif /* Management address */ {LLDP_SNMP_LOCAL_ADDR_LEN, ASN_INTEGER, RONLY, agent_h_local_management, 5, {1, 3, 8, 1, 3}}, diff --git a/src/cdp.c b/src/cdp.c index ef205793..e5762313 100644 --- a/src/cdp.c +++ b/src/cdp.c @@ -211,7 +211,9 @@ cdp_decode(struct lldpd *cfg, char *frame, int s, free(chassis); return -1; } +#ifdef ENABLE_DOT1 TAILQ_INIT(&port->p_vlans); +#endif if (s < sizeof(struct ethllc) + sizeof(struct cdp_header)) { LLOG_WARNX("too short frame received on %s", hardware->h_ifname); @@ -445,7 +447,9 @@ malformed: free(chassis); free(port->p_id); free(port->p_descr); +#ifdef ENABLE_DOT1 lldpd_vlan_cleanup(port); +#endif free(port); return -1; } diff --git a/src/client.c b/src/client.c index e7377775..a4ea111d 100644 --- a/src/client.c +++ b/src/client.c @@ -21,7 +21,9 @@ struct client_handle client_handles[] = { { HMSG_GET_INTERFACES, client_handle_get_interfaces }, { HMSG_GET_CHASSIS, client_handle_get_port_related }, { HMSG_GET_PORT, client_handle_get_port_related }, +#ifdef ENABLE_DOT1 { HMSG_GET_VLANS, client_handle_get_port_related }, +#endif { HMSG_SHUTDOWN, client_handle_shutdown }, { 0, NULL } }; @@ -146,6 +148,7 @@ client_handle_get_port_related(struct lldpd *cfg, struct hmsg *r, struct hmsg *s } p = &s->data; switch (r->hdr.type) { +#ifdef ENABLE_DOT1 case HMSG_GET_VLANS: if (ctl_msg_pack_list(STRUCT_LLDPD_VLAN, &hardware->h_rport->p_vlans, @@ -156,6 +159,7 @@ client_handle_get_port_related(struct lldpd *cfg, struct hmsg *r, struct hmsg *s return; } break; +#endif case HMSG_GET_PORT: if (ctl_msg_pack_structure(STRUCT_LLDPD_PORT, hardware->h_rport, diff --git a/src/edp.c b/src/edp.c index 8e403b17..aca278a9 100644 --- a/src/edp.c +++ b/src/edp.c @@ -34,13 +34,16 @@ edp_send(struct lldpd *global, struct lldpd_chassis *chassis, const u_int8_t mcastaddr[] = EDP_MULTICAST_ADDR; const u_int8_t llcorg[] = LLC_ORG_EXTREME; struct iovec *iov = NULL; +#ifdef ENABLE_DOT1 struct edp_tlv_vlan *ovlan = NULL; struct lldpd_vlan *vlan; + unsigned int state = 0; +#endif struct edp_tlv_head device; struct edp_tlv_head null; struct edp_tlv_info info; u_int8_t edp_fakeversion[] = {7, 6, 4, 99}; - unsigned int i, c, v, len, state = 0; + unsigned int i, c, v, len; /* Subsequent XXX can be replaced by other values. We place them here to ensure the position of "" to be a bit invariant with version changes. */ @@ -51,9 +54,11 @@ edp_send(struct lldpd *global, struct lldpd_chassis *chassis, sizeof(struct iovec))) == NULL) \ fatal(NULL); +#ifdef ENABLE_DOT1 while (state != 2) { free(iov); iov = NULL; free(ovlan); ovlan = NULL; +#endif c = v = -1; /* Ether + LLC */ @@ -84,8 +89,10 @@ edp_send(struct lldpd *global, struct lldpd_chassis *chassis, iov[c].iov_base = &eh; iov[c].iov_len = sizeof(eh); +#ifdef ENABLE_DOT1 switch (state) { case 0: +#endif /* Display TLV */ memset(&device, 0, sizeof(device)); device.tlv_marker = EDP_TLV_MARKER; @@ -121,6 +128,7 @@ edp_send(struct lldpd *global, struct lldpd_chassis *chassis, IOV_NEW; iov[c].iov_base = &info; iov[c].iov_len = sizeof(info); +#ifdef ENABLE_DOT1 break; case 1: v = 0; @@ -157,6 +165,7 @@ edp_send(struct lldpd *global, struct lldpd_chassis *chassis, if ((state == 1) && (v == -1)) /* No VLAN, no need to send another TLV */ break; +#endif /* Null TLV */ memset(&null, 0, sizeof(null)); @@ -184,16 +193,22 @@ edp_send(struct lldpd *global, struct lldpd_chassis *chassis, hardware->h_raw, iov, c) == -1) { LLOG_WARN("unable to send packet on real device for %s", hardware->h_ifname); +#ifdef ENABLE_DOT1 free(ovlan); +#endif free(iov); return ENETDOWN; } - + +#ifdef ENABLE_DOT1 state++; } +#endif hardware->h_tx_cnt++; +#ifdef ENABLE_DOT1 free(ovlan); +#endif free(iov); return 0; @@ -210,8 +225,10 @@ edp_decode(struct lldpd *cfg, char *frame, int s, struct edp_header *eh; struct edp_tlv_head *tlv; struct edp_tlv_info *info; +#ifdef ENABLE_DOT1 struct edp_tlv_vlan *vlan; struct lldpd_vlan *lvlan, *lvlan_next; +#endif const unsigned char edpaddr[] = EDP_MULTICAST_ADDR; struct iovec iov; int f, len, gotend = 0, gotvlans = 0; @@ -225,7 +242,9 @@ edp_decode(struct lldpd *cfg, char *frame, int s, free(chassis); return -1; } +#ifdef ENABLE_DOT1 TAILQ_INIT(&port->p_vlans); +#endif if (s < sizeof(struct ethllc) + sizeof(struct edp_header)) { LLOG_WARNX("too short frame received on %s", hardware->h_ifname); @@ -364,6 +383,7 @@ edp_decode(struct lldpd *cfg, char *frame, int s, gotend = 1; break; case EDP_TLV_VLAN: +#ifdef ENABLE_DOT1 if (len < sizeof(struct edp_tlv_vlan) - sizeof(struct edp_tlv_head)) { LLOG_WARNX("wrong size for EDP TLV vlan for frame " @@ -405,6 +425,7 @@ edp_decode(struct lldpd *cfg, char *frame, int s, } TAILQ_INSERT_TAIL(&port->p_vlans, lvlan, v_entries); +#endif gotvlans = 1; break; default: @@ -420,6 +441,7 @@ edp_decode(struct lldpd *cfg, char *frame, int s, (chassis->c_descr == NULL) || (port->p_descr == NULL) || (gotend == 0)) { +#ifdef ENABLE_DOT1 if (gotvlans && gotend) { /* VLAN can be sent in a separate frames. We need to add * those vlans to an existing chassis */ @@ -445,6 +467,10 @@ edp_decode(struct lldpd *cfg, char *frame, int s, /* We discard the remaining frame */ goto malformed; } +#else + if (gotvlans) + goto malformed; +#endif LLOG_WARNX("some mandatory tlv are missing for frame received on %s", hardware->h_ifname); goto malformed; @@ -460,7 +486,9 @@ malformed: free(chassis); free(port->p_id); free(port->p_descr); +#ifdef ENABLE_DOT1 lldpd_vlan_cleanup(port); +#endif free(port); return -1; } diff --git a/src/lldp.c b/src/lldp.c index 5a2a93d8..7a80da39 100644 --- a/src/lldp.c +++ b/src/lldp.c @@ -31,10 +31,7 @@ lldp_send(struct lldpd *global, struct lldpd_chassis *chassis, { struct ether_header eh; const u_int8_t mcastaddr[] = LLDP_MULTICAST_ADDR; - const u_int8_t dot1[] = LLDP_TLV_ORG_DOT1; - const u_int8_t dot3[] = LLDP_TLV_ORG_DOT3; struct iovec *iov = NULL; - struct lldp_vlan *ovlan = NULL; struct lldp_id chid, pid; struct lldp_ttl ttl; struct lldp_end end; @@ -43,17 +40,25 @@ lldp_send(struct lldpd *global, struct lldpd_chassis *chassis, struct lldp_string str; struct lldp_cap cap; struct lldp_mgmt mgmt; +#ifdef ENABLE_DOT1 + const u_int8_t dot1[] = LLDP_TLV_ORG_DOT1; + struct lldp_vlan *ovlan = NULL; + int v; + struct lldpd_vlan *vlan; +#endif +#ifdef ENABLE_DOT3 + const u_int8_t dot3[] = LLDP_TLV_ORG_DOT3; struct lldp_aggreg aggreg; struct lldp_macphy macphy; +#endif #ifdef ENABLE_LLDPMED const u_int8_t med[] = LLDP_TLV_ORG_MED; struct lldpmed_cap medcap; struct lldp_org medhw, medfw, medsw, medsn, medmodel, medasset, medmanuf; #endif - struct lldpd_vlan *vlan; struct lldpd_port *port = &hardware->h_lport; - u_int c = -1, len = 0, v; + u_int c = -1, len = 0; struct lldpd_frame *buffer; #define IOV_NEW \ @@ -181,6 +186,7 @@ lldp_send(struct lldpd *global, struct lldpd_chassis *chassis, iov[c].iov_base = port->p_descr; iov[c].iov_len = strlen(port->p_descr); +#ifdef ENABLE_DOT1 /* VLANs */ v = 0; TAILQ_FOREACH(vlan, &port->p_vlans, v_entries) @@ -208,7 +214,9 @@ lldp_send(struct lldpd *global, struct lldpd_chassis *chassis, iov[c].iov_len = strlen(vlan->v_name); } } +#endif +#ifdef ENABLE_DOT3 /* Aggregation status */ memset(&aggreg, 0, sizeof(aggreg)); aggreg.tlv_head.type_len = LLDP_TLV_HEAD(LLDP_TLV_ORG, @@ -239,6 +247,7 @@ lldp_send(struct lldpd *global, struct lldpd_chassis *chassis, IOV_NEW; iov[c].iov_base = &macphy; iov[c].iov_len = sizeof(macphy); +#endif #ifdef ENABLE_LLDPMED if (global->g_lchassis.c_med_cap) { @@ -309,7 +318,9 @@ lldp_send(struct lldpd *global, struct lldpd_chassis *chassis, LLOG_WARN("unable to send packet on real device for %s", hardware->h_ifname); free(iov); +#ifdef ENABLE_DOT1 free(ovlan); +#endif return ENETDOWN; } @@ -318,7 +329,9 @@ lldp_send(struct lldpd *global, struct lldpd_chassis *chassis, iov_dump(&buffer, iov, c); free(iov); +#ifdef ENABLE_DOT1 free(ovlan); +#endif if (buffer != NULL) { /* We assume that LLDP frame is the reference */ @@ -362,7 +375,9 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, free(chassis); return -1; } +#ifdef ENABLE_DOT1 TAILQ_INIT(&port->p_vlans); +#endif if (s < sizeof(struct ether_header)) { LLOG_WARNX("too short frame received on %s", hardware->h_ifname); @@ -506,6 +521,10 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, goto malformed; } if (memcmp(dot1, frame + f, 3) == 0) { +#ifndef ENABLE_DOT1 + f += size; + hardware->h_rx_unrecognized_cnt++; +#else /* Dot1 */ if ((*(u_int8_t*)(frame + f + 3)) == LLDP_TLV_DOT1_VLANNAME) { @@ -542,10 +561,17 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, TAILQ_INSERT_TAIL(&port->p_vlans, vlan, v_entries); f += vlan_len; - } else + } else { /* Unknown Dot1 TLV, ignore it */ f += size; + hardware->h_rx_unrecognized_cnt++; + } +#endif } else if (memcmp(dot3, frame + f, 3) == 0) { +#ifndef ENABLE_DOT3 + f += size; + hardware->h_rx_unrecognized_cnt++; +#else /* Dot3 */ subtype = *(u_int8_t*)(frame + f + 3); switch (subtype) { @@ -585,6 +611,7 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, f += size; hardware->h_rx_unrecognized_cnt++; } +#endif } else if (memcmp(med, frame + f, 3) == 0) { /* LLDP-MED */ #ifndef ENABLE_LLDPMED @@ -722,7 +749,9 @@ malformed: free(chassis); free(port->p_id); free(port->p_descr); +#ifdef ENABLE_DOT1 lldpd_vlan_cleanup(port); +#endif free(port); return -1; } diff --git a/src/lldpctl.c b/src/lldpctl.c index a1e02033..2c24cb3c 100644 --- a/src/lldpctl.c +++ b/src/lldpctl.c @@ -27,13 +27,16 @@ void usage(void); TAILQ_HEAD(interfaces, lldpd_interface); +#ifdef ENABLE_DOT1 TAILQ_HEAD(vlans, lldpd_vlan); +#endif struct value_string { int value; char *string; }; +#ifdef ENABLE_DOT3 static const struct value_string operational_mau_type_values[] = { { 1, "AUI - no internal MAU, view from AUI" }, { 2, "10Base5 - thick coax MAU" }, @@ -77,6 +80,7 @@ static const struct value_string operational_mau_type_values[] = { { 40, "10GigBaseSW - W fiber over 850 nm optics" }, { 0, NULL } }; +#endif void usage(void) @@ -135,6 +139,7 @@ get_interfaces(int s, struct interfaces *ifs) fatalx("get_interfaces: unable to retrieve the list of interfaces"); } +#ifdef ENABLE_DOT1 int get_vlans(int s, struct vlans *vls, char *interface) { @@ -158,6 +163,7 @@ get_vlans(int s, struct vlans *vls, char *interface) fatalx("get_vlans: unable to retrieve the list of vlans"); return 1; } +#endif int get_chassis(int s, struct lldpd_chassis *chassis, char *interface) @@ -353,6 +359,7 @@ display_chassis(struct lldpd_chassis *chassis) printf("\n"); } +#ifdef ENABLE_DOT3 void display_autoneg(struct lldpd_port *port, int bithd, int bitfd, char *desc) { @@ -371,12 +378,15 @@ display_autoneg(struct lldpd_port *port, int bithd, int bitfd, char *desc) } printf("(FD) "); } +#endif void display_port(struct lldpd_port *port) { char *pid; +#ifdef ENABLE_DOT3 int i; +#endif if ((pid = (char *)malloc(port->p_id_len + 1)) == NULL) fatal(NULL); @@ -410,6 +420,7 @@ display_port(struct lldpd_port *port) dump(port->p_id, port->p_id_len, 16, ' ')); } printf(" PortDescr: "); pretty_print(port->p_descr); +#ifdef ENABLE_DOT3 if (port->p_aggregid) printf("\n Port is aggregated. PortAggregID: %d\n", port->p_aggregid); @@ -446,8 +457,10 @@ display_port(struct lldpd_port *port) } if (operational_mau_type_values[i].value == 0) printf("unknown (%d)\n", port->p_mau_type); +#endif } +#ifdef ENABLE_DOT1 void display_vlans(struct lldpd_port *port) { @@ -459,6 +472,7 @@ display_vlans(struct lldpd_port *port) if (i % 2) printf("\n"); } +#endif int main(int argc, char *argv[]) @@ -466,7 +480,9 @@ main(int argc, char *argv[]) int s; int ch, debug = 1; struct interfaces ifs; +#ifdef ENABLE_DOT1 struct vlans vls; +#endif struct lldpd_interface *iff; struct lldpd_chassis chassis; struct lldpd_port port; @@ -503,6 +519,7 @@ main(int argc, char *argv[]) display_chassis(&chassis); printf("\n"); display_port(&port); +#ifdef ENABLE_DOT1 if (get_vlans(s, &vls, iff->name) != -1) { memcpy(&port.p_vlans, &vls, sizeof(struct vlans)); if (!TAILQ_EMPTY(&port.p_vlans)) { @@ -510,6 +527,7 @@ main(int argc, char *argv[]) display_vlans(&port); } } +#endif #ifdef ENABLE_LLDPMED if (chassis.c_med_cap) { printf("\n"); diff --git a/src/lldpd.c b/src/lldpd.c index fe5dbbff..bf906338 100644 --- a/src/lldpd.c +++ b/src/lldpd.c @@ -351,7 +351,7 @@ lldpd_iface_switchto(struct lldpd *cfg, short int filter, struct lldpd_hardware return 0; } - +#ifdef ENABLE_DOT1 void lldpd_vlan_cleanup(struct lldpd_port *port) { @@ -365,11 +365,14 @@ lldpd_vlan_cleanup(struct lldpd_port *port) free(vlan); } } +#endif void lldpd_port_cleanup(struct lldpd_port *port) { +#ifdef ENABLE_DOT1 lldpd_vlan_cleanup(port); +#endif free(port->p_id); free(port->p_descr); free(port); @@ -426,7 +429,9 @@ lldpd_cleanup(struct lldpd *cfg) if (hardware->h_flags == 0) { TAILQ_REMOVE(&cfg->g_hardware, hardware, h_entries); lldpd_iface_close(cfg, hardware); +#ifdef ENABLE_DOT1 lldpd_vlan_cleanup(&hardware->h_lport); +#endif lldpd_remote_cleanup(cfg, hardware, 1); free(hardware->h_proto_macs); free(hardware->h_llastframe); @@ -507,12 +512,18 @@ lldpd_port_add_vlan(struct lldpd *cfg, struct ifaddrs *ifa) struct lldpd_hardware * lldpd_port_add(struct lldpd *cfg, struct ifaddrs *ifa) { +#if defined (ENABLE_DOT1) || defined (ENABLE_DOT3) struct ifaddrs *oifap, *oifa; +#endif struct lldpd_hardware *hardware; struct lldpd_port *port; +#ifdef ENABLE_DOT1 struct lldpd_vlan *vlan; struct vlan_ioctl_args ifv; +#endif +#ifdef ENABLE_DOT3 struct ethtool_cmd ethc; +#endif u_int8_t *lladdr; TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { @@ -528,9 +539,11 @@ lldpd_port_add(struct lldpd *cfg, struct ifaddrs *ifa) hardware->h_raw_real = -1; hardware->h_start_probe = 0; hardware->h_proto_macs = (u_int8_t*)calloc(cfg->g_multi+1, ETH_ALEN); +#ifdef ENABLE_DOT1 TAILQ_INIT(&hardware->h_lport.p_vlans); } else { lldpd_vlan_cleanup(&hardware->h_lport); +#endif } port = &hardware->h_lport; @@ -555,9 +568,11 @@ lldpd_port_add(struct lldpd *cfg, struct ifaddrs *ifa) } /* Get VLANS and aggregation status */ +#if defined (ENABLE_DOT3) || defined (ENABLE_DOT1) if (getifaddrs(&oifap) != 0) fatal("lldpd_port_add: failed to get interface list"); for (oifa = oifap; oifa != NULL; oifa = oifa->ifa_next) { +#ifdef ENABLE_DOT1 /* Check if we already have checked this one */ int skip = 0; TAILQ_FOREACH(vlan, &port->p_vlans, v_entries) { @@ -565,11 +580,15 @@ lldpd_port_add(struct lldpd *cfg, struct ifaddrs *ifa) skip = 1; } if (skip) continue; +#endif /* Aggregation check */ +#ifdef ENABLE_DOT3 if (iface_is_bond_slave(cfg, hardware->h_ifname, oifa->ifa_name)) port->p_aggregid = if_nametoindex(oifa->ifa_name); - +#endif + +#ifdef ENABLE_DOT1 /* VLAN check */ memset(&ifv, 0, sizeof(ifv)); ifv.cmd = GET_VLAN_REALDEV_NAME_CMD; @@ -596,9 +615,12 @@ lldpd_port_add(struct lldpd *cfg, struct ifaddrs *ifa) TAILQ_INSERT_TAIL(&port->p_vlans, vlan, v_entries); } } +#endif } freeifaddrs(oifap); +#endif +#ifdef ENABLE_DOT3 /* MAC/PHY */ if (priv_ethtool(hardware->h_ifname, ðc) == 0) { int j; @@ -655,12 +677,15 @@ lldpd_port_add(struct lldpd *cfg, struct ifaddrs *ifa) if (ethc.port == PORT_AUI) port->p_mau_type = LLDP_DOT3_MAU_AUI; } else LLOG_DEBUG("unable to get eth info for %s", hardware->h_ifname); +#endif if (!INTERFACE_OPENED(hardware)) { if (lldpd_iface_init(cfg, hardware) != 0) { LLOG_WARN("unable to initialize %s", hardware->h_ifname); +#ifdef ENABLE_DOT1 lldpd_vlan_cleanup(&hardware->h_lport); +#endif free(hardware->h_proto_macs); free(hardware); return (NULL); diff --git a/src/lldpd.h b/src/lldpd.h index 42ce3edd..ab650071 100644 --- a/src/lldpd.h +++ b/src/lldpd.h @@ -59,12 +59,14 @@ #define USING_AGENTX_SUBAGENT_MODULE 1 +#ifdef ENABLE_DOT1 struct lldpd_vlan { TAILQ_ENTRY(lldpd_vlan) v_entries; char *v_name; u_int16_t v_vid; }; #define STRUCT_LLDPD_VLAN "Lsw" +#endif struct lldpd_chassis { u_int8_t c_id_subtype; @@ -94,11 +96,12 @@ struct lldpd_chassis { #endif }; -#ifndef ENABLE_LLDPMED -#define STRUCT_LLDPD_CHASSIS "bCsswwwll" +#ifdef ENABLE_LLDPMED +#define STRUCT_LLDPD_CHASSIS_MED "wbsssssss" #else -#define STRUCT_LLDPD_CHASSIS "bCsswwwllwbsssssss" +#define STRUCT_LLDPD_CHASSIS_MED "" #endif +#define STRUCT_LLDPD_CHASSIS "bCsswwwll" STRUCT_LLDPD_CHASSIS_MED struct lldpd_port { u_int8_t p_id_subtype; @@ -106,16 +109,31 @@ struct lldpd_port { int p_id_len; char *p_descr; +#ifdef ENABLE_DOT3 /* Dot3 stuff */ u_int32_t p_aggregid; u_int8_t p_autoneg_support; u_int8_t p_autoneg_enabled; u_int16_t p_autoneg_advertised; u_int16_t p_mau_type; +#endif +#ifdef ENABLE_DOT1 TAILQ_HEAD(, lldpd_vlan) p_vlans; +#endif }; -#define STRUCT_LLDPD_PORT "bCslbbwwPP" + +#ifdef ENABLE_DOT3 +#define STRUCT_LLDPD_PORT_DOT3 "lbbww" +#else +#define STRUCT_LLDPD_PORT_DOT3 "" +#endif +#ifdef ENABLE_DOT1 +#define STRUCT_LLDPD_PORT_DOT1 "PP" +#else +#define STRUCT_LLDPD_PORT_DOT1 "" +#endif +#define STRUCT_LLDPD_PORT "bCs" STRUCT_LLDPD_PORT_DOT3 STRUCT_LLDPD_PORT_DOT1 struct lldpd_frame { int size; @@ -262,7 +280,9 @@ struct hmsg { /* lldpd.c */ void lldpd_cleanup(struct lldpd *); +#ifdef ENABLE_DOT1 void lldpd_vlan_cleanup(struct lldpd_port *); +#endif void lldpd_remote_cleanup(struct lldpd *, struct lldpd_hardware *, int); void lldpd_port_cleanup(struct lldpd_port *); void lldpd_chassis_cleanup(struct lldpd_chassis *); diff --git a/src/sonmp.c b/src/sonmp.c index 151edd6b..887e1707 100644 --- a/src/sonmp.c +++ b/src/sonmp.c @@ -244,7 +244,9 @@ sonmp_decode(struct lldpd *cfg, char *frame, int s, free(chassis); return -1; } +#ifdef ENABLE_DOT1 TAILQ_INIT(&port->p_vlans); +#endif if (s < sizeof(struct sonmp)) { LLOG_WARNX("too short frame received on %s", hardware->h_ifname); -- 2.39.5