Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / tcpdump / print-llc.c
blobc3f65b9d576c05d0c241a45868312a2203d73412
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 * Code by Matt Thomas, Digital Equipment Corporation
24 * with an awful lot of hacking by Jeffrey Mogul, DECWRL
27 #include <sys/cdefs.h>
28 #ifndef lint
29 #if 0
30 static const char rcsid[] _U_ =
31 "@(#) Header: /tcpdump/master/tcpdump/print-llc.c,v 1.61.2.10 2007/02/08 07:07:51 guy Exp";
32 #else
33 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
34 #endif
35 #endif
37 #ifdef HAVE_CONFIG_H
38 #include "config.h"
39 #endif
41 #include <tcpdump-stdinc.h>
43 #include <stdio.h>
44 #include <string.h>
46 #include "interface.h"
47 #include "addrtoname.h"
48 #include "extract.h" /* must come after interface.h */
50 #include "llc.h"
51 #include "ethertype.h"
52 #include "oui.h"
54 static struct tok llc_values[] = {
55 { LLCSAP_NULL, "Null" },
56 { LLCSAP_GLOBAL, "Global" },
57 { LLCSAP_8021B_I, "802.1B I" },
58 { LLCSAP_8021B_G, "802.1B G" },
59 { LLCSAP_IP, "IP" },
60 { LLCSAP_SNA, "SNA" },
61 { LLCSAP_PROWAYNM, "ProWay NM" },
62 { LLCSAP_8021D, "STP" },
63 { LLCSAP_RS511, "RS511" },
64 { LLCSAP_ISO8208, "ISO8208" },
65 { LLCSAP_PROWAY, "ProWay" },
66 { LLCSAP_SNAP, "SNAP" },
67 { LLCSAP_IPX, "IPX" },
68 { LLCSAP_NETBEUI, "NetBeui" },
69 { LLCSAP_ISONS, "OSI" },
70 { 0, NULL },
73 static struct tok llc_cmd_values[] = {
74 { LLC_UI, "ui" },
75 { LLC_TEST, "test" },
76 { LLC_XID, "xid" },
77 { LLC_UA, "ua" },
78 { LLC_DISC, "disc" },
79 { LLC_DM, "dm" },
80 { LLC_SABME, "sabme" },
81 { LLC_FRMR, "frmr" },
82 { 0, NULL }
85 static const struct tok llc_flag_values[] = {
86 { 0, "Command" },
87 { LLC_GSAP, "Response" },
88 { LLC_U_POLL, "Poll" },
89 { LLC_GSAP|LLC_U_POLL, "Final" },
90 { LLC_IS_POLL, "Poll" },
91 { LLC_GSAP|LLC_IS_POLL, "Final" },
92 { 0, NULL }
96 static const struct tok llc_ig_flag_values[] = {
97 { 0, "Individual" },
98 { LLC_IG, "Group" },
99 { 0, NULL }
103 static const struct tok llc_supervisory_values[] = {
104 { 0, "Receiver Ready" },
105 { 1, "Receiver not Ready" },
106 { 2, "Reject" },
107 { 0, NULL }
111 static const struct tok cisco_values[] = {
112 { PID_CISCO_CDP, "CDP" },
113 { PID_CISCO_VTP, "VTP" },
114 { PID_CISCO_DTP, "DTP" },
115 { 0, NULL }
118 static const struct tok bridged_values[] = {
119 { PID_RFC2684_ETH_FCS, "Ethernet + FCS" },
120 { PID_RFC2684_ETH_NOFCS, "Ethernet w/o FCS" },
121 { PID_RFC2684_802_4_FCS, "802.4 + FCS" },
122 { PID_RFC2684_802_4_NOFCS, "802.4 w/o FCS" },
123 { PID_RFC2684_802_5_FCS, "Token Ring + FCS" },
124 { PID_RFC2684_802_5_NOFCS, "Token Ring w/o FCS" },
125 { PID_RFC2684_FDDI_FCS, "FDDI + FCS" },
126 { PID_RFC2684_FDDI_NOFCS, "FDDI w/o FCS" },
127 { PID_RFC2684_802_6_FCS, "802.6 + FCS" },
128 { PID_RFC2684_802_6_NOFCS, "802.6 w/o FCS" },
129 { PID_RFC2684_BPDU, "BPDU" },
130 { 0, NULL },
133 static const struct tok null_values[] = {
134 { 0, NULL }
137 struct oui_tok {
138 u_int32_t oui;
139 const struct tok *tok;
142 static const struct oui_tok oui_to_tok[] = {
143 { OUI_ENCAP_ETHER, ethertype_values },
144 { OUI_CISCO_90, ethertype_values }, /* uses some Ethertype values */
145 { OUI_APPLETALK, ethertype_values }, /* uses some Ethertype values */
146 { OUI_CISCO, cisco_values },
147 { OUI_RFC2684, bridged_values }, /* bridged, RFC 2427 FR or RFC 2864 ATM */
148 { 0, NULL }
152 * Returns non-zero IFF it succeeds in printing the header
155 llc_print(const u_char *p, u_int length, u_int caplen,
156 const u_char *esrc, const u_char *edst, u_short *extracted_ethertype)
158 u_int8_t dsap_field, dsap, ssap_field, ssap;
159 u_int16_t control;
160 int is_u;
161 register int ret;
163 *extracted_ethertype = 0;
165 if (caplen < 3) {
166 (void)printf("[|llc]");
167 default_print((u_char *)p, caplen);
168 return(0);
171 dsap_field = *p;
172 ssap_field = *(p + 1);
175 * OK, what type of LLC frame is this? The length
176 * of the control field depends on that - I frames
177 * have a two-byte control field, and U frames have
178 * a one-byte control field.
180 control = *(p + 2);
181 if ((control & LLC_U_FMT) == LLC_U_FMT) {
183 * U frame.
185 is_u = 1;
186 } else {
188 * The control field in I and S frames is
189 * 2 bytes...
191 if (caplen < 4) {
192 (void)printf("[|llc]");
193 default_print((u_char *)p, caplen);
194 return(0);
198 * ...and is little-endian.
200 control = EXTRACT_LE_16BITS(p + 2);
201 is_u = 0;
204 if (ssap_field == LLCSAP_GLOBAL && dsap_field == LLCSAP_GLOBAL) {
206 * This is an Ethernet_802.3 IPX frame; it has an
207 * 802.3 header (i.e., an Ethernet header where the
208 * type/length field is <= ETHERMTU, i.e. it's a length
209 * field, not a type field), but has no 802.2 header -
210 * the IPX packet starts right after the Ethernet header,
211 * with a signature of two bytes of 0xFF (which is
212 * LLCSAP_GLOBAL).
214 * (It might also have been an Ethernet_802.3 IPX at
215 * one time, but got bridged onto another network,
216 * such as an 802.11 network; this has appeared in at
217 * least one capture file.)
220 if (eflag)
221 printf("IPX 802.3: ");
223 ipx_print(p, length);
224 return (1);
227 dsap = dsap_field & ~LLC_IG;
228 ssap = ssap_field & ~LLC_GSAP;
230 if (eflag) {
231 printf("LLC, dsap %s (0x%02x) %s, ssap %s (0x%02x) %s",
232 tok2str(llc_values, "Unknown", dsap),
233 dsap,
234 tok2str(llc_ig_flag_values, "Unknown", dsap_field & LLC_IG),
235 tok2str(llc_values, "Unknown", ssap),
236 ssap,
237 tok2str(llc_flag_values, "Unknown", ssap_field & LLC_GSAP));
239 if (is_u) {
240 printf(", ctrl 0x%02x: ", control);
241 } else {
242 printf(", ctrl 0x%04x: ", control);
246 if (ssap == LLCSAP_8021D && dsap == LLCSAP_8021D &&
247 control == LLC_UI) {
248 stp_print(p+3, length-3);
249 return (1);
252 if (ssap == LLCSAP_IP && dsap == LLCSAP_IP &&
253 control == LLC_UI) {
254 ip_print(gndo, p+4, length-4);
255 return (1);
258 if (ssap == LLCSAP_IPX && dsap == LLCSAP_IPX &&
259 control == LLC_UI) {
261 * This is an Ethernet_802.2 IPX frame, with an 802.3
262 * header and an 802.2 LLC header with the source and
263 * destination SAPs being the IPX SAP.
265 * Skip DSAP, LSAP, and control field.
267 if (eflag)
268 printf("IPX 802.2: ");
270 ipx_print(p+3, length-3);
271 return (1);
274 #ifdef TCPDUMP_DO_SMB
275 if (ssap == LLCSAP_NETBEUI && dsap == LLCSAP_NETBEUI
276 && (!(control & LLC_S_FMT) || control == LLC_U_FMT)) {
278 * we don't actually have a full netbeui parser yet, but the
279 * smb parser can handle many smb-in-netbeui packets, which
280 * is very useful, so we call that
282 * We don't call it for S frames, however, just I frames
283 * (which are frames that don't have the low-order bit,
284 * LLC_S_FMT, set in the first byte of the control field)
285 * and UI frames (whose control field is just 3, LLC_U_FMT).
289 * Skip the LLC header.
291 if (is_u) {
292 p += 3;
293 length -= 3;
294 caplen -= 3;
295 } else {
296 p += 4;
297 length -= 4;
298 caplen -= 4;
300 netbeui_print(control, p, length);
301 return (1);
303 #endif
304 if (ssap == LLCSAP_ISONS && dsap == LLCSAP_ISONS
305 && control == LLC_UI) {
306 isoclns_print(p + 3, length - 3, caplen - 3);
307 return (1);
310 if (ssap == LLCSAP_SNAP && dsap == LLCSAP_SNAP
311 && control == LLC_UI) {
313 * XXX - what *is* the right bridge pad value here?
314 * Does anybody ever bridge one form of LAN traffic
315 * over a networking type that uses 802.2 LLC?
317 ret = snap_print(p+3, length-3, caplen-3, extracted_ethertype,
319 if (ret)
320 return (ret);
323 if (!eflag) {
324 if (ssap == dsap) {
325 if (esrc == NULL || edst == NULL)
326 (void)printf("%s ", tok2str(llc_values, "Unknown DSAP 0x%02x", dsap));
327 else
328 (void)printf("%s > %s %s ",
329 etheraddr_string(esrc),
330 etheraddr_string(edst),
331 tok2str(llc_values, "Unknown DSAP 0x%02x", dsap));
332 } else {
333 if (esrc == NULL || edst == NULL)
334 (void)printf("%s > %s ",
335 tok2str(llc_values, "Unknown SSAP 0x%02x", ssap),
336 tok2str(llc_values, "Unknown DSAP 0x%02x", dsap));
337 else
338 (void)printf("%s %s > %s %s ",
339 etheraddr_string(esrc),
340 tok2str(llc_values, "Unknown SSAP 0x%02x", ssap),
341 etheraddr_string(edst),
342 tok2str(llc_values, "Unknown DSAP 0x%02x", dsap));
346 if (is_u) {
347 printf("Unnumbered, %s, Flags [%s], length %u",
348 tok2str(llc_cmd_values, "%02x", LLC_U_CMD(control)),
349 tok2str(llc_flag_values,"?",(ssap_field & LLC_GSAP) | (control & LLC_U_POLL)),
350 length);
352 p += 3;
353 length -= 3;
354 caplen -= 3;
356 if ((control & ~LLC_U_POLL) == LLC_XID) {
357 if (*p == LLC_XID_FI) {
358 printf(": %02x %02x", p[1], p[2]);
359 p += 3;
360 length -= 3;
361 caplen -= 3;
364 } else {
365 if ((control & LLC_S_FMT) == LLC_S_FMT) {
366 (void)printf("Supervisory, %s, rcv seq %u, Flags [%s], length %u",
367 tok2str(llc_supervisory_values,"?",LLC_S_CMD(control)),
368 LLC_IS_NR(control),
369 tok2str(llc_flag_values,"?",(ssap_field & LLC_GSAP) | (control & LLC_IS_POLL)),
370 length);
371 } else {
372 (void)printf("Information, send seq %u, rcv seq %u, Flags [%s], length %u",
373 LLC_I_NS(control),
374 LLC_IS_NR(control),
375 tok2str(llc_flag_values,"?",(ssap_field & LLC_GSAP) | (control & LLC_IS_POLL)),
376 length);
378 p += 4;
379 length -= 4;
380 caplen -= 4;
382 return(1);
386 snap_print(const u_char *p, u_int length, u_int caplen,
387 u_short *extracted_ethertype, u_int bridge_pad)
389 u_int32_t orgcode;
390 register u_short et;
391 register int ret;
393 TCHECK2(*p, 5);
394 orgcode = EXTRACT_24BITS(p);
395 et = EXTRACT_16BITS(p + 3);
397 if (eflag) {
398 const struct tok *tok = null_values;
399 const struct oui_tok *otp;
401 for (otp = &oui_to_tok[0]; otp->tok != NULL; otp++) {
402 if (otp->oui == orgcode) {
403 tok = otp->tok;
404 break;
407 (void)printf("oui %s (0x%06x), %s %s (0x%04x): ",
408 tok2str(oui_values, "Unknown", orgcode),
409 orgcode,
410 (orgcode == 0x000000 ? "ethertype" : "pid"),
411 tok2str(tok, "Unknown", et),
412 et);
414 p += 5;
415 length -= 5;
416 caplen -= 5;
418 switch (orgcode) {
419 case OUI_ENCAP_ETHER:
420 case OUI_CISCO_90:
422 * This is an encapsulated Ethernet packet,
423 * or a packet bridged by some piece of
424 * Cisco hardware; the protocol ID is
425 * an Ethernet protocol type.
427 ret = ether_encap_print(et, p, length, caplen,
428 extracted_ethertype);
429 if (ret)
430 return (ret);
431 break;
433 case OUI_APPLETALK:
434 if (et == ETHERTYPE_ATALK) {
436 * No, I have no idea why Apple used one
437 * of their own OUIs, rather than
438 * 0x000000, and an Ethernet packet
439 * type, for Appletalk data packets,
440 * but used 0x000000 and an Ethernet
441 * packet type for AARP packets.
443 ret = ether_encap_print(et, p, length, caplen,
444 extracted_ethertype);
445 if (ret)
446 return (ret);
448 break;
450 case OUI_CISCO:
451 if (et == PID_CISCO_CDP) {
452 cdp_print(p, length, caplen);
453 return (1);
455 break;
457 case OUI_RFC2684:
458 switch (et) {
460 case PID_RFC2684_ETH_FCS:
461 case PID_RFC2684_ETH_NOFCS:
463 * XXX - remove the last two bytes for
464 * PID_RFC2684_ETH_FCS?
467 * Skip the padding.
469 TCHECK2(*p, bridge_pad);
470 caplen -= bridge_pad;
471 length -= bridge_pad;
472 p += bridge_pad;
475 * What remains is an Ethernet packet.
477 ether_print(p, length, caplen);
478 return (1);
480 case PID_RFC2684_802_5_FCS:
481 case PID_RFC2684_802_5_NOFCS:
483 * XXX - remove the last two bytes for
484 * PID_RFC2684_ETH_FCS?
487 * Skip the padding, but not the Access
488 * Control field.
490 TCHECK2(*p, bridge_pad);
491 caplen -= bridge_pad;
492 length -= bridge_pad;
493 p += bridge_pad;
496 * What remains is an 802.5 Token Ring
497 * packet.
499 token_print(p, length, caplen);
500 return (1);
502 case PID_RFC2684_FDDI_FCS:
503 case PID_RFC2684_FDDI_NOFCS:
505 * XXX - remove the last two bytes for
506 * PID_RFC2684_ETH_FCS?
509 * Skip the padding.
511 TCHECK2(*p, bridge_pad + 1);
512 caplen -= bridge_pad + 1;
513 length -= bridge_pad + 1;
514 p += bridge_pad + 1;
517 * What remains is an FDDI packet.
519 fddi_print(p, length, caplen);
520 return (1);
522 case PID_RFC2684_BPDU:
523 stp_print(p, length);
524 return (1);
527 return (0);
529 trunc:
530 (void)printf("[|snap]");
531 return (1);
536 * Local Variables:
537 * c-style: whitesmith
538 * c-basic-offset: 8
539 * End: