4 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 * Code by Matt Thomas, Digital Equipment Corporation
24 * with an awful lot of hacking by Jeffrey Mogul, DECWRL
27 #include <sys/cdefs.h>
30 static const char rcsid
[] _U_
=
31 "@(#) Header: /tcpdump/master/tcpdump/print-llc.c,v 1.61.2.10 2007/02/08 07:07:51 guy Exp";
33 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
41 #include <tcpdump-stdinc.h>
46 #include "interface.h"
47 #include "addrtoname.h"
48 #include "extract.h" /* must come after interface.h */
51 #include "ethertype.h"
54 static struct tok llc_values
[] = {
55 { LLCSAP_NULL
, "Null" },
56 { LLCSAP_GLOBAL
, "Global" },
57 { LLCSAP_8021B_I
, "802.1B I" },
58 { LLCSAP_8021B_G
, "802.1B G" },
60 { LLCSAP_SNA
, "SNA" },
61 { LLCSAP_PROWAYNM
, "ProWay NM" },
62 { LLCSAP_8021D
, "STP" },
63 { LLCSAP_RS511
, "RS511" },
64 { LLCSAP_ISO8208
, "ISO8208" },
65 { LLCSAP_PROWAY
, "ProWay" },
66 { LLCSAP_SNAP
, "SNAP" },
67 { LLCSAP_IPX
, "IPX" },
68 { LLCSAP_NETBEUI
, "NetBeui" },
69 { LLCSAP_ISONS
, "OSI" },
73 static struct tok llc_cmd_values
[] = {
80 { LLC_SABME
, "sabme" },
85 static const struct tok llc_flag_values
[] = {
87 { LLC_GSAP
, "Response" },
88 { LLC_U_POLL
, "Poll" },
89 { LLC_GSAP
|LLC_U_POLL
, "Final" },
90 { LLC_IS_POLL
, "Poll" },
91 { LLC_GSAP
|LLC_IS_POLL
, "Final" },
96 static const struct tok llc_ig_flag_values
[] = {
103 static const struct tok llc_supervisory_values
[] = {
104 { 0, "Receiver Ready" },
105 { 1, "Receiver not Ready" },
111 static const struct tok cisco_values
[] = {
112 { PID_CISCO_CDP
, "CDP" },
113 { PID_CISCO_VTP
, "VTP" },
114 { PID_CISCO_DTP
, "DTP" },
118 static const struct tok bridged_values
[] = {
119 { PID_RFC2684_ETH_FCS
, "Ethernet + FCS" },
120 { PID_RFC2684_ETH_NOFCS
, "Ethernet w/o FCS" },
121 { PID_RFC2684_802_4_FCS
, "802.4 + FCS" },
122 { PID_RFC2684_802_4_NOFCS
, "802.4 w/o FCS" },
123 { PID_RFC2684_802_5_FCS
, "Token Ring + FCS" },
124 { PID_RFC2684_802_5_NOFCS
, "Token Ring w/o FCS" },
125 { PID_RFC2684_FDDI_FCS
, "FDDI + FCS" },
126 { PID_RFC2684_FDDI_NOFCS
, "FDDI w/o FCS" },
127 { PID_RFC2684_802_6_FCS
, "802.6 + FCS" },
128 { PID_RFC2684_802_6_NOFCS
, "802.6 w/o FCS" },
129 { PID_RFC2684_BPDU
, "BPDU" },
133 static const struct tok null_values
[] = {
139 const struct tok
*tok
;
142 static const struct oui_tok oui_to_tok
[] = {
143 { OUI_ENCAP_ETHER
, ethertype_values
},
144 { OUI_CISCO_90
, ethertype_values
}, /* uses some Ethertype values */
145 { OUI_APPLETALK
, ethertype_values
}, /* uses some Ethertype values */
146 { OUI_CISCO
, cisco_values
},
147 { OUI_RFC2684
, bridged_values
}, /* bridged, RFC 2427 FR or RFC 2864 ATM */
152 * Returns non-zero IFF it succeeds in printing the header
155 llc_print(const u_char
*p
, u_int length
, u_int caplen
,
156 const u_char
*esrc
, const u_char
*edst
, u_short
*extracted_ethertype
)
158 u_int8_t dsap_field
, dsap
, ssap_field
, ssap
;
163 *extracted_ethertype
= 0;
166 (void)printf("[|llc]");
167 default_print((u_char
*)p
, caplen
);
172 ssap_field
= *(p
+ 1);
175 * OK, what type of LLC frame is this? The length
176 * of the control field depends on that - I frames
177 * have a two-byte control field, and U frames have
178 * a one-byte control field.
181 if ((control
& LLC_U_FMT
) == LLC_U_FMT
) {
188 * The control field in I and S frames is
192 (void)printf("[|llc]");
193 default_print((u_char
*)p
, caplen
);
198 * ...and is little-endian.
200 control
= EXTRACT_LE_16BITS(p
+ 2);
204 if (ssap_field
== LLCSAP_GLOBAL
&& dsap_field
== LLCSAP_GLOBAL
) {
206 * This is an Ethernet_802.3 IPX frame; it has an
207 * 802.3 header (i.e., an Ethernet header where the
208 * type/length field is <= ETHERMTU, i.e. it's a length
209 * field, not a type field), but has no 802.2 header -
210 * the IPX packet starts right after the Ethernet header,
211 * with a signature of two bytes of 0xFF (which is
214 * (It might also have been an Ethernet_802.3 IPX at
215 * one time, but got bridged onto another network,
216 * such as an 802.11 network; this has appeared in at
217 * least one capture file.)
221 printf("IPX 802.3: ");
223 ipx_print(p
, length
);
227 dsap
= dsap_field
& ~LLC_IG
;
228 ssap
= ssap_field
& ~LLC_GSAP
;
231 printf("LLC, dsap %s (0x%02x) %s, ssap %s (0x%02x) %s",
232 tok2str(llc_values
, "Unknown", dsap
),
234 tok2str(llc_ig_flag_values
, "Unknown", dsap_field
& LLC_IG
),
235 tok2str(llc_values
, "Unknown", ssap
),
237 tok2str(llc_flag_values
, "Unknown", ssap_field
& LLC_GSAP
));
240 printf(", ctrl 0x%02x: ", control
);
242 printf(", ctrl 0x%04x: ", control
);
246 if (ssap
== LLCSAP_8021D
&& dsap
== LLCSAP_8021D
&&
248 stp_print(p
+3, length
-3);
252 if (ssap
== LLCSAP_IP
&& dsap
== LLCSAP_IP
&&
254 ip_print(gndo
, p
+4, length
-4);
258 if (ssap
== LLCSAP_IPX
&& dsap
== LLCSAP_IPX
&&
261 * This is an Ethernet_802.2 IPX frame, with an 802.3
262 * header and an 802.2 LLC header with the source and
263 * destination SAPs being the IPX SAP.
265 * Skip DSAP, LSAP, and control field.
268 printf("IPX 802.2: ");
270 ipx_print(p
+3, length
-3);
274 #ifdef TCPDUMP_DO_SMB
275 if (ssap
== LLCSAP_NETBEUI
&& dsap
== LLCSAP_NETBEUI
276 && (!(control
& LLC_S_FMT
) || control
== LLC_U_FMT
)) {
278 * we don't actually have a full netbeui parser yet, but the
279 * smb parser can handle many smb-in-netbeui packets, which
280 * is very useful, so we call that
282 * We don't call it for S frames, however, just I frames
283 * (which are frames that don't have the low-order bit,
284 * LLC_S_FMT, set in the first byte of the control field)
285 * and UI frames (whose control field is just 3, LLC_U_FMT).
289 * Skip the LLC header.
300 netbeui_print(control
, p
, length
);
304 if (ssap
== LLCSAP_ISONS
&& dsap
== LLCSAP_ISONS
305 && control
== LLC_UI
) {
306 isoclns_print(p
+ 3, length
- 3, caplen
- 3);
310 if (ssap
== LLCSAP_SNAP
&& dsap
== LLCSAP_SNAP
311 && control
== LLC_UI
) {
313 * XXX - what *is* the right bridge pad value here?
314 * Does anybody ever bridge one form of LAN traffic
315 * over a networking type that uses 802.2 LLC?
317 ret
= snap_print(p
+3, length
-3, caplen
-3, extracted_ethertype
,
325 if (esrc
== NULL
|| edst
== NULL
)
326 (void)printf("%s ", tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
328 (void)printf("%s > %s %s ",
329 etheraddr_string(esrc
),
330 etheraddr_string(edst
),
331 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
333 if (esrc
== NULL
|| edst
== NULL
)
334 (void)printf("%s > %s ",
335 tok2str(llc_values
, "Unknown SSAP 0x%02x", ssap
),
336 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
338 (void)printf("%s %s > %s %s ",
339 etheraddr_string(esrc
),
340 tok2str(llc_values
, "Unknown SSAP 0x%02x", ssap
),
341 etheraddr_string(edst
),
342 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
347 printf("Unnumbered, %s, Flags [%s], length %u",
348 tok2str(llc_cmd_values
, "%02x", LLC_U_CMD(control
)),
349 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_U_POLL
)),
356 if ((control
& ~LLC_U_POLL
) == LLC_XID
) {
357 if (*p
== LLC_XID_FI
) {
358 printf(": %02x %02x", p
[1], p
[2]);
365 if ((control
& LLC_S_FMT
) == LLC_S_FMT
) {
366 (void)printf("Supervisory, %s, rcv seq %u, Flags [%s], length %u",
367 tok2str(llc_supervisory_values
,"?",LLC_S_CMD(control
)),
369 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_IS_POLL
)),
372 (void)printf("Information, send seq %u, rcv seq %u, Flags [%s], length %u",
375 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_IS_POLL
)),
386 snap_print(const u_char
*p
, u_int length
, u_int caplen
,
387 u_short
*extracted_ethertype
, u_int bridge_pad
)
394 orgcode
= EXTRACT_24BITS(p
);
395 et
= EXTRACT_16BITS(p
+ 3);
398 const struct tok
*tok
= null_values
;
399 const struct oui_tok
*otp
;
401 for (otp
= &oui_to_tok
[0]; otp
->tok
!= NULL
; otp
++) {
402 if (otp
->oui
== orgcode
) {
407 (void)printf("oui %s (0x%06x), %s %s (0x%04x): ",
408 tok2str(oui_values
, "Unknown", orgcode
),
410 (orgcode
== 0x000000 ? "ethertype" : "pid"),
411 tok2str(tok
, "Unknown", et
),
419 case OUI_ENCAP_ETHER
:
422 * This is an encapsulated Ethernet packet,
423 * or a packet bridged by some piece of
424 * Cisco hardware; the protocol ID is
425 * an Ethernet protocol type.
427 ret
= ether_encap_print(et
, p
, length
, caplen
,
428 extracted_ethertype
);
434 if (et
== ETHERTYPE_ATALK
) {
436 * No, I have no idea why Apple used one
437 * of their own OUIs, rather than
438 * 0x000000, and an Ethernet packet
439 * type, for Appletalk data packets,
440 * but used 0x000000 and an Ethernet
441 * packet type for AARP packets.
443 ret
= ether_encap_print(et
, p
, length
, caplen
,
444 extracted_ethertype
);
451 if (et
== PID_CISCO_CDP
) {
452 cdp_print(p
, length
, caplen
);
460 case PID_RFC2684_ETH_FCS
:
461 case PID_RFC2684_ETH_NOFCS
:
463 * XXX - remove the last two bytes for
464 * PID_RFC2684_ETH_FCS?
469 TCHECK2(*p
, bridge_pad
);
470 caplen
-= bridge_pad
;
471 length
-= bridge_pad
;
475 * What remains is an Ethernet packet.
477 ether_print(p
, length
, caplen
);
480 case PID_RFC2684_802_5_FCS
:
481 case PID_RFC2684_802_5_NOFCS
:
483 * XXX - remove the last two bytes for
484 * PID_RFC2684_ETH_FCS?
487 * Skip the padding, but not the Access
490 TCHECK2(*p
, bridge_pad
);
491 caplen
-= bridge_pad
;
492 length
-= bridge_pad
;
496 * What remains is an 802.5 Token Ring
499 token_print(p
, length
, caplen
);
502 case PID_RFC2684_FDDI_FCS
:
503 case PID_RFC2684_FDDI_NOFCS
:
505 * XXX - remove the last two bytes for
506 * PID_RFC2684_ETH_FCS?
511 TCHECK2(*p
, bridge_pad
+ 1);
512 caplen
-= bridge_pad
+ 1;
513 length
-= bridge_pad
+ 1;
517 * What remains is an FDDI packet.
519 fddi_print(p
, length
, caplen
);
522 case PID_RFC2684_BPDU
:
523 stp_print(p
, length
);
530 (void)printf("[|snap]");
537 * c-style: whitesmith