From: Vincent Bernat Date: Fri, 28 Nov 2008 17:06:11 +0000 (+0100) Subject: Add an option to not send LLDP-MED inventory TLV X-Git-Tag: 0.3~31 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e809a587bb1ad836488f3a97890e337109bd6258;p=thirdparty%2Flldpd.git Add an option to not send LLDP-MED inventory TLV --- diff --git a/man/lldpd.8 b/man/lldpd.8 index 701642b5..db8057fd 100644 --- a/man/lldpd.8 +++ b/man/lldpd.8 @@ -21,7 +21,7 @@ .Nd LLDP daemon .Sh SYNOPSIS .Nm -.Op Fl dvxcse +.Op Fl dvxcsei .Op Fl m Ar management .Op Fl p Ar probe time .Op Fl M Ar class @@ -105,6 +105,12 @@ Communication Device Endpoints (Class III) .It Ar 4 Network Connectivity Device .El +.It Fl i +Disable LLDP-MED inventory TLV transmission. +.Nm +will still receive (and publish using SNMP if enabled) those LLDP-MED +TLV but will not send them. Use this option if you don't want to +transmit sensible information like serial numbers. .Sh FILES .Bl -tag -width "/var/run/lldpd.socketXX" -compact .It /var/run/lldpd.socket diff --git a/src/lldp.c b/src/lldp.c index 755e9184..ff1dceb9 100644 --- a/src/lldp.c +++ b/src/lldp.c @@ -285,20 +285,23 @@ lldp_send(struct lldpd *global, struct lldpd_chassis *chassis, iov[c].iov_base = value; \ iov[c].iov_len = len; \ } - LLDP_INVENTORY(global->g_lchassis.c_med_hw, - medhw, LLDP_TLV_MED_IV_HW); - LLDP_INVENTORY(global->g_lchassis.c_med_fw, - medfw, LLDP_TLV_MED_IV_FW); - LLDP_INVENTORY(global->g_lchassis.c_med_sw, - medsw, LLDP_TLV_MED_IV_SW); - LLDP_INVENTORY(global->g_lchassis.c_med_sn, - medsn, LLDP_TLV_MED_IV_SN); - LLDP_INVENTORY(global->g_lchassis.c_med_manuf, - medmanuf, LLDP_TLV_MED_IV_MANUF); - LLDP_INVENTORY(global->g_lchassis.c_med_model, - medmodel, LLDP_TLV_MED_IV_MODEL); - LLDP_INVENTORY(global->g_lchassis.c_med_asset, - medasset, LLDP_TLV_MED_IV_ASSET); + + if (!global->g_med_noinventory) { + LLDP_INVENTORY(global->g_lchassis.c_med_hw, + medhw, LLDP_TLV_MED_IV_HW); + LLDP_INVENTORY(global->g_lchassis.c_med_fw, + medfw, LLDP_TLV_MED_IV_FW); + LLDP_INVENTORY(global->g_lchassis.c_med_sw, + medsw, LLDP_TLV_MED_IV_SW); + LLDP_INVENTORY(global->g_lchassis.c_med_sn, + medsn, LLDP_TLV_MED_IV_SN); + LLDP_INVENTORY(global->g_lchassis.c_med_manuf, + medmanuf, LLDP_TLV_MED_IV_MANUF); + LLDP_INVENTORY(global->g_lchassis.c_med_model, + medmodel, LLDP_TLV_MED_IV_MODEL); + LLDP_INVENTORY(global->g_lchassis.c_med_asset, + medasset, LLDP_TLV_MED_IV_ASSET); + } } #endif diff --git a/src/lldpd.c b/src/lldpd.c index bf906338..d5cf46df 100644 --- a/src/lldpd.c +++ b/src/lldpd.c @@ -178,11 +178,8 @@ void usage(void) { extern const char *__progname; -#ifndef USE_SNMP - fprintf(stderr, "usage: %s [-dvcse] [-p|-P] [-m ip]\n", __progname); -#else /* USE_SNMP */ - fprintf(stderr, "usage: %s [-dvcsex] [-p|-P] [-m ip]\n", __progname); -#endif /* USE_SNMP */ + fprintf(stderr, "usage: %s [options]\n", __progname); + fprintf(stderr, "see manual page lldpd(8) for more information\n"); exit(1); } @@ -1377,12 +1374,15 @@ int main(int argc, char *argv[]) { struct lldpd *cfg; - int ch, snmp = 0, debug = 0; + int ch, debug = 0; +#ifdef USE_SNMP + int snmp = 0; +#endif char *mgmtp = NULL; - char *popt, opts[] = "vdxm:p:@ "; + char *popt, opts[] = "vdxm:p:M:i@ "; int probe = 0, i, found, vlan = 0; #ifdef ENABLE_LLDPMED - int lldpmed = 0; + int lldpmed = 0, noinventory = 0; #endif saved_argv = argv; @@ -1395,10 +1395,6 @@ main(int argc, char *argv[]) if (protos[i].enabled == 1) continue; *(popt++) = protos[i].arg; } -#ifdef ENABLE_LLDPMED - *(popt++) = 'M'; - *(popt++) = ':'; -#endif *popt = '\0'; while ((ch = getopt(argc, argv, opts)) != -1) { switch (ch) { @@ -1411,18 +1407,36 @@ main(int argc, char *argv[]) case 'm': mgmtp = optarg; break; -#ifdef ENABLE_LLDPMED case 'M': +#ifdef ENABLE_LLDPMED lldpmed = atoi(optarg); - if ((lldpmed < 1) || (lldpmed > 4)) + if ((lldpmed < 1) || (lldpmed > 4)) { + fprintf(stderr, "-M requires an argument between 1 and 4\n"); usage(); + } +#else + fprintf(stderr, "LLDP-MED support is not built-in\n"); + usage(); +#endif break; + case 'i': +#ifdef ENABLE_LLDPMED + noinventory = 1; +#else + fprintf(stderr, "LLDP-MED support is not built-in\n"); + usage(); #endif + break; case 'p': probe = atoi(optarg); break; case 'x': +#ifdef USE_SNMP snmp = 1; +#else + fprintf(stderr, "SNMP support is not built-in\n"); + usage(); +#endif break; default: found = 0; @@ -1480,7 +1494,10 @@ main(int argc, char *argv[]) if (lldpmed == LLDPMED_CLASS_III) cfg->g_lchassis.c_cap_available |= LLDP_CAP_TELEPHONE; cfg->g_lchassis.c_med_type = lldpmed; - cfg->g_lchassis.c_med_cap = LLDPMED_CAP_CAP | LLDPMED_CAP_IV; + cfg->g_lchassis.c_med_cap = LLDPMED_CAP_CAP; + if (!noinventory) + cfg->g_lchassis.c_med_cap |= LLDPMED_CAP_IV; + cfg->g_med_noinventory = noinventory; } #endif