xref: /dflybsd-src/contrib/tcpdump/print-llc.c (revision 59c07fbdf8168fa08c76c515186d561b5a92690c)
141c99275SPeter Avalos /*
241c99275SPeter Avalos  * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
341c99275SPeter Avalos  *	The Regents of the University of California.  All rights reserved.
441c99275SPeter Avalos  *
541c99275SPeter Avalos  * Redistribution and use in source and binary forms, with or without
641c99275SPeter Avalos  * modification, are permitted provided that: (1) source code distributions
741c99275SPeter Avalos  * retain the above copyright notice and this paragraph in its entirety, (2)
841c99275SPeter Avalos  * distributions including binary code include the above copyright notice and
941c99275SPeter Avalos  * this paragraph in its entirety in the documentation or other materials
1041c99275SPeter Avalos  * provided with the distribution, and (3) all advertising materials mentioning
1141c99275SPeter Avalos  * features or use of this software display the following acknowledgement:
1241c99275SPeter Avalos  * ``This product includes software developed by the University of California,
1341c99275SPeter Avalos  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1441c99275SPeter Avalos  * the University nor the names of its contributors may be used to endorse
1541c99275SPeter Avalos  * or promote products derived from this software without specific prior
1641c99275SPeter Avalos  * written permission.
1741c99275SPeter Avalos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1841c99275SPeter Avalos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1941c99275SPeter Avalos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2041c99275SPeter Avalos  *
2141c99275SPeter Avalos  * Code by Matt Thomas, Digital Equipment Corporation
2241c99275SPeter Avalos  *	with an awful lot of hacking by Jeffrey Mogul, DECWRL
2341c99275SPeter Avalos  */
2441c99275SPeter Avalos 
25411677aeSAaron LI /* \summary: IEEE 802.2 LLC printer */
2641c99275SPeter Avalos 
2741c99275SPeter Avalos #ifdef HAVE_CONFIG_H
28*ed775ee7SAntonio Huete Jimenez #include <config.h>
2941c99275SPeter Avalos #endif
3041c99275SPeter Avalos 
31*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
3241c99275SPeter Avalos 
33411677aeSAaron LI #include "netdissect.h"
3441c99275SPeter Avalos #include "addrtoname.h"
35411677aeSAaron LI #include "extract.h"
3641c99275SPeter Avalos 
3741c99275SPeter Avalos #include "llc.h"
3841c99275SPeter Avalos #include "ethertype.h"
3941c99275SPeter Avalos #include "oui.h"
4041c99275SPeter Avalos 
41411677aeSAaron LI static const struct tok llc_values[] = {
4241c99275SPeter Avalos         { LLCSAP_NULL,     "Null" },
4341c99275SPeter Avalos         { LLCSAP_GLOBAL,   "Global" },
4441c99275SPeter Avalos         { LLCSAP_8021B_I,  "802.1B I" },
4541c99275SPeter Avalos         { LLCSAP_8021B_G,  "802.1B G" },
4641c99275SPeter Avalos         { LLCSAP_IP,       "IP" },
4741c99275SPeter Avalos         { LLCSAP_SNA,      "SNA" },
4841c99275SPeter Avalos         { LLCSAP_PROWAYNM, "ProWay NM" },
4941c99275SPeter Avalos         { LLCSAP_8021D,    "STP" },
5041c99275SPeter Avalos         { LLCSAP_RS511,    "RS511" },
5141c99275SPeter Avalos         { LLCSAP_ISO8208,  "ISO8208" },
5241c99275SPeter Avalos         { LLCSAP_PROWAY,   "ProWay" },
5341c99275SPeter Avalos         { LLCSAP_SNAP,     "SNAP" },
5441c99275SPeter Avalos         { LLCSAP_IPX,      "IPX" },
5541c99275SPeter Avalos         { LLCSAP_NETBEUI,  "NetBeui" },
5641c99275SPeter Avalos         { LLCSAP_ISONS,    "OSI" },
5741c99275SPeter Avalos         { 0,               NULL },
5841c99275SPeter Avalos };
5941c99275SPeter Avalos 
60411677aeSAaron LI static const struct tok llc_cmd_values[] = {
6141c99275SPeter Avalos 	{ LLC_UI,	"ui" },
6241c99275SPeter Avalos 	{ LLC_TEST,	"test" },
6341c99275SPeter Avalos 	{ LLC_XID,	"xid" },
6441c99275SPeter Avalos 	{ LLC_UA,	"ua" },
6541c99275SPeter Avalos 	{ LLC_DISC,	"disc" },
6641c99275SPeter Avalos 	{ LLC_DM,	"dm" },
6741c99275SPeter Avalos 	{ LLC_SABME,	"sabme" },
6841c99275SPeter Avalos 	{ LLC_FRMR,	"frmr" },
6941c99275SPeter Avalos 	{ 0,		NULL }
7041c99275SPeter Avalos };
7141c99275SPeter Avalos 
7241c99275SPeter Avalos static const struct tok llc_flag_values[] = {
7341c99275SPeter Avalos         { 0, "Command" },
7441c99275SPeter Avalos         { LLC_GSAP, "Response" },
7541c99275SPeter Avalos         { LLC_U_POLL, "Poll" },
7641c99275SPeter Avalos         { LLC_GSAP|LLC_U_POLL, "Final" },
7741c99275SPeter Avalos         { LLC_IS_POLL, "Poll" },
7841c99275SPeter Avalos         { LLC_GSAP|LLC_IS_POLL, "Final" },
7941c99275SPeter Avalos 	{ 0, NULL }
8041c99275SPeter Avalos };
8141c99275SPeter Avalos 
8241c99275SPeter Avalos 
8341c99275SPeter Avalos static const struct tok llc_ig_flag_values[] = {
8441c99275SPeter Avalos         { 0, "Individual" },
8541c99275SPeter Avalos         { LLC_IG, "Group" },
8641c99275SPeter Avalos 	{ 0, NULL }
8741c99275SPeter Avalos };
8841c99275SPeter Avalos 
8941c99275SPeter Avalos 
9041c99275SPeter Avalos static const struct tok llc_supervisory_values[] = {
9141c99275SPeter Avalos         { 0, "Receiver Ready" },
9241c99275SPeter Avalos         { 1, "Receiver not Ready" },
9341c99275SPeter Avalos         { 2, "Reject" },
9441c99275SPeter Avalos 	{ 0,             NULL }
9541c99275SPeter Avalos };
9641c99275SPeter Avalos 
9741c99275SPeter Avalos 
9841c99275SPeter Avalos static const struct tok cisco_values[] = {
9941c99275SPeter Avalos 	{ PID_CISCO_CDP, "CDP" },
10041c99275SPeter Avalos 	{ PID_CISCO_VTP, "VTP" },
10141c99275SPeter Avalos 	{ PID_CISCO_DTP, "DTP" },
102ea7b4bf5SPeter Avalos 	{ PID_CISCO_UDLD, "UDLD" },
103ea7b4bf5SPeter Avalos 	{ PID_CISCO_PVST, "PVST" },
104411677aeSAaron LI 	{ PID_CISCO_VLANBRIDGE, "VLAN Bridge" },
10541c99275SPeter Avalos 	{ 0,             NULL }
10641c99275SPeter Avalos };
10741c99275SPeter Avalos 
10841c99275SPeter Avalos static const struct tok bridged_values[] = {
10941c99275SPeter Avalos 	{ PID_RFC2684_ETH_FCS,     "Ethernet + FCS" },
11041c99275SPeter Avalos 	{ PID_RFC2684_ETH_NOFCS,   "Ethernet w/o FCS" },
11141c99275SPeter Avalos 	{ PID_RFC2684_802_4_FCS,   "802.4 + FCS" },
11241c99275SPeter Avalos 	{ PID_RFC2684_802_4_NOFCS, "802.4 w/o FCS" },
11341c99275SPeter Avalos 	{ PID_RFC2684_802_5_FCS,   "Token Ring + FCS" },
11441c99275SPeter Avalos 	{ PID_RFC2684_802_5_NOFCS, "Token Ring w/o FCS" },
11541c99275SPeter Avalos 	{ PID_RFC2684_FDDI_FCS,    "FDDI + FCS" },
11641c99275SPeter Avalos 	{ PID_RFC2684_FDDI_NOFCS,  "FDDI w/o FCS" },
11741c99275SPeter Avalos 	{ PID_RFC2684_802_6_FCS,   "802.6 + FCS" },
11841c99275SPeter Avalos 	{ PID_RFC2684_802_6_NOFCS, "802.6 w/o FCS" },
11941c99275SPeter Avalos 	{ PID_RFC2684_BPDU,        "BPDU" },
12041c99275SPeter Avalos 	{ 0,                       NULL },
12141c99275SPeter Avalos };
12241c99275SPeter Avalos 
12341c99275SPeter Avalos static const struct tok null_values[] = {
12441c99275SPeter Avalos 	{ 0,             NULL }
12541c99275SPeter Avalos };
12641c99275SPeter Avalos 
12741c99275SPeter Avalos struct oui_tok {
128411677aeSAaron LI 	uint32_t	oui;
12941c99275SPeter Avalos 	const struct tok *tok;
13041c99275SPeter Avalos };
13141c99275SPeter Avalos 
13241c99275SPeter Avalos static const struct oui_tok oui_to_tok[] = {
13341c99275SPeter Avalos 	{ OUI_ENCAP_ETHER, ethertype_values },
13441c99275SPeter Avalos 	{ OUI_CISCO_90, ethertype_values },	/* uses some Ethertype values */
13541c99275SPeter Avalos 	{ OUI_APPLETALK, ethertype_values },	/* uses some Ethertype values */
13641c99275SPeter Avalos 	{ OUI_CISCO, cisco_values },
13741c99275SPeter Avalos 	{ OUI_RFC2684, bridged_values },	/* bridged, RFC 2427 FR or RFC 2864 ATM */
13841c99275SPeter Avalos 	{ 0, NULL }
13941c99275SPeter Avalos };
14041c99275SPeter Avalos 
14141c99275SPeter Avalos /*
142411677aeSAaron LI  * If we printed information about the payload, returns the length of the LLC
143411677aeSAaron LI  * header, plus the length of any SNAP header following it.
144411677aeSAaron LI  *
145411677aeSAaron LI  * Otherwise (for example, if the packet has unknown SAPs or has a SNAP
146411677aeSAaron LI  * header with an unknown OUI/PID combination), returns the *negative*
147411677aeSAaron LI  * of that value.
14841c99275SPeter Avalos  */
14941c99275SPeter Avalos int
llc_print(netdissect_options * ndo,const u_char * p,u_int length,u_int caplen,const struct lladdr_info * src,const struct lladdr_info * dst)150411677aeSAaron LI llc_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
151411677aeSAaron LI 	  const struct lladdr_info *src, const struct lladdr_info *dst)
15241c99275SPeter Avalos {
153411677aeSAaron LI 	uint8_t dsap_field, dsap, ssap_field, ssap;
154411677aeSAaron LI 	uint16_t control;
155411677aeSAaron LI 	int hdrlen;
15641c99275SPeter Avalos 	int is_u;
15741c99275SPeter Avalos 
158*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "llc";
15941c99275SPeter Avalos 	if (caplen < 3) {
160*ed775ee7SAntonio Huete Jimenez 		nd_print_trunc(ndo);
161411677aeSAaron LI 		ND_DEFAULTPRINT((const u_char *)p, caplen);
162411677aeSAaron LI 		return (caplen);
163411677aeSAaron LI 	}
164411677aeSAaron LI 	if (length < 3) {
165*ed775ee7SAntonio Huete Jimenez 		nd_print_trunc(ndo);
166411677aeSAaron LI 		ND_DEFAULTPRINT((const u_char *)p, caplen);
167411677aeSAaron LI 		return (length);
16841c99275SPeter Avalos 	}
16941c99275SPeter Avalos 
170*ed775ee7SAntonio Huete Jimenez 	dsap_field = GET_U_1(p);
171*ed775ee7SAntonio Huete Jimenez 	ssap_field = GET_U_1(p + 1);
17241c99275SPeter Avalos 
17341c99275SPeter Avalos 	/*
17441c99275SPeter Avalos 	 * OK, what type of LLC frame is this?  The length
17541c99275SPeter Avalos 	 * of the control field depends on that - I frames
17641c99275SPeter Avalos 	 * have a two-byte control field, and U frames have
17741c99275SPeter Avalos 	 * a one-byte control field.
17841c99275SPeter Avalos 	 */
179*ed775ee7SAntonio Huete Jimenez 	control = GET_U_1(p + 2);
18041c99275SPeter Avalos 	if ((control & LLC_U_FMT) == LLC_U_FMT) {
18141c99275SPeter Avalos 		/*
18241c99275SPeter Avalos 		 * U frame.
18341c99275SPeter Avalos 		 */
18441c99275SPeter Avalos 		is_u = 1;
185411677aeSAaron LI 		hdrlen = 3;	/* DSAP, SSAP, 1-byte control field */
18641c99275SPeter Avalos 	} else {
18741c99275SPeter Avalos 		/*
18841c99275SPeter Avalos 		 * The control field in I and S frames is
18941c99275SPeter Avalos 		 * 2 bytes...
19041c99275SPeter Avalos 		 */
19141c99275SPeter Avalos 		if (caplen < 4) {
192*ed775ee7SAntonio Huete Jimenez 			nd_print_trunc(ndo);
193411677aeSAaron LI 			ND_DEFAULTPRINT((const u_char *)p, caplen);
194411677aeSAaron LI 			return (caplen);
195411677aeSAaron LI 		}
196411677aeSAaron LI 		if (length < 4) {
197*ed775ee7SAntonio Huete Jimenez 			nd_print_trunc(ndo);
198411677aeSAaron LI 			ND_DEFAULTPRINT((const u_char *)p, caplen);
199411677aeSAaron LI 			return (length);
20041c99275SPeter Avalos 		}
20141c99275SPeter Avalos 
20241c99275SPeter Avalos 		/*
20341c99275SPeter Avalos 		 * ...and is little-endian.
20441c99275SPeter Avalos 		 */
205*ed775ee7SAntonio Huete Jimenez 		control = GET_LE_U_2(p + 2);
20641c99275SPeter Avalos 		is_u = 0;
207411677aeSAaron LI 		hdrlen = 4;	/* DSAP, SSAP, 2-byte control field */
20841c99275SPeter Avalos 	}
20941c99275SPeter Avalos 
21041c99275SPeter Avalos 	if (ssap_field == LLCSAP_GLOBAL && dsap_field == LLCSAP_GLOBAL) {
21141c99275SPeter Avalos 		/*
21241c99275SPeter Avalos 		 * This is an Ethernet_802.3 IPX frame; it has an
21341c99275SPeter Avalos 		 * 802.3 header (i.e., an Ethernet header where the
214*ed775ee7SAntonio Huete Jimenez 		 * type/length field is <= MAX_ETHERNET_LENGTH_VAL,
215*ed775ee7SAntonio Huete Jimenez 		 * i.e. it's a length field, not a type field), but
216*ed775ee7SAntonio Huete Jimenez 		 * has no 802.2 header - the IPX packet starts right
217*ed775ee7SAntonio Huete Jimenez 		 * after the Ethernet header, with a signature of two
218*ed775ee7SAntonio Huete Jimenez 		 * bytes of 0xFF (which is LLCSAP_GLOBAL).
21941c99275SPeter Avalos 		 *
22041c99275SPeter Avalos 		 * (It might also have been an Ethernet_802.3 IPX at
22141c99275SPeter Avalos 		 * one time, but got bridged onto another network,
22241c99275SPeter Avalos 		 * such as an 802.11 network; this has appeared in at
22341c99275SPeter Avalos 		 * least one capture file.)
22441c99275SPeter Avalos 		 */
22541c99275SPeter Avalos 
226411677aeSAaron LI             if (ndo->ndo_eflag)
227*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("IPX 802.3: ");
22841c99275SPeter Avalos 
229411677aeSAaron LI             ipx_print(ndo, p, length);
230411677aeSAaron LI             return (0);		/* no LLC header */
23141c99275SPeter Avalos 	}
23241c99275SPeter Avalos 
23341c99275SPeter Avalos 	dsap = dsap_field & ~LLC_IG;
23441c99275SPeter Avalos 	ssap = ssap_field & ~LLC_GSAP;
23541c99275SPeter Avalos 
236411677aeSAaron LI 	if (ndo->ndo_eflag) {
237*ed775ee7SAntonio Huete Jimenez                 ND_PRINT("LLC, dsap %s (0x%02x) %s, ssap %s (0x%02x) %s",
23841c99275SPeter Avalos                        tok2str(llc_values, "Unknown", dsap),
23941c99275SPeter Avalos                        dsap,
24041c99275SPeter Avalos                        tok2str(llc_ig_flag_values, "Unknown", dsap_field & LLC_IG),
24141c99275SPeter Avalos                        tok2str(llc_values, "Unknown", ssap),
24241c99275SPeter Avalos                        ssap,
243*ed775ee7SAntonio Huete Jimenez                        tok2str(llc_flag_values, "Unknown", ssap_field & LLC_GSAP));
24441c99275SPeter Avalos 
24541c99275SPeter Avalos 		if (is_u) {
246*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(", ctrl 0x%02x: ", control);
24741c99275SPeter Avalos 		} else {
248*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(", ctrl 0x%04x: ", control);
24941c99275SPeter Avalos 		}
25041c99275SPeter Avalos 	}
25141c99275SPeter Avalos 
252411677aeSAaron LI 	/*
253411677aeSAaron LI 	 * Skip LLC header.
254411677aeSAaron LI 	 */
255411677aeSAaron LI 	p += hdrlen;
256411677aeSAaron LI 	length -= hdrlen;
257411677aeSAaron LI 	caplen -= hdrlen;
258411677aeSAaron LI 
259411677aeSAaron LI 	if (ssap == LLCSAP_SNAP && dsap == LLCSAP_SNAP
260411677aeSAaron LI 	    && control == LLC_UI) {
261411677aeSAaron LI 		/*
262411677aeSAaron LI 		 * XXX - what *is* the right bridge pad value here?
263411677aeSAaron LI 		 * Does anybody ever bridge one form of LAN traffic
264411677aeSAaron LI 		 * over a networking type that uses 802.2 LLC?
265411677aeSAaron LI 		 */
266411677aeSAaron LI 		if (!snap_print(ndo, p, length, caplen, src, dst, 2)) {
267411677aeSAaron LI 			/*
268411677aeSAaron LI 			 * Unknown packet type; tell our caller, by
269411677aeSAaron LI 			 * returning a negative value, so they
270411677aeSAaron LI 			 * can print the raw packet.
271411677aeSAaron LI 			 */
272411677aeSAaron LI 			return (-(hdrlen + 5));	/* include LLC and SNAP header */
273411677aeSAaron LI 		} else
274411677aeSAaron LI 			return (hdrlen + 5);	/* include LLC and SNAP header */
275411677aeSAaron LI 	}
276411677aeSAaron LI 
27741c99275SPeter Avalos 	if (ssap == LLCSAP_8021D && dsap == LLCSAP_8021D &&
27841c99275SPeter Avalos 	    control == LLC_UI) {
279411677aeSAaron LI 		stp_print(ndo, p, length);
280411677aeSAaron LI 		return (hdrlen);
28141c99275SPeter Avalos 	}
28241c99275SPeter Avalos 
28341c99275SPeter Avalos 	if (ssap == LLCSAP_IP && dsap == LLCSAP_IP &&
28441c99275SPeter Avalos 	    control == LLC_UI) {
285411677aeSAaron LI 		/*
286411677aeSAaron LI 		 * This is an RFC 948-style IP packet, with
287411677aeSAaron LI 		 * an 802.3 header and an 802.2 LLC header
288411677aeSAaron LI 		 * with the source and destination SAPs being
289411677aeSAaron LI 		 * the IP SAP.
290411677aeSAaron LI 		 */
291411677aeSAaron LI 		ip_print(ndo, p, length);
292411677aeSAaron LI 		return (hdrlen);
29341c99275SPeter Avalos 	}
29441c99275SPeter Avalos 
29541c99275SPeter Avalos 	if (ssap == LLCSAP_IPX && dsap == LLCSAP_IPX &&
29641c99275SPeter Avalos 	    control == LLC_UI) {
29741c99275SPeter Avalos 		/*
29841c99275SPeter Avalos 		 * This is an Ethernet_802.2 IPX frame, with an 802.3
29941c99275SPeter Avalos 		 * header and an 802.2 LLC header with the source and
30041c99275SPeter Avalos 		 * destination SAPs being the IPX SAP.
30141c99275SPeter Avalos 		 */
302411677aeSAaron LI                 if (ndo->ndo_eflag)
303*ed775ee7SAntonio Huete Jimenez                         ND_PRINT("IPX 802.2: ");
30441c99275SPeter Avalos 
305411677aeSAaron LI 		ipx_print(ndo, p, length);
306411677aeSAaron LI 		return (hdrlen);
30741c99275SPeter Avalos 	}
30841c99275SPeter Avalos 
309411677aeSAaron LI #ifdef ENABLE_SMB
31041c99275SPeter Avalos 	if (ssap == LLCSAP_NETBEUI && dsap == LLCSAP_NETBEUI
31141c99275SPeter Avalos 	    && (!(control & LLC_S_FMT) || control == LLC_U_FMT)) {
31241c99275SPeter Avalos 		/*
31341c99275SPeter Avalos 		 * we don't actually have a full netbeui parser yet, but the
31441c99275SPeter Avalos 		 * smb parser can handle many smb-in-netbeui packets, which
31541c99275SPeter Avalos 		 * is very useful, so we call that
31641c99275SPeter Avalos 		 *
31741c99275SPeter Avalos 		 * We don't call it for S frames, however, just I frames
31841c99275SPeter Avalos 		 * (which are frames that don't have the low-order bit,
31941c99275SPeter Avalos 		 * LLC_S_FMT, set in the first byte of the control field)
32041c99275SPeter Avalos 		 * and UI frames (whose control field is just 3, LLC_U_FMT).
32141c99275SPeter Avalos 		 */
322411677aeSAaron LI 		netbeui_print(ndo, control, p, length);
323411677aeSAaron LI 		return (hdrlen);
32441c99275SPeter Avalos 	}
32541c99275SPeter Avalos #endif
32641c99275SPeter Avalos 	if (ssap == LLCSAP_ISONS && dsap == LLCSAP_ISONS
32741c99275SPeter Avalos 	    && control == LLC_UI) {
328411677aeSAaron LI 		isoclns_print(ndo, p, length);
329411677aeSAaron LI 		return (hdrlen);
33041c99275SPeter Avalos 	}
33141c99275SPeter Avalos 
332411677aeSAaron LI 	if (!ndo->ndo_eflag) {
33341c99275SPeter Avalos 		if (ssap == dsap) {
334411677aeSAaron LI 			if (src == NULL || dst == NULL)
335*ed775ee7SAntonio Huete Jimenez 				ND_PRINT("%s ", tok2str(llc_values, "Unknown DSAP 0x%02x", dsap));
33641c99275SPeter Avalos 			else
337*ed775ee7SAntonio Huete Jimenez 				ND_PRINT("%s > %s %s ",
338411677aeSAaron LI 						(src->addr_string)(ndo, src->addr),
339411677aeSAaron LI 						(dst->addr_string)(ndo, dst->addr),
340*ed775ee7SAntonio Huete Jimenez 						tok2str(llc_values, "Unknown DSAP 0x%02x", dsap));
34141c99275SPeter Avalos 		} else {
342411677aeSAaron LI 			if (src == NULL || dst == NULL)
343*ed775ee7SAntonio Huete Jimenez 				ND_PRINT("%s > %s ",
34441c99275SPeter Avalos                                         tok2str(llc_values, "Unknown SSAP 0x%02x", ssap),
345*ed775ee7SAntonio Huete Jimenez 					tok2str(llc_values, "Unknown DSAP 0x%02x", dsap));
34641c99275SPeter Avalos 			else
347*ed775ee7SAntonio Huete Jimenez 				ND_PRINT("%s %s > %s %s ",
348411677aeSAaron LI 					(src->addr_string)(ndo, src->addr),
34941c99275SPeter Avalos                                         tok2str(llc_values, "Unknown SSAP 0x%02x", ssap),
350411677aeSAaron LI 					(dst->addr_string)(ndo, dst->addr),
351*ed775ee7SAntonio Huete Jimenez 					tok2str(llc_values, "Unknown DSAP 0x%02x", dsap));
35241c99275SPeter Avalos 		}
35341c99275SPeter Avalos 	}
35441c99275SPeter Avalos 
35541c99275SPeter Avalos 	if (is_u) {
356*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("Unnumbered, %s, Flags [%s], length %u",
35741c99275SPeter Avalos                        tok2str(llc_cmd_values, "%02x", LLC_U_CMD(control)),
35841c99275SPeter Avalos                        tok2str(llc_flag_values,"?",(ssap_field & LLC_GSAP) | (control & LLC_U_POLL)),
359*ed775ee7SAntonio Huete Jimenez                        length + hdrlen);
36041c99275SPeter Avalos 
36141c99275SPeter Avalos 		if ((control & ~LLC_U_POLL) == LLC_XID) {
362411677aeSAaron LI 			if (length == 0) {
363411677aeSAaron LI 				/*
364411677aeSAaron LI 				 * XID with no payload.
365411677aeSAaron LI 				 * This could, for example, be an SNA
366411677aeSAaron LI 				 * "short form" XID.
367411677aeSAaron LI                                  */
368411677aeSAaron LI 				return (hdrlen);
369411677aeSAaron LI 			}
370411677aeSAaron LI 			if (caplen < 1) {
371*ed775ee7SAntonio Huete Jimenez 				nd_print_trunc(ndo);
372411677aeSAaron LI 				if (caplen > 0)
373411677aeSAaron LI 					ND_DEFAULTPRINT((const u_char *)p, caplen);
374411677aeSAaron LI 				return (hdrlen);
375411677aeSAaron LI 			}
376*ed775ee7SAntonio Huete Jimenez 			if (GET_U_1(p) == LLC_XID_FI) {
377411677aeSAaron LI 				if (caplen < 3 || length < 3) {
378*ed775ee7SAntonio Huete Jimenez 					nd_print_trunc(ndo);
379411677aeSAaron LI 					if (caplen > 0)
380411677aeSAaron LI 						ND_DEFAULTPRINT((const u_char *)p, caplen);
381411677aeSAaron LI 				} else
382*ed775ee7SAntonio Huete Jimenez 					ND_PRINT(": %02x %02x",
383*ed775ee7SAntonio Huete Jimenez 						  GET_U_1(p + 1),
384*ed775ee7SAntonio Huete Jimenez 						  GET_U_1(p + 2));
385411677aeSAaron LI 				return (hdrlen);
38641c99275SPeter Avalos 			}
38741c99275SPeter Avalos 		}
38841c99275SPeter Avalos 	} else {
38941c99275SPeter Avalos 		if ((control & LLC_S_FMT) == LLC_S_FMT) {
390*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("Supervisory, %s, rcv seq %u, Flags [%s], length %u",
39141c99275SPeter Avalos 				tok2str(llc_supervisory_values,"?",LLC_S_CMD(control)),
39241c99275SPeter Avalos 				LLC_IS_NR(control),
39341c99275SPeter Avalos 				tok2str(llc_flag_values,"?",(ssap_field & LLC_GSAP) | (control & LLC_IS_POLL)),
394*ed775ee7SAntonio Huete Jimenez                                 length + hdrlen);
395411677aeSAaron LI 			return (hdrlen);	/* no payload to print */
39641c99275SPeter Avalos 		} else {
397*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("Information, send seq %u, rcv seq %u, Flags [%s], length %u",
39841c99275SPeter Avalos 				LLC_I_NS(control),
39941c99275SPeter Avalos 				LLC_IS_NR(control),
40041c99275SPeter Avalos 				tok2str(llc_flag_values,"?",(ssap_field & LLC_GSAP) | (control & LLC_IS_POLL)),
401*ed775ee7SAntonio Huete Jimenez                                 length + hdrlen);
40241c99275SPeter Avalos 		}
40341c99275SPeter Avalos 	}
404411677aeSAaron LI 	return (-hdrlen);
40541c99275SPeter Avalos }
40641c99275SPeter Avalos 
407411677aeSAaron LI static const struct tok *
oui_to_struct_tok(uint32_t orgcode)408411677aeSAaron LI oui_to_struct_tok(uint32_t orgcode)
40941c99275SPeter Avalos {
41041c99275SPeter Avalos 	const struct tok *tok = null_values;
41141c99275SPeter Avalos 	const struct oui_tok *otp;
41241c99275SPeter Avalos 
41341c99275SPeter Avalos 	for (otp = &oui_to_tok[0]; otp->tok != NULL; otp++) {
41441c99275SPeter Avalos 		if (otp->oui == orgcode) {
41541c99275SPeter Avalos 			tok = otp->tok;
41641c99275SPeter Avalos 			break;
41741c99275SPeter Avalos 		}
41841c99275SPeter Avalos 	}
419411677aeSAaron LI 	return (tok);
420411677aeSAaron LI }
421411677aeSAaron LI 
422411677aeSAaron LI int
snap_print(netdissect_options * ndo,const u_char * p,u_int length,u_int caplen,const struct lladdr_info * src,const struct lladdr_info * dst,u_int bridge_pad)423411677aeSAaron LI snap_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
424411677aeSAaron LI 	const struct lladdr_info *src, const struct lladdr_info *dst,
425411677aeSAaron LI 	u_int bridge_pad)
426411677aeSAaron LI {
427411677aeSAaron LI 	uint32_t orgcode;
428*ed775ee7SAntonio Huete Jimenez 	u_short et;
429*ed775ee7SAntonio Huete Jimenez 	int ret;
430411677aeSAaron LI 
431*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "snap";
432*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_5(p);
433411677aeSAaron LI 	if (caplen < 5 || length < 5)
434411677aeSAaron LI 		goto trunc;
435*ed775ee7SAntonio Huete Jimenez 	orgcode = GET_BE_U_3(p);
436*ed775ee7SAntonio Huete Jimenez 	et = GET_BE_U_2(p + 3);
437411677aeSAaron LI 
438411677aeSAaron LI 	if (ndo->ndo_eflag) {
439411677aeSAaron LI 		/*
440411677aeSAaron LI 		 * Somebody's already printed the MAC addresses, if there
441411677aeSAaron LI 		 * are any, so just print the SNAP header, not the MAC
442411677aeSAaron LI 		 * addresses.
443411677aeSAaron LI 		 */
444*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("oui %s (0x%06x), %s %s (0x%04x), length %u: ",
44541c99275SPeter Avalos 		     tok2str(oui_values, "Unknown", orgcode),
44641c99275SPeter Avalos 		     orgcode,
44741c99275SPeter Avalos 		     (orgcode == 0x000000 ? "ethertype" : "pid"),
448411677aeSAaron LI 		     tok2str(oui_to_struct_tok(orgcode), "Unknown", et),
449*ed775ee7SAntonio Huete Jimenez 		     et, length - 5);
45041c99275SPeter Avalos 	}
45141c99275SPeter Avalos 	p += 5;
45241c99275SPeter Avalos 	length -= 5;
45341c99275SPeter Avalos 	caplen -= 5;
45441c99275SPeter Avalos 
45541c99275SPeter Avalos 	switch (orgcode) {
45641c99275SPeter Avalos 	case OUI_ENCAP_ETHER:
45741c99275SPeter Avalos 	case OUI_CISCO_90:
45841c99275SPeter Avalos 		/*
45941c99275SPeter Avalos 		 * This is an encapsulated Ethernet packet,
46041c99275SPeter Avalos 		 * or a packet bridged by some piece of
46141c99275SPeter Avalos 		 * Cisco hardware; the protocol ID is
46241c99275SPeter Avalos 		 * an Ethernet protocol type.
46341c99275SPeter Avalos 		 */
464411677aeSAaron LI 		ret = ethertype_print(ndo, et, p, length, caplen, src, dst);
46541c99275SPeter Avalos 		if (ret)
46641c99275SPeter Avalos 			return (ret);
46741c99275SPeter Avalos 		break;
46841c99275SPeter Avalos 
46941c99275SPeter Avalos 	case OUI_APPLETALK:
47041c99275SPeter Avalos 		if (et == ETHERTYPE_ATALK) {
47141c99275SPeter Avalos 			/*
47241c99275SPeter Avalos 			 * No, I have no idea why Apple used one
47341c99275SPeter Avalos 			 * of their own OUIs, rather than
47441c99275SPeter Avalos 			 * 0x000000, and an Ethernet packet
47541c99275SPeter Avalos 			 * type, for Appletalk data packets,
47641c99275SPeter Avalos 			 * but used 0x000000 and an Ethernet
47741c99275SPeter Avalos 			 * packet type for AARP packets.
47841c99275SPeter Avalos 			 */
479411677aeSAaron LI 			ret = ethertype_print(ndo, et, p, length, caplen, src, dst);
48041c99275SPeter Avalos 			if (ret)
48141c99275SPeter Avalos 				return (ret);
48241c99275SPeter Avalos 		}
48341c99275SPeter Avalos 		break;
48441c99275SPeter Avalos 
48541c99275SPeter Avalos 	case OUI_CISCO:
486ea7b4bf5SPeter Avalos                 switch (et) {
487ea7b4bf5SPeter Avalos                 case PID_CISCO_CDP:
488*ed775ee7SAntonio Huete Jimenez                         cdp_print(ndo, p, length);
48941c99275SPeter Avalos                         return (1);
490ea7b4bf5SPeter Avalos                 case PID_CISCO_DTP:
491411677aeSAaron LI                         dtp_print(ndo, p, length);
492ea7b4bf5SPeter Avalos                         return (1);
493ea7b4bf5SPeter Avalos                 case PID_CISCO_UDLD:
494411677aeSAaron LI                         udld_print(ndo, p, length);
495ea7b4bf5SPeter Avalos                         return (1);
496ea7b4bf5SPeter Avalos                 case PID_CISCO_VTP:
497411677aeSAaron LI                         vtp_print(ndo, p, length);
498ea7b4bf5SPeter Avalos                         return (1);
499ea7b4bf5SPeter Avalos                 case PID_CISCO_PVST:
500411677aeSAaron LI                 case PID_CISCO_VLANBRIDGE:
501411677aeSAaron LI                         stp_print(ndo, p, length);
502ea7b4bf5SPeter Avalos                         return (1);
503ea7b4bf5SPeter Avalos                 default:
50441c99275SPeter Avalos                         break;
505ea7b4bf5SPeter Avalos                 }
506411677aeSAaron LI 		break;
50741c99275SPeter Avalos 
50841c99275SPeter Avalos 	case OUI_RFC2684:
50941c99275SPeter Avalos 		switch (et) {
51041c99275SPeter Avalos 
51141c99275SPeter Avalos 		case PID_RFC2684_ETH_FCS:
51241c99275SPeter Avalos 		case PID_RFC2684_ETH_NOFCS:
51341c99275SPeter Avalos 			/*
51441c99275SPeter Avalos 			 * XXX - remove the last two bytes for
51541c99275SPeter Avalos 			 * PID_RFC2684_ETH_FCS?
51641c99275SPeter Avalos 			 */
51741c99275SPeter Avalos 			/*
51841c99275SPeter Avalos 			 * Skip the padding.
51941c99275SPeter Avalos 			 */
520*ed775ee7SAntonio Huete Jimenez 			ND_TCHECK_LEN(p, bridge_pad);
52141c99275SPeter Avalos 			caplen -= bridge_pad;
52241c99275SPeter Avalos 			length -= bridge_pad;
52341c99275SPeter Avalos 			p += bridge_pad;
52441c99275SPeter Avalos 
52541c99275SPeter Avalos 			/*
52641c99275SPeter Avalos 			 * What remains is an Ethernet packet.
52741c99275SPeter Avalos 			 */
528411677aeSAaron LI 			ether_print(ndo, p, length, caplen, NULL, NULL);
52941c99275SPeter Avalos 			return (1);
53041c99275SPeter Avalos 
53141c99275SPeter Avalos 		case PID_RFC2684_802_5_FCS:
53241c99275SPeter Avalos 		case PID_RFC2684_802_5_NOFCS:
53341c99275SPeter Avalos 			/*
53441c99275SPeter Avalos 			 * XXX - remove the last two bytes for
53541c99275SPeter Avalos 			 * PID_RFC2684_ETH_FCS?
53641c99275SPeter Avalos 			 */
53741c99275SPeter Avalos 			/*
53841c99275SPeter Avalos 			 * Skip the padding, but not the Access
53941c99275SPeter Avalos 			 * Control field.
54041c99275SPeter Avalos 			 */
541*ed775ee7SAntonio Huete Jimenez 			ND_TCHECK_LEN(p, bridge_pad);
54241c99275SPeter Avalos 			caplen -= bridge_pad;
54341c99275SPeter Avalos 			length -= bridge_pad;
54441c99275SPeter Avalos 			p += bridge_pad;
54541c99275SPeter Avalos 
54641c99275SPeter Avalos 			/*
54741c99275SPeter Avalos 			 * What remains is an 802.5 Token Ring
54841c99275SPeter Avalos 			 * packet.
54941c99275SPeter Avalos 			 */
550411677aeSAaron LI 			token_print(ndo, p, length, caplen);
55141c99275SPeter Avalos 			return (1);
55241c99275SPeter Avalos 
55341c99275SPeter Avalos 		case PID_RFC2684_FDDI_FCS:
55441c99275SPeter Avalos 		case PID_RFC2684_FDDI_NOFCS:
55541c99275SPeter Avalos 			/*
55641c99275SPeter Avalos 			 * XXX - remove the last two bytes for
55741c99275SPeter Avalos 			 * PID_RFC2684_ETH_FCS?
55841c99275SPeter Avalos 			 */
55941c99275SPeter Avalos 			/*
56041c99275SPeter Avalos 			 * Skip the padding.
56141c99275SPeter Avalos 			 */
562*ed775ee7SAntonio Huete Jimenez 			ND_TCHECK_LEN(p, bridge_pad + 1);
56341c99275SPeter Avalos 			caplen -= bridge_pad + 1;
56441c99275SPeter Avalos 			length -= bridge_pad + 1;
56541c99275SPeter Avalos 			p += bridge_pad + 1;
56641c99275SPeter Avalos 
56741c99275SPeter Avalos 			/*
56841c99275SPeter Avalos 			 * What remains is an FDDI packet.
56941c99275SPeter Avalos 			 */
570411677aeSAaron LI 			fddi_print(ndo, p, length, caplen);
57141c99275SPeter Avalos 			return (1);
57241c99275SPeter Avalos 
57341c99275SPeter Avalos 		case PID_RFC2684_BPDU:
574411677aeSAaron LI 			stp_print(ndo, p, length);
57541c99275SPeter Avalos 			return (1);
57641c99275SPeter Avalos 		}
57741c99275SPeter Avalos 	}
578411677aeSAaron LI 	if (!ndo->ndo_eflag) {
579411677aeSAaron LI 		/*
580411677aeSAaron LI 		 * Nobody printed the link-layer addresses, so print them, if
581411677aeSAaron LI 		 * we have any.
582411677aeSAaron LI 		 */
583411677aeSAaron LI 		if (src != NULL && dst != NULL) {
584*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("%s > %s ",
585411677aeSAaron LI 				(src->addr_string)(ndo, src->addr),
586*ed775ee7SAntonio Huete Jimenez 				(dst->addr_string)(ndo, dst->addr));
587411677aeSAaron LI 		}
588411677aeSAaron LI 		/*
589411677aeSAaron LI 		 * Print the SNAP header, but if the OUI is 000000, don't
590411677aeSAaron LI 		 * bother printing it, and report the PID as being an
591411677aeSAaron LI 		 * ethertype.
592411677aeSAaron LI 		 */
593411677aeSAaron LI 		if (orgcode == 0x000000) {
594*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("SNAP, ethertype %s (0x%04x), length %u: ",
595411677aeSAaron LI 			     tok2str(ethertype_values, "Unknown", et),
596*ed775ee7SAntonio Huete Jimenez 			     et, length);
597411677aeSAaron LI 		} else {
598*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("SNAP, oui %s (0x%06x), pid %s (0x%04x), length %u: ",
599411677aeSAaron LI 			     tok2str(oui_values, "Unknown", orgcode),
600411677aeSAaron LI 			     orgcode,
601411677aeSAaron LI 			     tok2str(oui_to_struct_tok(orgcode), "Unknown", et),
602*ed775ee7SAntonio Huete Jimenez 			     et, length);
603411677aeSAaron LI 		}
604411677aeSAaron LI 	}
60541c99275SPeter Avalos 	return (0);
60641c99275SPeter Avalos 
60741c99275SPeter Avalos trunc:
608*ed775ee7SAntonio Huete Jimenez 	nd_print_trunc(ndo);
60941c99275SPeter Avalos 	return (1);
61041c99275SPeter Avalos }
611