From fb1b78bb76117a361aed81077e43dec978be4e6c Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Mon, 18 May 2015 09:10:32 +0300 Subject: [PATCH] lldpd: make custom TLV code optional Signed-off-by: Alexandru Ardelean --- .travis.yml | 1 + configure.ac | 2 ++ redhat/lldpd.spec | 6 ++++++ src/client/conf-lldp.c | 4 ++++ src/daemon/client.c | 2 ++ src/daemon/lldpd.c | 2 ++ src/daemon/protocols/lldp.c | 10 ++++++++++ src/lib/atom.h | 4 ++++ src/lib/atoms/custom.c | 4 ++++ src/lib/atoms/port.c | 6 ++++++ src/lldpd-structs.c | 4 ++++ src/lldpd-structs.h | 12 ++++++++++++ 12 files changed, 57 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0b2a9b82..9b3bdd6e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ env: - LLDPD_CONFIG_ARGS="--with-embedded-libevent" - LLDPD_CONFIG_ARGS="--disable-privsep --with-snmp" - LLDPD_CONFIG_ARGS="--with-snmp --with-xml --with-json --disable-lldpmed --disable-dot1 --disable-dot3" + - LLDPD_CONFIG_ARGS="--with-snmp --with-xml --with-json --disable-lldpmed --disable-dot1 --disable-dot3 --disable-custom" matrix: include: - os: linux diff --git a/configure.ac b/configure.ac index eac2c65d..b21b814f 100644 --- a/configure.ac +++ b/configure.ac @@ -276,6 +276,7 @@ lldp_ARG_ENABLE([sonmp], [SynOptics Network Management Protocol], [yes]) lldp_ARG_ENABLE([lldpmed], [LLDP-MED extension], [yes]) lldp_ARG_ENABLE([dot1], [Dot1 extension (VLAN stuff)], [yes]) lldp_ARG_ENABLE([dot3], [Dot3 extension (PHY stuff)], [yes]) +lldp_ARG_ENABLE([custom], [Custom TLV support], [yes]) # Oldies lldp_ARG_ENABLE([oldies], [compatibility with Linux kernel older than 2.6.18], [no]) @@ -319,6 +320,7 @@ cat < 0 && 0%{?rhel_version} < 500 || 0%{?centos_version} > 0 && 0%{?centos_version} < 500 @@ -137,6 +138,11 @@ to adjacent network devices. --enable-dot3 \ %else --disable-dot3 \ +%endif +%if %{with custom} + --enable-custom \ +%else + --disable-custom \ %endif --with-privsep-user=%lldpd_user \ --with-privsep-group=%lldpd_group \ diff --git a/src/client/conf-lldp.c b/src/client/conf-lldp.c index 47d379ca..a0cfe42f 100644 --- a/src/client/conf-lldp.c +++ b/src/client/conf-lldp.c @@ -202,6 +202,7 @@ cmd_chassis_mgmt_advertise(struct lldpctl_conn_t *conn, struct writer *w, return 1; } +#ifdef ENABLE_CUSTOM static int cmd_custom_tlv_set(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, void *arg) @@ -325,6 +326,7 @@ register_commands_configure_lldp_custom_tlvs(struct cmd_node *configure_lldp) NEWLINE, "Add custom TLV(s) to be broadcast on ports", NULL, cmd_custom_tlv_set, "enable"); } +#endif /* ENABLE_CUSTOM */ /** * Register `configure lldp` commands. @@ -445,6 +447,7 @@ register_commands_configure_lldp(struct cmd_node *configure, NULL, cmd_chassis_mgmt_advertise, NULL); +#ifdef ENABLE_CUSTOM register_commands_configure_lldp_custom_tlvs(configure_lldp); commands_new( commands_new(unconfigure_lldp, @@ -453,4 +456,5 @@ register_commands_configure_lldp(struct cmd_node *configure, NULL, NULL, NULL), NEWLINE, "Clear all (previously set) custom TLVs", NULL, cmd_custom_tlv_set, NULL); +#endif } diff --git a/src/daemon/client.c b/src/daemon/client.c index 2f98c393..bc7c317c 100644 --- a/src/daemon/client.c +++ b/src/daemon/client.c @@ -369,6 +369,7 @@ client_handle_set_port(struct lldpd *cfg, enum hmsg_type *type, sizeof(struct lldpd_dot3_power)); } #endif +#ifdef ENABLE_CUSTOM if (set->custom_list_clear) { log_debug("rpc", "requested custom TLVs clear"); lldpd_custom_list_cleanup(port); @@ -382,6 +383,7 @@ client_handle_set_port(struct lldpd *cfg, enum hmsg_type *type, } else log_warn("rpc", "could not allocate memory for custom TLV"); } +#endif ret = 1; break; diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index 782e9232..b6977359 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -169,7 +169,9 @@ lldpd_alloc_hardware(struct lldpd *cfg, char *name, int index) TAILQ_INIT(&hardware->h_lport.p_ppvids); TAILQ_INIT(&hardware->h_lport.p_pids); #endif +#ifdef ENABLE_CUSTOM TAILQ_INIT(&hardware->h_lport.p_custom_list); +#endif levent_hardware_init(hardware); return hardware; diff --git a/src/daemon/protocols/lldp.c b/src/daemon/protocols/lldp.c index c4a30a41..7ff08fc0 100644 --- a/src/daemon/protocols/lldp.c +++ b/src/daemon/protocols/lldp.c @@ -84,7 +84,9 @@ static int _lldp_send(struct lldpd *global, int i; const u_int8_t med[] = LLDP_TLV_ORG_MED; #endif +#ifdef ENABLE_CUSTOM struct lldpd_custom *custom; +#endif port = &hardware->h_lport; chassis = port->p_chassis; length = hardware->h_mtu; @@ -432,6 +434,7 @@ static int _lldp_send(struct lldpd *global, } #endif +#ifdef ENABLE_CUSTOM TAILQ_FOREACH(custom, &port->p_custom_list, next) { if (!( POKE_START_LLDP_TLV(LLDP_TLV_ORG) && @@ -441,6 +444,7 @@ static int _lldp_send(struct lldpd *global, POKE_END_LLDP_TLV)) goto toobig; } +#endif end: /* END */ @@ -590,7 +594,9 @@ 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; +#ifdef ENABLE_CUSTOM struct lldpd_custom *custom; +#endif log_debug("lldp", "receive LLDP PDU on %s", hardware->h_ifname); @@ -610,7 +616,9 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, TAILQ_INIT(&port->p_ppvids); TAILQ_INIT(&port->p_pids); #endif +#ifdef ENABLE_CUSTOM TAILQ_INIT(&port->p_custom_list); +#endif length = s; pos = (u_int8_t*)frame; @@ -1091,6 +1099,7 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, orgid[0], orgid[1], orgid[2], hardware->h_ifname); hardware->h_rx_unrecognized_cnt++; +#ifdef ENABLE_CUSTOM custom = (struct lldpd_custom*)calloc(1, sizeof(struct lldpd_custom)); if (!custom) return ENOMEM; @@ -1100,6 +1109,7 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, if (custom->oui_info_len > 0) PEEK_BYTES(custom->oui_info, custom->oui_info_len); TAILQ_INSERT_TAIL(&port->p_custom_list, custom, next); +#endif } break; default: diff --git a/src/lib/atom.h b/src/lib/atom.h index 731ff6ca..95221b49 100644 --- a/src/lib/atom.h +++ b/src/lib/atom.h @@ -111,8 +111,10 @@ typedef enum { atom_med_caelement, atom_med_power, #endif +#ifdef ENABLE_CUSTOM atom_custom_list, atom_custom, +#endif } atom_t; void *_lldpctl_alloc_in_atom(lldpctl_atom_t *, size_t); @@ -251,6 +253,7 @@ struct _lldpctl_atom_med_power_t { }; #endif +#ifdef ENABLE_CUSTOM struct _lldpctl_atom_custom_list_t { lldpctl_atom_t base; struct _lldpctl_atom_port_t *parent; @@ -262,6 +265,7 @@ struct _lldpctl_atom_custom_t { struct _lldpctl_atom_port_t *parent; struct lldpd_custom *tlv; }; +#endif struct lldpctl_atom_t *_lldpctl_new_atom(lldpctl_conn_t *conn, atom_t type, ...); diff --git a/src/lib/atoms/custom.c b/src/lib/atoms/custom.c index bcf63fa7..0b22fa21 100644 --- a/src/lib/atoms/custom.c +++ b/src/lib/atoms/custom.c @@ -26,6 +26,8 @@ #include "atom.h" #include "helpers.h" +#ifdef ENABLE_CUSTOM + #define min(x,y) ( (x > y) ? y : x ) static lldpctl_atom_iter_t* @@ -184,3 +186,5 @@ static struct atom_builder custom = ATOM_BUILDER_REGISTER(custom_list, 22); ATOM_BUILDER_REGISTER(custom, 23); +#endif /* ENABLE_CUSTOM */ + diff --git a/src/lib/atoms/port.c b/src/lib/atoms/port.c index 20713d10..e7fac042 100644 --- a/src/lib/atoms/port.c +++ b/src/lib/atoms/port.c @@ -273,8 +273,10 @@ _lldpctl_atom_get_atom_port(lldpctl_atom_t *atom, lldpctl_key_t key) case lldpctl_k_port_med_power: return _lldpctl_new_atom(atom->conn, atom_med_power, p); #endif +#ifdef ENABLE_CUSTOM case lldpctl_k_custom_tlvs: return _lldpctl_new_atom(atom->conn, atom_custom_list, p); +#endif default: SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); return NULL; @@ -299,7 +301,9 @@ _lldpctl_atom_set_atom_port(lldpctl_atom_t *atom, lldpctl_key_t key, lldpctl_ato struct _lldpctl_atom_med_policy_t *mpol; struct _lldpctl_atom_med_location_t *mloc; #endif +#ifdef ENABLE_CUSTOM struct _lldpctl_atom_custom_t *custom; +#endif /* Local port only */ if (hardware == NULL) { @@ -352,6 +356,7 @@ _lldpctl_atom_set_atom_port(lldpctl_atom_t *atom, lldpctl_key_t key, lldpctl_ato set.med_location = mloc->location; break; #endif +#ifdef ENABLE_CUSTOM case lldpctl_k_custom_tlvs_clear: set.custom_list_clear = 1; break; @@ -363,6 +368,7 @@ _lldpctl_atom_set_atom_port(lldpctl_atom_t *atom, lldpctl_key_t key, lldpctl_ato custom = (struct _lldpctl_atom_custom_t *)value; set.custom = custom->tlv; break; +#endif default: SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); return NULL; diff --git a/src/lldpd-structs.c b/src/lldpd-structs.c index f713abdf..f983b7c2 100644 --- a/src/lldpd-structs.c +++ b/src/lldpd-structs.c @@ -103,6 +103,7 @@ lldpd_pi_cleanup(struct lldpd_port *port) } #endif +#ifdef ENABLE_CUSTOM void lldpd_custom_list_cleanup(struct lldpd_port *port) { @@ -115,6 +116,7 @@ lldpd_custom_list_cleanup(struct lldpd_port *port) } TAILQ_INIT(&port->p_custom_list); } +#endif /* Cleanup a remote port. The before last argument, `expire` is a function that * should be called when a remote port is removed. If the last argument is 1, @@ -184,7 +186,9 @@ lldpd_port_cleanup(struct lldpd_port *port, int all) port->p_chassis->c_refcount--; port->p_chassis = NULL; } +#ifdef ENABLE_CUSTOM lldpd_custom_list_cleanup(port); +#endif } } diff --git a/src/lldpd-structs.h b/src/lldpd-structs.h index cf7617bd..a892fd6a 100644 --- a/src/lldpd-structs.h +++ b/src/lldpd-structs.h @@ -214,6 +214,7 @@ MARSHAL_STR(lldpd_chassis, c_med_asset) #endif MARSHAL_END(lldpd_chassis); +#ifdef ENABLE_CUSTOM /* Custom TLV struct as defined on page 35 of IEEE 802.1AB-2005 */ struct lldpd_custom { TAILQ_ENTRY(lldpd_custom) next; /* Pointer to next custom TLV */ @@ -230,6 +231,7 @@ struct lldpd_custom { MARSHAL_BEGIN(lldpd_custom) MARSHAL_TQE(lldpd_custom, next) MARSHAL_END(lldpd_custom); +#endif struct lldpd_port { TAILQ_ENTRY(lldpd_port) p_entries; @@ -269,7 +271,9 @@ struct lldpd_port { TAILQ_HEAD(, lldpd_ppvid) p_ppvids; TAILQ_HEAD(, lldpd_pi) p_pids; #endif +#ifdef ENABLE_CUSTOM TAILQ_HEAD(, lldpd_custom) p_custom_list; +#endif }; MARSHAL_BEGIN(lldpd_port) MARSHAL_TQE(lldpd_port, p_entries) @@ -287,7 +291,9 @@ MARSHAL_SUBTQ(lldpd_port, lldpd_vlan, p_vlans) MARSHAL_SUBTQ(lldpd_port, lldpd_ppvid, p_ppvids) MARSHAL_SUBTQ(lldpd_port, lldpd_pi, p_pids) #endif +#ifdef ENABLE_CUSTOM MARSHAL_SUBTQ(lldpd_port, lldpd_custom, p_custom_list) +#endif MARSHAL_END(lldpd_port); /* Used to modify some port related settings */ @@ -303,8 +309,10 @@ struct lldpd_port_set { #ifdef ENABLE_DOT3 struct lldpd_dot3_power *dot3_power; #endif +#ifdef ENABLE_CUSTOM struct lldpd_custom *custom; int custom_list_clear; +#endif }; MARSHAL_BEGIN(lldpd_port_set) MARSHAL_STR(lldpd_port_set, ifname) @@ -318,7 +326,9 @@ MARSHAL_POINTER(lldpd_port_set, lldpd_med_power, med_power) #ifdef ENABLE_DOT3 MARSHAL_POINTER(lldpd_port_set, lldpd_dot3_power, dot3_power) #endif +#ifdef ENABLE_CUSTOM MARSHAL_POINTER(lldpd_port_set, lldpd_custom, custom) +#endif MARSHAL_END(lldpd_port_set); /* Smart mode / Hide mode */ @@ -504,6 +514,8 @@ void lldpd_ppvid_cleanup(struct lldpd_port *); void lldpd_vlan_cleanup(struct lldpd_port *); void lldpd_pi_cleanup(struct lldpd_port *); #endif +#ifdef ENABLE_CUSTOM void lldpd_custom_list_cleanup(struct lldpd_port *); +#endif #endif -- 2.39.5