2 * Copyright (c) 1998-2007 The TCPDUMP project
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.
15 * support for the IEEE Link Discovery Protocol as per 802.1ab
17 * Original code by Hannes Gredler (hannes@juniper.net)
21 static const char rcsid
[] _U_
=
22 "@(#) $Header: /tcpdump/master/tcpdump/print-lldp.c,v 1.2 2007-08-08 14:39:52 hannes Exp $";
29 #include <tcpdump-stdinc.h>
35 #include "interface.h"
37 #include "addrtoname.h"
41 #define LLDP_EXTRACT_TYPE(x) (((x)&0xfe00)>>9)
42 #define LLDP_EXTRACT_LEN(x) ((x)&0x01ff)
47 #define LLDP_END_TLV 0
48 #define LLDP_CHASSIS_ID_TLV 1
49 #define LLDP_PORT_ID_TLV 2
50 #define LLDP_TTL_TLV 3
51 #define LLDP_PORT_DESCR_TLV 4
52 #define LLDP_SYSTEM_NAME_TLV 5
53 #define LLDP_SYSTEM_DESCR_TLV 6
54 #define LLDP_SYSTEM_CAP_TLV 7
55 #define LLDP_MGMT_ADDR_TLV 8
56 #define LLDP_PRIVATE_TLV 127
58 static const struct tok lldp_tlv_values
[] = {
59 { LLDP_END_TLV
, "End" },
60 { LLDP_CHASSIS_ID_TLV
, "Chassis ID" },
61 { LLDP_PORT_ID_TLV
, "Port ID" },
62 { LLDP_TTL_TLV
, "Time to Live" },
63 { LLDP_PORT_DESCR_TLV
, "Port Description" },
64 { LLDP_SYSTEM_NAME_TLV
, "System Name" },
65 { LLDP_SYSTEM_DESCR_TLV
, "System Description" },
66 { LLDP_SYSTEM_CAP_TLV
, "System Capabilities" },
67 { LLDP_MGMT_ADDR_TLV
, "Management Address" },
68 { LLDP_PRIVATE_TLV
, "Organization specific" },
75 #define LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE 1
76 #define LLDP_CHASSIS_INTF_ALIAS_SUBTYPE 2
77 #define LLDP_CHASSIS_PORT_COMP_SUBTYPE 3
78 #define LLDP_CHASSIS_MAC_ADDR_SUBTYPE 4
79 #define LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE 5
80 #define LLDP_CHASSIS_INTF_NAME_SUBTYPE 6
81 #define LLDP_CHASSIS_LOCAL_SUBTYPE 7
83 static const struct tok lldp_chassis_subtype_values
[] = {
84 { LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE
, "Chassis component"},
85 { LLDP_CHASSIS_INTF_ALIAS_SUBTYPE
, "Interface alias"},
86 { LLDP_CHASSIS_PORT_COMP_SUBTYPE
, "Port component"},
87 { LLDP_CHASSIS_MAC_ADDR_SUBTYPE
, "MAC address"},
88 { LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE
, "Network address"},
89 { LLDP_CHASSIS_INTF_NAME_SUBTYPE
, "Interface name"},
90 { LLDP_CHASSIS_LOCAL_SUBTYPE
, "Local"},
97 #define LLDP_PORT_INTF_ALIAS_SUBTYPE 1
98 #define LLDP_PORT_PORT_COMP_SUBTYPE 2
99 #define LLDP_PORT_MAC_ADDR_SUBTYPE 3
100 #define LLDP_PORT_NETWORK_ADDR_SUBTYPE 4
101 #define LLDP_PORT_INTF_NAME_SUBTYPE 5
102 #define LLDP_PORT_AGENT_CIRC_ID_SUBTYPE 6
103 #define LLDP_PORT_LOCAL_SUBTYPE 7
105 static const struct tok lldp_port_subtype_values
[] = {
106 { LLDP_PORT_INTF_ALIAS_SUBTYPE
, "Interface alias"},
107 { LLDP_PORT_PORT_COMP_SUBTYPE
, "Port component"},
108 { LLDP_PORT_MAC_ADDR_SUBTYPE
, "MAC address"},
109 { LLDP_PORT_NETWORK_ADDR_SUBTYPE
, "Network Address"},
110 { LLDP_PORT_INTF_NAME_SUBTYPE
, "Interface Name"},
111 { LLDP_PORT_AGENT_CIRC_ID_SUBTYPE
, "Agent circuit ID"},
112 { LLDP_PORT_LOCAL_SUBTYPE
, "Local"},
117 * System Capabilities
119 #define LLDP_CAP_OTHER 1 << 0
120 #define LLDP_CAP_REPEATER 1 << 1
121 #define LLDP_CAP_BRIDGE 1 << 2
122 #define LLDP_CAP_WLAN_AP 1 << 3
123 #define LLDP_CAP_ROUTER 1 << 4
124 #define LLDP_CAP_PHONE 1 << 5
125 #define LLDP_CAP_DOCSIS 1 << 6
126 #define LLDP_CAP_STATION_ONLY 1 << 7
128 static const struct tok lldp_cap_values
[] = {
129 { LLDP_CAP_OTHER
, "Other"},
130 { LLDP_CAP_REPEATER
, "Repeater"},
131 { LLDP_CAP_BRIDGE
, "Bridge"},
132 { LLDP_CAP_WLAN_AP
, "WLAN AP"},
133 { LLDP_CAP_ROUTER
, "Router"},
134 { LLDP_CAP_PHONE
, "Telephone"},
135 { LLDP_CAP_DOCSIS
, "Docsis"},
136 { LLDP_CAP_STATION_ONLY
, "Station Only"},
141 * Interface numbering subtypes.
143 #define LLDP_INTF_NUMB_IFX_SUBTYPE 2
144 #define LLDP_INTF_NUMB_SYSPORT_SUBTYPE 3
146 static const struct tok lldp_intf_numb_subtype_values
[] = {
147 { LLDP_INTF_NUMB_IFX_SUBTYPE
, "Interface Index" },
148 { LLDP_INTF_NUMB_SYSPORT_SUBTYPE
, "System Port Number" },
154 lldp_network_addr_print(const u_char
*tptr
) {
157 static char buf
[BUFSIZE
];
158 const char * (*pfunc
)(const u_char
*);
171 pfunc
= etheraddr_string
;
179 snprintf(buf
, sizeof(buf
), "AFI %s (%u) XXX",
180 tok2str(af_values
, "Unknown", af
), af
);
182 snprintf(buf
, sizeof(buf
), "AFI %s (%u): %s",
183 tok2str(af_values
, "Unknown", af
), af
, (*pfunc
)(tptr
+1));
190 lldp_mgmt_addr_tlv_print(const u_char
*pptr
, u_int len
) {
192 u_int8_t mgmt_addr_len
, intf_num_subtype
, oid_len
;
199 mgmt_addr_len
= *tptr
++;
202 if (tlen
< mgmt_addr_len
) {
206 printf("\n\t Management Address length %u, %s",
208 lldp_network_addr_print(tptr
));
209 tptr
+= mgmt_addr_len
;
210 tlen
-= mgmt_addr_len
;
216 intf_num_subtype
= *tptr
;
217 printf("\n\t %s Interface Numbering (%u): %u",
218 tok2str(lldp_intf_numb_subtype_values
, "Unknown", intf_num_subtype
),
220 EXTRACT_32BITS(tptr
+1));
225 * The OID is optional.
231 printf("\n\t OID length %u", oid_len
);
232 safeputs((const char *)tptr
+1, oid_len
);
240 lldp_print(register const u_char
*pptr
, register u_int len
) {
243 u_int16_t tlv
, cap
, ena_cap
;
244 u_int oui
, tlen
, hexdump
, tlv_type
, tlv_len
;
251 printf("LLDP, length %u", len
);
254 while (tlen
>= sizeof(tlv
)) {
256 TCHECK2(*tptr
, sizeof(tlv
));
258 tlv
= EXTRACT_16BITS(tptr
);
260 tlv_type
= LLDP_EXTRACT_TYPE(tlv
);
261 tlv_len
= LLDP_EXTRACT_LEN(tlv
);
268 printf("\n\t%s TLV (%u), length %u",
269 tok2str(lldp_tlv_values
, "Unknown", tlv_type
),
273 /* infinite loop check */
274 if (!tlv_type
|| !tlv_len
) {
278 TCHECK2(*tptr
, tlv_len
);
283 printf(": TTL %us", EXTRACT_16BITS(tptr
));
287 case LLDP_SYSTEM_NAME_TLV
:
290 * The system name is also print in non-verbose mode
291 * similar to the CDP printer.
295 safeputs((const char *)tptr
, tlv_len
);
297 printf("LLDP, name ");
298 safeputs((const char *)tptr
, tlv_len
);
299 printf(", length %u", len
);
303 case LLDP_PORT_DESCR_TLV
:
306 safeputs((const char *)tptr
, tlv_len
);
310 case LLDP_SYSTEM_DESCR_TLV
:
313 safeputs((const char *)tptr
, tlv_len
);
318 case LLDP_CHASSIS_ID_TLV
:
321 printf("\n\t Subtype %s (%u): ",
322 tok2str(lldp_chassis_subtype_values
, "Unknown", subtype
),
326 case LLDP_CHASSIS_MAC_ADDR_SUBTYPE
:
327 printf("%s", etheraddr_string(tptr
+1));
330 case LLDP_CHASSIS_INTF_NAME_SUBTYPE
: /* fall through */
331 case LLDP_CHASSIS_LOCAL_SUBTYPE
:
332 case LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE
:
333 case LLDP_CHASSIS_INTF_ALIAS_SUBTYPE
:
334 case LLDP_CHASSIS_PORT_COMP_SUBTYPE
:
335 safeputs((const char *)tptr
+1, tlv_len
-1);
338 case LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE
:
339 printf("%s", lldp_network_addr_print(tptr
+1));
349 case LLDP_PORT_ID_TLV
:
352 printf("\n\t Subtype %s (%u): ",
353 tok2str(lldp_port_subtype_values
, "Unknown", subtype
),
357 case LLDP_PORT_MAC_ADDR_SUBTYPE
:
358 printf("%s", etheraddr_string(tptr
+1));
361 case LLDP_PORT_INTF_NAME_SUBTYPE
: /* fall through */
362 case LLDP_PORT_LOCAL_SUBTYPE
:
363 case LLDP_PORT_AGENT_CIRC_ID_SUBTYPE
:
364 case LLDP_PORT_INTF_ALIAS_SUBTYPE
:
365 case LLDP_PORT_PORT_COMP_SUBTYPE
:
366 safeputs((const char *)tptr
+1, tlv_len
-1);
369 case LLDP_PORT_NETWORK_ADDR_SUBTYPE
:
370 printf("%s", lldp_network_addr_print(tptr
+1));
380 case LLDP_PRIVATE_TLV
:
383 oui
= EXTRACT_24BITS(tptr
);
384 printf(": OUI %s (0x%06x)", tok2str(oui_values
, "Unknown", oui
), oui
);
389 case LLDP_SYSTEM_CAP_TLV
:
391 cap
= EXTRACT_16BITS(tptr
);
392 ena_cap
= EXTRACT_16BITS(tptr
+2);
393 printf("\n\t System Capabilities [%s] (0x%04x)",
394 bittok2str(lldp_cap_values
, "none", cap
), cap
);
395 printf("\n\t Enabled Capabilities [%s] (0x%04x)",
396 bittok2str(lldp_cap_values
, "none", ena_cap
), ena_cap
);
400 case LLDP_MGMT_ADDR_TLV
:
402 if (!lldp_mgmt_addr_tlv_print(tptr
, tlen
)) {
413 /* do we also want to see a hex dump ? */
414 if (vflag
> 1 || (vflag
&& hexdump
)) {
415 print_unknown_data(tptr
,"\n\t ", tlv_len
);
423 printf("\n\t[|LLDP]");
428 * c-style: whitesmith