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
26 static const char rcsid
[] _U_
=
27 "@(#) $Header: /tcpdump/master/tcpdump/print-llc.c,v 1.75 2007-04-13 09:43:11 hannes Exp $";
34 #include <tcpdump-stdinc.h>
39 #include "interface.h"
40 #include "addrtoname.h"
41 #include "extract.h" /* must come after interface.h */
44 #include "ethertype.h"
47 static struct tok llc_values
[] = {
48 { LLCSAP_NULL
, "Null" },
49 { LLCSAP_GLOBAL
, "Global" },
50 { LLCSAP_8021B_I
, "802.1B I" },
51 { LLCSAP_8021B_G
, "802.1B G" },
53 { LLCSAP_SNA
, "SNA" },
54 { LLCSAP_PROWAYNM
, "ProWay NM" },
55 { LLCSAP_8021D
, "STP" },
56 { LLCSAP_RS511
, "RS511" },
57 { LLCSAP_ISO8208
, "ISO8208" },
58 { LLCSAP_PROWAY
, "ProWay" },
59 { LLCSAP_SNAP
, "SNAP" },
60 { LLCSAP_IPX
, "IPX" },
61 { LLCSAP_NETBEUI
, "NetBeui" },
62 { LLCSAP_ISONS
, "OSI" },
66 static struct tok llc_cmd_values
[] = {
73 { LLC_SABME
, "sabme" },
78 static const struct tok llc_flag_values
[] = {
80 { LLC_GSAP
, "Response" },
81 { LLC_U_POLL
, "Poll" },
82 { LLC_GSAP
|LLC_U_POLL
, "Final" },
83 { LLC_IS_POLL
, "Poll" },
84 { LLC_GSAP
|LLC_IS_POLL
, "Final" },
89 static const struct tok llc_ig_flag_values
[] = {
96 static const struct tok llc_supervisory_values
[] = {
97 { 0, "Receiver Ready" },
98 { 1, "Receiver not Ready" },
104 static const struct tok cisco_values
[] = {
105 { PID_CISCO_CDP
, "CDP" },
106 { PID_CISCO_VTP
, "VTP" },
107 { PID_CISCO_DTP
, "DTP" },
108 { PID_CISCO_UDLD
, "UDLD" },
109 { PID_CISCO_PVST
, "PVST" },
113 static const struct tok bridged_values
[] = {
114 { PID_RFC2684_ETH_FCS
, "Ethernet + FCS" },
115 { PID_RFC2684_ETH_NOFCS
, "Ethernet w/o FCS" },
116 { PID_RFC2684_802_4_FCS
, "802.4 + FCS" },
117 { PID_RFC2684_802_4_NOFCS
, "802.4 w/o FCS" },
118 { PID_RFC2684_802_5_FCS
, "Token Ring + FCS" },
119 { PID_RFC2684_802_5_NOFCS
, "Token Ring w/o FCS" },
120 { PID_RFC2684_FDDI_FCS
, "FDDI + FCS" },
121 { PID_RFC2684_FDDI_NOFCS
, "FDDI w/o FCS" },
122 { PID_RFC2684_802_6_FCS
, "802.6 + FCS" },
123 { PID_RFC2684_802_6_NOFCS
, "802.6 w/o FCS" },
124 { PID_RFC2684_BPDU
, "BPDU" },
128 static const struct tok null_values
[] = {
134 const struct tok
*tok
;
137 static const struct oui_tok oui_to_tok
[] = {
138 { OUI_ENCAP_ETHER
, ethertype_values
},
139 { OUI_CISCO_90
, ethertype_values
}, /* uses some Ethertype values */
140 { OUI_APPLETALK
, ethertype_values
}, /* uses some Ethertype values */
141 { OUI_CISCO
, cisco_values
},
142 { OUI_RFC2684
, bridged_values
}, /* bridged, RFC 2427 FR or RFC 2864 ATM */
147 * Returns non-zero IFF it succeeds in printing the header
150 llc_print(const u_char
*p
, u_int length
, u_int caplen
,
151 const u_char
*esrc
, const u_char
*edst
, u_short
*extracted_ethertype
)
153 u_int8_t dsap_field
, dsap
, ssap_field
, ssap
;
158 *extracted_ethertype
= 0;
161 (void)printf("[|llc]");
162 default_print((u_char
*)p
, caplen
);
167 ssap_field
= *(p
+ 1);
170 * OK, what type of LLC frame is this? The length
171 * of the control field depends on that - I frames
172 * have a two-byte control field, and U frames have
173 * a one-byte control field.
176 if ((control
& LLC_U_FMT
) == LLC_U_FMT
) {
183 * The control field in I and S frames is
187 (void)printf("[|llc]");
188 default_print((u_char
*)p
, caplen
);
193 * ...and is little-endian.
195 control
= EXTRACT_LE_16BITS(p
+ 2);
199 if (ssap_field
== LLCSAP_GLOBAL
&& dsap_field
== LLCSAP_GLOBAL
) {
201 * This is an Ethernet_802.3 IPX frame; it has an
202 * 802.3 header (i.e., an Ethernet header where the
203 * type/length field is <= ETHERMTU, i.e. it's a length
204 * field, not a type field), but has no 802.2 header -
205 * the IPX packet starts right after the Ethernet header,
206 * with a signature of two bytes of 0xFF (which is
209 * (It might also have been an Ethernet_802.3 IPX at
210 * one time, but got bridged onto another network,
211 * such as an 802.11 network; this has appeared in at
212 * least one capture file.)
216 printf("IPX 802.3: ");
218 ipx_print(p
, length
);
222 dsap
= dsap_field
& ~LLC_IG
;
223 ssap
= ssap_field
& ~LLC_GSAP
;
226 printf("LLC, dsap %s (0x%02x) %s, ssap %s (0x%02x) %s",
227 tok2str(llc_values
, "Unknown", dsap
),
229 tok2str(llc_ig_flag_values
, "Unknown", dsap_field
& LLC_IG
),
230 tok2str(llc_values
, "Unknown", ssap
),
232 tok2str(llc_flag_values
, "Unknown", ssap_field
& LLC_GSAP
));
235 printf(", ctrl 0x%02x: ", control
);
237 printf(", ctrl 0x%04x: ", control
);
241 if (ssap
== LLCSAP_8021D
&& dsap
== LLCSAP_8021D
&&
243 stp_print(p
+3, length
-3);
247 if (ssap
== LLCSAP_IP
&& dsap
== LLCSAP_IP
&&
249 ip_print(gndo
, p
+4, length
-4);
253 if (ssap
== LLCSAP_IPX
&& dsap
== LLCSAP_IPX
&&
256 * This is an Ethernet_802.2 IPX frame, with an 802.3
257 * header and an 802.2 LLC header with the source and
258 * destination SAPs being the IPX SAP.
260 * Skip DSAP, LSAP, and control field.
263 printf("IPX 802.2: ");
265 ipx_print(p
+3, length
-3);
269 #ifdef TCPDUMP_DO_SMB
270 if (ssap
== LLCSAP_NETBEUI
&& dsap
== LLCSAP_NETBEUI
271 && (!(control
& LLC_S_FMT
) || control
== LLC_U_FMT
)) {
273 * we don't actually have a full netbeui parser yet, but the
274 * smb parser can handle many smb-in-netbeui packets, which
275 * is very useful, so we call that
277 * We don't call it for S frames, however, just I frames
278 * (which are frames that don't have the low-order bit,
279 * LLC_S_FMT, set in the first byte of the control field)
280 * and UI frames (whose control field is just 3, LLC_U_FMT).
284 * Skip the LLC header.
295 netbeui_print(control
, p
, length
);
299 if (ssap
== LLCSAP_ISONS
&& dsap
== LLCSAP_ISONS
300 && control
== LLC_UI
) {
301 isoclns_print(p
+ 3, length
- 3, caplen
- 3);
305 if (ssap
== LLCSAP_SNAP
&& dsap
== LLCSAP_SNAP
306 && control
== LLC_UI
) {
308 * XXX - what *is* the right bridge pad value here?
309 * Does anybody ever bridge one form of LAN traffic
310 * over a networking type that uses 802.2 LLC?
312 ret
= snap_print(p
+3, length
-3, caplen
-3, 2);
319 if (esrc
== NULL
|| edst
== NULL
)
320 (void)printf("%s ", tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
322 (void)printf("%s > %s %s ",
323 etheraddr_string(esrc
),
324 etheraddr_string(edst
),
325 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
327 if (esrc
== NULL
|| edst
== NULL
)
328 (void)printf("%s > %s ",
329 tok2str(llc_values
, "Unknown SSAP 0x%02x", ssap
),
330 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
332 (void)printf("%s %s > %s %s ",
333 etheraddr_string(esrc
),
334 tok2str(llc_values
, "Unknown SSAP 0x%02x", ssap
),
335 etheraddr_string(edst
),
336 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
341 printf("Unnumbered, %s, Flags [%s], length %u",
342 tok2str(llc_cmd_values
, "%02x", LLC_U_CMD(control
)),
343 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_U_POLL
)),
350 if ((control
& ~LLC_U_POLL
) == LLC_XID
) {
351 if (*p
== LLC_XID_FI
) {
352 printf(": %02x %02x", p
[1], p
[2]);
359 if ((control
& LLC_S_FMT
) == LLC_S_FMT
) {
360 (void)printf("Supervisory, %s, rcv seq %u, Flags [%s], length %u",
361 tok2str(llc_supervisory_values
,"?",LLC_S_CMD(control
)),
363 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_IS_POLL
)),
366 (void)printf("Information, send seq %u, rcv seq %u, Flags [%s], length %u",
369 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_IS_POLL
)),
380 snap_print(const u_char
*p
, u_int length
, u_int caplen
, u_int bridge_pad
)
387 orgcode
= EXTRACT_24BITS(p
);
388 et
= EXTRACT_16BITS(p
+ 3);
391 const struct tok
*tok
= null_values
;
392 const struct oui_tok
*otp
;
394 for (otp
= &oui_to_tok
[0]; otp
->tok
!= NULL
; otp
++) {
395 if (otp
->oui
== orgcode
) {
400 (void)printf("oui %s (0x%06x), %s %s (0x%04x): ",
401 tok2str(oui_values
, "Unknown", orgcode
),
403 (orgcode
== 0x000000 ? "ethertype" : "pid"),
404 tok2str(tok
, "Unknown", et
),
412 case OUI_ENCAP_ETHER
:
415 * This is an encapsulated Ethernet packet,
416 * or a packet bridged by some piece of
417 * Cisco hardware; the protocol ID is
418 * an Ethernet protocol type.
420 ret
= ethertype_print(gndo
, et
, p
, length
, caplen
);
426 if (et
== ETHERTYPE_ATALK
) {
428 * No, I have no idea why Apple used one
429 * of their own OUIs, rather than
430 * 0x000000, and an Ethernet packet
431 * type, for Appletalk data packets,
432 * but used 0x000000 and an Ethernet
433 * packet type for AARP packets.
435 ret
= ethertype_print(gndo
, et
, p
, length
, caplen
);
444 cdp_print(p
, length
, caplen
);
447 dtp_print(p
, length
);
450 udld_print(p
, length
);
453 vtp_print(p
, length
);
456 stp_print(p
, length
);
465 case PID_RFC2684_ETH_FCS
:
466 case PID_RFC2684_ETH_NOFCS
:
468 * XXX - remove the last two bytes for
469 * PID_RFC2684_ETH_FCS?
474 TCHECK2(*p
, bridge_pad
);
475 caplen
-= bridge_pad
;
476 length
-= bridge_pad
;
480 * What remains is an Ethernet packet.
482 ether_print(gndo
, p
, length
, caplen
, NULL
, NULL
);
485 case PID_RFC2684_802_5_FCS
:
486 case PID_RFC2684_802_5_NOFCS
:
488 * XXX - remove the last two bytes for
489 * PID_RFC2684_ETH_FCS?
492 * Skip the padding, but not the Access
495 TCHECK2(*p
, bridge_pad
);
496 caplen
-= bridge_pad
;
497 length
-= bridge_pad
;
501 * What remains is an 802.5 Token Ring
504 token_print(p
, length
, caplen
);
507 case PID_RFC2684_FDDI_FCS
:
508 case PID_RFC2684_FDDI_NOFCS
:
510 * XXX - remove the last two bytes for
511 * PID_RFC2684_ETH_FCS?
516 TCHECK2(*p
, bridge_pad
+ 1);
517 caplen
-= bridge_pad
+ 1;
518 length
-= bridge_pad
+ 1;
522 * What remains is an FDDI packet.
524 fddi_print(p
, length
, caplen
);
527 case PID_RFC2684_BPDU
:
528 stp_print(p
, length
);
535 (void)printf("[|snap]");
542 * c-style: whitesmith