X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/707a7ce369c4056be0d2fcf9741c07ca89ba84c1..refs/heads/tcpdump-4.1:/print-lldp.c diff --git a/print-lldp.c b/print-lldp.c index 51008f87..e8f67fd2 100644 --- a/print-lldp.c +++ b/print-lldp.c @@ -20,7 +20,7 @@ #ifndef lint static const char rcsid[] _U_ = -"@(#) $Header: /tcpdump/master/tcpdump/print-lldp.c,v 1.6 2007-08-19 09:14:49 hannes Exp $"; +"@(#) $Header: /tcpdump/master/tcpdump/print-lldp.c,v 1.10 2008-03-20 09:30:56 hannes Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -138,16 +138,38 @@ static const struct tok lldp_cap_values[] = { { 0, NULL} }; -#define LLDP_PRIVATE_8023_SUTBYPE_MACPHY 1 -#define LLDP_PRIVATE_8023_SUTBYPE_MDIPOWER 2 -#define LLDP_PRIVATE_8023_SUTBYPE_LINKAGGR 3 -#define LLDP_PRIVATE_8023_SUTBYPE_MTU 4 +#define LLDP_PRIVATE_8021_SUBTYPE_PORT_VLAN_ID 1 +#define LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_VLAN_ID 2 +#define LLDP_PRIVATE_8021_SUBTYPE_VLAN_NAME 3 +#define LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_IDENTITY 4 + +static const struct tok lldp_8021_subtype_values[] = { + { LLDP_PRIVATE_8021_SUBTYPE_PORT_VLAN_ID, "Port VLAN Id"}, + { LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_VLAN_ID, "Port and Protocol VLAN ID"}, + { LLDP_PRIVATE_8021_SUBTYPE_VLAN_NAME, "VLAN name"}, + { LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_IDENTITY, "Protocol Identity"}, + { 0, NULL} +}; + +#define LLDP_8021_PORT_PROTOCOL_VLAN_SUPPORT (1 << 1) +#define LLDP_8021_PORT_PROTOCOL_VLAN_STATUS (1 << 2) + +static const struct tok lldp_8021_port_protocol_id_values[] = { + { LLDP_8021_PORT_PROTOCOL_VLAN_SUPPORT, "supported"}, + { LLDP_8021_PORT_PROTOCOL_VLAN_STATUS, "enabled"}, + { 0, NULL} +}; + +#define LLDP_PRIVATE_8023_SUBTYPE_MACPHY 1 +#define LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER 2 +#define LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR 3 +#define LLDP_PRIVATE_8023_SUBTYPE_MTU 4 static const struct tok lldp_8023_subtype_values[] = { - { LLDP_PRIVATE_8023_SUTBYPE_MACPHY, "MAC/PHY configuration/status"}, - { LLDP_PRIVATE_8023_SUTBYPE_MDIPOWER, "Power via MDI"}, - { LLDP_PRIVATE_8023_SUTBYPE_LINKAGGR, "Link aggregation"}, - { LLDP_PRIVATE_8023_SUTBYPE_MTU, "Max frame size"}, + { LLDP_PRIVATE_8023_SUBTYPE_MACPHY, "MAC/PHY configuration/status"}, + { LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER, "Power via MDI"}, + { LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR, "Link aggregation"}, + { LLDP_PRIVATE_8023_SUBTYPE_MTU, "Max frame size"}, { 0, NULL} }; @@ -178,11 +200,39 @@ static const struct tok lldp_tia_subtype_values[] = { { 0, NULL} }; -#define LLDP_NETWORK_CONNECTIVITY_TLV -#define LLDP_ENDPOINT_CLASS_1_TLV -#define LLDP_ENDPOINT_CLASS_2_TLV -#define LLDP_ENDPOINT_CLASS_3_TLV -#define LLDP_INVENTORY_TLV +#define LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_METERS 1 +#define LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_FLOORS 2 + +static const struct tok lldp_tia_location_altitude_type_values[] = { + { LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_METERS, "meters"}, + { LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_FLOORS, "floors"}, + { 0, NULL} +}; + +/* ANSI/TIA-1057 - Annex B */ +#define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A1 1 +#define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A2 2 +#define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A3 3 +#define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A4 4 +#define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A5 5 +#define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A6 6 + +static const struct tok lldp_tia_location_lci_catype_values[] = { + { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A1, "national subdivisions (state,canton,region,province,prefecture)"}, + { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A2, "county, parish, gun, district"}, + { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A3, "city, township, shi"}, + { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A4, "city division, borough, city district, ward chou"}, + { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A5, "neighborhood, block"}, + { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A6, "street"}, + { 0, NULL} +}; + +static const struct tok lldp_tia_location_lci_what_values[] = { + { 0, "location of DHCP server"}, + { 1, "location of the network element believed to be closest to the client"}, + { 2, "location of the client"}, + { 0, NULL} +}; /* * From RFC 3636 - dot3MauType @@ -360,6 +410,17 @@ static const struct tok lldp_tia_location_data_format_values[] = { { 0, NULL} }; +#define LLDP_TIA_LOCATION_DATUM_WGS_84 1 +#define LLDP_TIA_LOCATION_DATUM_NAD_83_NAVD_88 2 +#define LLDP_TIA_LOCATION_DATUM_NAD_83_MLLW 3 + +static const struct tok lldp_tia_location_datum_type_values[] = { + { LLDP_TIA_LOCATION_DATUM_WGS_84, "World Geodesic System 1984"}, + { LLDP_TIA_LOCATION_DATUM_NAD_83_NAVD_88, "North American Datum 1983 (NAVD88)"}, + { LLDP_TIA_LOCATION_DATUM_NAD_83_MLLW, "North American Datum 1983 (MLLW)"}, + { 0, NULL} +}; + #define LLDP_TIA_POWER_SOURCE_PSE 1 #define LLDP_TIA_POWER_SOURCE_LOCAL 2 #define LLDP_TIA_POWER_SOURCE_PSE_AND_LOCAL 3 @@ -398,22 +459,22 @@ static const struct tok lldp_tia_inventory_values[] = { /* * From RFC 3636 - ifMauAutoNegCapAdvertisedBits */ -#define LLDP_MAU_PMD_OTHER (1 << 0) -#define LLDP_MAU_PMD_10BASE_T (1 << 1) -#define LLDP_MAU_PMD_10BASE_T_FD (1 << 2) -#define LLDP_MAU_PMD_100BASE_T4 (1 << 3) -#define LLDP_MAU_PMD_100BASE_TX (1 << 4) -#define LLDP_MAU_PMD_100BASE_TX_FD (1 << 5) -#define LLDP_MAU_PMD_100BASE_T2 (1 << 6) -#define LLDP_MAU_PMD_100BASE_T2_FD (1 << 7) -#define LLDP_MAU_PMD_FDXPAUSE (1 << 8) -#define LLDP_MAU_PMD_FDXAPAUSE (1 << 9) -#define LLDP_MAU_PMD_FDXSPAUSE (1 << 10) -#define LLDP_MAU_PMD_FDXBPAUSE (1 << 11) -#define LLDP_MAU_PMD_1000BASE_X (1 << 12) -#define LLDP_MAU_PMD_1000BASE_X_FD (1 << 13) -#define LLDP_MAU_PMD_1000BASE_T (1 << 14) -#define LLDP_MAU_PMD_1000BASE_T_FD (1 << 15) +#define LLDP_MAU_PMD_OTHER (1 << 15) +#define LLDP_MAU_PMD_10BASE_T (1 << 14) +#define LLDP_MAU_PMD_10BASE_T_FD (1 << 13) +#define LLDP_MAU_PMD_100BASE_T4 (1 << 12) +#define LLDP_MAU_PMD_100BASE_TX (1 << 11) +#define LLDP_MAU_PMD_100BASE_TX_FD (1 << 10) +#define LLDP_MAU_PMD_100BASE_T2 (1 << 9) +#define LLDP_MAU_PMD_100BASE_T2_FD (1 << 8) +#define LLDP_MAU_PMD_FDXPAUSE (1 << 7) +#define LLDP_MAU_PMD_FDXAPAUSE (1 << 6) +#define LLDP_MAU_PMD_FDXSPAUSE (1 << 5) +#define LLDP_MAU_PMD_FDXBPAUSE (1 << 4) +#define LLDP_MAU_PMD_1000BASE_X (1 << 3) +#define LLDP_MAU_PMD_1000BASE_X_FD (1 << 2) +#define LLDP_MAU_PMD_1000BASE_T (1 << 1) +#define LLDP_MAU_PMD_1000BASE_T_FD (1 << 0) static const struct tok lldp_pmd_capability_values[] = { { LLDP_MAU_PMD_10BASE_T, "10BASE-T hdx"}, @@ -495,7 +556,51 @@ static const struct tok lldp_intf_numb_subtype_values[] = { #define LLDP_INTF_NUM_LEN 5 /* - * Print IEEE private extensions. + * Print IEEE private extensions. (802.1 annex F) + */ +static int +lldp_private_8021_print(const u_char *tptr) +{ + int subtype, hexdump = FALSE; + + subtype = *(tptr+3); + + printf("\n\t %s Subtype (%u)", + tok2str(lldp_8021_subtype_values, "unknown", subtype), + subtype); + + switch (subtype) { + case LLDP_PRIVATE_8021_SUBTYPE_PORT_VLAN_ID: + printf("\n\t port vlan id (PVID): %u", + EXTRACT_16BITS(tptr+4)); + break; + case LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_VLAN_ID: + printf("\n\t port and protocol vlan id (PPVID): %u, flags [%s] (0x%02x)", + EXTRACT_16BITS(tptr+5), + bittok2str(lldp_8021_port_protocol_id_values, "none", *(tptr+4)), + *(tptr+4)); + break; + case LLDP_PRIVATE_8021_SUBTYPE_VLAN_NAME: + printf("\n\t vlan id (VID): %u", + EXTRACT_16BITS(tptr+4)); + printf("\n\t vlan name: "); + safeputs((const char *)tptr+7, *(tptr+6)); + break; + case LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_IDENTITY: + printf("\n\t protocol identity: "); + safeputs((const char *)tptr+5, *(tptr+4)); + break; + + default: + hexdump = TRUE; + break; + } + + return hexdump; +} + +/* + * Print IEEE private extensions. (802.3) */ static int lldp_private_8023_print(const u_char *tptr) @@ -509,7 +614,7 @@ lldp_private_8023_print(const u_char *tptr) subtype); switch (subtype) { - case LLDP_PRIVATE_8023_SUTBYPE_MACPHY: + case LLDP_PRIVATE_8023_SUBTYPE_MACPHY: printf("\n\t autonegotiation [%s] (0x%02x)", bittok2str(lldp_8023_autonegotiation_values, "none", *(tptr+4)), *(tptr+4)); @@ -521,20 +626,20 @@ lldp_private_8023_print(const u_char *tptr) EXTRACT_16BITS(tptr+7)); break; - case LLDP_PRIVATE_8023_SUTBYPE_MDIPOWER: + case LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER: printf("\n\t MDI power support [%s], power pair %s, power class %s", bittok2str(lldp_mdi_values, "none", *(tptr+4)), tok2str(lldp_mdi_power_pairs_values, "unknown", *(tptr+5)), tok2str(lldp_mdi_power_class_values, "unknown", *(tptr+6))); break; - case LLDP_PRIVATE_8023_SUTBYPE_LINKAGGR: + case LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR: printf("\n\t aggregation status [%s], aggregation port ID %u", - bittok2str(lldp_aggregation_values, "none", (*tptr+4)), + bittok2str(lldp_aggregation_values, "none", *(tptr+4)), EXTRACT_32BITS(tptr+5)); break; - case LLDP_PRIVATE_8023_SUTBYPE_MTU: + case LLDP_PRIVATE_8023_SUBTYPE_MTU: printf("\n\t MTU size %u", EXTRACT_16BITS(tptr+4)); break; @@ -546,6 +651,20 @@ lldp_private_8023_print(const u_char *tptr) return hexdump; } +/* + * Extract 34bits of latitude/longitude coordinates. + */ +static u_int64_t +lldp_extract_latlon(const u_char *tptr) +{ + u_int64_t latlon; + + latlon = *tptr & 0x3; + latlon = (latlon << 32) | EXTRACT_32BITS(tptr+1); + + return latlon; +} + /* * Print private TIA extensions. */ @@ -555,6 +674,7 @@ lldp_private_tia_print(const u_char *tptr, u_int tlv_len) int subtype, hexdump = FALSE; u_int8_t location_format; u_int16_t power_val; + u_int8_t lci_len, ca_type, ca_len; subtype = *(tptr+3); @@ -579,24 +699,77 @@ lldp_private_tia_print(const u_char *tptr, u_int tlv_len) printf(", Flags [%s]", bittok2str( lldp_tia_network_policy_bits_values, "none", *(tptr+5))); printf("\n\t Vlan id %u", - LLDP_EXTRACT_NETWORK_POLICY_VLAN(EXTRACT_16BITS(tptr+5))); + LLDP_EXTRACT_NETWORK_POLICY_VLAN(EXTRACT_16BITS(tptr+5))); printf(", L2 priority %u", - LLDP_EXTRACT_NETWORK_POLICY_L2_PRIORITY(EXTRACT_16BITS(tptr+6))); + LLDP_EXTRACT_NETWORK_POLICY_L2_PRIORITY(EXTRACT_16BITS(tptr+6))); printf(", DSCP value %u", - LLDP_EXTRACT_NETWORK_POLICY_DSCP(EXTRACT_16BITS(tptr+6))); + LLDP_EXTRACT_NETWORK_POLICY_DSCP(EXTRACT_16BITS(tptr+6))); break; case LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID: location_format = *(tptr+4); - printf("\n\t Location data format [%s] (0x%02x)", - tok2str(lldp_tia_location_data_format_values, "none", location_format), + printf("\n\t Location data format %s (0x%02x)", + tok2str(lldp_tia_location_data_format_values, "unknown", location_format), location_format); switch (location_format) { - /* FIXME - print location ID based on location data format */ case LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED: + printf("\n\t Latitude resolution %u, latitude value %" PRIu64, + (*(tptr+5)>>2), lldp_extract_latlon(tptr+5)); + printf("\n\t Longitude resolution %u, longitude value %" PRIu64, + (*(tptr+10)>>2), lldp_extract_latlon(tptr+10)); + printf("\n\t Altitude type %s (%u)", + tok2str(lldp_tia_location_altitude_type_values, "unknown",(*(tptr+15)>>4)), + (*(tptr+15)>>4)); + printf("\n\t Altitude resolution %u, altitude value 0x%x", + (EXTRACT_16BITS(tptr+15)>>6)&0x3f, + ((EXTRACT_32BITS(tptr+16)&0x3fffffff))); + printf("\n\t Datum %s (0x%02x)", + tok2str(lldp_tia_location_datum_type_values, "unknown", *(tptr+20)), + *(tptr+20)); + break; + case LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS: + lci_len = *(tptr+5); + printf("\n\t LCI length %u, LCI what %s (0x%02x), Country-code ", + lci_len, + tok2str(lldp_tia_location_lci_what_values, "unknown", *(tptr+6)), + *(tptr+6)); + + /* Country code */ + safeputs((const char *)(tptr+7), 2); + + lci_len = lci_len-3; + tptr = tptr + 9; + + /* Decode each civic address element */ + while (lci_len > 0) { + ca_type = *(tptr); + ca_len = *(tptr+1); + + tptr += 2; + lci_len -= 2; + + printf("\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; + } + + safeputs((const char *)tptr, ca_len); + tptr += ca_len; + lci_len -= ca_len; + } + break; + case LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN: + printf("\n\t ECS ELIN id "); + safeputs((const char *)tptr+5, tlv_len-5); + break; + default: printf("\n\t Location ID "); print_unknown_data(tptr+5, "\n\t ", tlv_len-5); @@ -626,8 +799,8 @@ lldp_private_tia_print(const u_char *tptr, u_int tlv_len) case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME: case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME: case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID: - printf("\n\t %s ", - tok2str(lldp_tia_inventory_values, "unknown", subtype)); + printf("\n\t %s ", + tok2str(lldp_tia_inventory_values, "unknown", subtype)); safeputs((const char *)tptr+4, tlv_len-4); break; @@ -873,7 +1046,10 @@ lldp_print(register const u_char *pptr, register u_int len) { printf(": OUI %s (0x%06x)", tok2str(oui_values, "Unknown", oui), oui); switch (oui) { - case OUI_IEEE_PRIVATE: + case OUI_IEEE_8021_PRIVATE: + hexdump = lldp_private_8021_print(tptr); + break; + case OUI_IEEE_8023_PRIVATE: hexdump = lldp_private_8023_print(tptr); break; case OUI_TIA: