+int ldp_tlv_print(register const u_char *);
+
+/*
+ * ldp tlv header
+ *
+ * 0 1 2 3
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |U|F| Type | Length |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | |
+ * | Value |
+ * ~ ~
+ * | |
+ * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+
+int
+ldp_tlv_print(register const u_char *tptr) {
+
+ struct ldp_tlv_header {
+ u_int8_t type[2];
+ u_int8_t length[2];
+ };
+
+ const struct ldp_tlv_header *ldp_tlv_header;
+ u_short tlv_type,tlv_len,tlv_tlen;
+
+ ldp_tlv_header = (const struct ldp_tlv_header *)tptr;
+ tlv_len=EXTRACT_16BITS(ldp_tlv_header->length);
+ tlv_tlen=tlv_len;
+ tlv_type=LDP_MASK_TLV_TYPE(EXTRACT_16BITS(ldp_tlv_header->type));
+
+ /* FIXME vendor private / experimental check */
+ printf("\n\t %s TLV (0x%04x), length: %u, Flags: [%s and %s forward if unknown]",
+ tok2str(ldp_tlv_values,
+ "Unknown",
+ tlv_type),
+ tlv_type,
+ tlv_len,
+ LDP_MASK_U_BIT(EXTRACT_16BITS(&ldp_tlv_header->type)) ? "continue processing" : "ignore",
+ LDP_MASK_F_BIT(EXTRACT_16BITS(&ldp_tlv_header->type)) ? "do" : "don't");
+
+ tptr+=sizeof(struct ldp_tlv_header);
+
+ switch(tlv_type) {
+
+ case LDP_TLV_COMMON_HELLO:
+ printf("\n\t Hold Time: %us, Flags: [%s Hello%s]",
+ EXTRACT_16BITS(tptr),
+ (EXTRACT_16BITS(tptr+2)&0x8000) ? "Targeted" : "Link",
+ (EXTRACT_16BITS(tptr+2)&0x4000) ? ", Request for targeted Hellos" : "");
+ break;
+
+ case LDP_TLV_IPV4_TRANSPORT_ADDR:
+ printf("\n\t IPv4 Transport Address: %s", ipaddr_string(tptr));
+ break;
+#ifdef INET6
+ case LDP_TLV_IPV6_TRANSPORT_ADDR:
+ printf("\n\t IPv6 Transport Address: %s", ip6addr_string(tptr));
+ break;
+#endif
+ case LDP_TLV_CONFIG_SEQ_NUMBER:
+ printf("\n\t Sequence Number: %u", EXTRACT_32BITS(tptr));
+ break;
+
+ /*
+ * FIXME those are the defined TLVs that lack a decoder
+ * you are welcome to contribute code ;-)
+ */
+
+ case LDP_TLV_FEC:
+ case LDP_TLV_ADDRESS_LIST:
+ case LDP_TLV_HOP_COUNT:
+ case LDP_TLV_PATH_VECTOR:
+ case LDP_TLV_GENERIC_LABEL:
+ case LDP_TLV_ATM_LABEL:
+ case LDP_TLV_FR_LABEL:
+ case LDP_TLV_STATUS:
+ case LDP_TLV_EXTD_STATUS:
+ case LDP_TLV_RETURNED_PDU:
+ case LDP_TLV_RETURNED_MSG:
+ case LDP_TLV_COMMON_SESSION:
+ case LDP_TLV_ATM_SESSION_PARM:
+ case LDP_TLV_FR_SESSION_PARM:
+ case LDP_TLV_LABEL_REQUEST_MSG_ID:
+
+ default:
+ if (vflag <= 1)
+ print_unknown_data(tptr,"\n\t ",tlv_tlen);
+ break;
+ }
+ return(tlv_len+4); /* Type & Length fields not included */
+}
+