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
29 #include <tcpdump-stdinc.h>
31 #include "netdissect.h"
32 #include "addrtoname.h"
33 #include "extract.h" /* must come after interface.h */
36 #include "ethertype.h"
39 static const struct tok llc_values
[] = {
40 { LLCSAP_NULL
, "Null" },
41 { LLCSAP_GLOBAL
, "Global" },
42 { LLCSAP_8021B_I
, "802.1B I" },
43 { LLCSAP_8021B_G
, "802.1B G" },
45 { LLCSAP_SNA
, "SNA" },
46 { LLCSAP_PROWAYNM
, "ProWay NM" },
47 { LLCSAP_8021D
, "STP" },
48 { LLCSAP_RS511
, "RS511" },
49 { LLCSAP_ISO8208
, "ISO8208" },
50 { LLCSAP_PROWAY
, "ProWay" },
51 { LLCSAP_SNAP
, "SNAP" },
52 { LLCSAP_IPX
, "IPX" },
53 { LLCSAP_NETBEUI
, "NetBeui" },
54 { LLCSAP_ISONS
, "OSI" },
58 static const struct tok llc_cmd_values
[] = {
65 { LLC_SABME
, "sabme" },
70 static const struct tok llc_flag_values
[] = {
72 { LLC_GSAP
, "Response" },
73 { LLC_U_POLL
, "Poll" },
74 { LLC_GSAP
|LLC_U_POLL
, "Final" },
75 { LLC_IS_POLL
, "Poll" },
76 { LLC_GSAP
|LLC_IS_POLL
, "Final" },
81 static const struct tok llc_ig_flag_values
[] = {
88 static const struct tok llc_supervisory_values
[] = {
89 { 0, "Receiver Ready" },
90 { 1, "Receiver not Ready" },
96 static const struct tok cisco_values
[] = {
97 { PID_CISCO_CDP
, "CDP" },
98 { PID_CISCO_VTP
, "VTP" },
99 { PID_CISCO_DTP
, "DTP" },
100 { PID_CISCO_UDLD
, "UDLD" },
101 { PID_CISCO_PVST
, "PVST" },
102 { PID_CISCO_VLANBRIDGE
, "VLAN Bridge" },
106 static const struct tok bridged_values
[] = {
107 { PID_RFC2684_ETH_FCS
, "Ethernet + FCS" },
108 { PID_RFC2684_ETH_NOFCS
, "Ethernet w/o FCS" },
109 { PID_RFC2684_802_4_FCS
, "802.4 + FCS" },
110 { PID_RFC2684_802_4_NOFCS
, "802.4 w/o FCS" },
111 { PID_RFC2684_802_5_FCS
, "Token Ring + FCS" },
112 { PID_RFC2684_802_5_NOFCS
, "Token Ring w/o FCS" },
113 { PID_RFC2684_FDDI_FCS
, "FDDI + FCS" },
114 { PID_RFC2684_FDDI_NOFCS
, "FDDI w/o FCS" },
115 { PID_RFC2684_802_6_FCS
, "802.6 + FCS" },
116 { PID_RFC2684_802_6_NOFCS
, "802.6 w/o FCS" },
117 { PID_RFC2684_BPDU
, "BPDU" },
121 static const struct tok null_values
[] = {
127 const struct tok
*tok
;
130 static const struct oui_tok oui_to_tok
[] = {
131 { OUI_ENCAP_ETHER
, ethertype_values
},
132 { OUI_CISCO_90
, ethertype_values
}, /* uses some Ethertype values */
133 { OUI_APPLETALK
, ethertype_values
}, /* uses some Ethertype values */
134 { OUI_CISCO
, cisco_values
},
135 { OUI_RFC2684
, bridged_values
}, /* bridged, RFC 2427 FR or RFC 2864 ATM */
140 * If we printed information about the payload, returns the length of the LLC
141 * header, plus the length of any SNAP header following it.
143 * Otherwise (for example, if the packet has unknown SAPs or has a SNAP
144 * header with an unknown OUI/PID combination), returns the *negative*
148 llc_print(netdissect_options
*ndo
, const u_char
*p
, u_int length
, u_int caplen
,
149 const u_char
*esrc
, const u_char
*edst
)
151 uint8_t dsap_field
, dsap
, ssap_field
, ssap
;
157 ND_PRINT((ndo
, "[|llc]"));
158 ND_DEFAULTPRINT((const u_char
*)p
, caplen
);
162 ND_PRINT((ndo
, "[|llc]"));
163 ND_DEFAULTPRINT((const u_char
*)p
, caplen
);
168 ssap_field
= *(p
+ 1);
171 * OK, what type of LLC frame is this? The length
172 * of the control field depends on that - I frames
173 * have a two-byte control field, and U frames have
174 * a one-byte control field.
177 if ((control
& LLC_U_FMT
) == LLC_U_FMT
) {
182 hdrlen
= 3; /* DSAP, SSAP, 1-byte control field */
185 * The control field in I and S frames is
189 ND_PRINT((ndo
, "[|llc]"));
190 ND_DEFAULTPRINT((const u_char
*)p
, caplen
);
194 ND_PRINT((ndo
, "[|llc]"));
195 ND_DEFAULTPRINT((const u_char
*)p
, caplen
);
200 * ...and is little-endian.
202 control
= EXTRACT_LE_16BITS(p
+ 2);
204 hdrlen
= 4; /* DSAP, SSAP, 2-byte control field */
207 if (ssap_field
== LLCSAP_GLOBAL
&& dsap_field
== LLCSAP_GLOBAL
) {
209 * This is an Ethernet_802.3 IPX frame; it has an
210 * 802.3 header (i.e., an Ethernet header where the
211 * type/length field is <= ETHERMTU, i.e. it's a length
212 * field, not a type field), but has no 802.2 header -
213 * the IPX packet starts right after the Ethernet header,
214 * with a signature of two bytes of 0xFF (which is
217 * (It might also have been an Ethernet_802.3 IPX at
218 * one time, but got bridged onto another network,
219 * such as an 802.11 network; this has appeared in at
220 * least one capture file.)
224 ND_PRINT((ndo
, "IPX 802.3: "));
226 ipx_print(ndo
, p
, length
);
227 return (0); /* no LLC header */
230 dsap
= dsap_field
& ~LLC_IG
;
231 ssap
= ssap_field
& ~LLC_GSAP
;
233 if (ndo
->ndo_eflag
) {
234 ND_PRINT((ndo
, "LLC, dsap %s (0x%02x) %s, ssap %s (0x%02x) %s",
235 tok2str(llc_values
, "Unknown", dsap
),
237 tok2str(llc_ig_flag_values
, "Unknown", dsap_field
& LLC_IG
),
238 tok2str(llc_values
, "Unknown", ssap
),
240 tok2str(llc_flag_values
, "Unknown", ssap_field
& LLC_GSAP
)));
243 ND_PRINT((ndo
, ", ctrl 0x%02x: ", control
));
245 ND_PRINT((ndo
, ", ctrl 0x%04x: ", control
));
256 if (ssap
== LLCSAP_SNAP
&& dsap
== LLCSAP_SNAP
257 && control
== LLC_UI
) {
259 * XXX - what *is* the right bridge pad value here?
260 * Does anybody ever bridge one form of LAN traffic
261 * over a networking type that uses 802.2 LLC?
263 if (!snap_print(ndo
, p
, length
, caplen
, esrc
, edst
, 2)) {
265 * Unknown packet type; tell our caller, by
266 * returning a negative value, so they
267 * can print the raw packet.
269 return (-(hdrlen
+ 5)); /* include LLC and SNAP header */
271 return (hdrlen
+ 5); /* include LLC and SNAP header */
274 if (ssap
== LLCSAP_8021D
&& dsap
== LLCSAP_8021D
&&
276 stp_print(ndo
, p
, length
);
280 if (ssap
== LLCSAP_IP
&& dsap
== LLCSAP_IP
&&
283 * This is an RFC 948-style IP packet, with
284 * an 802.3 header and an 802.2 LLC header
285 * with the source and destination SAPs being
288 ip_print(ndo
, p
, length
);
292 if (ssap
== LLCSAP_IPX
&& dsap
== LLCSAP_IPX
&&
295 * This is an Ethernet_802.2 IPX frame, with an 802.3
296 * header and an 802.2 LLC header with the source and
297 * destination SAPs being the IPX SAP.
300 ND_PRINT((ndo
, "IPX 802.2: "));
302 ipx_print(ndo
, p
, length
);
306 #ifdef TCPDUMP_DO_SMB
307 if (ssap
== LLCSAP_NETBEUI
&& dsap
== LLCSAP_NETBEUI
308 && (!(control
& LLC_S_FMT
) || control
== LLC_U_FMT
)) {
310 * we don't actually have a full netbeui parser yet, but the
311 * smb parser can handle many smb-in-netbeui packets, which
312 * is very useful, so we call that
314 * We don't call it for S frames, however, just I frames
315 * (which are frames that don't have the low-order bit,
316 * LLC_S_FMT, set in the first byte of the control field)
317 * and UI frames (whose control field is just 3, LLC_U_FMT).
319 netbeui_print(ndo
, control
, p
, length
);
323 if (ssap
== LLCSAP_ISONS
&& dsap
== LLCSAP_ISONS
324 && control
== LLC_UI
) {
325 isoclns_print(ndo
, p
, length
, caplen
);
329 if (!ndo
->ndo_eflag
) {
331 if (esrc
== NULL
|| edst
== NULL
)
332 ND_PRINT((ndo
, "%s ", tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
)));
334 ND_PRINT((ndo
, "%s > %s %s ",
335 etheraddr_string(ndo
, esrc
),
336 etheraddr_string(ndo
, edst
),
337 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
)));
339 if (esrc
== NULL
|| edst
== NULL
)
340 ND_PRINT((ndo
, "%s > %s ",
341 tok2str(llc_values
, "Unknown SSAP 0x%02x", ssap
),
342 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
)));
344 ND_PRINT((ndo
, "%s %s > %s %s ",
345 etheraddr_string(ndo
, esrc
),
346 tok2str(llc_values
, "Unknown SSAP 0x%02x", ssap
),
347 etheraddr_string(ndo
, edst
),
348 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
)));
353 ND_PRINT((ndo
, "Unnumbered, %s, Flags [%s], length %u",
354 tok2str(llc_cmd_values
, "%02x", LLC_U_CMD(control
)),
355 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_U_POLL
)),
358 if ((control
& ~LLC_U_POLL
) == LLC_XID
) {
359 if (*p
== LLC_XID_FI
) {
360 ND_PRINT((ndo
, ": %02x %02x", p
[1], p
[2]));
365 if ((control
& LLC_S_FMT
) == LLC_S_FMT
) {
366 ND_PRINT((ndo
, "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
)),
371 return (hdrlen
); /* no payload to print */
373 ND_PRINT((ndo
, "Information, send seq %u, rcv seq %u, Flags [%s], length %u",
376 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_IS_POLL
)),
383 static const struct tok
*
384 oui_to_struct_tok(uint32_t orgcode
)
386 const struct tok
*tok
= null_values
;
387 const struct oui_tok
*otp
;
389 for (otp
= &oui_to_tok
[0]; otp
->tok
!= NULL
; otp
++) {
390 if (otp
->oui
== orgcode
) {
399 snap_print(netdissect_options
*ndo
, const u_char
*p
, u_int length
, u_int caplen
,
400 const u_char
*esrc
, const u_char
*edst
, u_int bridge_pad
)
407 if (caplen
< 5 || length
< 5)
409 orgcode
= EXTRACT_24BITS(p
);
410 et
= EXTRACT_16BITS(p
+ 3);
412 if (ndo
->ndo_eflag
) {
414 * Somebody's already printed the MAC addresses, if there
415 * are any, so just print the SNAP header, not the MAC
418 ND_PRINT((ndo
, "oui %s (0x%06x), %s %s (0x%04x), length %u: ",
419 tok2str(oui_values
, "Unknown", orgcode
),
421 (orgcode
== 0x000000 ? "ethertype" : "pid"),
422 tok2str(oui_to_struct_tok(orgcode
), "Unknown", et
),
430 case OUI_ENCAP_ETHER
:
433 * This is an encapsulated Ethernet packet,
434 * or a packet bridged by some piece of
435 * Cisco hardware; the protocol ID is
436 * an Ethernet protocol type.
438 ret
= ethertype_print(ndo
, et
, p
, length
, caplen
);
444 if (et
== ETHERTYPE_ATALK
) {
446 * No, I have no idea why Apple used one
447 * of their own OUIs, rather than
448 * 0x000000, and an Ethernet packet
449 * type, for Appletalk data packets,
450 * but used 0x000000 and an Ethernet
451 * packet type for AARP packets.
453 ret
= ethertype_print(ndo
, et
, p
, length
, caplen
);
462 cdp_print(ndo
, p
, length
, caplen
);
465 dtp_print(ndo
, p
, length
);
468 udld_print(ndo
, p
, length
);
471 vtp_print(ndo
, p
, length
);
474 case PID_CISCO_VLANBRIDGE
:
475 stp_print(ndo
, p
, length
);
485 case PID_RFC2684_ETH_FCS
:
486 case PID_RFC2684_ETH_NOFCS
:
488 * XXX - remove the last two bytes for
489 * PID_RFC2684_ETH_FCS?
494 ND_TCHECK2(*p
, bridge_pad
);
495 caplen
-= bridge_pad
;
496 length
-= bridge_pad
;
500 * What remains is an Ethernet packet.
502 ether_print(ndo
, p
, length
, caplen
, NULL
, NULL
);
505 case PID_RFC2684_802_5_FCS
:
506 case PID_RFC2684_802_5_NOFCS
:
508 * XXX - remove the last two bytes for
509 * PID_RFC2684_ETH_FCS?
512 * Skip the padding, but not the Access
515 ND_TCHECK2(*p
, bridge_pad
);
516 caplen
-= bridge_pad
;
517 length
-= bridge_pad
;
521 * What remains is an 802.5 Token Ring
524 token_print(ndo
, p
, length
, caplen
);
527 case PID_RFC2684_FDDI_FCS
:
528 case PID_RFC2684_FDDI_NOFCS
:
530 * XXX - remove the last two bytes for
531 * PID_RFC2684_ETH_FCS?
536 ND_TCHECK2(*p
, bridge_pad
+ 1);
537 caplen
-= bridge_pad
+ 1;
538 length
-= bridge_pad
+ 1;
542 * What remains is an FDDI packet.
544 fddi_print(ndo
, p
, length
, caplen
);
547 case PID_RFC2684_BPDU
:
548 stp_print(ndo
, p
, length
);
552 if (!ndo
->ndo_eflag
) {
554 * Nobody printed the MAC addresses, so print them, if
557 if (esrc
!= NULL
&& edst
!= NULL
) {
558 ND_PRINT((ndo
, "%s > %s ",
559 etheraddr_string(ndo
, esrc
),
560 etheraddr_string(ndo
, edst
)));
563 * Print the SNAP header, but if the OUI is 000000, don't
564 * bother printing it, and report the PID as being an
567 if (orgcode
== 0x000000) {
568 ND_PRINT((ndo
, "SNAP, ethertype %s (0x%04x), length %u: ",
569 tok2str(ethertype_values
, "Unknown", et
),
572 ND_PRINT((ndo
, "SNAP, oui %s (0x%06x), pid %s (0x%04x), length %u: ",
573 tok2str(oui_values
, "Unknown", orgcode
),
575 tok2str(oui_to_struct_tok(orgcode
), "Unknown", et
),
582 ND_PRINT((ndo
, "[|snap]"));
589 * c-style: whitesmith