]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpd: make custom TLV code optional
authorAlexandru Ardelean <ardeleanalex@gmail.com>
Mon, 18 May 2015 06:10:32 +0000 (09:10 +0300)
committerAlexandru Ardelean <ardeleanalex@gmail.com>
Tue, 19 May 2015 06:54:48 +0000 (09:54 +0300)
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
12 files changed:
.travis.yml
configure.ac
redhat/lldpd.spec
src/client/conf-lldp.c
src/daemon/client.c
src/daemon/lldpd.c
src/daemon/protocols/lldp.c
src/lib/atom.h
src/lib/atoms/custom.c
src/lib/atoms/port.c
src/lldpd-structs.c
src/lldpd-structs.h

index 0b2a9b82e3005657b33ccc9a50f1628562c9b09e..9b3bdd6e1621c37a9b61c1b57bc84778b1c48c6a 100644 (file)
@@ -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
index eac2c65dae7a4524fdb56b02e0ec82d616e1c381..b21b814f0b9d38b12b7ee4964b7ea54b1818984a 100644 (file)
@@ -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 <<EOF
   LLDPMED........: $enable_lldpmed
   DOT1...........: $enable_dot1
   DOT3...........: $enable_dot3
+  CUSTOM.........: $enable_custom
   XML output.....: ${with_xml-no}
   JSON output....: ${with_json-no}
   Oldies support.: $enable_oldies
index 42fb302c7868633ea7c0af825e01a17dc7f0e2b0..1be407e8a10a002492c19a55a3009cc16a4a4bcb 100644 (file)
@@ -14,6 +14,7 @@
 %bcond_without lldpmed
 %bcond_without dot1
 %bcond_without dot3
+%bcond_without custom
 
 # On RHEL < 5, disable SNMP, Net-SNMP installation seems broken
 %if 0%{?rhel_version} > 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 \
index 47d379ca2a92955174778beefb6df0961095b35b..a0cfe42fdf1f8c0451e28d5259c724c4fb680da9 100644 (file)
@@ -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
 }
index 2f98c393e563df513a1516efacc917fdf9a5b33b..bc7c317c40b92f2c1d9c567887d93e3e63826185 100644 (file)
@@ -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;
index 782e9232e1cbc5ac75982b45b6e92c7daaafd3d6..b6977359a4213c5a0638a5c7ccef33d59e6187bf 100644 (file)
@@ -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;
index c4a30a41b84f6da599beb86a17b18b333fa77abd..7ff08fc0eea5a2858f5edea46e03d7be69df0fe7 100644 (file)
@@ -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:
index 731ff6ca564873b3dce77b864426f36701c8e082..95221b49ea41c861a20925f28c65905ce2ae8bdc 100644 (file)
@@ -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, ...);
 
index bcf63fa720412aa70d15b3199fb28cc75cc225b4..0b22fa2117ff1c4b88f91836fed4a235c18b6e1f 100644 (file)
@@ -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 */
+
index 20713d10165444dbfd850f98cf3ecbb22623f770..e7fac04274cb13f32c05b932f16db2dded904e52 100644 (file)
@@ -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;
index f713abdfa7595bd8052181e76111d0ffad5f689d..f983b7c2ed221f7cb45bf531b1eba9531cd4ccb1 100644 (file)
@@ -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
        }
 }
 
index cf7617bdbaaaf40439769409632f9e0d6554535c..a892fd6a979372762e8c024f2969dc67911db6a3 100644 (file)
@@ -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