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)
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);
}
}
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
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;
}
int vlan_len;
struct lldpd_ppvid *ppvid;
struct lldpd_pi *pi;
- int pi_len;
#endif
if ((chassis = calloc(1, sizeof(struct lldpd_chassis))) == NULL) {
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;
#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;
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
#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;