From d4afb919c2cbdfd58754748f3b494d883a936b14 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sat, 25 Feb 2012 11:37:43 +0100 Subject: [PATCH] cdp: allow to override value of platform TLV (Linux by default) --- man/lldpd.8 | 4 ++++ src/cdp.c | 4 +++- src/lldpd.c | 13 ++++++++++--- src/lldpd.h | 3 ++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/man/lldpd.8 b/man/lldpd.8 index 447dd109..3a5dbdb8 100644 --- a/man/lldpd.8 +++ b/man/lldpd.8 @@ -23,6 +23,7 @@ .Nm .Op Fl dxcseiklr .Op Fl S Ar description +.Op Fl P Ar platform .Op Fl X Ar socket .Op Fl m Ar management .Op Fl I Ar interfaces @@ -69,6 +70,9 @@ description is the kernel name, the node name, the kernel version, the build date and the architecture (except if you use the .Fl k flag described above). +.It Fl P Ar platform +Override the CDP platform name with the provided value. The default +description is the kernel name (Linux). .It Fl x Enable SNMP subagent. With this option, diff --git a/src/cdp.c b/src/cdp.c index 4d873534..609773b8 100644 --- a/src/cdp.c +++ b/src/cdp.c @@ -164,9 +164,11 @@ cdp_send(struct lldpd *global, goto toobig; /* Platform */ + char *platform = "Linux"; + if (global && global->g_platform_override) platform = global->g_platform_override; if (!( POKE_START_CDP_TLV(CDP_TLV_PLATFORM) && - POKE_BYTES("Linux", strlen("Linux")) && + POKE_BYTES(platform, strlen(platform)) && POKE_END_CDP_TLV)) goto toobig; POKE_SAVE(end); diff --git a/src/lldpd.c b/src/lldpd.c index 5371aa80..ba72c207 100644 --- a/src/lldpd.c +++ b/src/lldpd.c @@ -92,6 +92,7 @@ usage(void) fprintf(stderr, "-i Disable LLDP-MED inventory TLV transmission.\n"); fprintf(stderr, "-k Disable advertising of kernel release, version, machine.\n"); fprintf(stderr, "-S descr Override the default system description.\n"); + fprintf(stderr, "-P name Override the default hardware platform.\n"); fprintf(stderr, "-m IP Specify the management address of this system.\n"); fprintf(stderr, "-H mode Specify the behaviour when detecting multiple neighbors.\n"); fprintf(stderr, "-I iface Limit interfaces to use.\n"); @@ -1120,12 +1121,13 @@ lldpd_main(int argc, char *argv[]) char *cidp = NULL; char *interfaces = NULL; char *popt, opts[] = - "H:hkrdxX:m:I:C:p:M:S:i@ "; + "H:hkrdxX:m:I:C:p:M:P:S:i@ "; int i, found, advertise_version = 1; #ifdef ENABLE_LLDPMED int lldpmed = 0, noinventory = 0; #endif - char *descr_override = NULL; + char *descr_override = NULL; + char *platform_override = NULL; char *lsb_release = NULL; int smart = 15; int receiveonly = 0; @@ -1176,7 +1178,6 @@ lldpd_main(int argc, char *argv[]) #else case 'M': case 'i': - case 'P': fprintf(stderr, "LLDP-MED support is not built-in\n"); usage(); break; @@ -1199,6 +1200,9 @@ lldpd_main(int argc, char *argv[]) case 'S': descr_override = strdup(optarg); break; + case 'P': + platform_override = strdup(optarg); + break; case 'H': smart = atoi(optarg); break; @@ -1279,6 +1283,9 @@ lldpd_main(int argc, char *argv[]) if (descr_override) cfg->g_descr_override = descr_override; + if (platform_override) + cfg->g_platform_override = platform_override; + /* Set system capabilities */ if ((lchassis = (struct lldpd_chassis*) calloc(1, sizeof(struct lldpd_chassis))) == NULL) diff --git a/src/lldpd.h b/src/lldpd.h index d7fed395..696c710f 100644 --- a/src/lldpd.h +++ b/src/lldpd.h @@ -418,7 +418,8 @@ struct lldpd { char *g_cid_pattern; char *g_interfaces; - char *g_descr_override; + char *g_descr_override; + char *g_platform_override; char *g_lsb_release; int g_advertise_version; #ifdef ENABLE_LLDPMED -- 2.39.5