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
28 static const char rcsid[] _U_ =
29 "@(#) $Header: /tcpdump/master/tcpdump/print-llc.c,v 1.75 2007-04-13 09:43:11 hannes Exp $";
36 #include <tcpdump-stdinc.h>
41 #include "interface.h"
42 #include "addrtoname.h"
43 #include "extract.h" /* must come after interface.h */
46 #include "ethertype.h"
49 static struct tok llc_values[] = {
50 { LLCSAP_NULL, "Null" },
51 { LLCSAP_GLOBAL, "Global" },
52 { LLCSAP_8021B_I, "802.1B I" },
53 { LLCSAP_8021B_G, "802.1B G" },
55 { LLCSAP_SNA, "SNA" },
56 { LLCSAP_PROWAYNM, "ProWay NM" },
57 { LLCSAP_8021D, "STP" },
58 { LLCSAP_RS511, "RS511" },
59 { LLCSAP_ISO8208, "ISO8208" },
60 { LLCSAP_PROWAY, "ProWay" },
61 { LLCSAP_SNAP, "SNAP" },
62 { LLCSAP_IPX, "IPX" },
63 { LLCSAP_NETBEUI, "NetBeui" },
64 { LLCSAP_ISONS, "OSI" },
68 static struct tok llc_cmd_values[] = {
75 { LLC_SABME, "sabme" },
80 static const struct tok llc_flag_values[] = {
82 { LLC_GSAP, "Response" },
83 { LLC_U_POLL, "Poll" },
84 { LLC_GSAP|LLC_U_POLL, "Final" },
85 { LLC_IS_POLL, "Poll" },
86 { LLC_GSAP|LLC_IS_POLL, "Final" },
91 static const struct tok llc_ig_flag_values[] = {
98 static const struct tok llc_supervisory_values[] = {
99 { 0, "Receiver Ready" },
100 { 1, "Receiver not Ready" },
106 static const struct tok cisco_values[] = {
107 { PID_CISCO_CDP, "CDP" },
108 { PID_CISCO_VTP, "VTP" },
109 { PID_CISCO_DTP, "DTP" },
110 { PID_CISCO_UDLD, "UDLD" },
111 { PID_CISCO_PVST, "PVST" },
115 static const struct tok bridged_values[] = {
116 { PID_RFC2684_ETH_FCS, "Ethernet + FCS" },
117 { PID_RFC2684_ETH_NOFCS, "Ethernet w/o FCS" },
118 { PID_RFC2684_802_4_FCS, "802.4 + FCS" },
119 { PID_RFC2684_802_4_NOFCS, "802.4 w/o FCS" },
120 { PID_RFC2684_802_5_FCS, "Token Ring + FCS" },
121 { PID_RFC2684_802_5_NOFCS, "Token Ring w/o FCS" },
122 { PID_RFC2684_FDDI_FCS, "FDDI + FCS" },
123 { PID_RFC2684_FDDI_NOFCS, "FDDI w/o FCS" },
124 { PID_RFC2684_802_6_FCS, "802.6 + FCS" },
125 { PID_RFC2684_802_6_NOFCS, "802.6 w/o FCS" },
126 { PID_RFC2684_BPDU, "BPDU" },
130 static const struct tok null_values[] = {
136 const struct tok *tok;
139 static const struct oui_tok oui_to_tok[] = {
140 { OUI_ENCAP_ETHER, ethertype_values },
141 { OUI_CISCO_90, ethertype_values }, /* uses some Ethertype values */
142 { OUI_APPLETALK, ethertype_values }, /* uses some Ethertype values */
143 { OUI_CISCO, cisco_values },
144 { OUI_RFC2684, bridged_values }, /* bridged, RFC 2427 FR or RFC 2864 ATM */
149 * Returns non-zero IFF it succeeds in printing the header
152 llc_print(const u_char *p, u_int length, u_int caplen,
153 const u_char *esrc, const u_char *edst, u_short *extracted_ethertype)
155 u_int8_t dsap_field, dsap, ssap_field, ssap;
160 *extracted_ethertype = 0;
163 (void)printf("[|llc]");
164 default_print((u_char *)p, caplen);
169 ssap_field = *(p + 1);
172 * OK, what type of LLC frame is this? The length
173 * of the control field depends on that - I frames
174 * have a two-byte control field, and U frames have
175 * a one-byte control field.
178 if ((control & LLC_U_FMT) == LLC_U_FMT) {
185 * The control field in I and S frames is
189 (void)printf("[|llc]");
190 default_print((u_char *)p, caplen);
195 * ...and is little-endian.
197 control = EXTRACT_LE_16BITS(p + 2);
201 if (ssap_field == LLCSAP_GLOBAL && dsap_field == LLCSAP_GLOBAL) {
203 * This is an Ethernet_802.3 IPX frame; it has an
204 * 802.3 header (i.e., an Ethernet header where the
205 * type/length field is <= ETHERMTU, i.e. it's a length
206 * field, not a type field), but has no 802.2 header -
207 * the IPX packet starts right after the Ethernet header,
208 * with a signature of two bytes of 0xFF (which is
211 * (It might also have been an Ethernet_802.3 IPX at
212 * one time, but got bridged onto another network,
213 * such as an 802.11 network; this has appeared in at
214 * least one capture file.)
218 printf("IPX 802.3: ");
220 ipx_print(p, length);
224 dsap = dsap_field & ~LLC_IG;
225 ssap = ssap_field & ~LLC_GSAP;
228 printf("LLC, dsap %s (0x%02x) %s, ssap %s (0x%02x) %s",
229 tok2str(llc_values, "Unknown", dsap),
231 tok2str(llc_ig_flag_values, "Unknown", dsap_field & LLC_IG),
232 tok2str(llc_values, "Unknown", ssap),
234 tok2str(llc_flag_values, "Unknown", ssap_field & LLC_GSAP));
237 printf(", ctrl 0x%02x: ", control);
239 printf(", ctrl 0x%04x: ", control);
243 if (ssap == LLCSAP_8021D && dsap == LLCSAP_8021D &&
245 stp_print(p+3, length-3);
249 if (ssap == LLCSAP_IP && dsap == LLCSAP_IP &&
251 ip_print(gndo, p+4, length-4);
255 if (ssap == LLCSAP_IPX && dsap == LLCSAP_IPX &&
258 * This is an Ethernet_802.2 IPX frame, with an 802.3
259 * header and an 802.2 LLC header with the source and
260 * destination SAPs being the IPX SAP.
262 * Skip DSAP, LSAP, and control field.
265 printf("IPX 802.2: ");
267 ipx_print(p+3, length-3);
271 #ifdef TCPDUMP_DO_SMB
272 if (ssap == LLCSAP_NETBEUI && dsap == LLCSAP_NETBEUI
273 && (!(control & LLC_S_FMT) || control == LLC_U_FMT)) {
275 * we don't actually have a full netbeui parser yet, but the
276 * smb parser can handle many smb-in-netbeui packets, which
277 * is very useful, so we call that
279 * We don't call it for S frames, however, just I frames
280 * (which are frames that don't have the low-order bit,
281 * LLC_S_FMT, set in the first byte of the control field)
282 * and UI frames (whose control field is just 3, LLC_U_FMT).
286 * Skip the LLC header.
297 netbeui_print(control, p, length);
301 if (ssap == LLCSAP_ISONS && dsap == LLCSAP_ISONS
302 && control == LLC_UI) {
303 isoclns_print(p + 3, length - 3, caplen - 3);
307 if (ssap == LLCSAP_SNAP && dsap == LLCSAP_SNAP
308 && control == LLC_UI) {
310 * XXX - what *is* the right bridge pad value here?
311 * Does anybody ever bridge one form of LAN traffic
312 * over a networking type that uses 802.2 LLC?
314 ret = snap_print(p+3, length-3, caplen-3, 2);
321 if (esrc == NULL || edst == NULL)
322 (void)printf("%s ", tok2str(llc_values, "Unknown DSAP 0x%02x", dsap));
324 (void)printf("%s > %s %s ",
325 etheraddr_string(esrc),
326 etheraddr_string(edst),
327 tok2str(llc_values, "Unknown DSAP 0x%02x", dsap));
329 if (esrc == NULL || edst == NULL)
330 (void)printf("%s > %s ",
331 tok2str(llc_values, "Unknown SSAP 0x%02x", ssap),
332 tok2str(llc_values, "Unknown DSAP 0x%02x", dsap));
334 (void)printf("%s %s > %s %s ",
335 etheraddr_string(esrc),
336 tok2str(llc_values, "Unknown SSAP 0x%02x", ssap),
337 etheraddr_string(edst),
338 tok2str(llc_values, "Unknown DSAP 0x%02x", dsap));
343 printf("Unnumbered, %s, Flags [%s], length %u",
344 tok2str(llc_cmd_values, "%02x", LLC_U_CMD(control)),
345 tok2str(llc_flag_values,"?",(ssap_field & LLC_GSAP) | (control & LLC_U_POLL)),
352 if ((control & ~LLC_U_POLL) == LLC_XID) {
353 if (*p == LLC_XID_FI) {
354 printf(": %02x %02x", p[1], p[2]);
361 if ((control & LLC_S_FMT) == LLC_S_FMT) {
362 (void)printf("Supervisory, %s, rcv seq %u, Flags [%s], length %u",
363 tok2str(llc_supervisory_values,"?",LLC_S_CMD(control)),
365 tok2str(llc_flag_values,"?",(ssap_field & LLC_GSAP) | (control & LLC_IS_POLL)),
368 (void)printf("Information, send seq %u, rcv seq %u, Flags [%s], length %u",
371 tok2str(llc_flag_values,"?",(ssap_field & LLC_GSAP) | (control & LLC_IS_POLL)),
382 snap_print(const u_char *p, u_int length, u_int caplen, u_int bridge_pad)
389 orgcode = EXTRACT_24BITS(p);
390 et = EXTRACT_16BITS(p + 3);
393 const struct tok *tok = null_values;
394 const struct oui_tok *otp;
396 for (otp = &oui_to_tok[0]; otp->tok != NULL; otp++) {
397 if (otp->oui == orgcode) {
402 (void)printf("oui %s (0x%06x), %s %s (0x%04x): ",
403 tok2str(oui_values, "Unknown", orgcode),
405 (orgcode == 0x000000 ? "ethertype" : "pid"),
406 tok2str(tok, "Unknown", et),
414 case OUI_ENCAP_ETHER:
417 * This is an encapsulated Ethernet packet,
418 * or a packet bridged by some piece of
419 * Cisco hardware; the protocol ID is
420 * an Ethernet protocol type.
422 ret = ethertype_print(et, p, length, caplen);
428 if (et == ETHERTYPE_ATALK) {
430 * No, I have no idea why Apple used one
431 * of their own OUIs, rather than
432 * 0x000000, and an Ethernet packet
433 * type, for Appletalk data packets,
434 * but used 0x000000 and an Ethernet
435 * packet type for AARP packets.
437 ret = ethertype_print(et, p, length, caplen);
446 cdp_print(p, length, caplen);
449 dtp_print(p, length);
452 udld_print(p, length);
455 vtp_print(p, length);
458 stp_print(p, length);
467 case PID_RFC2684_ETH_FCS:
468 case PID_RFC2684_ETH_NOFCS:
470 * XXX - remove the last two bytes for
471 * PID_RFC2684_ETH_FCS?
476 TCHECK2(*p, bridge_pad);
477 caplen -= bridge_pad;
478 length -= bridge_pad;
482 * What remains is an Ethernet packet.
484 ether_print(p, length, caplen, NULL, NULL);
487 case PID_RFC2684_802_5_FCS:
488 case PID_RFC2684_802_5_NOFCS:
490 * XXX - remove the last two bytes for
491 * PID_RFC2684_ETH_FCS?
494 * Skip the padding, but not the Access
497 TCHECK2(*p, bridge_pad);
498 caplen -= bridge_pad;
499 length -= bridge_pad;
503 * What remains is an 802.5 Token Ring
506 token_print(p, length, caplen);
509 case PID_RFC2684_FDDI_FCS:
510 case PID_RFC2684_FDDI_NOFCS:
512 * XXX - remove the last two bytes for
513 * PID_RFC2684_ETH_FCS?
518 TCHECK2(*p, bridge_pad + 1);
519 caplen -= bridge_pad + 1;
520 length -= bridge_pad + 1;
524 * What remains is an FDDI packet.
526 fddi_print(p, length, caplen);
529 case PID_RFC2684_BPDU:
530 stp_print(p, length);
537 (void)printf("[|snap]");
544 * c-style: whitesmith