2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 * Code by Gert Doering, SpaceNet GmbH, gert@space.net
23 * Reference documentation:
24 * http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm
27 #define NETDISSECT_REWORKED
32 #include <tcpdump-stdinc.h>
36 #include "interface.h"
37 #include "addrtoname.h"
38 #include "extract.h" /* must come after interface.h */
41 static const char tstr
[] = "[|cdp]";
43 #define CDP_HEADER_LEN 4
45 static const struct tok cdp_tlv_values
[] = {
49 { 0x04, "Capability"},
50 { 0x05, "Version String"},
53 { 0x08, "Protocol-Hello option"},
54 { 0x09, "VTP Management Domain"},
55 { 0x0a, "Native VLAN ID"},
57 { 0x0e, "ATA-186 VoIP VLAN request"},
58 { 0x0f, "ATA-186 VoIP VLAN assignment"},
59 { 0x10, "power consumption"},
61 { 0x12, "AVVID trust bitmap"},
62 { 0x13, "AVVID untrusted ports CoS"},
63 { 0x14, "System Name"},
64 { 0x15, "System Object ID (not decoded)"},
65 { 0x16, "Management Addresses"},
66 { 0x17, "Physical Location"},
70 static const struct tok cdp_capability_values
[] = {
72 { 0x02, "Transparent Bridge" },
73 { 0x04, "Source Route Bridge" },
74 { 0x08, "L2 Switch" },
75 { 0x10, "L3 capable" },
76 { 0x20, "IGMP snooping" },
77 { 0x40, "L1 capable" },
81 static int cdp_print_addr(netdissect_options
*, const u_char
*, int);
82 static int cdp_print_prefixes(netdissect_options
*, const u_char
*, int);
83 static unsigned long cdp_get_number(const u_char
*, int);
86 cdp_print(netdissect_options
*ndo
,
87 const u_char
*pptr
, u_int length
, u_int caplen
)
92 if (caplen
< CDP_HEADER_LEN
) {
93 ND_PRINT((ndo
, "%s", tstr
));
97 tptr
= pptr
; /* temporary pointer */
99 ND_TCHECK2(*tptr
, CDP_HEADER_LEN
);
100 ND_PRINT((ndo
, "CDPv%u, ttl: %us", *tptr
, *(tptr
+ 1)));
102 ND_PRINT((ndo
, ", checksum: %u (unverified), length %u", EXTRACT_16BITS(tptr
), length
));
103 tptr
+= CDP_HEADER_LEN
;
105 while (tptr
< (pptr
+length
)) {
106 ND_TCHECK2(*tptr
, 4); /* read out Type and Length */
107 type
= EXTRACT_16BITS(tptr
);
108 len
= EXTRACT_16BITS(tptr
+2); /* object length includes the 4 bytes header length */
112 ND_TCHECK2(*tptr
, len
);
114 if (ndo
->ndo_vflag
|| type
== 1) { /* in non-verbose mode just print Device-ID */
117 ND_PRINT((ndo
, "\n\t%s (0x%02x), length: %u byte%s: ",
118 tok2str(cdp_tlv_values
,"unknown field type", type
),
121 PLURAL_SUFFIX(len
))); /* plural */
125 case 0x01: /* Device-ID */
127 ND_PRINT((ndo
, ", Device-ID "));
128 ND_PRINT((ndo
, "'"));
129 fn_printn(ndo
, tptr
, len
, NULL
);
130 ND_PRINT((ndo
, "'"));
132 case 0x02: /* Address */
133 if (cdp_print_addr(ndo
, tptr
, len
) < 0)
136 case 0x03: /* Port-ID */
137 ND_PRINT((ndo
, "'"));
138 fn_printn(ndo
, tptr
, len
, NULL
);
139 ND_PRINT((ndo
, "'"));
141 case 0x04: /* Capabilities */
142 ND_PRINT((ndo
, "(0x%08x): %s",
143 EXTRACT_32BITS(tptr
),
144 bittok2str(cdp_capability_values
, "none", EXTRACT_32BITS(tptr
))));
146 case 0x05: /* Version */
147 ND_PRINT((ndo
, "\n\t "));
148 for (i
=0;i
<len
;i
++) {
150 ND_PRINT((ndo
, "%c", j
));
151 if (j
== 0x0a) /* lets rework the version string to get a nice identation */
152 ND_PRINT((ndo
, "\t "));
155 case 0x06: /* Platform */
156 ND_PRINT((ndo
, "'"));
157 fn_printn(ndo
, tptr
, len
, NULL
);
158 ND_PRINT((ndo
, "'"));
160 case 0x07: /* Prefixes */
161 if (cdp_print_prefixes(ndo
, tptr
, len
) < 0)
164 case 0x08: /* Protocol Hello Option - not documented */
166 case 0x09: /* VTP Mgmt Domain - not documented */
167 ND_PRINT((ndo
, "'"));
168 fn_printn(ndo
, tptr
, len
, NULL
);
169 ND_PRINT((ndo
, "'"));
171 case 0x0a: /* Native VLAN ID - not documented */
172 ND_PRINT((ndo
, "%d", EXTRACT_16BITS(tptr
)));
174 case 0x0b: /* Duplex - not documented */
175 ND_PRINT((ndo
, "%s", *(tptr
) ? "full": "half"));
178 /* http://www.cisco.com/univercd/cc/td/doc/product/voice/ata/atarn/186rn21m.htm
179 * plus more details from other sources
181 case 0x0e: /* ATA-186 VoIP VLAN request - incomplete doc. */
182 ND_PRINT((ndo
, "app %d, vlan %d", *(tptr
), EXTRACT_16BITS(tptr
+ 1)));
184 case 0x10: /* ATA-186 VoIP VLAN assignment - incomplete doc. */
185 ND_PRINT((ndo
, "%1.2fW", cdp_get_number(tptr
, len
) / 1000.0));
187 case 0x11: /* MTU - not documented */
188 ND_PRINT((ndo
, "%u bytes", EXTRACT_32BITS(tptr
)));
190 case 0x12: /* AVVID trust bitmap - not documented */
191 ND_PRINT((ndo
, "0x%02x", *(tptr
)));
193 case 0x13: /* AVVID untrusted port CoS - not documented */
194 ND_PRINT((ndo
, "0x%02x", *(tptr
)));
196 case 0x14: /* System Name - not documented */
197 ND_PRINT((ndo
, "'"));
198 fn_printn(ndo
, tptr
, len
, NULL
);
199 ND_PRINT((ndo
, "'"));
201 case 0x16: /* System Object ID - not documented */
202 if (cdp_print_addr(ndo
, tptr
, len
) < 0)
205 case 0x17: /* Physical Location - not documented */
206 ND_PRINT((ndo
, "0x%02x", *(tptr
)));
208 ND_PRINT((ndo
, "/"));
209 fn_printn(ndo
, tptr
+ 1, len
- 1, NULL
);
213 print_unknown_data(ndo
, tptr
, "\n\t ", len
);
217 /* avoid infinite loop */
222 if (ndo
->ndo_vflag
< 1)
223 ND_PRINT((ndo
, ", length %u", caplen
));
227 ND_PRINT((ndo
, "%s", tstr
));
231 * Protocol type values.
233 * PT_NLPID means that the protocol type field contains an OSI NLPID.
235 * PT_IEEE_802_2 means that the protocol type field contains an IEEE 802.2
236 * LLC header that specifies that the payload is for that protocol.
238 #define PT_NLPID 1 /* OSI NLPID */
239 #define PT_IEEE_802_2 2 /* IEEE 802.2 LLC header */
242 cdp_print_addr(netdissect_options
*ndo
,
243 const u_char
* p
, int l
)
246 const u_char
*endp
= p
+ l
;
248 static const u_char prot_ipv6
[] = {
249 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x86, 0xdd
254 num
= EXTRACT_32BITS(p
);
257 while (p
< endp
&& num
>= 0) {
261 pt
= p
[0]; /* type of "protocol" field */
262 pl
= p
[1]; /* length of "protocol" field */
265 ND_TCHECK2(p
[pl
], 2);
266 if (p
+ pl
+ 2 > endp
)
268 al
= EXTRACT_16BITS(&p
[pl
]); /* address length */
270 if (pt
== PT_NLPID
&& pl
== 1 && *p
== NLPID_IP
&& al
== 4) {
272 * IPv4: protocol type = NLPID, protocol length = 1
273 * (1-byte NLPID), protocol = 0xcc (NLPID for IPv4),
281 ND_PRINT((ndo
, "IPv4 (%u) %s", num
, ipaddr_string(ndo
, p
)));
285 else if (pt
== PT_IEEE_802_2
&& pl
== 8 &&
286 memcmp(p
, prot_ipv6
, 8) == 0 && al
== 16) {
288 * IPv6: protocol type = IEEE 802.2 header,
289 * protocol length = 8 (size of LLC+SNAP header),
290 * protocol = LLC+SNAP header with the IPv6
291 * Ethertype, address length = 16
298 ND_PRINT((ndo
, "IPv6 (%u) %s", num
, ip6addr_string(ndo
, p
)));
304 * Generic case: just print raw data
309 ND_PRINT((ndo
, "pt=0x%02x, pl=%d, pb=", *(p
- 2), pl
));
311 ND_PRINT((ndo
, " %02x", *p
++));
315 al
= (*p
<< 8) + *(p
+ 1);
316 ND_PRINT((ndo
, ", al=%d, a=", al
));
322 ND_PRINT((ndo
, " %02x", *p
++));
326 ND_PRINT((ndo
, " "));
337 cdp_print_prefixes(netdissect_options
*ndo
,
338 const u_char
* p
, int l
)
343 ND_PRINT((ndo
, " IPv4 Prefixes (%d):", l
/ 5));
346 ND_PRINT((ndo
, " %u.%u.%u.%u/%u", p
[0], p
[1], p
[2], p
[3], p
[4]));
357 /* read in a <n>-byte number, MSB first
358 * (of course this can handle max sizeof(long))
360 static unsigned long cdp_get_number(const u_char
* p
, int l
)