]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
cdp: compute default platform when updating the chassis
authorVincent Bernat <vincent@bernat.im>
Wed, 12 Aug 2015 15:01:46 +0000 (17:01 +0200)
committerVincent Bernat <vincent@bernat.im>
Wed, 12 Aug 2015 15:01:46 +0000 (17:01 +0200)
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.

src/daemon/lldpd.c
src/daemon/protocols/cdp.c
tests/check_cdp.c

index 894ad7fb5fe254189d7b7b0db84e6a9c7d1a6496..876fcc9057cc44e256ab43ec6dd444caa2fbf149 100644 (file)
@@ -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)) {
index 86013e61a18630c2679808c428994c7a168f1bf6..5dfa20eaf6718e63becdf486f34510cb7005d33c 100644 (file)
@@ -21,8 +21,6 @@
 
 #if defined (ENABLE_CDP) || defined (ENABLE_FDP)
 
-#include <sys/utsname.h>
-
 #include <stdio.h>
 #include <unistd.h>
 #include <errno.h>
@@ -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) &&
index 23215a9ebe67e16fe368eedfb61336ecf97a5846..ef11218bf9a4da0d1a91aa5fcff54226cccdcc21 100644 (file)
@@ -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;