]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Some fixes for PPVID and PI.
authorVincent Bernat <bernat@luffy.cx>
Thu, 22 Sep 2011 20:13:38 +0000 (22:13 +0200)
committerVincent Bernat <bernat@luffy.cx>
Thu, 22 Sep 2011 20:13:38 +0000 (22:13 +0200)
PI are bytes, not a string. Grab bytes when reading and display using
hexadecimal. Rework a bit how PPVID are displayed.

src/display.c
src/lldp.c
src/lldpd.h

index 009872edc7fbae58251823aa3e999896337109cf..7586a9a9b1cc045a40c248a26265e5a004763c0a 100644 (file)
@@ -438,7 +438,7 @@ get_pids(int s, struct pids *pids, char *interface, int nb)
        if (ctl_msg_recv(s, h) == -1)
                fatalx("get_pids: unable to receive answer");
        if (h->hdr.type != HMSG_GET_PIDS)
-               fatalx("get_ppvids: unknown answer type received");
+               fatalx("get_pids: unknown answer type received");
        p = &h->data;
        if (ctl_msg_unpack_list(STRUCT_LLDPD_PI,
                pids, sizeof(struct lldpd_pi), h, &p) == -1)
@@ -1059,23 +1059,12 @@ display_ppvids(struct writer *w, struct lldpd_port *port)
        struct lldpd_ppvid *ppvid;
        TAILQ_FOREACH(ppvid, &port->p_ppvids, p_entries) {
                tag_start(w, "ppvid", "PPVID");
-               switch(ppvid->p_cap_status) {
-                       case LLDPD_PPVID_CAP_SUPPORTED:
-                               tag_attr(w, "ppvid-cap-status supported", "",
-                                       u2str(ppvid->p_cap_status));
-                       break;
-                       case LLDPD_PPVID_CAP_ENABLED:
-                               tag_attr(w, "ppvid-cap-status enabled", "",
-                                       u2str(ppvid->p_cap_status));
-                       break;
-                       case LLDPD_PPVID_CAP_SUPPORTED_AND_ENABLED:
-                               tag_attr(w,
-                                       "ppvid-cap-status supported, enabled",
-                                       "",
-                                       u2str(ppvid->p_cap_status));
-                       break;
-               }
-               tag_attr(w, "ppvid", "", u2str(ppvid->p_ppvid));
+               if (ppvid->p_ppvid)
+                       tag_attr(w, "value", "", u2str(ppvid->p_ppvid));
+               tag_attr(w, "supported", "supported",
+                        (ppvid->p_cap_status & LLDPD_PPVID_CAP_SUPPORTED)?"yes":"no");
+               tag_attr(w, "enabled", "enabled",
+                        (ppvid->p_cap_status & LLDPD_PPVID_CAP_ENABLED)?"yes":"no");
                tag_end(w);
        }
 }
@@ -1084,10 +1073,18 @@ static void
 display_pids(struct writer *w, struct lldpd_port *port)
 {
        struct lldpd_pi *pi;
+       char *hex;
        TAILQ_FOREACH(pi, &port->p_pids, p_entries) {
+               if (!pi->p_pi_len) continue;
                tag_start(w, "pi", "PI");
-               tag_data(w, pi->p_pi);
+               /* Convert to hex for display */
+               if ((hex = malloc(pi->p_pi_len * 2 + 1)) == NULL)
+                       fatal(NULL);
+               for (int i = 0; i < pi->p_pi_len; i++)
+                       snprintf(hex + 2*i, 3, "%02X", (unsigned char)pi->p_pi[i]);
+               tag_data(w, hex);
                tag_end(w);
+               free(hex);
        }
 }
 #endif
index 6ebaab1559fbc9f646bb485f3d9ea03910c55aa3..d5366915a2889e8b590de24265e9c3d72ff582c8 100644 (file)
@@ -195,8 +195,8 @@ lldp_send(struct lldpd *global,
                      POKE_START_LLDP_TLV(LLDP_TLV_ORG) &&
                      POKE_BYTES(dot1, sizeof(dot1)) &&
                      POKE_UINT8(LLDP_TLV_DOT1_PI) &&
-                     POKE_UINT8(strlen(pi->p_pi)) &&
-                     POKE_BYTES(pi->p_pi, strlen(pi->p_pi)) &&
+                     POKE_UINT8(pi->p_pi_len) &&
+                     POKE_BYTES(pi->p_pi, pi->p_pi_len) &&
                      POKE_END_LLDP_TLV))
                        goto toobig;
        }
@@ -453,7 +453,6 @@ lldp_decode(struct lldpd *cfg, char *frame, int s,
        int vlan_len;
        struct lldpd_ppvid *ppvid;
        struct lldpd_pi *pi;
-       int pi_len;
 #endif
 
        if ((chassis = calloc(1, sizeof(struct lldpd_chassis))) == NULL) {
@@ -661,16 +660,16 @@ lldp_decode(struct lldpd *cfg, char *frame, int s,
                                                    hardware->h_ifname);
                                                goto malformed;
                                        }
-                                       pi_len = PEEK_UINT8;
-                                       CHECK_TLV_SIZE(1 + pi_len, "PI");
+                                       pi->p_pi_len = PEEK_UINT8;
+                                       CHECK_TLV_SIZE(1 + pi->p_pi_len, "PI");
                                        if ((pi->p_pi =
-                                               (char *)calloc(1, pi_len + 1)) == NULL) {
+                                               (char *)calloc(1, pi->p_pi_len)) == NULL) {
                                                LLOG_WARN("unable to alloc pid name for "
                                                    "tlv received on %s",
                                                    hardware->h_ifname);
                                                goto malformed;
                                        }
-                                       PEEK_BYTES(pi->p_pi, pi_len);
+                                       PEEK_BYTES(pi->p_pi, pi->p_pi_len);
                                        TAILQ_INSERT_TAIL(&port->p_pids,
                                            pi, p_entries);
                                        break;
index 119e20653909e72cea73a0e3fa73ba017f40b598..71a9a167fbd985e4e08b310d32ebb9ebc0a6c05b 100644 (file)
@@ -67,9 +67,8 @@
 #define USING_AGENTX_SUBAGENT_MODULE 1
 
 #ifdef ENABLE_DOT1
-#define LLDPD_PPVID_CAP_SUPPORTED              0x01
-#define LLDPD_PPVID_CAP_ENABLED                        0x02
-#define LLDPD_PPVID_CAP_SUPPORTED_AND_ENABLED  0x03
+#define LLDPD_PPVID_CAP_SUPPORTED              (1 << 1)
+#define LLDPD_PPVID_CAP_ENABLED                        (1 << 2)
 
 struct lldpd_ppvid {
        TAILQ_ENTRY(lldpd_ppvid) p_entries;
@@ -88,8 +87,9 @@ struct lldpd_vlan {
 struct lldpd_pi {
        TAILQ_ENTRY(lldpd_pi)  p_entries;
        char                    *p_pi;
+       int                      p_pi_len;
 };
-#define STRUCT_LLDPD_PI "(Ls)"
+#define STRUCT_LLDPD_PI "(LC)"
 #endif
 
 #ifdef ENABLE_LLDPMED
@@ -230,7 +230,7 @@ struct lldpd_port {
 #endif
 
 #ifdef ENABLE_DOT1
-#define STRUCT_LLDPD_PORT_DOT1 "wPPP"
+#define STRUCT_LLDPD_PORT_DOT1 "wPPPPPP"
        u_int16_t                p_pvid;
        TAILQ_HEAD(, lldpd_vlan) p_vlans;
        TAILQ_HEAD(, lldpd_ppvid) p_ppvids;