]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
client: display custom TLVs when lldpctl is called
authorAlexandru Ardelean <ardeleanalex@gmail.com>
Thu, 9 Apr 2015 14:56:53 +0000 (17:56 +0300)
committerAlexandru Ardelean <ardeleanalex@gmail.com>
Tue, 19 May 2015 06:54:48 +0000 (09:54 +0300)
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
src/client/display.c

index a34640e7334a4ca02070a31ae1bffd138a8e0737..f68027d8273bd4575029ae58d1dca7d20bb9d0f7 100644 (file)
@@ -263,6 +263,53 @@ display_chassis(struct writer* w, lldpctl_atom_t* neighbor, int details)
        tag_end(w);
 }
 
+static void
+display_custom_tlvs(struct writer* w, lldpctl_atom_t* neighbor, int details)
+{
+       lldpctl_atom_t *custom_list, *custom;
+       int have_custom_tlvs = 0;
+       size_t i, len, slen;
+       const uint8_t *oui, *oui_info;
+       char buf[1600]; /* should be enough for printing */
+
+       custom_list = lldpctl_atom_get(neighbor, lldpctl_k_custom_tlvs);
+       lldpctl_atom_foreach(custom_list, custom) {
+               /* This tag gets added only once, if there are any custom TLVs */
+               if (!have_custom_tlvs) {
+                       tag_start(w, "unknown-tlvs", "UnknownTLVs");
+                       have_custom_tlvs++;
+               }
+               len = 0;
+               oui = lldpctl_atom_get_buffer(custom, lldpctl_k_custom_tlv_oui, &len);
+               len = 0;
+               oui_info = lldpctl_atom_get_buffer(custom, lldpctl_k_custom_tlv_oui_info_string, &len);
+               if (!oui)
+                       continue;
+               tag_start(w, "unknown-tlv", "TLV");
+
+               /* Add OUI as attribute */
+               snprintf(buf, sizeof(buf), "%02X,%02X,%02X", oui[0], oui[1], oui[2]);
+               tag_attr(w, "oui", "OUI", buf);
+               snprintf(buf, sizeof(buf), "%d",
+                        (int)lldpctl_atom_get_int(custom, lldpctl_k_custom_tlv_oui_subtype));
+               tag_attr(w, "subtype", "SubType", buf);
+               snprintf(buf, sizeof(buf), "%d", (int)len);
+               tag_attr(w, "len", "Len", buf);
+               if (len > 0) {
+                       for (slen=0, i=0; i < len; ++i)
+                               slen += snprintf(buf + slen, sizeof(buf) > slen ? sizeof(buf) - slen : 0, 
+                                                "%02X%s", oui_info[i], ((i < len - 1) ? "," : ""));
+                       tag_data(w, buf);
+               }
+               tag_end(w);
+       }
+       lldpctl_atom_dec_ref(custom_list);
+
+       if (have_custom_tlvs)
+               tag_end(w);
+}
+
+
 static void
 display_autoneg(struct writer * w, int advertised, int bithd, int bitfd, char *desc)
 {
@@ -536,6 +583,8 @@ display_interface(lldpctl_conn_t *conn, struct writer *w, int hidden,
                display_med(w, neighbor);
        }
 
+       display_custom_tlvs(w, neighbor, details);
+
        tag_end(w);
 }