From: Vincent Bernat Date: Wed, 12 Aug 2015 15:01:46 +0000 (+0200) Subject: cdp: compute default platform when updating the chassis X-Git-Tag: 0.7.17~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=96beef68762fff43542609c6d0c4ef2ccc066c83;p=thirdparty%2Flldpd.git cdp: compute default platform when updating the chassis Like for other data, collect the default platform name for CDP in `lldpd_update_localchassis()`. Code in `cdp.c` should be independant of the environment. Also, fix the unittests. --- diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index 894ad7fb..876fcc90 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -1060,6 +1060,8 @@ lldpd_update_localchassis(struct lldpd *cfg) fatal("localchassis", "failed to set minimal system description"); } } + if (cfg->g_config.c_platform == NULL) + cfg->g_config.c_platform = strdup(un.sysname); /* Check routing */ if (lldpd_routing_enabled(cfg)) { diff --git a/src/daemon/protocols/cdp.c b/src/daemon/protocols/cdp.c index 86013e61..5dfa20ea 100644 --- a/src/daemon/protocols/cdp.c +++ b/src/daemon/protocols/cdp.c @@ -21,8 +21,6 @@ #if defined (ENABLE_CDP) || defined (ENABLE_FDP) -#include - #include #include #include @@ -33,8 +31,7 @@ static int cdp_send(struct lldpd *global, struct lldpd_hardware *hardware, int version) { - const char *platform; - struct utsname utsname; + const char *platform = "Unknown"; struct lldpd_chassis *chassis; struct lldpd_mgmt *mgmt; struct lldpd_port *port; @@ -201,12 +198,7 @@ cdp_send(struct lldpd *global, goto toobig; /* Platform */ - if (global && global->g_config.c_platform) - platform = global->g_config.c_platform; - else { - uname(&utsname); - platform = utsname.sysname; - } + if (global && global->g_config.c_platform) platform = global->g_config.c_platform; if (!( POKE_START_CDP_TLV(CDP_TLV_PLATFORM) && diff --git a/tests/check_cdp.c b/tests/check_cdp.c index 23215a9e..ef11218b 100644 --- a/tests/check_cdp.c +++ b/tests/check_cdp.c @@ -107,6 +107,11 @@ Cisco Discovery Protocol struct packet *pkt; in_addr_t addr; struct lldpd_mgmt *mgmt; + struct lldpd cfg = { + .g_config = { + .c_platform = "Linux" + } + }; /* Populate port and chassis */ hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME; @@ -128,7 +133,7 @@ Cisco Discovery Protocol TAILQ_INSERT_TAIL(&chassis.c_mgmt, mgmt, m_entries); /* Build packet */ - n = cdpv1_send(NULL, &hardware); + n = cdpv1_send(&cfg, &hardware); if (n != 0) { fail("unable to build packet"); return; @@ -236,6 +241,11 @@ Cisco Discovery Protocol in_addr_t addr2; struct lldpd_mgmt *mgmt1; struct lldpd_mgmt *mgmt2; + struct lldpd cfg = { + .g_config = { + .c_platform = "Linux" + } + }; /* Populate port and chassis */ hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_LLADDR; @@ -262,7 +272,7 @@ Cisco Discovery Protocol TAILQ_INSERT_TAIL(&chassis.c_mgmt, mgmt2, m_entries); /* Build packet */ - n = cdpv2_send(NULL, &hardware); + n = cdpv2_send(&cfg, &hardware); if (n != 0) { fail("unable to build packet"); return;