]> The Tcpdump Group git mirrors - tcpdump/blob - print-lldp.c
Clean up types to squelch narrowing warnings.
[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 * Original code by Hannes Gredler (hannes@gredler.at)
16 * IEEE and TIA extensions by Carles Kishimoto <carles.kishimoto@gmail.com>
17 * DCBX extensions by Kaladhar Musunuru <kaladharm@sourceforge.net>
18 */
19
20 /* \summary: IEEE 802.1ab Link Layer Discovery Protocol (LLDP) printer */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include "netdissect-stdinc.h"
27
28 #include <stdio.h>
29
30 #include "netdissect.h"
31 #include "extract.h"
32 #include "addrtoname.h"
33 #include "af.h"
34 #include "oui.h"
35
36 #define LLDP_EXTRACT_TYPE(x) (((x)&0xfe00)>>9)
37 #define LLDP_EXTRACT_LEN(x) ((x)&0x01ff)
38
39 /*
40 * TLV type codes
41 */
42 #define LLDP_END_TLV 0
43 #define LLDP_CHASSIS_ID_TLV 1
44 #define LLDP_PORT_ID_TLV 2
45 #define LLDP_TTL_TLV 3
46 #define LLDP_PORT_DESCR_TLV 4
47 #define LLDP_SYSTEM_NAME_TLV 5
48 #define LLDP_SYSTEM_DESCR_TLV 6
49 #define LLDP_SYSTEM_CAP_TLV 7
50 #define LLDP_MGMT_ADDR_TLV 8
51 #define LLDP_PRIVATE_TLV 127
52
53 static const struct tok lldp_tlv_values[] = {
54 { LLDP_END_TLV, "End" },
55 { LLDP_CHASSIS_ID_TLV, "Chassis ID" },
56 { LLDP_PORT_ID_TLV, "Port ID" },
57 { LLDP_TTL_TLV, "Time to Live" },
58 { LLDP_PORT_DESCR_TLV, "Port Description" },
59 { LLDP_SYSTEM_NAME_TLV, "System Name" },
60 { LLDP_SYSTEM_DESCR_TLV, "System Description" },
61 { LLDP_SYSTEM_CAP_TLV, "System Capabilities" },
62 { LLDP_MGMT_ADDR_TLV, "Management Address" },
63 { LLDP_PRIVATE_TLV, "Organization specific" },
64 { 0, NULL}
65 };
66
67 /*
68 * Chassis ID subtypes
69 */
70 #define LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE 1
71 #define LLDP_CHASSIS_INTF_ALIAS_SUBTYPE 2
72 #define LLDP_CHASSIS_PORT_COMP_SUBTYPE 3
73 #define LLDP_CHASSIS_MAC_ADDR_SUBTYPE 4
74 #define LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE 5
75 #define LLDP_CHASSIS_INTF_NAME_SUBTYPE 6
76 #define LLDP_CHASSIS_LOCAL_SUBTYPE 7
77
78 static const struct tok lldp_chassis_subtype_values[] = {
79 { LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE, "Chassis component"},
80 { LLDP_CHASSIS_INTF_ALIAS_SUBTYPE, "Interface alias"},
81 { LLDP_CHASSIS_PORT_COMP_SUBTYPE, "Port component"},
82 { LLDP_CHASSIS_MAC_ADDR_SUBTYPE, "MAC address"},
83 { LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE, "Network address"},
84 { LLDP_CHASSIS_INTF_NAME_SUBTYPE, "Interface name"},
85 { LLDP_CHASSIS_LOCAL_SUBTYPE, "Local"},
86 { 0, NULL}
87 };
88
89 /*
90 * Port ID subtypes
91 */
92 #define LLDP_PORT_INTF_ALIAS_SUBTYPE 1
93 #define LLDP_PORT_PORT_COMP_SUBTYPE 2
94 #define LLDP_PORT_MAC_ADDR_SUBTYPE 3
95 #define LLDP_PORT_NETWORK_ADDR_SUBTYPE 4
96 #define LLDP_PORT_INTF_NAME_SUBTYPE 5
97 #define LLDP_PORT_AGENT_CIRC_ID_SUBTYPE 6
98 #define LLDP_PORT_LOCAL_SUBTYPE 7
99
100 static const struct tok lldp_port_subtype_values[] = {
101 { LLDP_PORT_INTF_ALIAS_SUBTYPE, "Interface alias"},
102 { LLDP_PORT_PORT_COMP_SUBTYPE, "Port component"},
103 { LLDP_PORT_MAC_ADDR_SUBTYPE, "MAC address"},
104 { LLDP_PORT_NETWORK_ADDR_SUBTYPE, "Network Address"},
105 { LLDP_PORT_INTF_NAME_SUBTYPE, "Interface Name"},
106 { LLDP_PORT_AGENT_CIRC_ID_SUBTYPE, "Agent circuit ID"},
107 { LLDP_PORT_LOCAL_SUBTYPE, "Local"},
108 { 0, NULL}
109 };
110
111 /*
112 * System Capabilities
113 */
114 #define LLDP_CAP_OTHER (1 << 0)
115 #define LLDP_CAP_REPEATER (1 << 1)
116 #define LLDP_CAP_BRIDGE (1 << 2)
117 #define LLDP_CAP_WLAN_AP (1 << 3)
118 #define LLDP_CAP_ROUTER (1 << 4)
119 #define LLDP_CAP_PHONE (1 << 5)
120 #define LLDP_CAP_DOCSIS (1 << 6)
121 #define LLDP_CAP_STATION_ONLY (1 << 7)
122
123 static const struct tok lldp_cap_values[] = {
124 { LLDP_CAP_OTHER, "Other"},
125 { LLDP_CAP_REPEATER, "Repeater"},
126 { LLDP_CAP_BRIDGE, "Bridge"},
127 { LLDP_CAP_WLAN_AP, "WLAN AP"},
128 { LLDP_CAP_ROUTER, "Router"},
129 { LLDP_CAP_PHONE, "Telephone"},
130 { LLDP_CAP_DOCSIS, "Docsis"},
131 { LLDP_CAP_STATION_ONLY, "Station Only"},
132 { 0, NULL}
133 };
134
135 #define LLDP_PRIVATE_8021_SUBTYPE_PORT_VLAN_ID 1
136 #define LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_VLAN_ID 2
137 #define LLDP_PRIVATE_8021_SUBTYPE_VLAN_NAME 3
138 #define LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_IDENTITY 4
139 #define LLDP_PRIVATE_8021_SUBTYPE_CONGESTION_NOTIFICATION 8
140 #define LLDP_PRIVATE_8021_SUBTYPE_ETS_CONFIGURATION 9
141 #define LLDP_PRIVATE_8021_SUBTYPE_ETS_RECOMMENDATION 10
142 #define LLDP_PRIVATE_8021_SUBTYPE_PFC_CONFIGURATION 11
143 #define LLDP_PRIVATE_8021_SUBTYPE_APPLICATION_PRIORITY 12
144 #define LLDP_PRIVATE_8021_SUBTYPE_EVB 13
145 #define LLDP_PRIVATE_8021_SUBTYPE_CDCP 14
146
147 static const struct tok lldp_8021_subtype_values[] = {
148 { LLDP_PRIVATE_8021_SUBTYPE_PORT_VLAN_ID, "Port VLAN Id"},
149 { LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_VLAN_ID, "Port and Protocol VLAN ID"},
150 { LLDP_PRIVATE_8021_SUBTYPE_VLAN_NAME, "VLAN name"},
151 { LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_IDENTITY, "Protocol Identity"},
152 { LLDP_PRIVATE_8021_SUBTYPE_CONGESTION_NOTIFICATION, "Congestion Notification"},
153 { LLDP_PRIVATE_8021_SUBTYPE_ETS_CONFIGURATION, "ETS Configuration"},
154 { LLDP_PRIVATE_8021_SUBTYPE_ETS_RECOMMENDATION, "ETS Recommendation"},
155 { LLDP_PRIVATE_8021_SUBTYPE_PFC_CONFIGURATION, "Priority Flow Control Configuration"},
156 { LLDP_PRIVATE_8021_SUBTYPE_APPLICATION_PRIORITY, "Application Priority"},
157 { LLDP_PRIVATE_8021_SUBTYPE_EVB, "EVB"},
158 { LLDP_PRIVATE_8021_SUBTYPE_CDCP,"CDCP"},
159 { 0, NULL}
160 };
161
162 #define LLDP_8021_PORT_PROTOCOL_VLAN_SUPPORT (1 << 1)
163 #define LLDP_8021_PORT_PROTOCOL_VLAN_STATUS (1 << 2)
164
165 static const struct tok lldp_8021_port_protocol_id_values[] = {
166 { LLDP_8021_PORT_PROTOCOL_VLAN_SUPPORT, "supported"},
167 { LLDP_8021_PORT_PROTOCOL_VLAN_STATUS, "enabled"},
168 { 0, NULL}
169 };
170
171 #define LLDP_PRIVATE_8023_SUBTYPE_MACPHY 1
172 #define LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER 2
173 #define LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR 3
174 #define LLDP_PRIVATE_8023_SUBTYPE_MTU 4
175
176 static const struct tok lldp_8023_subtype_values[] = {
177 { LLDP_PRIVATE_8023_SUBTYPE_MACPHY, "MAC/PHY configuration/status"},
178 { LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER, "Power via MDI"},
179 { LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR, "Link aggregation"},
180 { LLDP_PRIVATE_8023_SUBTYPE_MTU, "Max frame size"},
181 { 0, NULL}
182 };
183
184 #define LLDP_PRIVATE_TIA_SUBTYPE_CAPABILITIES 1
185 #define LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY 2
186 #define LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID 3
187 #define LLDP_PRIVATE_TIA_SUBTYPE_EXTENDED_POWER_MDI 4
188 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV 5
189 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV 6
190 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV 7
191 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER 8
192 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME 9
193 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME 10
194 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID 11
195
196 static const struct tok lldp_tia_subtype_values[] = {
197 { LLDP_PRIVATE_TIA_SUBTYPE_CAPABILITIES, "LLDP-MED Capabilities" },
198 { LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY, "Network policy" },
199 { LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID, "Location identification" },
200 { LLDP_PRIVATE_TIA_SUBTYPE_EXTENDED_POWER_MDI, "Extended power-via-MDI" },
201 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV, "Inventory - hardware revision" },
202 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV, "Inventory - firmware revision" },
203 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV, "Inventory - software revision" },
204 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER, "Inventory - serial number" },
205 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME, "Inventory - manufacturer name" },
206 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME, "Inventory - model name" },
207 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID, "Inventory - asset ID" },
208 { 0, NULL}
209 };
210
211 #define LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_METERS 1
212 #define LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_FLOORS 2
213
214 static const struct tok lldp_tia_location_altitude_type_values[] = {
215 { LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_METERS, "meters"},
216 { LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_FLOORS, "floors"},
217 { 0, NULL}
218 };
219
220 /* ANSI/TIA-1057 - Annex B */
221 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A1 1
222 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A2 2
223 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A3 3
224 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A4 4
225 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A5 5
226 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A6 6
227
228 static const struct tok lldp_tia_location_lci_catype_values[] = {
229 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A1, "national subdivisions (state,canton,region,province,prefecture)"},
230 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A2, "county, parish, gun, district"},
231 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A3, "city, township, shi"},
232 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A4, "city division, borough, city district, ward chou"},
233 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A5, "neighborhood, block"},
234 { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A6, "street"},
235 { 0, NULL}
236 };
237
238 static const struct tok lldp_tia_location_lci_what_values[] = {
239 { 0, "location of DHCP server"},
240 { 1, "location of the network element believed to be closest to the client"},
241 { 2, "location of the client"},
242 { 0, NULL}
243 };
244
245 /*
246 * From RFC 3636 - dot3MauType
247 */
248 #define LLDP_MAU_TYPE_UNKNOWN 0
249 #define LLDP_MAU_TYPE_AUI 1
250 #define LLDP_MAU_TYPE_10BASE_5 2
251 #define LLDP_MAU_TYPE_FOIRL 3
252 #define LLDP_MAU_TYPE_10BASE_2 4
253 #define LLDP_MAU_TYPE_10BASE_T 5
254 #define LLDP_MAU_TYPE_10BASE_FP 6
255 #define LLDP_MAU_TYPE_10BASE_FB 7
256 #define LLDP_MAU_TYPE_10BASE_FL 8
257 #define LLDP_MAU_TYPE_10BROAD36 9
258 #define LLDP_MAU_TYPE_10BASE_T_HD 10
259 #define LLDP_MAU_TYPE_10BASE_T_FD 11
260 #define LLDP_MAU_TYPE_10BASE_FL_HD 12
261 #define LLDP_MAU_TYPE_10BASE_FL_FD 13
262 #define LLDP_MAU_TYPE_100BASE_T4 14
263 #define LLDP_MAU_TYPE_100BASE_TX_HD 15
264 #define LLDP_MAU_TYPE_100BASE_TX_FD 16
265 #define LLDP_MAU_TYPE_100BASE_FX_HD 17
266 #define LLDP_MAU_TYPE_100BASE_FX_FD 18
267 #define LLDP_MAU_TYPE_100BASE_T2_HD 19
268 #define LLDP_MAU_TYPE_100BASE_T2_FD 20
269 #define LLDP_MAU_TYPE_1000BASE_X_HD 21
270 #define LLDP_MAU_TYPE_1000BASE_X_FD 22
271 #define LLDP_MAU_TYPE_1000BASE_LX_HD 23
272 #define LLDP_MAU_TYPE_1000BASE_LX_FD 24
273 #define LLDP_MAU_TYPE_1000BASE_SX_HD 25
274 #define LLDP_MAU_TYPE_1000BASE_SX_FD 26
275 #define LLDP_MAU_TYPE_1000BASE_CX_HD 27
276 #define LLDP_MAU_TYPE_1000BASE_CX_FD 28
277 #define LLDP_MAU_TYPE_1000BASE_T_HD 29
278 #define LLDP_MAU_TYPE_1000BASE_T_FD 30
279 #define LLDP_MAU_TYPE_10GBASE_X 31
280 #define LLDP_MAU_TYPE_10GBASE_LX4 32
281 #define LLDP_MAU_TYPE_10GBASE_R 33
282 #define LLDP_MAU_TYPE_10GBASE_ER 34
283 #define LLDP_MAU_TYPE_10GBASE_LR 35
284 #define LLDP_MAU_TYPE_10GBASE_SR 36
285 #define LLDP_MAU_TYPE_10GBASE_W 37
286 #define LLDP_MAU_TYPE_10GBASE_EW 38
287 #define LLDP_MAU_TYPE_10GBASE_LW 39
288 #define LLDP_MAU_TYPE_10GBASE_SW 40
289
290 static const struct tok lldp_mau_types_values[] = {
291 { LLDP_MAU_TYPE_UNKNOWN, "Unknown"},
292 { LLDP_MAU_TYPE_AUI, "AUI"},
293 { LLDP_MAU_TYPE_10BASE_5, "10BASE_5"},
294 { LLDP_MAU_TYPE_FOIRL, "FOIRL"},
295 { LLDP_MAU_TYPE_10BASE_2, "10BASE2"},
296 { LLDP_MAU_TYPE_10BASE_T, "10BASET duplex mode unknown"},
297 { LLDP_MAU_TYPE_10BASE_FP, "10BASEFP"},
298 { LLDP_MAU_TYPE_10BASE_FB, "10BASEFB"},
299 { LLDP_MAU_TYPE_10BASE_FL, "10BASEFL duplex mode unknown"},
300 { LLDP_MAU_TYPE_10BROAD36, "10BROAD36"},
301 { LLDP_MAU_TYPE_10BASE_T_HD, "10BASET hdx"},
302 { LLDP_MAU_TYPE_10BASE_T_FD, "10BASET fdx"},
303 { LLDP_MAU_TYPE_10BASE_FL_HD, "10BASEFL hdx"},
304 { LLDP_MAU_TYPE_10BASE_FL_FD, "10BASEFL fdx"},
305 { LLDP_MAU_TYPE_100BASE_T4, "100BASET4"},
306 { LLDP_MAU_TYPE_100BASE_TX_HD, "100BASETX hdx"},
307 { LLDP_MAU_TYPE_100BASE_TX_FD, "100BASETX fdx"},
308 { LLDP_MAU_TYPE_100BASE_FX_HD, "100BASEFX hdx"},
309 { LLDP_MAU_TYPE_100BASE_FX_FD, "100BASEFX fdx"},
310 { LLDP_MAU_TYPE_100BASE_T2_HD, "100BASET2 hdx"},
311 { LLDP_MAU_TYPE_100BASE_T2_FD, "100BASET2 fdx"},
312 { LLDP_MAU_TYPE_1000BASE_X_HD, "1000BASEX hdx"},
313 { LLDP_MAU_TYPE_1000BASE_X_FD, "1000BASEX fdx"},
314 { LLDP_MAU_TYPE_1000BASE_LX_HD, "1000BASELX hdx"},
315 { LLDP_MAU_TYPE_1000BASE_LX_FD, "1000BASELX fdx"},
316 { LLDP_MAU_TYPE_1000BASE_SX_HD, "1000BASESX hdx"},
317 { LLDP_MAU_TYPE_1000BASE_SX_FD, "1000BASESX fdx"},
318 { LLDP_MAU_TYPE_1000BASE_CX_HD, "1000BASECX hdx"},
319 { LLDP_MAU_TYPE_1000BASE_CX_FD, "1000BASECX fdx"},
320 { LLDP_MAU_TYPE_1000BASE_T_HD, "1000BASET hdx"},
321 { LLDP_MAU_TYPE_1000BASE_T_FD, "1000BASET fdx"},
322 { LLDP_MAU_TYPE_10GBASE_X, "10GBASEX"},
323 { LLDP_MAU_TYPE_10GBASE_LX4, "10GBASELX4"},
324 { LLDP_MAU_TYPE_10GBASE_R, "10GBASER"},
325 { LLDP_MAU_TYPE_10GBASE_ER, "10GBASEER"},
326 { LLDP_MAU_TYPE_10GBASE_LR, "10GBASELR"},
327 { LLDP_MAU_TYPE_10GBASE_SR, "10GBASESR"},
328 { LLDP_MAU_TYPE_10GBASE_W, "10GBASEW"},
329 { LLDP_MAU_TYPE_10GBASE_EW, "10GBASEEW"},
330 { LLDP_MAU_TYPE_10GBASE_LW, "10GBASELW"},
331 { LLDP_MAU_TYPE_10GBASE_SW, "10GBASESW"},
332 { 0, NULL}
333 };
334
335 #define LLDP_8023_AUTONEGOTIATION_SUPPORT (1 << 0)
336 #define LLDP_8023_AUTONEGOTIATION_STATUS (1 << 1)
337
338 static const struct tok lldp_8023_autonegotiation_values[] = {
339 { LLDP_8023_AUTONEGOTIATION_SUPPORT, "supported"},
340 { LLDP_8023_AUTONEGOTIATION_STATUS, "enabled"},
341 { 0, NULL}
342 };
343
344 #define LLDP_TIA_CAPABILITY_MED (1 << 0)
345 #define LLDP_TIA_CAPABILITY_NETWORK_POLICY (1 << 1)
346 #define LLDP_TIA_CAPABILITY_LOCATION_IDENTIFICATION (1 << 2)
347 #define LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PSE (1 << 3)
348 #define LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PD (1 << 4)
349 #define LLDP_TIA_CAPABILITY_INVENTORY (1 << 5)
350
351 static const struct tok lldp_tia_capabilities_values[] = {
352 { LLDP_TIA_CAPABILITY_MED, "LLDP-MED capabilities"},
353 { LLDP_TIA_CAPABILITY_NETWORK_POLICY, "network policy"},
354 { LLDP_TIA_CAPABILITY_LOCATION_IDENTIFICATION, "location identification"},
355 { LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PSE, "extended power via MDI-PSE"},
356 { LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PD, "extended power via MDI-PD"},
357 { LLDP_TIA_CAPABILITY_INVENTORY, "Inventory"},
358 { 0, NULL}
359 };
360
361 #define LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_1 1
362 #define LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_2 2
363 #define LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_3 3
364 #define LLDP_TIA_DEVICE_TYPE_NETWORK_CONNECTIVITY 4
365
366 static const struct tok lldp_tia_device_type_values[] = {
367 { LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_1, "endpoint class 1"},
368 { LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_2, "endpoint class 2"},
369 { LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_3, "endpoint class 3"},
370 { LLDP_TIA_DEVICE_TYPE_NETWORK_CONNECTIVITY, "network connectivity"},
371 { 0, NULL}
372 };
373
374 #define LLDP_TIA_APPLICATION_TYPE_VOICE 1
375 #define LLDP_TIA_APPLICATION_TYPE_VOICE_SIGNALING 2
376 #define LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE 3
377 #define LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE_SIGNALING 4
378 #define LLDP_TIA_APPLICATION_TYPE_SOFTPHONE_VOICE 5
379 #define LLDP_TIA_APPLICATION_TYPE_VIDEO_CONFERENCING 6
380 #define LLDP_TIA_APPLICATION_TYPE_STREAMING_VIDEO 7
381 #define LLDP_TIA_APPLICATION_TYPE_VIDEO_SIGNALING 8
382
383 static const struct tok lldp_tia_application_type_values[] = {
384 { LLDP_TIA_APPLICATION_TYPE_VOICE, "voice"},
385 { LLDP_TIA_APPLICATION_TYPE_VOICE_SIGNALING, "voice signaling"},
386 { LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE, "guest voice"},
387 { LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE_SIGNALING, "guest voice signaling"},
388 { LLDP_TIA_APPLICATION_TYPE_SOFTPHONE_VOICE, "softphone voice"},
389 { LLDP_TIA_APPLICATION_TYPE_VIDEO_CONFERENCING, "video conferencing"},
390 { LLDP_TIA_APPLICATION_TYPE_STREAMING_VIDEO, "streaming video"},
391 { LLDP_TIA_APPLICATION_TYPE_VIDEO_SIGNALING, "video signaling"},
392 { 0, NULL}
393 };
394
395 #define LLDP_TIA_NETWORK_POLICY_X_BIT (1 << 5)
396 #define LLDP_TIA_NETWORK_POLICY_T_BIT (1 << 6)
397 #define LLDP_TIA_NETWORK_POLICY_U_BIT (1 << 7)
398
399 static const struct tok lldp_tia_network_policy_bits_values[] = {
400 { LLDP_TIA_NETWORK_POLICY_U_BIT, "Unknown"},
401 { LLDP_TIA_NETWORK_POLICY_T_BIT, "Tagged"},
402 { LLDP_TIA_NETWORK_POLICY_X_BIT, "reserved"},
403 { 0, NULL}
404 };
405
406 #define LLDP_EXTRACT_NETWORK_POLICY_VLAN(x) (((x)&0x1ffe)>>1)
407 #define LLDP_EXTRACT_NETWORK_POLICY_L2_PRIORITY(x) (((x)&0x01ff)>>6)
408 #define LLDP_EXTRACT_NETWORK_POLICY_DSCP(x) ((x)&0x003f)
409
410 #define LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED 1
411 #define LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS 2
412 #define LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN 3
413
414 static const struct tok lldp_tia_location_data_format_values[] = {
415 { LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED, "coordinate-based LCI"},
416 { LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS, "civic address LCI"},
417 { LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN, "ECS ELIN"},
418 { 0, NULL}
419 };
420
421 #define LLDP_TIA_LOCATION_DATUM_WGS_84 1
422 #define LLDP_TIA_LOCATION_DATUM_NAD_83_NAVD_88 2
423 #define LLDP_TIA_LOCATION_DATUM_NAD_83_MLLW 3
424
425 static const struct tok lldp_tia_location_datum_type_values[] = {
426 { LLDP_TIA_LOCATION_DATUM_WGS_84, "World Geodesic System 1984"},
427 { LLDP_TIA_LOCATION_DATUM_NAD_83_NAVD_88, "North American Datum 1983 (NAVD88)"},
428 { LLDP_TIA_LOCATION_DATUM_NAD_83_MLLW, "North American Datum 1983 (MLLW)"},
429 { 0, NULL}
430 };
431
432 #define LLDP_TIA_POWER_SOURCE_PSE 1
433 #define LLDP_TIA_POWER_SOURCE_LOCAL 2
434 #define LLDP_TIA_POWER_SOURCE_PSE_AND_LOCAL 3
435
436 static const struct tok lldp_tia_power_source_values[] = {
437 { LLDP_TIA_POWER_SOURCE_PSE, "PSE - primary power source"},
438 { LLDP_TIA_POWER_SOURCE_LOCAL, "local - backup power source"},
439 { LLDP_TIA_POWER_SOURCE_PSE_AND_LOCAL, "PSE+local - reserved"},
440 { 0, NULL}
441 };
442
443 #define LLDP_TIA_POWER_PRIORITY_CRITICAL 1
444 #define LLDP_TIA_POWER_PRIORITY_HIGH 2
445 #define LLDP_TIA_POWER_PRIORITY_LOW 3
446
447 static const struct tok lldp_tia_power_priority_values[] = {
448 { LLDP_TIA_POWER_PRIORITY_CRITICAL, "critical"},
449 { LLDP_TIA_POWER_PRIORITY_HIGH, "high"},
450 { LLDP_TIA_POWER_PRIORITY_LOW, "low"},
451 { 0, NULL}
452 };
453
454 #define LLDP_TIA_POWER_VAL_MAX 1024
455
456 static const struct tok lldp_tia_inventory_values[] = {
457 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV, "Hardware revision" },
458 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV, "Firmware revision" },
459 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV, "Software revision" },
460 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER, "Serial number" },
461 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME, "Manufacturer name" },
462 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME, "Model name" },
463 { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID, "Asset ID" },
464 { 0, NULL}
465 };
466
467 /*
468 * From RFC 3636 - ifMauAutoNegCapAdvertisedBits
469 */
470 #define LLDP_MAU_PMD_OTHER (1 << 15)
471 #define LLDP_MAU_PMD_10BASE_T (1 << 14)
472 #define LLDP_MAU_PMD_10BASE_T_FD (1 << 13)
473 #define LLDP_MAU_PMD_100BASE_T4 (1 << 12)
474 #define LLDP_MAU_PMD_100BASE_TX (1 << 11)
475 #define LLDP_MAU_PMD_100BASE_TX_FD (1 << 10)
476 #define LLDP_MAU_PMD_100BASE_T2 (1 << 9)
477 #define LLDP_MAU_PMD_100BASE_T2_FD (1 << 8)
478 #define LLDP_MAU_PMD_FDXPAUSE (1 << 7)
479 #define LLDP_MAU_PMD_FDXAPAUSE (1 << 6)
480 #define LLDP_MAU_PMD_FDXSPAUSE (1 << 5)
481 #define LLDP_MAU_PMD_FDXBPAUSE (1 << 4)
482 #define LLDP_MAU_PMD_1000BASE_X (1 << 3)
483 #define LLDP_MAU_PMD_1000BASE_X_FD (1 << 2)
484 #define LLDP_MAU_PMD_1000BASE_T (1 << 1)
485 #define LLDP_MAU_PMD_1000BASE_T_FD (1 << 0)
486
487 static const struct tok lldp_pmd_capability_values[] = {
488 { LLDP_MAU_PMD_10BASE_T, "10BASE-T hdx"},
489 { LLDP_MAU_PMD_10BASE_T_FD, "10BASE-T fdx"},
490 { LLDP_MAU_PMD_100BASE_T4, "100BASE-T4"},
491 { LLDP_MAU_PMD_100BASE_TX, "100BASE-TX hdx"},
492 { LLDP_MAU_PMD_100BASE_TX_FD, "100BASE-TX fdx"},
493 { LLDP_MAU_PMD_100BASE_T2, "100BASE-T2 hdx"},
494 { LLDP_MAU_PMD_100BASE_T2_FD, "100BASE-T2 fdx"},
495 { LLDP_MAU_PMD_FDXPAUSE, "Pause for fdx links"},
496 { LLDP_MAU_PMD_FDXAPAUSE, "Asym PAUSE for fdx"},
497 { LLDP_MAU_PMD_FDXSPAUSE, "Sym PAUSE for fdx"},
498 { LLDP_MAU_PMD_FDXBPAUSE, "Asym and Sym PAUSE for fdx"},
499 { LLDP_MAU_PMD_1000BASE_X, "1000BASE-{X LX SX CX} hdx"},
500 { LLDP_MAU_PMD_1000BASE_X_FD, "1000BASE-{X LX SX CX} fdx"},
501 { LLDP_MAU_PMD_1000BASE_T, "1000BASE-T hdx"},
502 { LLDP_MAU_PMD_1000BASE_T_FD, "1000BASE-T fdx"},
503 { 0, NULL}
504 };
505
506 #define LLDP_MDI_PORT_CLASS (1 << 0)
507 #define LLDP_MDI_POWER_SUPPORT (1 << 1)
508 #define LLDP_MDI_POWER_STATE (1 << 2)
509 #define LLDP_MDI_PAIR_CONTROL_ABILITY (1 << 3)
510
511 static const struct tok lldp_mdi_values[] = {
512 { LLDP_MDI_PORT_CLASS, "PSE"},
513 { LLDP_MDI_POWER_SUPPORT, "supported"},
514 { LLDP_MDI_POWER_STATE, "enabled"},
515 { LLDP_MDI_PAIR_CONTROL_ABILITY, "can be controlled"},
516 { 0, NULL}
517 };
518
519 #define LLDP_MDI_PSE_PORT_POWER_PAIRS_SIGNAL 1
520 #define LLDP_MDI_PSE_PORT_POWER_PAIRS_SPARE 2
521
522 static const struct tok lldp_mdi_power_pairs_values[] = {
523 { LLDP_MDI_PSE_PORT_POWER_PAIRS_SIGNAL, "signal"},
524 { LLDP_MDI_PSE_PORT_POWER_PAIRS_SPARE, "spare"},
525 { 0, NULL}
526 };
527
528 #define LLDP_MDI_POWER_CLASS0 1
529 #define LLDP_MDI_POWER_CLASS1 2
530 #define LLDP_MDI_POWER_CLASS2 3
531 #define LLDP_MDI_POWER_CLASS3 4
532 #define LLDP_MDI_POWER_CLASS4 5
533
534 static const struct tok lldp_mdi_power_class_values[] = {
535 { LLDP_MDI_POWER_CLASS0, "class0"},
536 { LLDP_MDI_POWER_CLASS1, "class1"},
537 { LLDP_MDI_POWER_CLASS2, "class2"},
538 { LLDP_MDI_POWER_CLASS3, "class3"},
539 { LLDP_MDI_POWER_CLASS4, "class4"},
540 { 0, NULL}
541 };
542
543 #define LLDP_AGGREGATION_CAPABILITY (1 << 0)
544 #define LLDP_AGGREGATION_STATUS (1 << 1)
545
546 static const struct tok lldp_aggregation_values[] = {
547 { LLDP_AGGREGATION_CAPABILITY, "supported"},
548 { LLDP_AGGREGATION_STATUS, "enabled"},
549 { 0, NULL}
550 };
551
552 /*
553 * DCBX protocol subtypes.
554 */
555 #define LLDP_DCBX_SUBTYPE_1 1
556 #define LLDP_DCBX_SUBTYPE_2 2
557
558 static const struct tok lldp_dcbx_subtype_values[] = {
559 { LLDP_DCBX_SUBTYPE_1, "DCB Capability Exchange Protocol Rev 1" },
560 { LLDP_DCBX_SUBTYPE_2, "DCB Capability Exchange Protocol Rev 1.01" },
561 { 0, NULL}
562 };
563
564 #define LLDP_DCBX_CONTROL_TLV 1
565 #define LLDP_DCBX_PRIORITY_GROUPS_TLV 2
566 #define LLDP_DCBX_PRIORITY_FLOW_CONTROL_TLV 3
567 #define LLDP_DCBX_APPLICATION_TLV 4
568
569 /*
570 * Interface numbering subtypes.
571 */
572 #define LLDP_INTF_NUMB_IFX_SUBTYPE 2
573 #define LLDP_INTF_NUMB_SYSPORT_SUBTYPE 3
574
575 static const struct tok lldp_intf_numb_subtype_values[] = {
576 { LLDP_INTF_NUMB_IFX_SUBTYPE, "Interface Index" },
577 { LLDP_INTF_NUMB_SYSPORT_SUBTYPE, "System Port Number" },
578 { 0, NULL}
579 };
580
581 #define LLDP_INTF_NUM_LEN 5
582
583 #define LLDP_EVB_MODE_NOT_SUPPORTED 0
584 #define LLDP_EVB_MODE_EVB_BRIDGE 1
585 #define LLDP_EVB_MODE_EVB_STATION 2
586 #define LLDP_EVB_MODE_RESERVED 3
587
588 static const struct tok lldp_evb_mode_values[]={
589 { LLDP_EVB_MODE_NOT_SUPPORTED, "Not Supported"},
590 { LLDP_EVB_MODE_EVB_BRIDGE, "EVB Bridge"},
591 { LLDP_EVB_MODE_EVB_STATION, "EVB Station"},
592 { LLDP_EVB_MODE_RESERVED, "Reserved for future Standardization"},
593 { 0, NULL},
594 };
595
596 #define NO_OF_BITS 8
597 #define LLDP_PRIVATE_8021_SUBTYPE_CONGESTION_NOTIFICATION_LENGTH 6
598 #define LLDP_PRIVATE_8021_SUBTYPE_ETS_CONFIGURATION_LENGTH 25
599 #define LLDP_PRIVATE_8021_SUBTYPE_ETS_RECOMMENDATION_LENGTH 25
600 #define LLDP_PRIVATE_8021_SUBTYPE_PFC_CONFIGURATION_LENGTH 6
601 #define LLDP_PRIVATE_8021_SUBTYPE_APPLICATION_PRIORITY_MIN_LENGTH 5
602 #define LLDP_PRIVATE_8021_SUBTYPE_EVB_LENGTH 9
603 #define LLDP_PRIVATE_8021_SUBTYPE_CDCP_MIN_LENGTH 8
604
605 #define LLDP_IANA_SUBTYPE_MUDURL 1
606
607 static const struct tok lldp_iana_subtype_values[] = {
608 { LLDP_IANA_SUBTYPE_MUDURL, "MUD-URL" },
609 { 0, NULL }
610 };
611
612
613 static void
614 print_ets_priority_assignment_table(netdissect_options *ndo,
615 const u_char *ptr)
616 {
617 ND_PRINT("\n\t Priority Assignment Table");
618 ND_PRINT("\n\t Priority : 0 1 2 3 4 5 6 7");
619 ND_PRINT("\n\t Value : %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-3d",
620 GET_U_1(ptr) >> 4, GET_U_1(ptr) & 0x0f,
621 GET_U_1(ptr + 1) >> 4, GET_U_1(ptr + 1) & 0x0f,
622 GET_U_1(ptr + 2) >> 4, GET_U_1(ptr + 2) & 0x0f,
623 GET_U_1(ptr + 3) >> 4, GET_U_1(ptr + 3) & 0x0f);
624 }
625
626 static void
627 print_tc_bandwidth_table(netdissect_options *ndo,
628 const u_char *ptr)
629 {
630 ND_PRINT("\n\t TC Bandwidth Table");
631 ND_PRINT("\n\t TC%% : 0 1 2 3 4 5 6 7");
632 ND_PRINT("\n\t Value : %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-3d",
633 GET_U_1(ptr), GET_U_1(ptr + 1), GET_U_1(ptr + 2),
634 GET_U_1(ptr + 3), GET_U_1(ptr + 4), GET_U_1(ptr + 5),
635 GET_U_1(ptr + 6), GET_U_1(ptr + 7));
636 }
637
638 static void
639 print_tsa_assignment_table(netdissect_options *ndo,
640 const u_char *ptr)
641 {
642 ND_PRINT("\n\t TSA Assignment Table");
643 ND_PRINT("\n\t Traffic Class: 0 1 2 3 4 5 6 7");
644 ND_PRINT("\n\t Value : %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-3d",
645 GET_U_1(ptr), GET_U_1(ptr + 1), GET_U_1(ptr + 2),
646 GET_U_1(ptr + 3), GET_U_1(ptr + 4), GET_U_1(ptr + 5),
647 GET_U_1(ptr + 6), GET_U_1(ptr + 7));
648 }
649
650 /*
651 * Print IEEE 802.1 private extensions. (802.1AB annex E)
652 */
653 static int
654 lldp_private_8021_print(netdissect_options *ndo,
655 const u_char *tptr, u_int tlv_len)
656 {
657 int hexdump = FALSE;
658 u_int subtype;
659 u_int sublen;
660 u_int tval;
661 u_int i;
662
663 if (tlv_len < 4) {
664 return hexdump;
665 }
666 subtype = GET_U_1(tptr + 3);
667
668 ND_PRINT("\n\t %s Subtype (%u)",
669 tok2str(lldp_8021_subtype_values, "unknown", subtype),
670 subtype);
671
672 switch (subtype) {
673 case LLDP_PRIVATE_8021_SUBTYPE_PORT_VLAN_ID:
674 if (tlv_len < 6) {
675 return hexdump;
676 }
677 ND_PRINT("\n\t port vlan id (PVID): %u",
678 GET_BE_U_2(tptr + 4));
679 break;
680 case LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_VLAN_ID:
681 if (tlv_len < 7) {
682 return hexdump;
683 }
684 ND_PRINT("\n\t port and protocol vlan id (PPVID): %u, flags [%s] (0x%02x)",
685 GET_BE_U_2(tptr + 5),
686 bittok2str(lldp_8021_port_protocol_id_values, "none", GET_U_1(tptr + 4)),
687 GET_U_1(tptr + 4));
688 break;
689 case LLDP_PRIVATE_8021_SUBTYPE_VLAN_NAME:
690 if (tlv_len < 6) {
691 return hexdump;
692 }
693 ND_PRINT("\n\t vlan id (VID): %u", GET_BE_U_2(tptr + 4));
694 if (tlv_len < 7) {
695 return hexdump;
696 }
697 sublen = GET_U_1(tptr + 6);
698 if (tlv_len < 7+sublen) {
699 return hexdump;
700 }
701 ND_PRINT("\n\t vlan name: ");
702 (void)nd_printzp(ndo, tptr + 7, sublen, NULL);
703 break;
704 case LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_IDENTITY:
705 if (tlv_len < 5) {
706 return hexdump;
707 }
708 sublen = GET_U_1(tptr + 4);
709 if (tlv_len < 5+sublen) {
710 return hexdump;
711 }
712 ND_PRINT("\n\t protocol identity: ");
713 (void)nd_printzp(ndo, tptr + 5, sublen, NULL);
714 break;
715 case LLDP_PRIVATE_8021_SUBTYPE_CONGESTION_NOTIFICATION:
716 if(tlv_len<LLDP_PRIVATE_8021_SUBTYPE_CONGESTION_NOTIFICATION_LENGTH){
717 return hexdump;
718 }
719 tval=GET_U_1(tptr + 4);
720 ND_PRINT("\n\t Pre-Priority CNPV Indicator");
721 ND_PRINT("\n\t Priority : 0 1 2 3 4 5 6 7");
722 ND_PRINT("\n\t Value : ");
723 for(i=0;i<NO_OF_BITS;i++)
724 ND_PRINT("%-2d ", (tval >> i) & 0x01);
725 tval=GET_U_1(tptr + 5);
726 ND_PRINT("\n\t Pre-Priority Ready Indicator");
727 ND_PRINT("\n\t Priority : 0 1 2 3 4 5 6 7");
728 ND_PRINT("\n\t Value : ");
729 for(i=0;i<NO_OF_BITS;i++)
730 ND_PRINT("%-2d ", (tval >> i) & 0x01);
731 break;
732
733 case LLDP_PRIVATE_8021_SUBTYPE_ETS_CONFIGURATION:
734 if(tlv_len<LLDP_PRIVATE_8021_SUBTYPE_ETS_CONFIGURATION_LENGTH) {
735 return hexdump;
736 }
737 tval=GET_U_1(tptr + 4);
738 ND_PRINT("\n\t Willing:%u, CBS:%u, RES:%u, Max TCs:%u",
739 tval >> 7, (tval >> 6) & 0x02, (tval >> 3) & 0x07, tval & 0x07);
740
741 /*Print Priority Assignment Table*/
742 print_ets_priority_assignment_table(ndo, tptr + 5);
743
744 /*Print TC Bandwidth Table*/
745 print_tc_bandwidth_table(ndo, tptr + 9);
746
747 /* Print TSA Assignment Table */
748 print_tsa_assignment_table(ndo, tptr + 17);
749
750 break;
751
752 case LLDP_PRIVATE_8021_SUBTYPE_ETS_RECOMMENDATION:
753 if(tlv_len<LLDP_PRIVATE_8021_SUBTYPE_ETS_RECOMMENDATION_LENGTH) {
754 return hexdump;
755 }
756 ND_PRINT("\n\t RES: %u", GET_U_1(tptr + 4));
757 /*Print Priority Assignment Table */
758 print_ets_priority_assignment_table(ndo, tptr + 5);
759 /*Print TC Bandwidth Table */
760 print_tc_bandwidth_table(ndo, tptr + 9);
761 /* Print TSA Assignment Table */
762 print_tsa_assignment_table(ndo, tptr + 17);
763 break;
764
765 case LLDP_PRIVATE_8021_SUBTYPE_PFC_CONFIGURATION:
766 if(tlv_len<LLDP_PRIVATE_8021_SUBTYPE_PFC_CONFIGURATION_LENGTH) {
767 return hexdump;
768 }
769 tval=GET_U_1(tptr + 4);
770 ND_PRINT("\n\t Willing: %u, MBC: %u, RES: %u, PFC cap:%u ",
771 tval >> 7, (tval >> 6) & 0x01, (tval >> 4) & 0x03, (tval & 0x0f));
772 ND_PRINT("\n\t PFC Enable");
773 tval=GET_U_1(tptr + 5);
774 ND_PRINT("\n\t Priority : 0 1 2 3 4 5 6 7");
775 ND_PRINT("\n\t Value : ");
776 for(i=0;i<NO_OF_BITS;i++)
777 ND_PRINT("%-2d ", (tval >> i) & 0x01);
778 break;
779
780 case LLDP_PRIVATE_8021_SUBTYPE_APPLICATION_PRIORITY:
781 if(tlv_len<LLDP_PRIVATE_8021_SUBTYPE_APPLICATION_PRIORITY_MIN_LENGTH) {
782 return hexdump;
783 }
784 ND_PRINT("\n\t RES: %u", GET_U_1(tptr + 4));
785 if(tlv_len<=LLDP_PRIVATE_8021_SUBTYPE_APPLICATION_PRIORITY_MIN_LENGTH){
786 return hexdump;
787 }
788 /* Length of Application Priority Table */
789 sublen=tlv_len-5;
790 if(sublen%3!=0){
791 return hexdump;
792 }
793 i=0;
794 ND_PRINT("\n\t Application Priority Table");
795 while(i<sublen) {
796 tval=GET_U_1(tptr + i + 5);
797 ND_PRINT("\n\t Priority: %u, RES: %u, Sel: %u, Protocol ID: %u",
798 tval >> 5, (tval >> 3) & 0x03, (tval & 0x07),
799 GET_BE_U_2(tptr + i + 6));
800 i=i+3;
801 }
802 break;
803 case LLDP_PRIVATE_8021_SUBTYPE_EVB:
804 if(tlv_len<LLDP_PRIVATE_8021_SUBTYPE_EVB_LENGTH){
805 return hexdump;
806 }
807 ND_PRINT("\n\t EVB Bridge Status");
808 tval=GET_U_1(tptr + 4);
809 ND_PRINT("\n\t RES: %u, BGID: %u, RRCAP: %u, RRCTR: %u",
810 tval >> 3, (tval >> 2) & 0x01, (tval >> 1) & 0x01, tval & 0x01);
811 ND_PRINT("\n\t EVB Station Status");
812 tval=GET_U_1(tptr + 5);
813 ND_PRINT("\n\t RES: %u, SGID: %u, RRREQ: %u,RRSTAT: %u",
814 tval >> 4, (tval >> 3) & 0x01, (tval >> 2) & 0x01, tval & 0x03);
815 tval=GET_U_1(tptr + 6);
816 ND_PRINT("\n\t R: %u, RTE: %u, ",tval >> 5, tval & 0x1f);
817 tval=GET_U_1(tptr + 7);
818 ND_PRINT("EVB Mode: %s [%u]",
819 tok2str(lldp_evb_mode_values, "unknown", tval >> 6), tval >> 6);
820 ND_PRINT("\n\t ROL: %u, RWD: %u, ", (tval >> 5) & 0x01, tval & 0x1f);
821 tval=GET_U_1(tptr + 8);
822 ND_PRINT("RES: %u, ROL: %u, RKA: %u", tval >> 6, (tval >> 5) & 0x01, tval & 0x1f);
823 break;
824
825 case LLDP_PRIVATE_8021_SUBTYPE_CDCP:
826 if(tlv_len<LLDP_PRIVATE_8021_SUBTYPE_CDCP_MIN_LENGTH){
827 return hexdump;
828 }
829 tval=GET_U_1(tptr + 4);
830 ND_PRINT("\n\t Role: %u, RES: %u, Scomp: %u ",
831 tval >> 7, (tval >> 4) & 0x07, (tval >> 3) & 0x01);
832 ND_PRINT("ChnCap: %u", GET_BE_U_2(tptr + 6) & 0x0fff);
833 sublen=tlv_len-8;
834 if(sublen%3!=0) {
835 return hexdump;
836 }
837 i=0;
838 while(i<sublen) {
839 tval=GET_BE_U_3(tptr + i + 8);
840 ND_PRINT("\n\t SCID: %u, SVID: %u",
841 tval >> 12, tval & 0x000fff);
842 i=i+3;
843 }
844 break;
845
846 default:
847 hexdump = TRUE;
848 break;
849 }
850
851 return hexdump;
852 }
853
854 /*
855 * Print IEEE 802.3 private extensions. (802.3bc)
856 */
857 static int
858 lldp_private_8023_print(netdissect_options *ndo,
859 const u_char *tptr, u_int tlv_len)
860 {
861 int hexdump = FALSE;
862 u_int subtype;
863
864 if (tlv_len < 4) {
865 return hexdump;
866 }
867 subtype = GET_U_1(tptr + 3);
868
869 ND_PRINT("\n\t %s Subtype (%u)",
870 tok2str(lldp_8023_subtype_values, "unknown", subtype),
871 subtype);
872
873 switch (subtype) {
874 case LLDP_PRIVATE_8023_SUBTYPE_MACPHY:
875 if (tlv_len < 9) {
876 return hexdump;
877 }
878 ND_PRINT("\n\t autonegotiation [%s] (0x%02x)",
879 bittok2str(lldp_8023_autonegotiation_values, "none", GET_U_1(tptr + 4)),
880 GET_U_1(tptr + 4));
881 ND_PRINT("\n\t PMD autoneg capability [%s] (0x%04x)",
882 bittok2str(lldp_pmd_capability_values,"unknown", GET_BE_U_2(tptr + 5)),
883 GET_BE_U_2(tptr + 5));
884 ND_PRINT("\n\t MAU type %s (0x%04x)",
885 tok2str(lldp_mau_types_values, "unknown", GET_BE_U_2(tptr + 7)),
886 GET_BE_U_2(tptr + 7));
887 break;
888
889 case LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER:
890 if (tlv_len < 7) {
891 return hexdump;
892 }
893 ND_PRINT("\n\t MDI power support [%s], power pair %s, power class %s",
894 bittok2str(lldp_mdi_values, "none", GET_U_1((tptr + 4))),
895 tok2str(lldp_mdi_power_pairs_values, "unknown", GET_U_1((tptr + 5))),
896 tok2str(lldp_mdi_power_class_values, "unknown", GET_U_1((tptr + 6))));
897 break;
898
899 case LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR:
900 if (tlv_len < 9) {
901 return hexdump;
902 }
903 ND_PRINT("\n\t aggregation status [%s], aggregation port ID %u",
904 bittok2str(lldp_aggregation_values, "none", GET_U_1((tptr + 4))),
905 GET_BE_U_4(tptr + 5));
906 break;
907
908 case LLDP_PRIVATE_8023_SUBTYPE_MTU:
909 if (tlv_len < 6) {
910 return hexdump;
911 }
912 ND_PRINT("\n\t MTU size %u", GET_BE_U_2(tptr + 4));
913 break;
914
915 default:
916 hexdump = TRUE;
917 break;
918 }
919
920 return hexdump;
921 }
922
923 /*
924 * Extract 34bits of latitude/longitude coordinates.
925 */
926 static uint64_t
927 lldp_extract_latlon(netdissect_options *ndo, const u_char *tptr)
928 {
929 uint64_t latlon;
930
931 latlon = GET_U_1(tptr) & 0x3;
932 latlon = (latlon << 32) | GET_BE_U_4(tptr + 1);
933
934 return latlon;
935 }
936
937 /* objects defined in IANA subtype 00 00 5e
938 * (right now there is only one)
939 */
940
941
942 static int
943 lldp_private_iana_print(netdissect_options *ndo,
944 const u_char *tptr, u_int tlv_len)
945 {
946 int hexdump = FALSE;
947 u_int subtype;
948
949 if (tlv_len < 8) {
950 return hexdump;
951 }
952 subtype = GET_U_1(tptr + 3);
953
954 ND_PRINT("\n\t %s Subtype (%u)",
955 tok2str(lldp_iana_subtype_values, "unknown", subtype),
956 subtype);
957
958 switch (subtype) {
959 case LLDP_IANA_SUBTYPE_MUDURL:
960 ND_PRINT("\n\t MUD-URL=");
961 (void)nd_printn(ndo, tptr+4, tlv_len-4, NULL);
962 break;
963 default:
964 hexdump=TRUE;
965 }
966
967 return hexdump;
968 }
969
970
971
972 /*
973 * Print private TIA extensions.
974 */
975 static int
976 lldp_private_tia_print(netdissect_options *ndo,
977 const u_char *tptr, u_int tlv_len)
978 {
979 int hexdump = FALSE;
980 u_int subtype;
981 uint8_t location_format;
982 uint16_t power_val;
983 u_int lci_len;
984 uint8_t ca_type, ca_len;
985
986 if (tlv_len < 4) {
987 return hexdump;
988 }
989 subtype = GET_U_1(tptr + 3);
990
991 ND_PRINT("\n\t %s Subtype (%u)",
992 tok2str(lldp_tia_subtype_values, "unknown", subtype),
993 subtype);
994
995 switch (subtype) {
996 case LLDP_PRIVATE_TIA_SUBTYPE_CAPABILITIES:
997 if (tlv_len < 7) {
998 return hexdump;
999 }
1000 ND_PRINT("\n\t Media capabilities [%s] (0x%04x)",
1001 bittok2str(lldp_tia_capabilities_values, "none",
1002 GET_BE_U_2(tptr + 4)), GET_BE_U_2(tptr + 4));
1003 ND_PRINT("\n\t Device type [%s] (0x%02x)",
1004 tok2str(lldp_tia_device_type_values, "unknown", GET_U_1(tptr + 6)),
1005 GET_U_1(tptr + 6));
1006 break;
1007
1008 case LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY:
1009 if (tlv_len < 8) {
1010 return hexdump;
1011 }
1012 ND_PRINT("\n\t Application type [%s] (0x%02x)",
1013 tok2str(lldp_tia_application_type_values, "none", GET_U_1(tptr + 4)),
1014 GET_U_1(tptr + 4));
1015 ND_PRINT(", Flags [%s]", bittok2str(
1016 lldp_tia_network_policy_bits_values, "none", GET_U_1((tptr + 5))));
1017 ND_PRINT("\n\t Vlan id %u",
1018 LLDP_EXTRACT_NETWORK_POLICY_VLAN(GET_BE_U_2(tptr + 5)));
1019 ND_PRINT(", L2 priority %u",
1020 LLDP_EXTRACT_NETWORK_POLICY_L2_PRIORITY(GET_BE_U_2(tptr + 6)));
1021 ND_PRINT(", DSCP value %u",
1022 LLDP_EXTRACT_NETWORK_POLICY_DSCP(GET_BE_U_2(tptr + 6)));
1023 break;
1024
1025 case LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID:
1026 if (tlv_len < 5) {
1027 return hexdump;
1028 }
1029 location_format = GET_U_1(tptr + 4);
1030 ND_PRINT("\n\t Location data format %s (0x%02x)",
1031 tok2str(lldp_tia_location_data_format_values, "unknown", location_format),
1032 location_format);
1033
1034 switch (location_format) {
1035 case LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED:
1036 if (tlv_len < 21) {
1037 return hexdump;
1038 }
1039 ND_PRINT("\n\t Latitude resolution %u, latitude value %" PRIu64,
1040 (GET_U_1(tptr + 5) >> 2),
1041 lldp_extract_latlon(ndo, tptr + 5));
1042 ND_PRINT("\n\t Longitude resolution %u, longitude value %" PRIu64,
1043 (GET_U_1(tptr + 10) >> 2),
1044 lldp_extract_latlon(ndo, tptr + 10));
1045 ND_PRINT("\n\t Altitude type %s (%u)",
1046 tok2str(lldp_tia_location_altitude_type_values, "unknown",GET_U_1(tptr + 15) >> 4),
1047 (GET_U_1(tptr + 15) >> 4));
1048 ND_PRINT("\n\t Altitude resolution %u, altitude value 0x%x",
1049 (GET_BE_U_2(tptr + 15)>>6)&0x3f,
1050 (GET_BE_U_4(tptr + 16) & 0x3fffffff));
1051 ND_PRINT("\n\t Datum %s (0x%02x)",
1052 tok2str(lldp_tia_location_datum_type_values, "unknown", GET_U_1(tptr + 20)),
1053 GET_U_1(tptr + 20));
1054 break;
1055
1056 case LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS:
1057 if (tlv_len < 6) {
1058 return hexdump;
1059 }
1060 lci_len = GET_U_1(tptr + 5);
1061 if (lci_len < 3) {
1062 return hexdump;
1063 }
1064 if (tlv_len < 7+lci_len) {
1065 return hexdump;
1066 }
1067 ND_PRINT("\n\t LCI length %u, LCI what %s (0x%02x), Country-code ",
1068 lci_len,
1069 tok2str(lldp_tia_location_lci_what_values, "unknown", GET_U_1(tptr + 6)),
1070 GET_U_1(tptr + 6));
1071
1072 /* Country code */
1073 (void)nd_printzp(ndo, tptr + 7, 2, NULL);
1074
1075 lci_len = lci_len-3;
1076 tptr = tptr + 9;
1077
1078 /* Decode each civic address element */
1079 while (lci_len > 0) {
1080 if (lci_len < 2) {
1081 return hexdump;
1082 }
1083 ca_type = GET_U_1(tptr);
1084 ca_len = GET_U_1(tptr + 1);
1085
1086 tptr += 2;
1087 lci_len -= 2;
1088
1089 ND_PRINT("\n\t CA type \'%s\' (%u), length %u: ",
1090 tok2str(lldp_tia_location_lci_catype_values, "unknown", ca_type),
1091 ca_type, ca_len);
1092
1093 /* basic sanity check */
1094 if ( ca_type == 0 || ca_len == 0) {
1095 return hexdump;
1096 }
1097 if (lci_len < ca_len) {
1098 return hexdump;
1099 }
1100
1101 (void)nd_printzp(ndo, tptr, ca_len, NULL);
1102 tptr += ca_len;
1103 lci_len -= ca_len;
1104 }
1105 break;
1106
1107 case LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN:
1108 ND_PRINT("\n\t ECS ELIN id ");
1109 (void)nd_printzp(ndo, tptr + 5, tlv_len - 5, NULL);
1110 break;
1111
1112 default:
1113 ND_PRINT("\n\t Location ID ");
1114 print_unknown_data(ndo, tptr + 5, "\n\t ", tlv_len - 5);
1115 }
1116 break;
1117
1118 case LLDP_PRIVATE_TIA_SUBTYPE_EXTENDED_POWER_MDI:
1119 if (tlv_len < 7) {
1120 return hexdump;
1121 }
1122 ND_PRINT("\n\t Power type [%s]",
1123 (GET_U_1(tptr + 4) & 0xC0 >> 6) ? "PD device" : "PSE device");
1124 ND_PRINT(", Power source [%s]",
1125 tok2str(lldp_tia_power_source_values, "none", (GET_U_1((tptr + 4)) & 0x30) >> 4));
1126 ND_PRINT("\n\t Power priority [%s] (0x%02x)",
1127 tok2str(lldp_tia_power_priority_values, "none", GET_U_1(tptr + 4) & 0x0f),
1128 GET_U_1(tptr + 4) & 0x0f);
1129 power_val = GET_BE_U_2(tptr + 5);
1130 if (power_val < LLDP_TIA_POWER_VAL_MAX) {
1131 ND_PRINT(", Power %.1f Watts", ((float)power_val) / 10);
1132 } else {
1133 ND_PRINT(", Power %u (Reserved)", power_val);
1134 }
1135 break;
1136
1137 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV:
1138 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV:
1139 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV:
1140 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER:
1141 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME:
1142 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME:
1143 case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID:
1144 ND_PRINT("\n\t %s ",
1145 tok2str(lldp_tia_inventory_values, "unknown", subtype));
1146 (void)nd_printzp(ndo, tptr + 4, tlv_len - 4, NULL);
1147 break;
1148
1149 default:
1150 hexdump = TRUE;
1151 break;
1152 }
1153
1154 return hexdump;
1155 }
1156
1157 /*
1158 * Print DCBX Protocol fields (V 1.01).
1159 */
1160 static int
1161 lldp_private_dcbx_print(netdissect_options *ndo,
1162 const u_char *pptr, u_int len)
1163 {
1164 int hexdump = FALSE;
1165 u_int subtype;
1166 uint8_t tval;
1167 uint16_t tlv;
1168 uint32_t i, pgval, uval;
1169 u_int tlen, tlv_type;
1170 uint16_t tlv_len;
1171 const u_char *tptr, *mptr;
1172
1173 if (len < 4) {
1174 return hexdump;
1175 }
1176 subtype = GET_U_1(pptr + 3);
1177
1178 ND_PRINT("\n\t %s Subtype (%u)",
1179 tok2str(lldp_dcbx_subtype_values, "unknown", subtype),
1180 subtype);
1181
1182 /* by passing old version */
1183 if (subtype == LLDP_DCBX_SUBTYPE_1)
1184 return TRUE;
1185
1186 tptr = pptr + 4;
1187 tlen = len - 4;
1188
1189 while (tlen >= sizeof(tlv)) {
1190
1191 ND_TCHECK_LEN(tptr, sizeof(tlv));
1192
1193 tlv = GET_BE_U_2(tptr);
1194
1195 tlv_type = LLDP_EXTRACT_TYPE(tlv);
1196 tlv_len = LLDP_EXTRACT_LEN(tlv);
1197 hexdump = FALSE;
1198
1199 tlen -= sizeof(tlv);
1200 tptr += sizeof(tlv);
1201
1202 /* loop check */
1203 if (!tlv_type || !tlv_len) {
1204 break;
1205 }
1206
1207 ND_TCHECK_LEN(tptr, tlv_len);
1208 if (tlen < tlv_len) {
1209 goto trunc;
1210 }
1211
1212 /* decode every tlv */
1213 switch (tlv_type) {
1214 case LLDP_DCBX_CONTROL_TLV:
1215 if (tlv_len < 10) {
1216 goto trunc;
1217 }
1218 ND_PRINT("\n\t Control - Protocol Control (type 0x%x, length %u)",
1219 LLDP_DCBX_CONTROL_TLV, tlv_len);
1220 ND_PRINT("\n\t Oper_Version: %u", GET_U_1(tptr));
1221 ND_PRINT("\n\t Max_Version: %u", GET_U_1(tptr + 1));
1222 ND_PRINT("\n\t Sequence Number: %u", GET_BE_U_4(tptr + 2));
1223 ND_PRINT("\n\t Acknowledgement Number: %u",
1224 GET_BE_U_4(tptr + 6));
1225 break;
1226 case LLDP_DCBX_PRIORITY_GROUPS_TLV:
1227 if (tlv_len < 17) {
1228 goto trunc;
1229 }
1230 ND_PRINT("\n\t Feature - Priority Group (type 0x%x, length %u)",
1231 LLDP_DCBX_PRIORITY_GROUPS_TLV, tlv_len);
1232 ND_PRINT("\n\t Oper_Version: %u", GET_U_1(tptr));
1233 ND_PRINT("\n\t Max_Version: %u", GET_U_1(tptr + 1));
1234 ND_PRINT("\n\t Info block(0x%02X): ", GET_U_1(tptr + 2));
1235 tval = GET_U_1(tptr + 2);
1236 ND_PRINT("Enable bit: %u, Willing bit: %u, Error Bit: %u",
1237 (tval & 0x80) ? 1 : 0, (tval & 0x40) ? 1 : 0,
1238 (tval & 0x20) ? 1 : 0);
1239 ND_PRINT("\n\t SubType: %u", GET_U_1(tptr + 3));
1240 ND_PRINT("\n\t Priority Allocation");
1241
1242 /*
1243 * Array of 8 4-bit priority group ID values; we fetch all
1244 * 32 bits and extract each nibble.
1245 */
1246 pgval = GET_BE_U_4(tptr + 4);
1247 for (i = 0; i <= 7; i++) {
1248 ND_PRINT("\n\t PgId_%u: %u",
1249 i, (pgval >> (28 - 4 * i)) & 0xF);
1250 }
1251 ND_PRINT("\n\t Priority Group Allocation");
1252 for (i = 0; i <= 7; i++)
1253 ND_PRINT("\n\t Pg percentage[%u]: %u", i,
1254 GET_U_1(tptr + 8 + i));
1255 ND_PRINT("\n\t NumTCsSupported: %u", GET_U_1(tptr + 8 + 8));
1256 break;
1257 case LLDP_DCBX_PRIORITY_FLOW_CONTROL_TLV:
1258 if (tlv_len < 6) {
1259 goto trunc;
1260 }
1261 ND_PRINT("\n\t Feature - Priority Flow Control");
1262 ND_PRINT(" (type 0x%x, length %u)",
1263 LLDP_DCBX_PRIORITY_FLOW_CONTROL_TLV, tlv_len);
1264 ND_PRINT("\n\t Oper_Version: %u", GET_U_1(tptr));
1265 ND_PRINT("\n\t Max_Version: %u", GET_U_1(tptr + 1));
1266 ND_PRINT("\n\t Info block(0x%02X): ", GET_U_1(tptr + 2));
1267 tval = GET_U_1(tptr + 2);
1268 ND_PRINT("Enable bit: %u, Willing bit: %u, Error Bit: %u",
1269 (tval & 0x80) ? 1 : 0, (tval & 0x40) ? 1 : 0,
1270 (tval & 0x20) ? 1 : 0);
1271 ND_PRINT("\n\t SubType: %u", GET_U_1(tptr + 3));
1272 tval = GET_U_1(tptr + 4);
1273 ND_PRINT("\n\t PFC Config (0x%02X)", GET_U_1(tptr + 4));
1274 for (i = 0; i <= 7; i++)
1275 ND_PRINT("\n\t Priority Bit %u: %s",
1276 i, (tval & (1 << i)) ? "Enabled" : "Disabled");
1277 ND_PRINT("\n\t NumTCPFCSupported: %u", GET_U_1(tptr + 5));
1278 break;
1279 case LLDP_DCBX_APPLICATION_TLV:
1280 if (tlv_len < 4) {
1281 goto trunc;
1282 }
1283 ND_PRINT("\n\t Feature - Application (type 0x%x, length %u)",
1284 LLDP_DCBX_APPLICATION_TLV, tlv_len);
1285 ND_PRINT("\n\t Oper_Version: %u", GET_U_1(tptr));
1286 ND_PRINT("\n\t Max_Version: %u", GET_U_1(tptr + 1));
1287 ND_PRINT("\n\t Info block(0x%02X): ", GET_U_1(tptr + 2));
1288 tval = GET_U_1(tptr + 2);
1289 ND_PRINT("Enable bit: %u, Willing bit: %u, Error Bit: %u",
1290 (tval & 0x80) ? 1 : 0, (tval & 0x40) ? 1 : 0,
1291 (tval & 0x20) ? 1 : 0);
1292 ND_PRINT("\n\t SubType: %u", GET_U_1(tptr + 3));
1293 tval = tlv_len - 4;
1294 mptr = tptr + 4;
1295 while (tval >= 6) {
1296 ND_PRINT("\n\t Application Value");
1297 ND_PRINT("\n\t Application Protocol ID: 0x%04x",
1298 GET_BE_U_2(mptr));
1299 uval = GET_BE_U_3(mptr + 2);
1300 ND_PRINT("\n\t SF (0x%x) Application Protocol ID is %s",
1301 (uval >> 22),
1302 (uval >> 22) ? "Socket Number" : "L2 EtherType");
1303 ND_PRINT("\n\t OUI: 0x%06x", uval & 0x3fffff);
1304 ND_PRINT("\n\t User Priority Map: 0x%02x",
1305 GET_U_1(mptr + 5));
1306 tval = tval - 6;
1307 mptr = mptr + 6;
1308 }
1309 break;
1310 default:
1311 hexdump = TRUE;
1312 break;
1313 }
1314
1315 /* do we also want to see a hex dump ? */
1316 if (ndo->ndo_vflag > 1 || (ndo->ndo_vflag && hexdump)) {
1317 print_unknown_data(ndo, tptr, "\n\t ", tlv_len);
1318 }
1319
1320 tlen -= tlv_len;
1321 tptr += tlv_len;
1322 }
1323
1324 trunc:
1325 return hexdump;
1326 }
1327
1328 static char *
1329 lldp_network_addr_print(netdissect_options *ndo, const u_char *tptr, u_int len)
1330 {
1331 uint8_t af;
1332 static char buf[BUFSIZE];
1333 const char * (*pfunc)(netdissect_options *, const u_char *);
1334
1335 if (len < 1)
1336 return NULL;
1337 len--;
1338 af = GET_U_1(tptr);
1339 switch (af) {
1340 case AFNUM_INET:
1341 if (len < 4)
1342 return NULL;
1343 /* This cannot be assigned to ipaddr_string(), which is a macro. */
1344 pfunc = ipaddr_string;
1345 break;
1346 case AFNUM_INET6:
1347 if (len < 16)
1348 return NULL;
1349 /* This cannot be assigned to ip6addr_string(), which is a macro. */
1350 pfunc = ip6addr_string;
1351 break;
1352 case AFNUM_802:
1353 if (len < 6)
1354 return NULL;
1355 pfunc = etheraddr_string;
1356 break;
1357 default:
1358 pfunc = NULL;
1359 break;
1360 }
1361
1362 if (!pfunc) {
1363 nd_snprintf(buf, sizeof(buf), "AFI %s (%u), no AF printer !",
1364 tok2str(af_values, "Unknown", af), af);
1365 } else {
1366 nd_snprintf(buf, sizeof(buf), "AFI %s (%u): %s",
1367 tok2str(af_values, "Unknown", af), af, (*pfunc)(ndo, tptr+1));
1368 }
1369
1370 return buf;
1371 }
1372
1373 static int
1374 lldp_mgmt_addr_tlv_print(netdissect_options *ndo,
1375 const u_char *pptr, u_int len)
1376 {
1377 uint8_t mgmt_addr_len, intf_num_subtype, oid_len;
1378 const u_char *tptr;
1379 u_int tlen;
1380 char *mgmt_addr;
1381
1382 tlen = len;
1383 tptr = pptr;
1384
1385 if (tlen < 1) {
1386 return 0;
1387 }
1388 mgmt_addr_len = GET_U_1(tptr);
1389 tptr++;
1390 tlen--;
1391
1392 if (tlen < mgmt_addr_len) {
1393 return 0;
1394 }
1395
1396 mgmt_addr = lldp_network_addr_print(ndo, tptr, mgmt_addr_len);
1397 if (mgmt_addr == NULL) {
1398 return 0;
1399 }
1400 ND_PRINT("\n\t Management Address length %u, %s",
1401 mgmt_addr_len, mgmt_addr);
1402 tptr += mgmt_addr_len;
1403 tlen -= mgmt_addr_len;
1404
1405 if (tlen < LLDP_INTF_NUM_LEN) {
1406 return 0;
1407 }
1408
1409 intf_num_subtype = GET_U_1(tptr);
1410 ND_PRINT("\n\t %s Interface Numbering (%u): %u",
1411 tok2str(lldp_intf_numb_subtype_values, "Unknown", intf_num_subtype),
1412 intf_num_subtype,
1413 GET_BE_U_4(tptr + 1));
1414
1415 tptr += LLDP_INTF_NUM_LEN;
1416 tlen -= LLDP_INTF_NUM_LEN;
1417
1418 /*
1419 * The OID is optional.
1420 */
1421 if (tlen) {
1422 oid_len = GET_U_1(tptr);
1423
1424 if (tlen < 1U + oid_len) {
1425 return 0;
1426 }
1427 if (oid_len) {
1428 ND_PRINT("\n\t OID length %u", oid_len);
1429 (void)nd_printzp(ndo, tptr + 1, oid_len, NULL);
1430 }
1431 }
1432
1433 return 1;
1434 }
1435
1436 void
1437 lldp_print(netdissect_options *ndo,
1438 const u_char *pptr, u_int len)
1439 {
1440 uint8_t subtype;
1441 uint16_t tlv, cap, ena_cap;
1442 u_int oui, tlen, hexdump, tlv_type, tlv_len;
1443 const u_char *tptr;
1444 char *network_addr;
1445
1446 ndo->ndo_protocol = "lldp";
1447 tptr = pptr;
1448 tlen = len;
1449
1450 ND_PRINT("LLDP, length %u", len);
1451
1452 while (tlen >= sizeof(tlv)) {
1453
1454 ND_TCHECK_LEN(tptr, sizeof(tlv));
1455
1456 tlv = GET_BE_U_2(tptr);
1457
1458 tlv_type = LLDP_EXTRACT_TYPE(tlv);
1459 tlv_len = LLDP_EXTRACT_LEN(tlv);
1460 hexdump = FALSE;
1461
1462 tlen -= sizeof(tlv);
1463 tptr += sizeof(tlv);
1464
1465 if (ndo->ndo_vflag) {
1466 ND_PRINT("\n\t%s TLV (%u), length %u",
1467 tok2str(lldp_tlv_values, "Unknown", tlv_type),
1468 tlv_type, tlv_len);
1469 }
1470
1471 /* infinite loop check */
1472 if (!tlv_type || !tlv_len) {
1473 break;
1474 }
1475
1476 ND_TCHECK_LEN(tptr, tlv_len);
1477 if (tlen < tlv_len) {
1478 goto trunc;
1479 }
1480
1481 switch (tlv_type) {
1482
1483 case LLDP_CHASSIS_ID_TLV:
1484 if (ndo->ndo_vflag) {
1485 if (tlv_len < 2) {
1486 goto trunc;
1487 }
1488 subtype = GET_U_1(tptr);
1489 ND_PRINT("\n\t Subtype %s (%u): ",
1490 tok2str(lldp_chassis_subtype_values, "Unknown", subtype),
1491 subtype);
1492
1493 switch (subtype) {
1494 case LLDP_CHASSIS_MAC_ADDR_SUBTYPE:
1495 if (tlv_len < 1+6) {
1496 goto trunc;
1497 }
1498 ND_PRINT("%s", etheraddr_string(ndo, tptr + 1));
1499 break;
1500
1501 case LLDP_CHASSIS_INTF_NAME_SUBTYPE: /* fall through */
1502 case LLDP_CHASSIS_LOCAL_SUBTYPE:
1503 case LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE:
1504 case LLDP_CHASSIS_INTF_ALIAS_SUBTYPE:
1505 case LLDP_CHASSIS_PORT_COMP_SUBTYPE:
1506 (void)nd_printzp(ndo, tptr + 1, tlv_len - 1, NULL);
1507 break;
1508
1509 case LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE:
1510 network_addr = lldp_network_addr_print(ndo, tptr+1, tlv_len-1);
1511 if (network_addr == NULL) {
1512 goto trunc;
1513 }
1514 ND_PRINT("%s", network_addr);
1515 break;
1516
1517 default:
1518 hexdump = TRUE;
1519 break;
1520 }
1521 }
1522 break;
1523
1524 case LLDP_PORT_ID_TLV:
1525 if (ndo->ndo_vflag) {
1526 if (tlv_len < 2) {
1527 goto trunc;
1528 }
1529 subtype = GET_U_1(tptr);
1530 ND_PRINT("\n\t Subtype %s (%u): ",
1531 tok2str(lldp_port_subtype_values, "Unknown", subtype),
1532 subtype);
1533
1534 switch (subtype) {
1535 case LLDP_PORT_MAC_ADDR_SUBTYPE:
1536 if (tlv_len < 1+6) {
1537 goto trunc;
1538 }
1539 ND_PRINT("%s", etheraddr_string(ndo, tptr + 1));
1540 break;
1541
1542 case LLDP_PORT_INTF_NAME_SUBTYPE: /* fall through */
1543 case LLDP_PORT_LOCAL_SUBTYPE:
1544 case LLDP_PORT_AGENT_CIRC_ID_SUBTYPE:
1545 case LLDP_PORT_INTF_ALIAS_SUBTYPE:
1546 case LLDP_PORT_PORT_COMP_SUBTYPE:
1547 (void)nd_printzp(ndo, tptr + 1, tlv_len - 1, NULL);
1548 break;
1549
1550 case LLDP_PORT_NETWORK_ADDR_SUBTYPE:
1551 network_addr = lldp_network_addr_print(ndo, tptr+1, tlv_len-1);
1552 if (network_addr == NULL) {
1553 goto trunc;
1554 }
1555 ND_PRINT("%s", network_addr);
1556 break;
1557
1558 default:
1559 hexdump = TRUE;
1560 break;
1561 }
1562 }
1563 break;
1564
1565 case LLDP_TTL_TLV:
1566 if (ndo->ndo_vflag) {
1567 if (tlv_len < 2) {
1568 goto trunc;
1569 }
1570 ND_PRINT(": TTL %us", GET_BE_U_2(tptr));
1571 }
1572 break;
1573
1574 case LLDP_PORT_DESCR_TLV:
1575 if (ndo->ndo_vflag) {
1576 ND_PRINT(": ");
1577 (void)nd_printzp(ndo, tptr, tlv_len, NULL);
1578 }
1579 break;
1580
1581 case LLDP_SYSTEM_NAME_TLV:
1582 /*
1583 * The system name is also print in non-verbose mode
1584 * similar to the CDP printer.
1585 */
1586 ND_PRINT(": ");
1587 (void)nd_printzp(ndo, tptr, tlv_len, NULL);
1588 break;
1589
1590 case LLDP_SYSTEM_DESCR_TLV:
1591 if (ndo->ndo_vflag) {
1592 ND_PRINT("\n\t ");
1593 (void)nd_printzp(ndo, tptr, tlv_len, NULL);
1594 }
1595 break;
1596
1597 case LLDP_SYSTEM_CAP_TLV:
1598 if (ndo->ndo_vflag) {
1599 /*
1600 * XXX - IEEE Std 802.1AB-2009 says the first octet
1601 * if a chassis ID subtype, with the system
1602 * capabilities and enabled capabilities following
1603 * it.
1604 */
1605 if (tlv_len < 4) {
1606 goto trunc;
1607 }
1608 cap = GET_BE_U_2(tptr);
1609 ena_cap = GET_BE_U_2(tptr + 2);
1610 ND_PRINT("\n\t System Capabilities [%s] (0x%04x)",
1611 bittok2str(lldp_cap_values, "none", cap), cap);
1612 ND_PRINT("\n\t Enabled Capabilities [%s] (0x%04x)",
1613 bittok2str(lldp_cap_values, "none", ena_cap), ena_cap);
1614 }
1615 break;
1616
1617 case LLDP_MGMT_ADDR_TLV:
1618 if (ndo->ndo_vflag) {
1619 if (!lldp_mgmt_addr_tlv_print(ndo, tptr, tlv_len)) {
1620 goto trunc;
1621 }
1622 }
1623 break;
1624
1625 case LLDP_PRIVATE_TLV:
1626 if (ndo->ndo_vflag) {
1627 if (tlv_len < 3) {
1628 goto trunc;
1629 }
1630 oui = GET_BE_U_3(tptr);
1631 ND_PRINT(": OUI %s (0x%06x)", tok2str(oui_values, "Unknown", oui), oui);
1632
1633 switch (oui) {
1634 case OUI_IEEE_8021_PRIVATE:
1635 hexdump = lldp_private_8021_print(ndo, tptr, tlv_len);
1636 break;
1637 case OUI_IEEE_8023_PRIVATE:
1638 hexdump = lldp_private_8023_print(ndo, tptr, tlv_len);
1639 break;
1640 case OUI_IANA:
1641 hexdump = lldp_private_iana_print(ndo, tptr, tlv_len);
1642 break;
1643 case OUI_TIA:
1644 hexdump = lldp_private_tia_print(ndo, tptr, tlv_len);
1645 break;
1646 case OUI_DCBX:
1647 hexdump = lldp_private_dcbx_print(ndo, tptr, tlv_len);
1648 break;
1649 default:
1650 hexdump = TRUE;
1651 break;
1652 }
1653 }
1654 break;
1655
1656 default:
1657 hexdump = TRUE;
1658 break;
1659 }
1660
1661 /* do we also want to see a hex dump ? */
1662 if (ndo->ndo_vflag > 1 || (ndo->ndo_vflag && hexdump)) {
1663 print_unknown_data(ndo, tptr, "\n\t ", tlv_len);
1664 }
1665
1666 tlen -= tlv_len;
1667 tptr += tlv_len;
1668 }
1669 return;
1670 trunc:
1671 nd_print_trunc(ndo);
1672 }