blob: be8886abdd4a11b48fe2eb0cb410c89484fccd6a [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
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
16 * written permission.
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.
20 *
21 * Code by Matt Thomas, Digital Equipment Corporation
22 * with an awful lot of hacking by Jeffrey Mogul, DECWRL
23 */
24
Elliott Hughese2e3bd12017-05-15 10:59:29 -070025/* \summary: IEEE 802.2 LLC printer */
26
The Android Open Source Project2949f582009-03-03 19:30:46 -080027#ifdef HAVE_CONFIG_H
28#include "config.h"
29#endif
30
Elliott Hughese2e3bd12017-05-15 10:59:29 -070031#include <netdissect-stdinc.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080032
Elliott Hughese2e3bd12017-05-15 10:59:29 -070033#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080034#include "addrtoname.h"
Elliott Hughese2e3bd12017-05-15 10:59:29 -070035#include "extract.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080036
37#include "llc.h"
38#include "ethertype.h"
39#include "oui.h"
40
JP Abgrall53f17a92014-02-12 14:02:41 -080041static const struct tok llc_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080042 { LLCSAP_NULL, "Null" },
43 { LLCSAP_GLOBAL, "Global" },
44 { LLCSAP_8021B_I, "802.1B I" },
45 { LLCSAP_8021B_G, "802.1B G" },
46 { LLCSAP_IP, "IP" },
47 { LLCSAP_SNA, "SNA" },
48 { LLCSAP_PROWAYNM, "ProWay NM" },
49 { LLCSAP_8021D, "STP" },
50 { LLCSAP_RS511, "RS511" },
51 { LLCSAP_ISO8208, "ISO8208" },
52 { LLCSAP_PROWAY, "ProWay" },
53 { LLCSAP_SNAP, "SNAP" },
54 { LLCSAP_IPX, "IPX" },
55 { LLCSAP_NETBEUI, "NetBeui" },
56 { LLCSAP_ISONS, "OSI" },
57 { 0, NULL },
58};
59
JP Abgrall53f17a92014-02-12 14:02:41 -080060static const struct tok llc_cmd_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080061 { LLC_UI, "ui" },
62 { LLC_TEST, "test" },
63 { LLC_XID, "xid" },
64 { LLC_UA, "ua" },
65 { LLC_DISC, "disc" },
66 { LLC_DM, "dm" },
67 { LLC_SABME, "sabme" },
68 { LLC_FRMR, "frmr" },
69 { 0, NULL }
70};
71
Elliott Hughes892a68b2015-10-19 14:43:53 -070072static const struct tok llc_flag_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080073 { 0, "Command" },
74 { LLC_GSAP, "Response" },
75 { LLC_U_POLL, "Poll" },
76 { LLC_GSAP|LLC_U_POLL, "Final" },
77 { LLC_IS_POLL, "Poll" },
78 { LLC_GSAP|LLC_IS_POLL, "Final" },
79 { 0, NULL }
80};
81
82
Elliott Hughes892a68b2015-10-19 14:43:53 -070083static const struct tok llc_ig_flag_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080084 { 0, "Individual" },
85 { LLC_IG, "Group" },
86 { 0, NULL }
87};
88
89
Elliott Hughes892a68b2015-10-19 14:43:53 -070090static const struct tok llc_supervisory_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080091 { 0, "Receiver Ready" },
92 { 1, "Receiver not Ready" },
93 { 2, "Reject" },
94 { 0, NULL }
95};
96
97
Elliott Hughes892a68b2015-10-19 14:43:53 -070098static const struct tok cisco_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080099 { PID_CISCO_CDP, "CDP" },
100 { PID_CISCO_VTP, "VTP" },
101 { PID_CISCO_DTP, "DTP" },
JP Abgrall53f17a92014-02-12 14:02:41 -0800102 { PID_CISCO_UDLD, "UDLD" },
103 { PID_CISCO_PVST, "PVST" },
104 { PID_CISCO_VLANBRIDGE, "VLAN Bridge" },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800105 { 0, NULL }
106};
107
Elliott Hughes892a68b2015-10-19 14:43:53 -0700108static const struct tok bridged_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800109 { PID_RFC2684_ETH_FCS, "Ethernet + FCS" },
110 { PID_RFC2684_ETH_NOFCS, "Ethernet w/o FCS" },
111 { PID_RFC2684_802_4_FCS, "802.4 + FCS" },
112 { PID_RFC2684_802_4_NOFCS, "802.4 w/o FCS" },
113 { PID_RFC2684_802_5_FCS, "Token Ring + FCS" },
114 { PID_RFC2684_802_5_NOFCS, "Token Ring w/o FCS" },
115 { PID_RFC2684_FDDI_FCS, "FDDI + FCS" },
116 { PID_RFC2684_FDDI_NOFCS, "FDDI w/o FCS" },
117 { PID_RFC2684_802_6_FCS, "802.6 + FCS" },
118 { PID_RFC2684_802_6_NOFCS, "802.6 w/o FCS" },
119 { PID_RFC2684_BPDU, "BPDU" },
120 { 0, NULL },
121};
122
Elliott Hughes892a68b2015-10-19 14:43:53 -0700123static const struct tok null_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800124 { 0, NULL }
125};
126
127struct oui_tok {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700128 uint32_t oui;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800129 const struct tok *tok;
130};
131
132static const struct oui_tok oui_to_tok[] = {
133 { OUI_ENCAP_ETHER, ethertype_values },
134 { OUI_CISCO_90, ethertype_values }, /* uses some Ethertype values */
135 { OUI_APPLETALK, ethertype_values }, /* uses some Ethertype values */
136 { OUI_CISCO, cisco_values },
137 { OUI_RFC2684, bridged_values }, /* bridged, RFC 2427 FR or RFC 2864 ATM */
138 { 0, NULL }
139};
140
141/*
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700142 * If we printed information about the payload, returns the length of the LLC
143 * header, plus the length of any SNAP header following it.
144 *
145 * Otherwise (for example, if the packet has unknown SAPs or has a SNAP
146 * header with an unknown OUI/PID combination), returns the *negative*
147 * of that value.
The Android Open Source Project2949f582009-03-03 19:30:46 -0800148 */
149int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700150llc_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700151 const struct lladdr_info *src, const struct lladdr_info *dst)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800152{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700153 uint8_t dsap_field, dsap, ssap_field, ssap;
154 uint16_t control;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700155 int hdrlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800156 int is_u;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800157
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700158 if (caplen < 3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700159 ND_PRINT((ndo, "[|llc]"));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700160 ND_DEFAULTPRINT((const u_char *)p, caplen);
161 return (caplen);
162 }
163 if (length < 3) {
164 ND_PRINT((ndo, "[|llc]"));
165 ND_DEFAULTPRINT((const u_char *)p, caplen);
166 return (length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800167 }
168
169 dsap_field = *p;
170 ssap_field = *(p + 1);
171
172 /*
173 * OK, what type of LLC frame is this? The length
174 * of the control field depends on that - I frames
175 * have a two-byte control field, and U frames have
176 * a one-byte control field.
177 */
178 control = *(p + 2);
179 if ((control & LLC_U_FMT) == LLC_U_FMT) {
180 /*
181 * U frame.
182 */
183 is_u = 1;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700184 hdrlen = 3; /* DSAP, SSAP, 1-byte control field */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800185 } else {
186 /*
187 * The control field in I and S frames is
188 * 2 bytes...
189 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700190 if (caplen < 4) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700191 ND_PRINT((ndo, "[|llc]"));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700192 ND_DEFAULTPRINT((const u_char *)p, caplen);
193 return (caplen);
194 }
195 if (length < 4) {
196 ND_PRINT((ndo, "[|llc]"));
197 ND_DEFAULTPRINT((const u_char *)p, caplen);
198 return (length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800199 }
200
201 /*
202 * ...and is little-endian.
203 */
204 control = EXTRACT_LE_16BITS(p + 2);
205 is_u = 0;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700206 hdrlen = 4; /* DSAP, SSAP, 2-byte control field */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800207 }
208
209 if (ssap_field == LLCSAP_GLOBAL && dsap_field == LLCSAP_GLOBAL) {
210 /*
211 * This is an Ethernet_802.3 IPX frame; it has an
212 * 802.3 header (i.e., an Ethernet header where the
213 * type/length field is <= ETHERMTU, i.e. it's a length
214 * field, not a type field), but has no 802.2 header -
215 * the IPX packet starts right after the Ethernet header,
216 * with a signature of two bytes of 0xFF (which is
217 * LLCSAP_GLOBAL).
218 *
219 * (It might also have been an Ethernet_802.3 IPX at
220 * one time, but got bridged onto another network,
221 * such as an 802.11 network; this has appeared in at
222 * least one capture file.)
223 */
224
Elliott Hughes892a68b2015-10-19 14:43:53 -0700225 if (ndo->ndo_eflag)
226 ND_PRINT((ndo, "IPX 802.3: "));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800227
Elliott Hughes892a68b2015-10-19 14:43:53 -0700228 ipx_print(ndo, p, length);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700229 return (0); /* no LLC header */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800230 }
231
232 dsap = dsap_field & ~LLC_IG;
233 ssap = ssap_field & ~LLC_GSAP;
234
Elliott Hughes892a68b2015-10-19 14:43:53 -0700235 if (ndo->ndo_eflag) {
236 ND_PRINT((ndo, "LLC, dsap %s (0x%02x) %s, ssap %s (0x%02x) %s",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800237 tok2str(llc_values, "Unknown", dsap),
238 dsap,
239 tok2str(llc_ig_flag_values, "Unknown", dsap_field & LLC_IG),
240 tok2str(llc_values, "Unknown", ssap),
241 ssap,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700242 tok2str(llc_flag_values, "Unknown", ssap_field & LLC_GSAP)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800243
244 if (is_u) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700245 ND_PRINT((ndo, ", ctrl 0x%02x: ", control));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800246 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700247 ND_PRINT((ndo, ", ctrl 0x%04x: ", control));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800248 }
249 }
250
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700251 /*
252 * Skip LLC header.
253 */
254 p += hdrlen;
255 length -= hdrlen;
256 caplen -= hdrlen;
257
258 if (ssap == LLCSAP_SNAP && dsap == LLCSAP_SNAP
259 && control == LLC_UI) {
260 /*
261 * XXX - what *is* the right bridge pad value here?
262 * Does anybody ever bridge one form of LAN traffic
263 * over a networking type that uses 802.2 LLC?
264 */
265 if (!snap_print(ndo, p, length, caplen, src, dst, 2)) {
266 /*
267 * Unknown packet type; tell our caller, by
268 * returning a negative value, so they
269 * can print the raw packet.
270 */
271 return (-(hdrlen + 5)); /* include LLC and SNAP header */
272 } else
273 return (hdrlen + 5); /* include LLC and SNAP header */
274 }
275
The Android Open Source Project2949f582009-03-03 19:30:46 -0800276 if (ssap == LLCSAP_8021D && dsap == LLCSAP_8021D &&
277 control == LLC_UI) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700278 stp_print(ndo, p, length);
279 return (hdrlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800280 }
281
282 if (ssap == LLCSAP_IP && dsap == LLCSAP_IP &&
283 control == LLC_UI) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700284 /*
285 * This is an RFC 948-style IP packet, with
286 * an 802.3 header and an 802.2 LLC header
287 * with the source and destination SAPs being
288 * the IP SAP.
289 */
290 ip_print(ndo, p, length);
291 return (hdrlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800292 }
293
294 if (ssap == LLCSAP_IPX && dsap == LLCSAP_IPX &&
295 control == LLC_UI) {
296 /*
297 * This is an Ethernet_802.2 IPX frame, with an 802.3
298 * header and an 802.2 LLC header with the source and
299 * destination SAPs being the IPX SAP.
The Android Open Source Project2949f582009-03-03 19:30:46 -0800300 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700301 if (ndo->ndo_eflag)
302 ND_PRINT((ndo, "IPX 802.2: "));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800303
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700304 ipx_print(ndo, p, length);
305 return (hdrlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800306 }
307
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700308#ifdef ENABLE_SMB
The Android Open Source Project2949f582009-03-03 19:30:46 -0800309 if (ssap == LLCSAP_NETBEUI && dsap == LLCSAP_NETBEUI
310 && (!(control & LLC_S_FMT) || control == LLC_U_FMT)) {
311 /*
312 * we don't actually have a full netbeui parser yet, but the
313 * smb parser can handle many smb-in-netbeui packets, which
314 * is very useful, so we call that
315 *
316 * We don't call it for S frames, however, just I frames
317 * (which are frames that don't have the low-order bit,
318 * LLC_S_FMT, set in the first byte of the control field)
319 * and UI frames (whose control field is just 3, LLC_U_FMT).
320 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700321 netbeui_print(ndo, control, p, length);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700322 return (hdrlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800323 }
324#endif
325 if (ssap == LLCSAP_ISONS && dsap == LLCSAP_ISONS
326 && control == LLC_UI) {
Elliott Hughescec480a2017-12-19 16:54:57 -0800327 isoclns_print(ndo, p, length);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700328 return (hdrlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800329 }
330
Elliott Hughes892a68b2015-10-19 14:43:53 -0700331 if (!ndo->ndo_eflag) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800332 if (ssap == dsap) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700333 if (src == NULL || dst == NULL)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700334 ND_PRINT((ndo, "%s ", tok2str(llc_values, "Unknown DSAP 0x%02x", dsap)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800335 else
Elliott Hughes892a68b2015-10-19 14:43:53 -0700336 ND_PRINT((ndo, "%s > %s %s ",
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700337 (src->addr_string)(ndo, src->addr),
338 (dst->addr_string)(ndo, dst->addr),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700339 tok2str(llc_values, "Unknown DSAP 0x%02x", dsap)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800340 } else {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700341 if (src == NULL || dst == NULL)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700342 ND_PRINT((ndo, "%s > %s ",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800343 tok2str(llc_values, "Unknown SSAP 0x%02x", ssap),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700344 tok2str(llc_values, "Unknown DSAP 0x%02x", dsap)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800345 else
Elliott Hughes892a68b2015-10-19 14:43:53 -0700346 ND_PRINT((ndo, "%s %s > %s %s ",
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700347 (src->addr_string)(ndo, src->addr),
The Android Open Source Project2949f582009-03-03 19:30:46 -0800348 tok2str(llc_values, "Unknown SSAP 0x%02x", ssap),
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700349 (dst->addr_string)(ndo, dst->addr),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700350 tok2str(llc_values, "Unknown DSAP 0x%02x", dsap)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800351 }
352 }
353
354 if (is_u) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700355 ND_PRINT((ndo, "Unnumbered, %s, Flags [%s], length %u",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800356 tok2str(llc_cmd_values, "%02x", LLC_U_CMD(control)),
357 tok2str(llc_flag_values,"?",(ssap_field & LLC_GSAP) | (control & LLC_U_POLL)),
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700358 length + hdrlen));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800359
360 if ((control & ~LLC_U_POLL) == LLC_XID) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700361 if (length == 0) {
362 /*
363 * XID with no payload.
364 * This could, for example, be an SNA
365 * "short form" XID.
366 */
367 return (hdrlen);
368 }
369 if (caplen < 1) {
370 ND_PRINT((ndo, "[|llc]"));
371 if (caplen > 0)
372 ND_DEFAULTPRINT((const u_char *)p, caplen);
373 return (hdrlen);
374 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800375 if (*p == LLC_XID_FI) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700376 if (caplen < 3 || length < 3) {
377 ND_PRINT((ndo, "[|llc]"));
378 if (caplen > 0)
379 ND_DEFAULTPRINT((const u_char *)p, caplen);
380 } else
381 ND_PRINT((ndo, ": %02x %02x", p[1], p[2]));
382 return (hdrlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800383 }
384 }
385 } else {
386 if ((control & LLC_S_FMT) == LLC_S_FMT) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700387 ND_PRINT((ndo, "Supervisory, %s, rcv seq %u, Flags [%s], length %u",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800388 tok2str(llc_supervisory_values,"?",LLC_S_CMD(control)),
389 LLC_IS_NR(control),
390 tok2str(llc_flag_values,"?",(ssap_field & LLC_GSAP) | (control & LLC_IS_POLL)),
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700391 length + hdrlen));
392 return (hdrlen); /* no payload to print */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800393 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700394 ND_PRINT((ndo, "Information, send seq %u, rcv seq %u, Flags [%s], length %u",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800395 LLC_I_NS(control),
396 LLC_IS_NR(control),
397 tok2str(llc_flag_values,"?",(ssap_field & LLC_GSAP) | (control & LLC_IS_POLL)),
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700398 length + hdrlen));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800399 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800400 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700401 return (-hdrlen);
402}
403
404static const struct tok *
405oui_to_struct_tok(uint32_t orgcode)
406{
407 const struct tok *tok = null_values;
408 const struct oui_tok *otp;
409
410 for (otp = &oui_to_tok[0]; otp->tok != NULL; otp++) {
411 if (otp->oui == orgcode) {
412 tok = otp->tok;
413 break;
414 }
415 }
416 return (tok);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800417}
418
419int
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700420snap_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen,
421 const struct lladdr_info *src, const struct lladdr_info *dst,
422 u_int bridge_pad)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800423{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700424 uint32_t orgcode;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800425 register u_short et;
426 register int ret;
427
Elliott Hughes892a68b2015-10-19 14:43:53 -0700428 ND_TCHECK2(*p, 5);
429 if (caplen < 5 || length < 5)
430 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800431 orgcode = EXTRACT_24BITS(p);
432 et = EXTRACT_16BITS(p + 3);
433
Elliott Hughes892a68b2015-10-19 14:43:53 -0700434 if (ndo->ndo_eflag) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700435 /*
436 * Somebody's already printed the MAC addresses, if there
437 * are any, so just print the SNAP header, not the MAC
438 * addresses.
439 */
440 ND_PRINT((ndo, "oui %s (0x%06x), %s %s (0x%04x), length %u: ",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800441 tok2str(oui_values, "Unknown", orgcode),
442 orgcode,
443 (orgcode == 0x000000 ? "ethertype" : "pid"),
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700444 tok2str(oui_to_struct_tok(orgcode), "Unknown", et),
445 et, length - 5));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800446 }
447 p += 5;
448 length -= 5;
449 caplen -= 5;
450
451 switch (orgcode) {
452 case OUI_ENCAP_ETHER:
453 case OUI_CISCO_90:
454 /*
455 * This is an encapsulated Ethernet packet,
456 * or a packet bridged by some piece of
457 * Cisco hardware; the protocol ID is
458 * an Ethernet protocol type.
459 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700460 ret = ethertype_print(ndo, et, p, length, caplen, src, dst);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800461 if (ret)
462 return (ret);
463 break;
464
465 case OUI_APPLETALK:
466 if (et == ETHERTYPE_ATALK) {
467 /*
468 * No, I have no idea why Apple used one
469 * of their own OUIs, rather than
470 * 0x000000, and an Ethernet packet
471 * type, for Appletalk data packets,
472 * but used 0x000000 and an Ethernet
473 * packet type for AARP packets.
474 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700475 ret = ethertype_print(ndo, et, p, length, caplen, src, dst);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800476 if (ret)
477 return (ret);
478 }
479 break;
480
481 case OUI_CISCO:
JP Abgrall53f17a92014-02-12 14:02:41 -0800482 switch (et) {
483 case PID_CISCO_CDP:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700484 cdp_print(ndo, p, length, caplen);
JP Abgrall53f17a92014-02-12 14:02:41 -0800485 return (1);
486 case PID_CISCO_DTP:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700487 dtp_print(ndo, p, length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800488 return (1);
489 case PID_CISCO_UDLD:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700490 udld_print(ndo, p, length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800491 return (1);
492 case PID_CISCO_VTP:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700493 vtp_print(ndo, p, length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800494 return (1);
495 case PID_CISCO_PVST:
496 case PID_CISCO_VLANBRIDGE:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700497 stp_print(ndo, p, length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800498 return (1);
499 default:
500 break;
501 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700502 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800503
504 case OUI_RFC2684:
505 switch (et) {
506
507 case PID_RFC2684_ETH_FCS:
508 case PID_RFC2684_ETH_NOFCS:
509 /*
510 * XXX - remove the last two bytes for
511 * PID_RFC2684_ETH_FCS?
512 */
513 /*
514 * Skip the padding.
515 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700516 ND_TCHECK2(*p, bridge_pad);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800517 caplen -= bridge_pad;
518 length -= bridge_pad;
519 p += bridge_pad;
520
521 /*
522 * What remains is an Ethernet packet.
523 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700524 ether_print(ndo, p, length, caplen, NULL, NULL);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800525 return (1);
526
527 case PID_RFC2684_802_5_FCS:
528 case PID_RFC2684_802_5_NOFCS:
529 /*
530 * XXX - remove the last two bytes for
531 * PID_RFC2684_ETH_FCS?
532 */
533 /*
534 * Skip the padding, but not the Access
535 * Control field.
536 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700537 ND_TCHECK2(*p, bridge_pad);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800538 caplen -= bridge_pad;
539 length -= bridge_pad;
540 p += bridge_pad;
541
542 /*
543 * What remains is an 802.5 Token Ring
544 * packet.
545 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700546 token_print(ndo, p, length, caplen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800547 return (1);
548
549 case PID_RFC2684_FDDI_FCS:
550 case PID_RFC2684_FDDI_NOFCS:
551 /*
552 * XXX - remove the last two bytes for
553 * PID_RFC2684_ETH_FCS?
554 */
555 /*
556 * Skip the padding.
557 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700558 ND_TCHECK2(*p, bridge_pad + 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800559 caplen -= bridge_pad + 1;
560 length -= bridge_pad + 1;
561 p += bridge_pad + 1;
562
563 /*
564 * What remains is an FDDI packet.
565 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700566 fddi_print(ndo, p, length, caplen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800567 return (1);
568
569 case PID_RFC2684_BPDU:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700570 stp_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800571 return (1);
572 }
573 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700574 if (!ndo->ndo_eflag) {
575 /*
576 * Nobody printed the link-layer addresses, so print them, if
577 * we have any.
578 */
579 if (src != NULL && dst != NULL) {
580 ND_PRINT((ndo, "%s > %s ",
581 (src->addr_string)(ndo, src->addr),
582 (dst->addr_string)(ndo, dst->addr)));
583 }
584 /*
585 * Print the SNAP header, but if the OUI is 000000, don't
586 * bother printing it, and report the PID as being an
587 * ethertype.
588 */
589 if (orgcode == 0x000000) {
590 ND_PRINT((ndo, "SNAP, ethertype %s (0x%04x), length %u: ",
591 tok2str(ethertype_values, "Unknown", et),
592 et, length));
593 } else {
594 ND_PRINT((ndo, "SNAP, oui %s (0x%06x), pid %s (0x%04x), length %u: ",
595 tok2str(oui_values, "Unknown", orgcode),
596 orgcode,
597 tok2str(oui_to_struct_tok(orgcode), "Unknown", et),
598 et, length));
599 }
600 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800601 return (0);
602
603trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700604 ND_PRINT((ndo, "[|snap]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800605 return (1);
606}
607
608
609/*
610 * Local Variables:
611 * c-style: whitesmith
612 * c-basic-offset: 8
613 * End:
614 */