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 #include <sys/cdefs.h>
27 __RCSID("$NetBSD: print-llc.c,v 1.6 2015/03/31 21:59:35 christos Exp $");
30 #define NETDISSECT_REWORKED
35 #include <tcpdump-stdinc.h>
37 #include "interface.h"
38 #include "addrtoname.h"
39 #include "extract.h" /* must come after interface.h */
42 #include "ethertype.h"
45 static const struct tok llc_values
[] = {
46 { LLCSAP_NULL
, "Null" },
47 { LLCSAP_GLOBAL
, "Global" },
48 { LLCSAP_8021B_I
, "802.1B I" },
49 { LLCSAP_8021B_G
, "802.1B G" },
51 { LLCSAP_SNA
, "SNA" },
52 { LLCSAP_PROWAYNM
, "ProWay NM" },
53 { LLCSAP_8021D
, "STP" },
54 { LLCSAP_RS511
, "RS511" },
55 { LLCSAP_ISO8208
, "ISO8208" },
56 { LLCSAP_PROWAY
, "ProWay" },
57 { LLCSAP_SNAP
, "SNAP" },
58 { LLCSAP_IPX
, "IPX" },
59 { LLCSAP_NETBEUI
, "NetBeui" },
60 { LLCSAP_ISONS
, "OSI" },
64 static const struct tok llc_cmd_values
[] = {
71 { LLC_SABME
, "sabme" },
76 static const struct tok llc_flag_values
[] = {
78 { LLC_GSAP
, "Response" },
79 { LLC_U_POLL
, "Poll" },
80 { LLC_GSAP
|LLC_U_POLL
, "Final" },
81 { LLC_IS_POLL
, "Poll" },
82 { LLC_GSAP
|LLC_IS_POLL
, "Final" },
87 static const struct tok llc_ig_flag_values
[] = {
94 static const struct tok llc_supervisory_values
[] = {
95 { 0, "Receiver Ready" },
96 { 1, "Receiver not Ready" },
102 static const struct tok cisco_values
[] = {
103 { PID_CISCO_CDP
, "CDP" },
104 { PID_CISCO_VTP
, "VTP" },
105 { PID_CISCO_DTP
, "DTP" },
106 { PID_CISCO_UDLD
, "UDLD" },
107 { PID_CISCO_PVST
, "PVST" },
108 { PID_CISCO_VLANBRIDGE
, "VLAN Bridge" },
112 static const struct tok bridged_values
[] = {
113 { PID_RFC2684_ETH_FCS
, "Ethernet + FCS" },
114 { PID_RFC2684_ETH_NOFCS
, "Ethernet w/o FCS" },
115 { PID_RFC2684_802_4_FCS
, "802.4 + FCS" },
116 { PID_RFC2684_802_4_NOFCS
, "802.4 w/o FCS" },
117 { PID_RFC2684_802_5_FCS
, "Token Ring + FCS" },
118 { PID_RFC2684_802_5_NOFCS
, "Token Ring w/o FCS" },
119 { PID_RFC2684_FDDI_FCS
, "FDDI + FCS" },
120 { PID_RFC2684_FDDI_NOFCS
, "FDDI w/o FCS" },
121 { PID_RFC2684_802_6_FCS
, "802.6 + FCS" },
122 { PID_RFC2684_802_6_NOFCS
, "802.6 w/o FCS" },
123 { PID_RFC2684_BPDU
, "BPDU" },
127 static const struct tok null_values
[] = {
133 const struct tok
*tok
;
136 static const struct oui_tok oui_to_tok
[] = {
137 { OUI_ENCAP_ETHER
, ethertype_values
},
138 { OUI_CISCO_90
, ethertype_values
}, /* uses some Ethertype values */
139 { OUI_APPLETALK
, ethertype_values
}, /* uses some Ethertype values */
140 { OUI_CISCO
, cisco_values
},
141 { OUI_RFC2684
, bridged_values
}, /* bridged, RFC 2427 FR or RFC 2864 ATM */
146 * Returns non-zero IFF it succeeds in printing the header
149 llc_print(netdissect_options
*ndo
, const u_char
*p
, u_int length
, u_int caplen
,
150 const u_char
*esrc
, const u_char
*edst
, u_short
*extracted_ethertype
)
152 uint8_t dsap_field
, dsap
, ssap_field
, ssap
;
157 *extracted_ethertype
= 0;
159 if (caplen
< 3 || length
< 3) {
160 ND_PRINT((ndo
, "[|llc]"));
161 ND_DEFAULTPRINT((u_char
*)p
, caplen
);
166 ssap_field
= *(p
+ 1);
169 * OK, what type of LLC frame is this? The length
170 * of the control field depends on that - I frames
171 * have a two-byte control field, and U frames have
172 * a one-byte control field.
175 if ((control
& LLC_U_FMT
) == LLC_U_FMT
) {
182 * The control field in I and S frames is
185 if (caplen
< 4 || length
< 4) {
186 ND_PRINT((ndo
, "[|llc]"));
187 ND_DEFAULTPRINT((u_char
*)p
, caplen
);
192 * ...and is little-endian.
194 control
= EXTRACT_LE_16BITS(p
+ 2);
198 if (ssap_field
== LLCSAP_GLOBAL
&& dsap_field
== LLCSAP_GLOBAL
) {
200 * This is an Ethernet_802.3 IPX frame; it has an
201 * 802.3 header (i.e., an Ethernet header where the
202 * type/length field is <= ETHERMTU, i.e. it's a length
203 * field, not a type field), but has no 802.2 header -
204 * the IPX packet starts right after the Ethernet header,
205 * with a signature of two bytes of 0xFF (which is
208 * (It might also have been an Ethernet_802.3 IPX at
209 * one time, but got bridged onto another network,
210 * such as an 802.11 network; this has appeared in at
211 * least one capture file.)
215 ND_PRINT((ndo
, "IPX 802.3: "));
217 ipx_print(ndo
, p
, length
);
221 dsap
= dsap_field
& ~LLC_IG
;
222 ssap
= ssap_field
& ~LLC_GSAP
;
224 if (ndo
->ndo_eflag
) {
225 ND_PRINT((ndo
, "LLC, dsap %s (0x%02x) %s, ssap %s (0x%02x) %s",
226 tok2str(llc_values
, "Unknown", dsap
),
228 tok2str(llc_ig_flag_values
, "Unknown", dsap_field
& LLC_IG
),
229 tok2str(llc_values
, "Unknown", ssap
),
231 tok2str(llc_flag_values
, "Unknown", ssap_field
& LLC_GSAP
)));
234 ND_PRINT((ndo
, ", ctrl 0x%02x: ", control
));
236 ND_PRINT((ndo
, ", ctrl 0x%04x: ", control
));
240 if (ssap
== LLCSAP_8021D
&& dsap
== LLCSAP_8021D
&&
242 stp_print(ndo
, p
+3, length
-3);
246 if (ssap
== LLCSAP_IP
&& dsap
== LLCSAP_IP
&&
248 if (caplen
< 4 || length
< 4) {
249 ND_PRINT((ndo
, "[|llc]"));
250 ND_DEFAULTPRINT((u_char
*)p
, caplen
);
253 ip_print(ndo
, p
+4, length
-4);
257 if (ssap
== LLCSAP_IPX
&& dsap
== LLCSAP_IPX
&&
260 * This is an Ethernet_802.2 IPX frame, with an 802.3
261 * header and an 802.2 LLC header with the source and
262 * destination SAPs being the IPX SAP.
264 * Skip DSAP, LSAP, and control field.
267 ND_PRINT((ndo
, "IPX 802.2: "));
269 ipx_print(ndo
, p
+3, length
-3);
273 #ifdef TCPDUMP_DO_SMB
274 if (ssap
== LLCSAP_NETBEUI
&& dsap
== LLCSAP_NETBEUI
275 && (!(control
& LLC_S_FMT
) || control
== LLC_U_FMT
)) {
277 * we don't actually have a full netbeui parser yet, but the
278 * smb parser can handle many smb-in-netbeui packets, which
279 * is very useful, so we call that
281 * We don't call it for S frames, however, just I frames
282 * (which are frames that don't have the low-order bit,
283 * LLC_S_FMT, set in the first byte of the control field)
284 * and UI frames (whose control field is just 3, LLC_U_FMT).
288 * Skip the LLC header.
297 netbeui_print(ndo
, control
, p
, length
);
301 if (ssap
== LLCSAP_ISONS
&& dsap
== LLCSAP_ISONS
302 && control
== LLC_UI
) {
303 isoclns_print(ndo
, 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(ndo
, p
+3, length
-3, caplen
-3, 2);
319 if (!ndo
->ndo_eflag
) {
321 if (esrc
== NULL
|| edst
== NULL
)
322 ND_PRINT((ndo
, "%s ", tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
)));
324 ND_PRINT((ndo
, "%s > %s %s ",
325 etheraddr_string(ndo
, esrc
),
326 etheraddr_string(ndo
, edst
),
327 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
)));
329 if (esrc
== NULL
|| edst
== NULL
)
330 ND_PRINT((ndo
, "%s > %s ",
331 tok2str(llc_values
, "Unknown SSAP 0x%02x", ssap
),
332 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
)));
334 ND_PRINT((ndo
, "%s %s > %s %s ",
335 etheraddr_string(ndo
, esrc
),
336 tok2str(llc_values
, "Unknown SSAP 0x%02x", ssap
),
337 etheraddr_string(ndo
, edst
),
338 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
)));
343 ND_PRINT((ndo
, "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
)),
350 if ((control
& ~LLC_U_POLL
) == LLC_XID
) {
351 if (*p
== LLC_XID_FI
) {
352 ND_PRINT((ndo
, ": %02x %02x", p
[1], p
[2]));
356 if ((control
& LLC_S_FMT
) == LLC_S_FMT
) {
357 ND_PRINT((ndo
, "Supervisory, %s, rcv seq %u, Flags [%s], length %u",
358 tok2str(llc_supervisory_values
,"?",LLC_S_CMD(control
)),
360 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_IS_POLL
)),
363 ND_PRINT((ndo
, "Information, send seq %u, rcv seq %u, Flags [%s], length %u",
366 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_IS_POLL
)),
374 snap_print(netdissect_options
*ndo
, const u_char
*p
, u_int length
, u_int caplen
, u_int bridge_pad
)
381 if (caplen
< 5 || length
< 5)
383 orgcode
= EXTRACT_24BITS(p
);
384 et
= EXTRACT_16BITS(p
+ 3);
386 if (ndo
->ndo_eflag
) {
387 const struct tok
*tok
= null_values
;
388 const struct oui_tok
*otp
;
390 for (otp
= &oui_to_tok
[0]; otp
->tok
!= NULL
; otp
++) {
391 if (otp
->oui
== orgcode
) {
396 ND_PRINT((ndo
, "oui %s (0x%06x), %s %s (0x%04x): ",
397 tok2str(oui_values
, "Unknown", orgcode
),
399 (orgcode
== 0x000000 ? "ethertype" : "pid"),
400 tok2str(tok
, "Unknown", et
),
408 case OUI_ENCAP_ETHER
:
411 * This is an encapsulated Ethernet packet,
412 * or a packet bridged by some piece of
413 * Cisco hardware; the protocol ID is
414 * an Ethernet protocol type.
416 ret
= ethertype_print(ndo
, et
, p
, length
, caplen
);
422 if (et
== ETHERTYPE_ATALK
) {
424 * No, I have no idea why Apple used one
425 * of their own OUIs, rather than
426 * 0x000000, and an Ethernet packet
427 * type, for Appletalk data packets,
428 * but used 0x000000 and an Ethernet
429 * packet type for AARP packets.
431 ret
= ethertype_print(ndo
, et
, p
, length
, caplen
);
440 cdp_print(ndo
, p
, length
, caplen
);
443 dtp_print(ndo
, p
, length
);
446 udld_print(ndo
, p
, length
);
449 vtp_print(ndo
, p
, length
);
452 case PID_CISCO_VLANBRIDGE
:
453 stp_print(ndo
, p
, length
);
463 case PID_RFC2684_ETH_FCS
:
464 case PID_RFC2684_ETH_NOFCS
:
466 * XXX - remove the last two bytes for
467 * PID_RFC2684_ETH_FCS?
472 ND_TCHECK2(*p
, bridge_pad
);
473 caplen
-= bridge_pad
;
474 length
-= bridge_pad
;
478 * What remains is an Ethernet packet.
480 ether_print(ndo
, p
, length
, caplen
, NULL
, NULL
);
483 case PID_RFC2684_802_5_FCS
:
484 case PID_RFC2684_802_5_NOFCS
:
486 * XXX - remove the last two bytes for
487 * PID_RFC2684_ETH_FCS?
490 * Skip the padding, but not the Access
493 ND_TCHECK2(*p
, bridge_pad
);
494 caplen
-= bridge_pad
;
495 length
-= bridge_pad
;
499 * What remains is an 802.5 Token Ring
502 token_print(ndo
, p
, length
, caplen
);
505 case PID_RFC2684_FDDI_FCS
:
506 case PID_RFC2684_FDDI_NOFCS
:
508 * XXX - remove the last two bytes for
509 * PID_RFC2684_ETH_FCS?
514 ND_TCHECK2(*p
, bridge_pad
+ 1);
515 caplen
-= bridge_pad
+ 1;
516 length
-= bridge_pad
+ 1;
520 * What remains is an FDDI packet.
522 fddi_print(ndo
, p
, length
, caplen
);
525 case PID_RFC2684_BPDU
:
526 stp_print(ndo
, p
, length
);
533 ND_PRINT((ndo
, "[|snap]"));
540 * c-style: whitesmith