]> The Tcpdump Group git mirrors - tcpdump/blob - print-lldp.c
From Carles Kishimoto <[email protected]>:
[tcpdump] / print-lldp.c
1 /*
2 * Copyright (c) 1998-2007 The TCPDUMP project
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that: (1) source code
6 * distributions retain the above copyright notice and this paragraph
7 * in its entirety, and (2) distributions including binary code include
8 * the above copyright notice and this paragraph in its entirety in
9 * the documentation or other materials provided with the distribution.
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
11 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
12 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
14 *
15 * support for the IEEE Link Discovery Protocol as per 802.1ab
16 *
17 * Original code by Hannes Gredler (hannes@juniper.net)
18 * IEEE and TIA extensions by Carles Kishimoto <carles.kishimoto@gmail.com>
19 */
20
21 #ifndef lint
22 static const char rcsid[] _U_ =
23 "@(#) $Header: /tcpdump/master/tcpdump/print-lldp.c,v 1.8 2007-12-08 09:52:31 hannes Exp $";
24 #endif
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include <tcpdump-stdinc.h>
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 #include "interface.h"
37 #include "extract.h"
38 #include "addrtoname.h"
39 #include "af.h"
40 #include "oui.h"
41
42 #define LLDP_EXTRACT_TYPE(x) (((x)&0xfe00)>>9)
43 #define LLDP_EXTRACT_LEN(x) ((x)&0x01ff)
44
45 /*
46 * TLV type codes
47 */
48 #define LLDP_END_TLV 0
49 #define LLDP_CHASSIS_ID_TLV 1
50 #define LLDP_PORT_ID_TLV 2
51 #define LLDP_TTL_TLV 3
52 #define LLDP_PORT_DESCR_TLV 4
53 #define LLDP_SYSTEM_NAME_TLV 5
54 #define LLDP_SYSTEM_DESCR_TLV 6
55 #define LLDP_SYSTEM_CAP_TLV 7
56 #define LLDP_MGMT_ADDR_TLV 8
57 #define LLDP_PRIVATE_TLV 127
58
59 static const struct tok lldp_tlv_values[] = {
60 { LLDP_END_TLV, "End" },
61 { LLDP_CHASSIS_ID_TLV, "Chassis ID" },
62 { LLDP_PORT_ID_TLV, "Port ID" },
63 { LLDP_TTL_TLV, "Time to Live" },
64 { LLDP_PORT_DESCR_TLV, "Port Description" },
65 { LLDP_SYSTEM_NAME_TLV, "System Name" },
66 { LLDP_SYSTEM_DESCR_TLV, "System Description" },
67 { LLDP_SYSTEM_CAP_TLV, "System Capabilities" },
68 { LLDP_MGMT_ADDR_TLV, "Management Address" },
69 { LLDP_PRIVATE_TLV, "Organization specific" },
70 { 0, NULL}
71 };
72
73 /*
74 * Chassis ID subtypes
75 */
76 #define LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE 1
77 #define LLDP_CHASSIS_INTF_ALIAS_SUBTYPE 2
78 #define LLDP_CHASSIS_PORT_COMP_SUBTYPE 3
79 #define LLDP_CHASSIS_MAC_ADDR_SUBTYPE 4
80 #define LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE 5
81 #define LLDP_CHASSIS_INTF_NAME_SUBTYPE 6
82 #define LLDP_CHASSIS_LOCAL_SUBTYPE 7
83
84 static const struct tok lldp_chassis_subtype_values[] = {
85 { LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE, "Chassis component"},
86 { LLDP_CHASSIS_INTF_ALIAS_SUBTYPE, "Interface alias"},
87 { LLDP_CHASSIS_PORT_COMP_SUBTYPE, "Port component"},
88 { LLDP_CHASSIS_MAC_ADDR_SUBTYPE, "MAC address"},
89 { LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE, "Network address"},
90 { LLDP_CHASSIS_INTF_NAME_SUBTYPE, "Interface name"},
91 { LLDP_CHASSIS_LOCAL_SUBTYPE, "Local"},
92 { 0, NULL}
93 };
94
95 /*
96 * Port ID subtypes
97 */
98 #define LLDP_PORT_INTF_ALIAS_SUBTYPE 1
99 #define LLDP_PORT_PORT_COMP_SUBTYPE 2
100 #define LLDP_PORT_MAC_ADDR_SUBTYPE 3
101 #define LLDP_PORT_NETWORK_ADDR_SUBTYPE 4
102 #define LLDP_PORT_INTF_NAME_SUBTYPE 5
103 #define LLDP_PORT_AGENT_CIRC_ID_SUBTYPE 6
104 #define LLDP_PORT_LOCAL_SUBTYPE 7
105
106 static const struct tok lldp_port_subtype_values[] = {
107 { LLDP_PORT_INTF_ALIAS_SUBTYPE, "Interface alias"},
108 { LLDP_PORT_PORT_COMP_SUBTYPE, "Port component"},
109 { LLDP_PORT_MAC_ADDR_SUBTYPE, "MAC address"},
110 { LLDP_PORT_NETWORK_ADDR_SUBTYPE, "Network Address"},
111 { LLDP_PORT_INTF_NAME_SUBTYPE, "Interface Name"},
112 { LLDP_PORT_AGENT_CIRC_ID_SUBTYPE, "Agent circuit ID"},
113 { LLDP_PORT_LOCAL_SUBTYPE, "Local"},
114 { 0, NULL}
115 };
116
117 /*
118 * System Capabilities
119 */
120 #define LLDP_CAP_OTHER (1 << 0)
121 #define LLDP_CAP_REPEATER (1 << 1)
122 #define LLDP_CAP_BRIDGE (1 << 2)
123 #define LLDP_CAP_WLAN_AP (1 << 3)
124 #define LLDP_CAP_ROUTER (1 << 4)
125 #define LLDP_CAP_PHONE (1 << 5)
126 #define LLDP_CAP_DOCSIS (1 << 6)
127 #define LLDP_CAP_STATION_ONLY (1 << 7)
128
129 static const struct tok lldp_cap_values[] = {
130 { LLDP_CAP_OTHER, "Other"},
131 { LLDP_CAP_REPEATER, "Repeater"},
132 { LLDP_CAP_BRIDGE, "Bridge"},
133 { LLDP_CAP_WLAN_AP, "WLAN AP"},
134 { LLDP_CAP_ROUTER, "Router"},
135 { LLDP_CAP_PHONE, "Telephone"},
136 { LLDP_CAP_DOCSIS, "Docsis"},
137 { LLDP_CAP_STATION_ONLY, "Station Only"},
138 { 0, NULL}
139 };
140
141 #define LLDP_PRIVATE_8023_SUBTYPE_MACPHY 1
142 #define LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER 2
143 #define LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR 3
144 #define LLDP_PRIVATE_8023_SUBTYPE_MTU 4
145
146 static const struct tok lldp_8023_subtype_values[] = {
147 { LLDP_PRIVATE_8023_SUBTYPE_MACPHY, "MAC/PHY configuration/status"},
148 { LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER, "Power via MDI"},
149 { LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR, "Link aggregation"},
150 { LLDP_PRIVATE_8023_SUBTYPE_MTU, "Max frame size"},
151 { 0, NULL}
152 };
153
154 #define LLDP_PRIVATE_TIA_SUBTYPE_CAPABILITIES 1
155 #define LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY 2
156 #define LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID 3
157 #define LLDP_PRIVATE_TIA_SUBTYPE_EXTENDED_POWER_MDI 4
158 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV 5
159 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV 6
160 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV 7
161 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER 8
162 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME 9
163 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME 10
164 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID 11
165
166 static const struct tok lldp_tia_subtype_values[] = {
167 { LLDP_PRIVATE_TIA_SUBTYPE_CAPABILITIES, "LLDP-MED Capabilities" },
168 { LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY, "Network policy" },
169 { LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID, "Location identification" },
170 { LLDP_PRIVATE_TIA_SUBTYPE_EXTENDED_POWER_MDI, "Extended power-via-MDI" },
171 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV, "Inventory - hardware revision" },
172 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV, "Inventory - firmware revision" },
173 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV, "Inventory - software revision" },
174 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER, "Inventory - serial number" },
175 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME, "Inventory - manufacturer name" },
176 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME, "Inventory - model name" },
177 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID, "Inventory - asset ID" },
178 { 0, NULL}
179 };
180
181 #define LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_METERS 1
182 #define LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_FLOORS 2
183
184 static const struct tok lldp_tia_location_altitude_type_values[] = {
185 { LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_METERS, "meters"},
186 { LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_FLOORS, "floors"},
187 { 0, NULL}
188 };
189
190 /* ANSI/TIA-1057 - Annex B */
191 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A1 1
192 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A2 2
193 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A3 3
194 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A4 4
195 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A5 5
196 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A6 6
197
198 static const struct tok lldp_tia_location_lci_catype_values[] = {
199 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A1, "national subdivisions (state,canton,region,province,prefecture)"},
200 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A2, "county, parish, gun, district"},
201 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A3, "city, township, shi"},
202 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A4, "city division, borough, city district, ward chou"},
203 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A5, "neighborhood, block"},
204 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A6, "street"},
205 { 0, NULL}
206 };
207
208 static const struct tok lldp_tia_location_lci_what_values[] = {
209 { 0, "location of DHCP server"},
210 { 1, "location of the network element believed to be closest to the client"},
211 { 2, "location of the client"},
212 { 0, NULL}
213 };
214
215 /*
216 * From RFC 3636 - dot3MauType
217 */
218 #define LLDP_MAU_TYPE_UNKNOWN 0
219 #define LLDP_MAU_TYPE_AUI 1
220 #define LLDP_MAU_TYPE_10BASE_5 2
221 #define LLDP_MAU_TYPE_FOIRL 3
222 #define LLDP_MAU_TYPE_10BASE_2 4
223 #define LLDP_MAU_TYPE_10BASE_T 5
224 #define LLDP_MAU_TYPE_10BASE_FP 6
225 #define LLDP_MAU_TYPE_10BASE_FB 7
226 #define LLDP_MAU_TYPE_10BASE_FL 8
227 #define LLDP_MAU_TYPE_10BROAD36 9
228 #define LLDP_MAU_TYPE_10BASE_T_HD 10
229 #define LLDP_MAU_TYPE_10BASE_T_FD 11
230 #define LLDP_MAU_TYPE_10BASE_FL_HD 12
231 #define LLDP_MAU_TYPE_10BASE_FL_FD 13
232 #define LLDP_MAU_TYPE_100BASE_T4 14
233 #define LLDP_MAU_TYPE_100BASE_TX_HD 15
234 #define LLDP_MAU_TYPE_100BASE_TX_FD 16
235 #define LLDP_MAU_TYPE_100BASE_FX_HD 17
236 #define LLDP_MAU_TYPE_100BASE_FX_FD 18
237 #define LLDP_MAU_TYPE_100BASE_T2_HD 19
238 #define LLDP_MAU_TYPE_100BASE_T2_FD 20
239 #define LLDP_MAU_TYPE_1000BASE_X_HD 21
240 #define LLDP_MAU_TYPE_1000BASE_X_FD 22
241 #define LLDP_MAU_TYPE_1000BASE_LX_HD 23
242 #define LLDP_MAU_TYPE_1000BASE_LX_FD 24
243 #define LLDP_MAU_TYPE_1000BASE_SX_HD 25
244 #define LLDP_MAU_TYPE_1000BASE_SX_FD 26
245 #define LLDP_MAU_TYPE_1000BASE_CX_HD 27
246 #define LLDP_MAU_TYPE_1000BASE_CX_FD 28
247 #define LLDP_MAU_TYPE_1000BASE_T_HD 29
248 #define LLDP_MAU_TYPE_1000BASE_T_FD 30
249 #define LLDP_MAU_TYPE_10GBASE_X 31
250 #define LLDP_MAU_TYPE_10GBASE_LX4 32
251 #define LLDP_MAU_TYPE_10GBASE_R 33
252 #define LLDP_MAU_TYPE_10GBASE_ER 34
253 #define LLDP_MAU_TYPE_10GBASE_LR 35
254 #define LLDP_MAU_TYPE_10GBASE_SR 36
255 #define LLDP_MAU_TYPE_10GBASE_W 37
256 #define LLDP_MAU_TYPE_10GBASE_EW 38
257 #define LLDP_MAU_TYPE_10GBASE_LW 39
258 #define LLDP_MAU_TYPE_10GBASE_SW 40
259
260 static const struct tok lldp_mau_types_values[] = {
261 { LLDP_MAU_TYPE_UNKNOWN, "Unknown"},
262 { LLDP_MAU_TYPE_AUI, "AUI"},
263 { LLDP_MAU_TYPE_10BASE_5, "10BASE_5"},
264 { LLDP_MAU_TYPE_FOIRL, "FOIRL"},
265 { LLDP_MAU_TYPE_10BASE_2, "10BASE2"},
266 { LLDP_MAU_TYPE_10BASE_T, "10BASET duplex mode unknown"},
267 { LLDP_MAU_TYPE_10BASE_FP, "10BASEFP"},
268 { LLDP_MAU_TYPE_10BASE_FB, "10BASEFB"},
269 { LLDP_MAU_TYPE_10BASE_FL, "10BASEFL duplex mode unknown"},
270 { LLDP_MAU_TYPE_10BROAD36, "10BROAD36"},
271 { LLDP_MAU_TYPE_10BASE_T_HD, "10BASET hdx"},
272 { LLDP_MAU_TYPE_10BASE_T_FD, "10BASET fdx"},
273 { LLDP_MAU_TYPE_10BASE_FL_HD, "10BASEFL hdx"},
274 { LLDP_MAU_TYPE_10BASE_FL_FD, "10BASEFL fdx"},
275 { LLDP_MAU_TYPE_100BASE_T4, "100BASET4"},
276 { LLDP_MAU_TYPE_100BASE_TX_HD, "100BASETX hdx"},
277 { LLDP_MAU_TYPE_100BASE_TX_FD, "100BASETX fdx"},
278 { LLDP_MAU_TYPE_100BASE_FX_HD, "100BASEFX hdx"},
279 { LLDP_MAU_TYPE_100BASE_FX_FD, "100BASEFX fdx"},
280 { LLDP_MAU_TYPE_100BASE_T2_HD, "100BASET2 hdx"},
281 { LLDP_MAU_TYPE_100BASE_T2_FD, "100BASET2 fdx"},
282 { LLDP_MAU_TYPE_1000BASE_X_HD, "1000BASEX hdx"},
283 { LLDP_MAU_TYPE_1000BASE_X_FD, "1000BASEX fdx"},
284 { LLDP_MAU_TYPE_1000BASE_LX_HD, "1000BASELX hdx"},
285 { LLDP_MAU_TYPE_1000BASE_LX_FD, "1000BASELX fdx"},
286 { LLDP_MAU_TYPE_1000BASE_SX_HD, "1000BASESX hdx"},
287 { LLDP_MAU_TYPE_1000BASE_SX_FD, "1000BASESX fdx"},
288 { LLDP_MAU_TYPE_1000BASE_CX_HD, "1000BASECX hdx"},
289 { LLDP_MAU_TYPE_1000BASE_CX_FD, "1000BASECX fdx"},
290 { LLDP_MAU_TYPE_1000BASE_T_HD, "1000BASET hdx"},
291 { LLDP_MAU_TYPE_1000BASE_T_FD, "1000BASET fdx"},
292 { LLDP_MAU_TYPE_10GBASE_X, "10GBASEX"},
293 { LLDP_MAU_TYPE_10GBASE_LX4, "10GBASELX4"},
294 { LLDP_MAU_TYPE_10GBASE_R, "10GBASER"},
295 { LLDP_MAU_TYPE_10GBASE_ER, "10GBASEER"},
296 { LLDP_MAU_TYPE_10GBASE_LR, "10GBASELR"},
297 { LLDP_MAU_TYPE_10GBASE_SR, "10GBASESR"},
298 { LLDP_MAU_TYPE_10GBASE_W, "10GBASEW"},
299 { LLDP_MAU_TYPE_10GBASE_EW, "10GBASEEW"},
300 { LLDP_MAU_TYPE_10GBASE_LW, "10GBASELW"},
301 { LLDP_MAU_TYPE_10GBASE_SW, "10GBASESW"},
302 { 0, NULL}
303 };
304
305 #define LLDP_8023_AUTONEGOTIATION_SUPPORT (1 << 0)
306 #define LLDP_8023_AUTONEGOTIATION_STATUS (1 << 1)
307
308 static const struct tok lldp_8023_autonegotiation_values[] = {
309 { LLDP_8023_AUTONEGOTIATION_SUPPORT, "supported"},
310 { LLDP_8023_AUTONEGOTIATION_STATUS, "enabled"},
311 { 0, NULL}
312 };
313
314 #define LLDP_TIA_CAPABILITY_MED (1 << 0)
315 #define LLDP_TIA_CAPABILITY_NETWORK_POLICY (1 << 1)
316 #define LLDP_TIA_CAPABILITY_LOCATION_IDENTIFICATION (1 << 2)
317 #define LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PSE (1 << 3)
318 #define LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PD (1 << 4)
319 #define LLDP_TIA_CAPABILITY_INVENTORY (1 << 5)
320
321 static const struct tok lldp_tia_capabilities_values[] = {
322 { LLDP_TIA_CAPABILITY_MED, "LLDP-MED capabilities"},
323 { LLDP_TIA_CAPABILITY_NETWORK_POLICY, "network policy"},
324 { LLDP_TIA_CAPABILITY_LOCATION_IDENTIFICATION, "location identification"},
325 { LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PSE, "extended power via MDI-PSE"},
326 { LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PD, "extended power via MDI-PD"},
327 { LLDP_TIA_CAPABILITY_INVENTORY, "Inventory"},
328 { 0, NULL}
329 };
330
331 #define LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_1 1
332 #define LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_2 2
333 #define LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_3 3
334 #define LLDP_TIA_DEVICE_TYPE_NETWORK_CONNECTIVITY 4
335
336 static const struct tok lldp_tia_device_type_values[] = {
337 { LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_1, "endpoint class 1"},
338 { LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_2, "endpoint class 2"},
339 { LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_3, "endpoint class 3"},
340 { LLDP_TIA_DEVICE_TYPE_NETWORK_CONNECTIVITY, "network connectivity"},
341 { 0, NULL}
342 };
343
344 #define LLDP_TIA_APPLICATION_TYPE_VOICE 1
345 #define LLDP_TIA_APPLICATION_TYPE_VOICE_SIGNALING 2
346 #define LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE 3
347 #define LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE_SIGNALING 4
348 #define LLDP_TIA_APPLICATION_TYPE_SOFTPHONE_VOICE 5
349 #define LLDP_TIA_APPLICATION_TYPE_VIDEO_CONFERENCING 6
350 #define LLDP_TIA_APPLICATION_TYPE_STREAMING_VIDEO 7
351 #define LLDP_TIA_APPLICATION_TYPE_VIDEO_SIGNALING 8
352
353 static const struct tok lldp_tia_application_type_values[] = {
354 { LLDP_TIA_APPLICATION_TYPE_VOICE, "voice"},
355 { LLDP_TIA_APPLICATION_TYPE_VOICE_SIGNALING, "voice signaling"},
356 { LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE, "guest voice"},
357 { LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE_SIGNALING, "guest voice signaling"},
358 { LLDP_TIA_APPLICATION_TYPE_SOFTPHONE_VOICE, "softphone voice"},
359 { LLDP_TIA_APPLICATION_TYPE_VIDEO_CONFERENCING, "video conferencing"},
360 { LLDP_TIA_APPLICATION_TYPE_STREAMING_VIDEO, "streaming video"},
361 { LLDP_TIA_APPLICATION_TYPE_VIDEO_SIGNALING, "video signaling"},
362 { 0, NULL}
363 };
364
365 #define LLDP_TIA_NETWORK_POLICY_U_BIT (1 << 5)
366 #define LLDP_TIA_NETWORK_POLICY_T_BIT (1 << 6)
367 #define LLDP_TIA_NETWORK_POLICY_X_BIT (1 << 7)
368
369 static const struct tok lldp_tia_network_policy_bits_values[] = {
370 { LLDP_TIA_NETWORK_POLICY_U_BIT, "Unknown"},
371 { LLDP_TIA_NETWORK_POLICY_T_BIT, "Tagged"},
372 { LLDP_TIA_NETWORK_POLICY_X_BIT, "reserved"},
373 { 0, NULL}
374 };
375
376 #define LLDP_EXTRACT_NETWORK_POLICY_VLAN(x) (((x)&0x1ffe)>>1)
377 #define LLDP_EXTRACT_NETWORK_POLICY_L2_PRIORITY(x) (((x)&0x01ff)>>6)
378 #define LLDP_EXTRACT_NETWORK_POLICY_DSCP(x) ((x)&0x003f)
379
380 #define LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED 1
381 #define LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS 2
382 #define LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN 3
383
384 static const struct tok lldp_tia_location_data_format_values[] = {
385 { LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED, "coordinate-based LCI"},
386 { LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS, "civic address LCI"},
387 { LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN, "ECS ELIN"},
388 { 0, NULL}
389 };
390
391 #define LLDP_TIA_LOCATION_DATUM_WGS_84 1
392 #define LLDP_TIA_LOCATION_DATUM_NAD_83_NAVD_88 2
393 #define LLDP_TIA_LOCATION_DATUM_NAD_83_MLLW 3
394
395 static const struct tok lldp_tia_location_datum_type_values[] = {
396 { LLDP_TIA_LOCATION_DATUM_WGS_84, "World Geodesic System 1984"},
397 { LLDP_TIA_LOCATION_DATUM_NAD_83_NAVD_88, "North American Datum 1983 (NAVD88)"},
398 { LLDP_TIA_LOCATION_DATUM_NAD_83_MLLW, "North American Datum 1983 (MLLW)"},
399 { 0, NULL}
400 };
401
402 #define LLDP_TIA_POWER_SOURCE_PSE 1
403 #define LLDP_TIA_POWER_SOURCE_LOCAL 2
404 #define LLDP_TIA_POWER_SOURCE_PSE_AND_LOCAL 3
405
406 static const struct tok lldp_tia_power_source_values[] = {
407 { LLDP_TIA_POWER_SOURCE_PSE, "PSE - primary power source"},
408 { LLDP_TIA_POWER_SOURCE_LOCAL, "local - backup power source"},
409 { LLDP_TIA_POWER_SOURCE_PSE_AND_LOCAL, "PSE+local - reserved"},
410 { 0, NULL}
411 };
412
413 #define LLDP_TIA_POWER_PRIORITY_CRITICAL 1
414 #define LLDP_TIA_POWER_PRIORITY_HIGH 2
415 #define LLDP_TIA_POWER_PRIORITY_LOW 3
416
417 static const struct tok lldp_tia_power_priority_values[] = {
418 { LLDP_TIA_POWER_PRIORITY_CRITICAL, "critical"},
419 { LLDP_TIA_POWER_PRIORITY_HIGH, "high"},
420 { LLDP_TIA_POWER_PRIORITY_LOW, "low"},
421 { 0, NULL}
422 };
423
424 #define LLDP_TIA_POWER_VAL_MAX 1024
425
426 static const struct tok lldp_tia_inventory_values[] = {
427 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV, "Hardware revision" },
428 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV, "Firmware revision" },
429 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV, "Software revision" },
430 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER, "Serial number" },
431 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME, "Manufacturer name" },
432 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME, "Model name" },
433 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID, "Asset ID" },
434 { 0, NULL}
435 };
436
437 /*
438 * From RFC 3636 - ifMauAutoNegCapAdvertisedBits
439 */
440 #define LLDP_MAU_PMD_OTHER (1 << 15)
441 #define LLDP_MAU_PMD_10BASE_T (1 << 14)
442 #define LLDP_MAU_PMD_10BASE_T_FD (1 << 13)
443 #define LLDP_MAU_PMD_100BASE_T4 (1 << 12)
444 #define LLDP_MAU_PMD_100BASE_TX (1 << 11)
445 #define LLDP_MAU_PMD_100BASE_TX_FD (1 << 10)
446 #define LLDP_MAU_PMD_100BASE_T2 (1 << 9)
447 #define LLDP_MAU_PMD_100BASE_T2_FD (1 << 8)
448 #define LLDP_MAU_PMD_FDXPAUSE (1 << 7)
449 #define LLDP_MAU_PMD_FDXAPAUSE (1 << 6)
450 #define LLDP_MAU_PMD_FDXSPAUSE (1 << 5)
451 #define LLDP_MAU_PMD_FDXBPAUSE (1 << 4)
452 #define LLDP_MAU_PMD_1000BASE_X (1 << 3)
453 #define LLDP_MAU_PMD_1000BASE_X_FD (1 << 2)
454 #define LLDP_MAU_PMD_1000BASE_T (1 << 1)
455 #define LLDP_MAU_PMD_1000BASE_T_FD (1 << 0)
456
457 static const struct tok lldp_pmd_capability_values[] = {
458 { LLDP_MAU_PMD_10BASE_T, "10BASE-T hdx"},
459 { LLDP_MAU_PMD_10BASE_T_FD, "10BASE-T fdx"},
460 { LLDP_MAU_PMD_100BASE_T4, "100BASE-T4"},
461 { LLDP_MAU_PMD_100BASE_TX, "100BASE-TX hdx"},
462 { LLDP_MAU_PMD_100BASE_TX_FD, "100BASE-TX fdx"},
463 { LLDP_MAU_PMD_100BASE_T2, "100BASE-T2 hdx"},
464 { LLDP_MAU_PMD_100BASE_T2_FD, "100BASE-T2 fdx"},
465 { LLDP_MAU_PMD_FDXPAUSE, "Pause for fdx links"},
466 { LLDP_MAU_PMD_FDXAPAUSE, "Asym PAUSE for fdx"},
467 { LLDP_MAU_PMD_FDXSPAUSE, "Sym PAUSE for fdx"},
468 { LLDP_MAU_PMD_FDXBPAUSE, "Asym and Sym PAUSE for fdx"},
469 { LLDP_MAU_PMD_1000BASE_X, "1000BASE-{X LX SX CX} hdx"},
470 { LLDP_MAU_PMD_1000BASE_X_FD, "1000BASE-{X LX SX CX} fdx"},
471 { LLDP_MAU_PMD_1000BASE_T, "1000BASE-T hdx"},
472 { LLDP_MAU_PMD_1000BASE_T_FD, "1000BASE-T fdx"},
473 { 0, NULL}
474 };
475
476 #define LLDP_MDI_PORT_CLASS (1 << 0)
477 #define LLDP_MDI_POWER_SUPPORT (1 << 1)
478 #define LLDP_MDI_POWER_STATE (1 << 2)
479 #define LLDP_MDI_PAIR_CONTROL_ABILITY (1 << 3)
480
481 static const struct tok lldp_mdi_values[] = {
482 { LLDP_MDI_PORT_CLASS, "PSE"},
483 { LLDP_MDI_POWER_SUPPORT, "supported"},
484 { LLDP_MDI_POWER_STATE, "enabled"},
485 { LLDP_MDI_PAIR_CONTROL_ABILITY, "can be controlled"},
486 { 0, NULL}
487 };
488
489 #define LLDP_MDI_PSE_PORT_POWER_PAIRS_SIGNAL 1
490 #define LLDP_MDI_PSE_PORT_POWER_PAIRS_SPARE 2
491
492 static const struct tok lldp_mdi_power_pairs_values[] = {
493 { LLDP_MDI_PSE_PORT_POWER_PAIRS_SIGNAL, "signal"},
494 { LLDP_MDI_PSE_PORT_POWER_PAIRS_SPARE, "spare"},
495 { 0, NULL}
496 };
497
498 #define LLDP_MDI_POWER_CLASS0 1
499 #define LLDP_MDI_POWER_CLASS1 2
500 #define LLDP_MDI_POWER_CLASS2 3
501 #define LLDP_MDI_POWER_CLASS3 4
502 #define LLDP_MDI_POWER_CLASS4 5
503
504 static const struct tok lldp_mdi_power_class_values[] = {
505 { LLDP_MDI_POWER_CLASS0, "class0"},
506 { LLDP_MDI_POWER_CLASS1, "class1"},
507 { LLDP_MDI_POWER_CLASS2, "class2"},
508 { LLDP_MDI_POWER_CLASS3, "class3"},
509 { LLDP_MDI_POWER_CLASS4, "class4"},
510 { 0, NULL}
511 };
512
513 #define LLDP_AGGREGATION_CAPABILTIY (1 << 0)
514 #define LLDP_AGGREGATION_STATUS (1 << 1)
515
516 static const struct tok lldp_aggregation_values[] = {
517 { LLDP_AGGREGATION_CAPABILTIY, "supported"},
518 { LLDP_AGGREGATION_STATUS, "enabled"},
519 { 0, NULL}
520 };
521
522 /*
523 * Interface numbering subtypes.
524 */
525 #define LLDP_INTF_NUMB_IFX_SUBTYPE 2
526 #define LLDP_INTF_NUMB_SYSPORT_SUBTYPE 3
527
528 static const struct tok lldp_intf_numb_subtype_values[] = {
529 { LLDP_INTF_NUMB_IFX_SUBTYPE, "Interface Index" },
530 { LLDP_INTF_NUMB_SYSPORT_SUBTYPE, "System Port Number" },
531 { 0, NULL}
532 };
533
534 #define LLDP_INTF_NUM_LEN 5
535
536 /*
537 * Print IEEE private extensions.
538 */
539 static int
540 lldp_private_8023_print(const u_char *tptr)
541 {
542 int subtype, hexdump = FALSE;
543
544 subtype = *(tptr+3);
545
546 printf("\n\t %s Subtype (%u)",
547 tok2str(lldp_8023_subtype_values, "unknown", subtype),
548 subtype);
549
550 switch (subtype) {
551 case LLDP_PRIVATE_8023_SUBTYPE_MACPHY:
552 printf("\n\t autonegotiation [%s] (0x%02x)",
553 bittok2str(lldp_8023_autonegotiation_values, "none", *(tptr+4)),
554 *(tptr+4));
555 printf("\n\t PMD autoneg capability [%s] (0x%04x)",
556 bittok2str(lldp_pmd_capability_values,"unknown", EXTRACT_16BITS(tptr+5)),
557 EXTRACT_16BITS(tptr+5));
558 printf("\n\t MAU type %s (0x%04x)",
559 tok2str(lldp_mau_types_values, "unknown", EXTRACT_16BITS(tptr+7)),
560 EXTRACT_16BITS(tptr+7));
561 break;
562
563 case LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER:
564 printf("\n\t MDI power support [%s], power pair %s, power class %s",
565 bittok2str(lldp_mdi_values, "none", *(tptr+4)),
566 tok2str(lldp_mdi_power_pairs_values, "unknown", *(tptr+5)),
567 tok2str(lldp_mdi_power_class_values, "unknown", *(tptr+6)));
568 break;
569
570 case LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR:
571 printf("\n\t aggregation status [%s], aggregation port ID %u",
572 bittok2str(lldp_aggregation_values, "none", (*tptr+4)),
573 EXTRACT_32BITS(tptr+5));
574 break;
575
576 case LLDP_PRIVATE_8023_SUBTYPE_MTU:
577 printf("\n\t MTU size %u", EXTRACT_16BITS(tptr+4));
578 break;
579
580 default:
581 hexdump = TRUE;
582 break;
583 }
584
585 return hexdump;
586 }
587
588 /*
589 * Extract 34bits of latitude/longitude coordinates.
590 */
591 static u_int64_t
592 lldp_extract_latlon(const u_char *tptr)
593 {
594 u_int64_t latlon;
595
596 latlon = *tptr & 0x3;
597 latlon = (latlon << 32) | EXTRACT_32BITS(tptr+1);
598
599 return latlon;
600 }
601
602 /*
603 * Print private TIA extensions.
604 */
605 static int
606 lldp_private_tia_print(const u_char *tptr, u_int tlv_len)
607 {
608 int subtype, hexdump = FALSE;
609 u_int8_t location_format;
610 u_int16_t power_val;
611 u_int8_t lci_len, ca_type, ca_len;
612
613 subtype = *(tptr+3);
614
615 printf("\n\t %s Subtype (%u)",
616 tok2str(lldp_tia_subtype_values, "unknown", subtype),
617 subtype);
618
619 switch (subtype) {
620 case LLDP_PRIVATE_TIA_SUBTYPE_CAPABILITIES:
621 printf("\n\t Media capabilities [%s] (0x%04x)",
622 bittok2str(lldp_tia_capabilities_values, "none",
623 EXTRACT_16BITS(tptr+4)), EXTRACT_16BITS(tptr+4));
624 printf("\n\t Device type [%s] (0x%02x)",
625 tok2str(lldp_tia_device_type_values, "unknown", *(tptr+6)),
626 *(tptr+6));
627 break;
628
629 case LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY:
630 printf("\n\t Application type [%s] (0x%02x)",
631 tok2str(lldp_tia_application_type_values, "none", *(tptr+4)),
632 *(tptr+4));
633 printf(", Flags [%s]", bittok2str(
634 lldp_tia_network_policy_bits_values, "none", *(tptr+5)));
635 printf("\n\t Vlan id %u",
636 LLDP_EXTRACT_NETWORK_POLICY_VLAN(EXTRACT_16BITS(tptr+5)));
637 printf(", L2 priority %u",
638 LLDP_EXTRACT_NETWORK_POLICY_L2_PRIORITY(EXTRACT_16BITS(tptr+6)));
639 printf(", DSCP value %u",
640 LLDP_EXTRACT_NETWORK_POLICY_DSCP(EXTRACT_16BITS(tptr+6)));
641 break;
642
643 case LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID:
644 location_format = *(tptr+4);
645 printf("\n\t Location data format %s (0x%02x)",
646 tok2str(lldp_tia_location_data_format_values, "unknown", location_format),
647 location_format);
648
649 switch (location_format) {
650 case LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED:
651 printf("\n\t Latitude resolution %u, latitude value %" PRIu64,
652 (*(tptr+5)>>2), lldp_extract_latlon(tptr+5));
653 printf("\n\t Longitude resolution %u, longitude value %" PRIu64,
654 (*(tptr+10)>>2), lldp_extract_latlon(tptr+10));
655 printf("\n\t Altitude type %s (%u)",
656 tok2str(lldp_tia_location_altitude_type_values, "unknown",(*(tptr+15)>>4)),
657 (*(tptr+15)>>4));
658 printf("\n\t Altitude resolution %u, altitude value 0x%x",
659 (EXTRACT_16BITS(tptr+15)>>6)&0x3f,
660 ((EXTRACT_32BITS(tptr+16)&0x3fffffff)));
661 printf("\n\t Datum %s (0x%02x)",
662 tok2str(lldp_tia_location_datum_type_values, "unknown", *(tptr+20)),
663 *(tptr+20));
664 break;
665
666 case LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS:
667 lci_len = *(tptr+5);
668 printf("\n\t LCI length %u, LCI what %s (0x%02x), Country-code ",
669 lci_len,
670 tok2str(lldp_tia_location_lci_what_values, "unknown", *(tptr+6)),
671 *(tptr+6));
672
673 /* Country code */
674 safeputs((const char *)(tptr+7), 2);
675
676 lci_len = lci_len-3;
677 tptr = tptr + 9;
678
679 /* Decode each civic address element */
680 while (lci_len > 0) {
681 ca_type = *(tptr);
682 ca_len = *(tptr+1);
683
684 tptr += 2;
685 lci_len -= 2;
686
687 printf("\n\t CA type \'%s\' (%u), length %u: ",
688 tok2str(lldp_tia_location_lci_catype_values, "unknown", ca_type),
689 ca_type, ca_len);
690
691 /* basic sanity check */
692 if ( ca_type == 0 || ca_len == 0) {
693 return hexdump;
694 }
695
696 safeputs((const char *)tptr, ca_len);
697 tptr += ca_len;
698 lci_len -= ca_len;
699 }
700 break;
701
702 case LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN:
703 printf("\n\t ECS ELIN id ");
704 safeputs((const char *)tptr+5, tlv_len-5);
705 break;
706
707 default:
708 printf("\n\t Location ID ");
709 print_unknown_data(tptr+5, "\n\t ", tlv_len-5);
710 }
711 break;
712
713 case LLDP_PRIVATE_TIA_SUBTYPE_EXTENDED_POWER_MDI:
714 printf("\n\t Power type [%s]",
715 (*(tptr+4)&0xC0>>6) ? "PD device" : "PSE device");
716 printf(", Power source [%s]",
717 tok2str(lldp_tia_power_source_values, "none", (*(tptr+4)&0x30)>>4));
718 printf("\n\t Power priority [%s] (0x%02x)",
719 tok2str(lldp_tia_power_priority_values, "none", *(tptr+4)&0x0f),
720 *(tptr+4)&0x0f);
721 power_val = EXTRACT_16BITS(tptr+5);
722 if (power_val < LLDP_TIA_POWER_VAL_MAX) {
723 printf(", Power %.1f Watts", ((float)power_val)/10);
724 } else {
725 printf(", Power %u (Reserved)", power_val);
726 }
727 break;
728
729 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV:
730 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV:
731 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV:
732 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER:
733 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME:
734 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME:
735 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID:
736 printf("\n\t %s ",
737 tok2str(lldp_tia_inventory_values, "unknown", subtype));
738 safeputs((const char *)tptr+4, tlv_len-4);
739 break;
740
741 default:
742 hexdump = TRUE;
743 break;
744 }
745
746 return hexdump;
747 }
748
749 static char *
750 lldp_network_addr_print(const u_char *tptr) {
751
752 u_int8_t af;
753 static char buf[BUFSIZE];
754 const char * (*pfunc)(const u_char *);
755
756 af = *tptr;
757 switch (af) {
758 case AFNUM_INET:
759 pfunc = getname;
760 break;
761 #ifdef INET6
762 case AFNUM_INET6:
763 pfunc = getname6;
764 break;
765 #endif
766 case AFNUM_802:
767 pfunc = etheraddr_string;
768 break;
769 default:
770 pfunc = NULL;
771 break;
772 }
773
774 if (!pfunc) {
775 snprintf(buf, sizeof(buf), "AFI %s (%u), no AF printer !",
776 tok2str(af_values, "Unknown", af), af);
777 } else {
778 snprintf(buf, sizeof(buf), "AFI %s (%u): %s",
779 tok2str(af_values, "Unknown", af), af, (*pfunc)(tptr+1));
780 }
781
782 return buf;
783 }
784
785 static int
786 lldp_mgmt_addr_tlv_print(const u_char *pptr, u_int len) {
787
788 u_int8_t mgmt_addr_len, intf_num_subtype, oid_len;
789 const u_char *tptr;
790 u_int tlen;
791
792 tlen = len;
793 tptr = pptr;
794
795 mgmt_addr_len = *tptr++;
796 tlen--;
797
798 if (tlen < mgmt_addr_len) {
799 return 0;
800 }
801
802 printf("\n\t Management Address length %u, %s",
803 mgmt_addr_len,
804 lldp_network_addr_print(tptr));
805 tptr += mgmt_addr_len;
806 tlen -= mgmt_addr_len;
807
808 if (tlen < LLDP_INTF_NUM_LEN) {
809 return 0;
810 }
811
812 intf_num_subtype = *tptr;
813 printf("\n\t %s Interface Numbering (%u): %u",
814 tok2str(lldp_intf_numb_subtype_values, "Unknown", intf_num_subtype),
815 intf_num_subtype,
816 EXTRACT_32BITS(tptr+1));
817
818 tptr += LLDP_INTF_NUM_LEN;
819 tlen -= LLDP_INTF_NUM_LEN;
820
821 /*
822 * The OID is optional.
823 */
824 if (tlen) {
825 oid_len = *tptr;
826
827 if (oid_len) {
828 printf("\n\t OID length %u", oid_len);
829 safeputs((const char *)tptr+1, oid_len);
830 }
831 }
832
833 return 1;
834 }
835
836 void
837 lldp_print(register const u_char *pptr, register u_int len) {
838
839 u_int8_t subtype;
840 u_int16_t tlv, cap, ena_cap;
841 u_int oui, tlen, hexdump, tlv_type, tlv_len;
842 const u_char *tptr;
843
844 tptr = pptr;
845 tlen = len;
846
847 if (vflag) {
848 printf("LLDP, length %u", len);
849 }
850
851 while (tlen >= sizeof(tlv)) {
852
853 TCHECK2(*tptr, sizeof(tlv));
854
855 tlv = EXTRACT_16BITS(tptr);
856
857 tlv_type = LLDP_EXTRACT_TYPE(tlv);
858 tlv_len = LLDP_EXTRACT_LEN(tlv);
859 hexdump = FALSE;
860
861 tlen -= sizeof(tlv);
862 tptr += sizeof(tlv);
863
864 if (vflag) {
865 printf("\n\t%s TLV (%u), length %u",
866 tok2str(lldp_tlv_values, "Unknown", tlv_type),
867 tlv_type, tlv_len);
868 }
869
870 /* infinite loop check */
871 if (!tlv_type || !tlv_len) {
872 break;
873 }
874
875 TCHECK2(*tptr, tlv_len);
876
877 switch (tlv_type) {
878 case LLDP_TTL_TLV:
879 if (vflag) {
880 printf(": TTL %us", EXTRACT_16BITS(tptr));
881 }
882 break;
883
884 case LLDP_SYSTEM_NAME_TLV:
885
886 /*
887 * The system name is also print in non-verbose mode
888 * similar to the CDP printer.
889 */
890 if (vflag) {
891 printf(": ");
892 safeputs((const char *)tptr, tlv_len);
893 } else {
894 printf("LLDP, name ");
895 safeputs((const char *)tptr, tlv_len);
896 printf(", length %u", len);
897 }
898 break;
899
900 case LLDP_PORT_DESCR_TLV:
901 if (vflag) {
902 printf(": ");
903 safeputs((const char *)tptr, tlv_len);
904 }
905 break;
906
907 case LLDP_SYSTEM_DESCR_TLV:
908 if (vflag) {
909 printf("\n\t ");
910 safeputs((const char *)tptr, tlv_len);
911 }
912 break;
913
914
915 case LLDP_CHASSIS_ID_TLV:
916 if (vflag) {
917 subtype = *tptr;
918 printf("\n\t Subtype %s (%u): ",
919 tok2str(lldp_chassis_subtype_values, "Unknown", subtype),
920 subtype);
921
922 switch (subtype) {
923 case LLDP_CHASSIS_MAC_ADDR_SUBTYPE:
924 printf("%s", etheraddr_string(tptr+1));
925 break;
926
927 case LLDP_CHASSIS_INTF_NAME_SUBTYPE: /* fall through */
928 case LLDP_CHASSIS_LOCAL_SUBTYPE:
929 case LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE:
930 case LLDP_CHASSIS_INTF_ALIAS_SUBTYPE:
931 case LLDP_CHASSIS_PORT_COMP_SUBTYPE:
932 safeputs((const char *)tptr+1, tlv_len-1);
933 break;
934
935 case LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE:
936 printf("%s", lldp_network_addr_print(tptr+1));
937 break;
938
939 default:
940 hexdump = TRUE;
941 break;
942 }
943 }
944 break;
945
946 case LLDP_PORT_ID_TLV:
947 if (vflag) {
948 subtype = *tptr;
949 printf("\n\t Subtype %s (%u): ",
950 tok2str(lldp_port_subtype_values, "Unknown", subtype),
951 subtype);
952
953 switch (subtype) {
954 case LLDP_PORT_MAC_ADDR_SUBTYPE:
955 printf("%s", etheraddr_string(tptr+1));
956 break;
957
958 case LLDP_PORT_INTF_NAME_SUBTYPE: /* fall through */
959 case LLDP_PORT_LOCAL_SUBTYPE:
960 case LLDP_PORT_AGENT_CIRC_ID_SUBTYPE:
961 case LLDP_PORT_INTF_ALIAS_SUBTYPE:
962 case LLDP_PORT_PORT_COMP_SUBTYPE:
963 safeputs((const char *)tptr+1, tlv_len-1);
964 break;
965
966 case LLDP_PORT_NETWORK_ADDR_SUBTYPE:
967 printf("%s", lldp_network_addr_print(tptr+1));
968 break;
969
970 default:
971 hexdump = TRUE;
972 break;
973 }
974 }
975 break;
976
977 case LLDP_PRIVATE_TLV:
978 if (vflag) {
979 oui = EXTRACT_24BITS(tptr);
980 printf(": OUI %s (0x%06x)", tok2str(oui_values, "Unknown", oui), oui);
981
982 switch (oui) {
983 case OUI_IEEE_PRIVATE:
984 hexdump = lldp_private_8023_print(tptr);
985 break;
986 case OUI_TIA:
987 hexdump = lldp_private_tia_print(tptr, tlv_len);
988 break;
989 default:
990 hexdump = TRUE;
991 break;
992 }
993 }
994 break;
995
996 case LLDP_SYSTEM_CAP_TLV:
997 if (vflag) {
998 cap = EXTRACT_16BITS(tptr);
999 ena_cap = EXTRACT_16BITS(tptr+2);
1000 printf("\n\t System Capabilities [%s] (0x%04x)",
1001 bittok2str(lldp_cap_values, "none", cap), cap);
1002 printf("\n\t Enabled Capabilities [%s] (0x%04x)",
1003 bittok2str(lldp_cap_values, "none", ena_cap), ena_cap);
1004 }
1005 break;
1006
1007 case LLDP_MGMT_ADDR_TLV:
1008 if (vflag) {
1009 if (!lldp_mgmt_addr_tlv_print(tptr, tlen)) {
1010 goto trunc;
1011 }
1012 }
1013 break;
1014
1015 default:
1016 hexdump = TRUE;
1017 break;
1018 }
1019
1020 /* do we also want to see a hex dump ? */
1021 if (vflag > 1 || (vflag && hexdump)) {
1022 print_unknown_data(tptr,"\n\t ", tlv_len);
1023 }
1024
1025 tlen -= tlv_len;
1026 tptr += tlv_len;
1027 }
1028 return;
1029 trunc:
1030 printf("\n\t[|LLDP]");
1031 }
1032
1033 /*
1034 * Local Variables:
1035 * c-style: whitesmith
1036 * c-basic-offset: 4
1037 * End:
1038 */