+
+static int
+lldp_private_iana_print(netdissect_options *ndo,
+ const u_char *tptr, u_int tlv_len)
+{
+ int hexdump = FALSE;
+ u_int subtype;
+
+ if (tlv_len < 8) {
+ return hexdump;
+ }
+ subtype = GET_U_1(tptr + 3);
+
+ ND_PRINT("\n\t %s Subtype (%u)",
+ tok2str(lldp_iana_subtype_values, "unknown", subtype),
+ subtype);
+
+ switch (subtype) {
+ case LLDP_IANA_SUBTYPE_MUDURL:
+ ND_PRINT("\n\t MUD-URL=");
+ nd_printjn(ndo, tptr+4, tlv_len-4);
+ break;
+ default:
+ hexdump=TRUE;
+ }
+
+ return hexdump;
+}
+
+
+
+/*
+ * Print private TIA extensions.
+ */
+static int
+lldp_private_tia_print(netdissect_options *ndo,
+ const u_char *tptr, u_int tlv_len)
+{
+ int hexdump = FALSE;
+ u_int subtype;
+ uint8_t location_format;
+ uint16_t power_val;
+ u_int lci_len;
+ uint8_t ca_type, ca_len;
+
+ if (tlv_len < 4) {
+ return hexdump;
+ }
+ subtype = GET_U_1(tptr + 3);
+
+ ND_PRINT("\n\t %s Subtype (%u)",
+ tok2str(lldp_tia_subtype_values, "unknown", subtype),
+ subtype);
+
+ switch (subtype) {
+ case LLDP_PRIVATE_TIA_SUBTYPE_CAPABILITIES:
+ if (tlv_len < 7) {
+ return hexdump;
+ }
+ ND_PRINT("\n\t Media capabilities [%s] (0x%04x)",
+ bittok2str(lldp_tia_capabilities_values, "none",
+ GET_BE_U_2(tptr + 4)), GET_BE_U_2(tptr + 4));
+ ND_PRINT("\n\t Device type [%s] (0x%02x)",
+ tok2str(lldp_tia_device_type_values, "unknown", GET_U_1(tptr + 6)),
+ GET_U_1(tptr + 6));
+ break;
+
+ case LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY:
+ if (tlv_len < 8) {
+ return hexdump;
+ }
+ ND_PRINT("\n\t Application type [%s] (0x%02x)",
+ tok2str(lldp_tia_application_type_values, "none", GET_U_1(tptr + 4)),
+ GET_U_1(tptr + 4));
+ ND_PRINT(", Flags [%s]", bittok2str(
+ lldp_tia_network_policy_bits_values, "none", GET_U_1((tptr + 5))));
+ ND_PRINT("\n\t Vlan id %u",
+ LLDP_EXTRACT_NETWORK_POLICY_VLAN(GET_BE_U_2(tptr + 5)));
+ ND_PRINT(", L2 priority %u",
+ LLDP_EXTRACT_NETWORK_POLICY_L2_PRIORITY(GET_BE_U_2(tptr + 6)));
+ ND_PRINT(", DSCP value %u",
+ LLDP_EXTRACT_NETWORK_POLICY_DSCP(GET_BE_U_2(tptr + 6)));
+ break;
+
+ case LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID:
+ if (tlv_len < 5) {
+ return hexdump;
+ }
+ location_format = GET_U_1(tptr + 4);
+ ND_PRINT("\n\t Location data format %s (0x%02x)",
+ tok2str(lldp_tia_location_data_format_values, "unknown", location_format),
+ location_format);
+
+ switch (location_format) {
+ case LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED:
+ if (tlv_len < 21) {
+ return hexdump;
+ }
+ ND_PRINT("\n\t Latitude resolution %u, latitude value %" PRIu64,
+ (GET_U_1(tptr + 5) >> 2),
+ lldp_extract_latlon(ndo, tptr + 5));
+ ND_PRINT("\n\t Longitude resolution %u, longitude value %" PRIu64,
+ (GET_U_1(tptr + 10) >> 2),
+ lldp_extract_latlon(ndo, tptr + 10));
+ ND_PRINT("\n\t Altitude type %s (%u)",
+ tok2str(lldp_tia_location_altitude_type_values, "unknown",GET_U_1(tptr + 15) >> 4),
+ (GET_U_1(tptr + 15) >> 4));
+ ND_PRINT("\n\t Altitude resolution %u, altitude value 0x%x",
+ (GET_BE_U_2(tptr + 15)>>6)&0x3f,
+ (GET_BE_U_4(tptr + 16) & 0x3fffffff));
+ ND_PRINT("\n\t Datum %s (0x%02x)",
+ tok2str(lldp_tia_location_datum_type_values, "unknown", GET_U_1(tptr + 20)),
+ GET_U_1(tptr + 20));
+ break;
+
+ case LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS:
+ if (tlv_len < 6) {
+ return hexdump;
+ }
+ lci_len = GET_U_1(tptr + 5);
+ if (lci_len < 3) {
+ return hexdump;
+ }
+ if (tlv_len < 7+lci_len) {
+ return hexdump;
+ }
+ ND_PRINT("\n\t LCI length %u, LCI what %s (0x%02x), Country-code ",
+ lci_len,
+ tok2str(lldp_tia_location_lci_what_values, "unknown", GET_U_1(tptr + 6)),
+ GET_U_1(tptr + 6));
+
+ /* Country code */
+ nd_printjnp(ndo, tptr + 7, 2);
+
+ lci_len = lci_len-3;
+ tptr = tptr + 9;
+
+ /* Decode each civic address element */
+ while (lci_len > 0) {
+ if (lci_len < 2) {
+ return hexdump;
+ }
+ ca_type = GET_U_1(tptr);
+ ca_len = GET_U_1(tptr + 1);
+
+ tptr += 2;
+ lci_len -= 2;
+
+ ND_PRINT("\n\t CA type \'%s\' (%u), length %u: ",
+ tok2str(lldp_tia_location_lci_catype_values, "unknown", ca_type),
+ ca_type, ca_len);
+
+ /* basic sanity check */
+ if ( ca_type == 0 || ca_len == 0) {
+ return hexdump;
+ }
+ if (lci_len < ca_len) {
+ return hexdump;
+ }
+
+ nd_printjnp(ndo, tptr, ca_len);
+ tptr += ca_len;
+ lci_len -= ca_len;
+ }
+ break;
+
+ case LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN:
+ ND_PRINT("\n\t ECS ELIN id ");
+ nd_printjnp(ndo, tptr + 5, tlv_len - 5);
+ break;
+
+ default:
+ ND_PRINT("\n\t Location ID ");
+ print_unknown_data(ndo, tptr + 5, "\n\t ", tlv_len - 5);
+ }
+ break;
+
+ case LLDP_PRIVATE_TIA_SUBTYPE_EXTENDED_POWER_MDI:
+ if (tlv_len < 7) {
+ return hexdump;
+ }
+ ND_PRINT("\n\t Power type [%s]",
+ (GET_U_1(tptr + 4) & 0xC0 >> 6) ? "PD device" : "PSE device");
+ ND_PRINT(", Power source [%s]",
+ tok2str(lldp_tia_power_source_values, "none", (GET_U_1((tptr + 4)) & 0x30) >> 4));
+ ND_PRINT("\n\t Power priority [%s] (0x%02x)",
+ tok2str(lldp_tia_power_priority_values, "none", GET_U_1(tptr + 4) & 0x0f),
+ GET_U_1(tptr + 4) & 0x0f);
+ power_val = GET_BE_U_2(tptr + 5);
+ if (power_val < LLDP_TIA_POWER_VAL_MAX) {
+ ND_PRINT(", Power %.1f Watts", ((float)power_val) / 10);
+ } else {
+ ND_PRINT(", Power %u (Reserved)", power_val);
+ }
+ break;
+
+ case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV:
+ case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV:
+ case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV:
+ case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER:
+ case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME:
+ case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME:
+ case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID:
+ ND_PRINT("\n\t %s ",
+ tok2str(lldp_tia_inventory_values, "unknown", subtype));
+ nd_printjnp(ndo, tptr + 4, tlv_len - 4);
+ break;
+
+ default:
+ hexdump = TRUE;
+ break;
+ }
+
+ return hexdump;
+}
+
+/*
+ * Print DCBX Protocol fields (V 1.01).
+ */
+static int
+lldp_private_dcbx_print(netdissect_options *ndo,
+ const u_char *pptr, u_int len)
+{
+ int hexdump = FALSE;
+ u_int subtype;
+ uint16_t tval;
+ uint16_t tlv;
+ uint32_t i, pgval, uval;
+ u_int tlen, tlv_type;
+ uint16_t tlv_len;
+ const u_char *tptr, *mptr;
+
+ if (len < 4) {
+ return hexdump;
+ }
+ subtype = GET_U_1(pptr + 3);
+
+ ND_PRINT("\n\t %s Subtype (%u)",
+ tok2str(lldp_dcbx_subtype_values, "unknown", subtype),
+ subtype);
+
+ /* by passing old version */
+ if (subtype == LLDP_DCBX_SUBTYPE_1)
+ return TRUE;
+
+ tptr = pptr + 4;
+ tlen = len - 4;
+
+ while (tlen >= sizeof(tlv)) {
+
+ ND_TCHECK_LEN(tptr, sizeof(tlv));
+
+ tlv = GET_BE_U_2(tptr);
+
+ tlv_type = LLDP_EXTRACT_TYPE(tlv);
+ tlv_len = LLDP_EXTRACT_LEN(tlv);
+ hexdump = FALSE;
+
+ tlen -= sizeof(tlv);
+ tptr += sizeof(tlv);
+
+ /* loop check */
+ if (!tlv_type || !tlv_len) {
+ break;
+ }
+
+ ND_TCHECK_LEN(tptr, tlv_len);
+ if (tlen < tlv_len) {
+ goto trunc;
+ }
+
+ /* decode every tlv */
+ switch (tlv_type) {
+ case LLDP_DCBX_CONTROL_TLV:
+ if (tlv_len < 10) {
+ goto trunc;
+ }
+ ND_PRINT("\n\t Control - Protocol Control (type 0x%x, length %u)",
+ LLDP_DCBX_CONTROL_TLV, tlv_len);
+ ND_PRINT("\n\t Oper_Version: %u", GET_U_1(tptr));
+ ND_PRINT("\n\t Max_Version: %u", GET_U_1(tptr + 1));
+ ND_PRINT("\n\t Sequence Number: %u", GET_BE_U_4(tptr + 2));
+ ND_PRINT("\n\t Acknowledgement Number: %u",
+ GET_BE_U_4(tptr + 6));
+ break;
+ case LLDP_DCBX_PRIORITY_GROUPS_TLV:
+ if (tlv_len < 17) {
+ goto trunc;
+ }
+ ND_PRINT("\n\t Feature - Priority Group (type 0x%x, length %u)",
+ LLDP_DCBX_PRIORITY_GROUPS_TLV, tlv_len);
+ ND_PRINT("\n\t Oper_Version: %u", GET_U_1(tptr));
+ ND_PRINT("\n\t Max_Version: %u", GET_U_1(tptr + 1));
+ ND_PRINT("\n\t Info block(0x%02X): ", GET_U_1(tptr + 2));
+ tval = GET_U_1(tptr + 2);
+ ND_PRINT("Enable bit: %u, Willing bit: %u, Error Bit: %u",
+ (tval & 0x80) ? 1 : 0, (tval & 0x40) ? 1 : 0,
+ (tval & 0x20) ? 1 : 0);
+ ND_PRINT("\n\t SubType: %u", GET_U_1(tptr + 3));
+ ND_PRINT("\n\t Priority Allocation");
+
+ /*
+ * Array of 8 4-bit priority group ID values; we fetch all
+ * 32 bits and extract each nibble.
+ */
+ pgval = GET_BE_U_4(tptr + 4);
+ for (i = 0; i <= 7; i++) {
+ ND_PRINT("\n\t PgId_%u: %u",
+ i, (pgval >> (28 - 4 * i)) & 0xF);
+ }
+ ND_PRINT("\n\t Priority Group Allocation");
+ for (i = 0; i <= 7; i++)
+ ND_PRINT("\n\t Pg percentage[%u]: %u", i,
+ GET_U_1(tptr + 8 + i));
+ ND_PRINT("\n\t NumTCsSupported: %u", GET_U_1(tptr + 8 + 8));
+ break;
+ case LLDP_DCBX_PRIORITY_FLOW_CONTROL_TLV:
+ if (tlv_len < 6) {
+ goto trunc;
+ }
+ ND_PRINT("\n\t Feature - Priority Flow Control");
+ ND_PRINT(" (type 0x%x, length %u)",
+ LLDP_DCBX_PRIORITY_FLOW_CONTROL_TLV, tlv_len);
+ ND_PRINT("\n\t Oper_Version: %u", GET_U_1(tptr));
+ ND_PRINT("\n\t Max_Version: %u", GET_U_1(tptr + 1));
+ ND_PRINT("\n\t Info block(0x%02X): ", GET_U_1(tptr + 2));
+ tval = GET_U_1(tptr + 2);
+ ND_PRINT("Enable bit: %u, Willing bit: %u, Error Bit: %u",
+ (tval & 0x80) ? 1 : 0, (tval & 0x40) ? 1 : 0,
+ (tval & 0x20) ? 1 : 0);
+ ND_PRINT("\n\t SubType: %u", GET_U_1(tptr + 3));
+ tval = GET_U_1(tptr + 4);
+ ND_PRINT("\n\t PFC Config (0x%02X)", GET_U_1(tptr + 4));
+ for (i = 0; i <= 7; i++)
+ ND_PRINT("\n\t Priority Bit %u: %s",
+ i, (tval & (1 << i)) ? "Enabled" : "Disabled");
+ ND_PRINT("\n\t NumTCPFCSupported: %u", GET_U_1(tptr + 5));
+ break;
+ case LLDP_DCBX_APPLICATION_TLV:
+ if (tlv_len < 4) {
+ goto trunc;
+ }
+ ND_PRINT("\n\t Feature - Application (type 0x%x, length %u)",
+ LLDP_DCBX_APPLICATION_TLV, tlv_len);
+ ND_PRINT("\n\t Oper_Version: %u", GET_U_1(tptr));
+ ND_PRINT("\n\t Max_Version: %u", GET_U_1(tptr + 1));
+ ND_PRINT("\n\t Info block(0x%02X): ", GET_U_1(tptr + 2));
+ tval = GET_U_1(tptr + 2);
+ ND_PRINT("Enable bit: %u, Willing bit: %u, Error Bit: %u",
+ (tval & 0x80) ? 1 : 0, (tval & 0x40) ? 1 : 0,
+ (tval & 0x20) ? 1 : 0);
+ ND_PRINT("\n\t SubType: %u", GET_U_1(tptr + 3));
+ tval = tlv_len - 4;
+ mptr = tptr + 4;
+ while (tval >= 6) {
+ ND_PRINT("\n\t Application Value");
+ ND_PRINT("\n\t Application Protocol ID: 0x%04x",
+ GET_BE_U_2(mptr));
+ uval = GET_BE_U_3(mptr + 2);
+ ND_PRINT("\n\t SF (0x%x) Application Protocol ID is %s",
+ (uval >> 22),
+ (uval >> 22) ? "Socket Number" : "L2 EtherType");
+ ND_PRINT("\n\t OUI: 0x%06x", uval & 0x3fffff);
+ ND_PRINT("\n\t User Priority Map: 0x%02x",
+ GET_U_1(mptr + 5));
+ tval = tval - 6;
+ mptr = mptr + 6;
+ }
+ break;
+ default:
+ hexdump = TRUE;
+ break;
+ }
+
+ /* do we also want to see a hex dump ? */
+ if (ndo->ndo_vflag > 1 || (ndo->ndo_vflag && hexdump)) {
+ print_unknown_data(ndo, tptr, "\n\t ", tlv_len);
+ }
+
+ tlen -= tlv_len;
+ tptr += tlv_len;
+ }
+
+ trunc:
+ return hexdump;
+}
+
+static char *
+lldp_network_addr_print(netdissect_options *ndo, const u_char *tptr, u_int len)
+{
+ uint8_t af;