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 Matt Thomas, Digital Equipment Corporation
22 * with an awful lot of hacking by Jeffrey Mogul, DECWRL
25 #define NETDISSECT_REWORKED
30 #include <tcpdump-stdinc.h>
32 #include "interface.h"
33 #include "addrtoname.h"
34 #include "extract.h" /* must come after interface.h */
37 #include "ethertype.h"
40 static const struct tok llc_values
[] = {
41 { LLCSAP_NULL
, "Null" },
42 { LLCSAP_GLOBAL
, "Global" },
43 { LLCSAP_8021B_I
, "802.1B I" },
44 { LLCSAP_8021B_G
, "802.1B G" },
46 { LLCSAP_SNA
, "SNA" },
47 { LLCSAP_PROWAYNM
, "ProWay NM" },
48 { LLCSAP_8021D
, "STP" },
49 { LLCSAP_RS511
, "RS511" },
50 { LLCSAP_ISO8208
, "ISO8208" },
51 { LLCSAP_PROWAY
, "ProWay" },
52 { LLCSAP_SNAP
, "SNAP" },
53 { LLCSAP_IPX
, "IPX" },
54 { LLCSAP_NETBEUI
, "NetBeui" },
55 { LLCSAP_ISONS
, "OSI" },
59 static const struct tok llc_cmd_values
[] = {
66 { LLC_SABME
, "sabme" },
71 static const struct tok llc_flag_values
[] = {
73 { LLC_GSAP
, "Response" },
74 { LLC_U_POLL
, "Poll" },
75 { LLC_GSAP
|LLC_U_POLL
, "Final" },
76 { LLC_IS_POLL
, "Poll" },
77 { LLC_GSAP
|LLC_IS_POLL
, "Final" },
82 static const struct tok llc_ig_flag_values
[] = {
89 static const struct tok llc_supervisory_values
[] = {
90 { 0, "Receiver Ready" },
91 { 1, "Receiver not Ready" },
97 static const struct tok cisco_values
[] = {
98 { PID_CISCO_CDP
, "CDP" },
99 { PID_CISCO_VTP
, "VTP" },
100 { PID_CISCO_DTP
, "DTP" },
101 { PID_CISCO_UDLD
, "UDLD" },
102 { PID_CISCO_PVST
, "PVST" },
103 { PID_CISCO_VLANBRIDGE
, "VLAN Bridge" },
107 static const struct tok bridged_values
[] = {
108 { PID_RFC2684_ETH_FCS
, "Ethernet + FCS" },
109 { PID_RFC2684_ETH_NOFCS
, "Ethernet w/o FCS" },
110 { PID_RFC2684_802_4_FCS
, "802.4 + FCS" },
111 { PID_RFC2684_802_4_NOFCS
, "802.4 w/o FCS" },
112 { PID_RFC2684_802_5_FCS
, "Token Ring + FCS" },
113 { PID_RFC2684_802_5_NOFCS
, "Token Ring w/o FCS" },
114 { PID_RFC2684_FDDI_FCS
, "FDDI + FCS" },
115 { PID_RFC2684_FDDI_NOFCS
, "FDDI w/o FCS" },
116 { PID_RFC2684_802_6_FCS
, "802.6 + FCS" },
117 { PID_RFC2684_802_6_NOFCS
, "802.6 w/o FCS" },
118 { PID_RFC2684_BPDU
, "BPDU" },
122 static const struct tok null_values
[] = {
128 const struct tok
*tok
;
131 static const struct oui_tok oui_to_tok
[] = {
132 { OUI_ENCAP_ETHER
, ethertype_values
},
133 { OUI_CISCO_90
, ethertype_values
}, /* uses some Ethertype values */
134 { OUI_APPLETALK
, ethertype_values
}, /* uses some Ethertype values */
135 { OUI_CISCO
, cisco_values
},
136 { OUI_RFC2684
, bridged_values
}, /* bridged, RFC 2427 FR or RFC 2864 ATM */
141 * Returns non-zero IFF it succeeds in printing the header
144 llc_print(netdissect_options
*ndo
, const u_char
*p
, u_int length
, u_int caplen
,
145 const u_char
*esrc
, const u_char
*edst
, u_short
*extracted_ethertype
)
147 uint8_t dsap_field
, dsap
, ssap_field
, ssap
;
152 *extracted_ethertype
= 0;
155 ND_PRINT((ndo
, "[|llc]"));
156 ND_DEFAULTPRINT((u_char
*)p
, caplen
);
161 ssap_field
= *(p
+ 1);
164 * OK, what type of LLC frame is this? The length
165 * of the control field depends on that - I frames
166 * have a two-byte control field, and U frames have
167 * a one-byte control field.
170 if ((control
& LLC_U_FMT
) == LLC_U_FMT
) {
177 * The control field in I and S frames is
181 ND_PRINT((ndo
, "[|llc]"));
182 ND_DEFAULTPRINT((u_char
*)p
, caplen
);
187 * ...and is little-endian.
189 control
= EXTRACT_LE_16BITS(p
+ 2);
193 if (ssap_field
== LLCSAP_GLOBAL
&& dsap_field
== LLCSAP_GLOBAL
) {
195 * This is an Ethernet_802.3 IPX frame; it has an
196 * 802.3 header (i.e., an Ethernet header where the
197 * type/length field is <= ETHERMTU, i.e. it's a length
198 * field, not a type field), but has no 802.2 header -
199 * the IPX packet starts right after the Ethernet header,
200 * with a signature of two bytes of 0xFF (which is
203 * (It might also have been an Ethernet_802.3 IPX at
204 * one time, but got bridged onto another network,
205 * such as an 802.11 network; this has appeared in at
206 * least one capture file.)
210 ND_PRINT((ndo
, "IPX 802.3: "));
212 ipx_print(ndo
, p
, length
);
216 dsap
= dsap_field
& ~LLC_IG
;
217 ssap
= ssap_field
& ~LLC_GSAP
;
219 if (ndo
->ndo_eflag
) {
220 ND_PRINT((ndo
, "LLC, dsap %s (0x%02x) %s, ssap %s (0x%02x) %s",
221 tok2str(llc_values
, "Unknown", dsap
),
223 tok2str(llc_ig_flag_values
, "Unknown", dsap_field
& LLC_IG
),
224 tok2str(llc_values
, "Unknown", ssap
),
226 tok2str(llc_flag_values
, "Unknown", ssap_field
& LLC_GSAP
)));
229 ND_PRINT((ndo
, ", ctrl 0x%02x: ", control
));
231 ND_PRINT((ndo
, ", ctrl 0x%04x: ", control
));
235 if (ssap
== LLCSAP_8021D
&& dsap
== LLCSAP_8021D
&&
237 stp_print(ndo
, p
+3, length
-3);
241 if (ssap
== LLCSAP_IP
&& dsap
== LLCSAP_IP
&&
243 ip_print(ndo
, p
+4, length
-4);
247 if (ssap
== LLCSAP_IPX
&& dsap
== LLCSAP_IPX
&&
250 * This is an Ethernet_802.2 IPX frame, with an 802.3
251 * header and an 802.2 LLC header with the source and
252 * destination SAPs being the IPX SAP.
254 * Skip DSAP, LSAP, and control field.
257 ND_PRINT((ndo
, "IPX 802.2: "));
259 ipx_print(ndo
, p
+3, length
-3);
263 #ifdef TCPDUMP_DO_SMB
264 if (ssap
== LLCSAP_NETBEUI
&& dsap
== LLCSAP_NETBEUI
265 && (!(control
& LLC_S_FMT
) || control
== LLC_U_FMT
)) {
267 * we don't actually have a full netbeui parser yet, but the
268 * smb parser can handle many smb-in-netbeui packets, which
269 * is very useful, so we call that
271 * We don't call it for S frames, however, just I frames
272 * (which are frames that don't have the low-order bit,
273 * LLC_S_FMT, set in the first byte of the control field)
274 * and UI frames (whose control field is just 3, LLC_U_FMT).
278 * Skip the LLC header.
287 netbeui_print(ndo
, control
, p
, length
);
291 if (ssap
== LLCSAP_ISONS
&& dsap
== LLCSAP_ISONS
292 && control
== LLC_UI
) {
293 isoclns_print(ndo
, p
+ 3, length
- 3, caplen
- 3);
297 if (ssap
== LLCSAP_SNAP
&& dsap
== LLCSAP_SNAP
298 && control
== LLC_UI
) {
300 * XXX - what *is* the right bridge pad value here?
301 * Does anybody ever bridge one form of LAN traffic
302 * over a networking type that uses 802.2 LLC?
304 ret
= snap_print(ndo
, p
+3, length
-3, caplen
-3, 2);
309 if (!ndo
->ndo_eflag
) {
311 if (esrc
== NULL
|| edst
== NULL
)
312 ND_PRINT((ndo
, "%s ", tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
)));
314 ND_PRINT((ndo
, "%s > %s %s ",
315 etheraddr_string(ndo
, esrc
),
316 etheraddr_string(ndo
, edst
),
317 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
)));
319 if (esrc
== NULL
|| edst
== NULL
)
320 ND_PRINT((ndo
, "%s > %s ",
321 tok2str(llc_values
, "Unknown SSAP 0x%02x", ssap
),
322 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
)));
324 ND_PRINT((ndo
, "%s %s > %s %s ",
325 etheraddr_string(ndo
, esrc
),
326 tok2str(llc_values
, "Unknown SSAP 0x%02x", ssap
),
327 etheraddr_string(ndo
, edst
),
328 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
)));
333 ND_PRINT((ndo
, "Unnumbered, %s, Flags [%s], length %u",
334 tok2str(llc_cmd_values
, "%02x", LLC_U_CMD(control
)),
335 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_U_POLL
)),
340 if ((control
& ~LLC_U_POLL
) == LLC_XID
) {
341 if (*p
== LLC_XID_FI
) {
342 ND_PRINT((ndo
, ": %02x %02x", p
[1], p
[2]));
346 if ((control
& LLC_S_FMT
) == LLC_S_FMT
) {
347 ND_PRINT((ndo
, "Supervisory, %s, rcv seq %u, Flags [%s], length %u",
348 tok2str(llc_supervisory_values
,"?",LLC_S_CMD(control
)),
350 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_IS_POLL
)),
353 ND_PRINT((ndo
, "Information, send seq %u, rcv seq %u, Flags [%s], length %u",
356 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_IS_POLL
)),
364 snap_print(netdissect_options
*ndo
, const u_char
*p
, u_int length
, u_int caplen
, u_int bridge_pad
)
371 orgcode
= EXTRACT_24BITS(p
);
372 et
= EXTRACT_16BITS(p
+ 3);
374 if (ndo
->ndo_eflag
) {
375 const struct tok
*tok
= null_values
;
376 const struct oui_tok
*otp
;
378 for (otp
= &oui_to_tok
[0]; otp
->tok
!= NULL
; otp
++) {
379 if (otp
->oui
== orgcode
) {
384 ND_PRINT((ndo
, "oui %s (0x%06x), %s %s (0x%04x): ",
385 tok2str(oui_values
, "Unknown", orgcode
),
387 (orgcode
== 0x000000 ? "ethertype" : "pid"),
388 tok2str(tok
, "Unknown", et
),
396 case OUI_ENCAP_ETHER
:
399 * This is an encapsulated Ethernet packet,
400 * or a packet bridged by some piece of
401 * Cisco hardware; the protocol ID is
402 * an Ethernet protocol type.
404 ret
= ethertype_print(ndo
, et
, p
, length
, caplen
);
410 if (et
== ETHERTYPE_ATALK
) {
412 * No, I have no idea why Apple used one
413 * of their own OUIs, rather than
414 * 0x000000, and an Ethernet packet
415 * type, for Appletalk data packets,
416 * but used 0x000000 and an Ethernet
417 * packet type for AARP packets.
419 ret
= ethertype_print(ndo
, et
, p
, length
, caplen
);
428 cdp_print(ndo
, p
, length
, caplen
);
431 dtp_print(ndo
, p
, length
);
434 udld_print(ndo
, p
, length
);
437 vtp_print(ndo
, p
, length
);
440 case PID_CISCO_VLANBRIDGE
:
441 stp_print(ndo
, p
, length
);
451 case PID_RFC2684_ETH_FCS
:
452 case PID_RFC2684_ETH_NOFCS
:
454 * XXX - remove the last two bytes for
455 * PID_RFC2684_ETH_FCS?
460 ND_TCHECK2(*p
, bridge_pad
);
461 caplen
-= bridge_pad
;
462 length
-= bridge_pad
;
466 * What remains is an Ethernet packet.
468 ether_print(ndo
, p
, length
, caplen
, NULL
, NULL
);
471 case PID_RFC2684_802_5_FCS
:
472 case PID_RFC2684_802_5_NOFCS
:
474 * XXX - remove the last two bytes for
475 * PID_RFC2684_ETH_FCS?
478 * Skip the padding, but not the Access
481 ND_TCHECK2(*p
, bridge_pad
);
482 caplen
-= bridge_pad
;
483 length
-= bridge_pad
;
487 * What remains is an 802.5 Token Ring
490 token_print(ndo
, p
, length
, caplen
);
493 case PID_RFC2684_FDDI_FCS
:
494 case PID_RFC2684_FDDI_NOFCS
:
496 * XXX - remove the last two bytes for
497 * PID_RFC2684_ETH_FCS?
502 ND_TCHECK2(*p
, bridge_pad
+ 1);
503 caplen
-= bridge_pad
+ 1;
504 length
-= bridge_pad
+ 1;
508 * What remains is an FDDI packet.
510 fddi_print(ndo
, p
, length
, caplen
);
513 case PID_RFC2684_BPDU
:
514 stp_print(ndo
, p
, length
);
521 ND_PRINT((ndo
, "[|snap]"));
528 * c-style: whitesmith