]> The Tcpdump Group git mirrors - tcpdump/blob - print-llc.c
add support for FRF.16 Multilink Frame-Relay (DLT_MFR)
[tcpdump] / print-llc.c
1 /*
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
25 #ifndef lint
26 static const char rcsid[] _U_ =
27 "@(#) $Header: /tcpdump/master/tcpdump/print-llc.c,v 1.69 2005-12-01 18:05:12 hannes Exp $";
28 #endif
29
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34 #include <tcpdump-stdinc.h>
35
36 #include <stdio.h>
37 #include <string.h>
38
39 #include "interface.h"
40 #include "addrtoname.h"
41 #include "extract.h" /* must come after interface.h */
42
43 #include "llc.h"
44 #include "ethertype.h"
45 #include "oui.h"
46
47 static struct tok llc_values[] = {
48 { LLCSAP_NULL, "Null" },
49 { LLCSAP_GLOBAL, "Global" },
50 { LLCSAP_8021B_I, "802.1B I" },
51 { LLCSAP_8021B_G, "802.1B G" },
52 { LLCSAP_IP, "IP" },
53 { LLCSAP_SNA, "SNA" },
54 { LLCSAP_PROWAYNM, "ProWay NM" },
55 { LLCSAP_8021D, "STP" },
56 { LLCSAP_RS511, "RS511" },
57 { LLCSAP_ISO8208, "ISO8208" },
58 { LLCSAP_PROWAY, "ProWay" },
59 { LLCSAP_SNAP, "SNAP" },
60 { LLCSAP_IPX, "IPX" },
61 { LLCSAP_NETBEUI, "NetBeui" },
62 { LLCSAP_ISONS, "OSI" },
63 { 0, NULL },
64 };
65
66 static struct tok llc_cmd_values[] = {
67 { LLC_UI, "ui" },
68 { LLC_TEST, "test" },
69 { LLC_XID, "xid" },
70 { LLC_UA, "ua" },
71 { LLC_DISC, "disc" },
72 { LLC_DM, "dm" },
73 { LLC_SABME, "sabme" },
74 { LLC_FRMR, "frmr" },
75 { 0, NULL }
76 };
77
78 static const struct tok llc_flag_values[] = {
79 { 0, "Command" },
80 { LLC_GSAP, "Response" },
81 { LLC_U_POLL, "Poll" },
82 { LLC_GSAP|LLC_U_POLL, "Final" },
83 { LLC_IS_POLL, "Poll" },
84 { LLC_GSAP|LLC_IS_POLL, "Final" },
85 { 0, NULL }
86 };
87
88
89 static const struct tok llc_ig_flag_values[] = {
90 { 0, "Individual" },
91 { LLC_IG, "Group" },
92 { 0, NULL }
93 };
94
95
96 static const struct tok llc_supervisory_values[] = {
97 { 0, "Receiver Ready" },
98 { 1, "Receiver not Ready" },
99 { 2, "Reject" },
100 { 0, NULL }
101 };
102
103
104 static const struct tok cisco_values[] = {
105 { PID_CISCO_CDP, "CDP" },
106 { 0, NULL }
107 };
108
109 static const struct tok bridged_values[] = {
110 { PID_RFC2684_ETH_FCS, "Ethernet + FCS" },
111 { PID_RFC2684_ETH_NOFCS, "Ethernet w/o FCS" },
112 { PID_RFC2684_802_4_FCS, "802.4 + FCS" },
113 { PID_RFC2684_802_4_NOFCS, "802.4 w/o FCS" },
114 { PID_RFC2684_802_5_FCS, "Token Ring + FCS" },
115 { PID_RFC2684_802_5_NOFCS, "Token Ring w/o FCS" },
116 { PID_RFC2684_FDDI_FCS, "FDDI + FCS" },
117 { PID_RFC2684_FDDI_NOFCS, "FDDI w/o FCS" },
118 { PID_RFC2684_802_6_FCS, "802.6 + FCS" },
119 { PID_RFC2684_802_6_NOFCS, "802.6 w/o FCS" },
120 { PID_RFC2684_BPDU, "BPDU" },
121 { 0, NULL },
122 };
123
124 struct oui_tok {
125 u_int32_t oui;
126 const struct tok *tok;
127 };
128
129 static const struct oui_tok oui_to_tok[] = {
130 { OUI_ENCAP_ETHER, ethertype_values },
131 { OUI_CISCO_90, ethertype_values }, /* uses some Ethertype values */
132 { OUI_APPLETALK, ethertype_values }, /* uses some Ethertype values */
133 { OUI_CISCO, cisco_values },
134 { OUI_RFC2684, bridged_values }, /* bridged, RFC 2427 FR or RFC 2864 ATM */
135 { 0, NULL }
136 };
137
138 /*
139 * Returns non-zero IFF it succeeds in printing the header
140 */
141 int
142 llc_print(const u_char *p, u_int length, u_int caplen,
143 const u_char *esrc, const u_char *edst, u_short *extracted_ethertype)
144 {
145 u_int8_t dsap_field, dsap, ssap_field, ssap;
146 u_int16_t control;
147 int is_u;
148 register int ret;
149
150 *extracted_ethertype = 0;
151
152 if (caplen < 3) {
153 (void)printf("[|llc]");
154 default_print((u_char *)p, caplen);
155 return(0);
156 }
157
158 dsap_field = *p;
159 ssap_field = *(p + 1);
160
161 /*
162 * OK, what type of LLC frame is this? The length
163 * of the control field depends on that - I frames
164 * have a two-byte control field, and U frames have
165 * a one-byte control field.
166 */
167 control = *(p + 2);
168 if ((control & LLC_U_FMT) == LLC_U_FMT) {
169 /*
170 * U frame.
171 */
172 is_u = 1;
173 } else {
174 /*
175 * The control field in I and S frames is
176 * 2 bytes...
177 */
178 if (caplen < 4) {
179 (void)printf("[|llc]");
180 default_print((u_char *)p, caplen);
181 return(0);
182 }
183
184 /*
185 * ...and is little-endian.
186 */
187 control = EXTRACT_LE_16BITS(p + 2);
188 is_u = 0;
189 }
190
191 if (ssap_field == LLCSAP_GLOBAL && dsap_field == LLCSAP_GLOBAL) {
192 /*
193 * This is an Ethernet_802.3 IPX frame; it has an
194 * 802.3 header (i.e., an Ethernet header where the
195 * type/length field is <= ETHERMTU, i.e. it's a length
196 * field, not a type field), but has no 802.2 header -
197 * the IPX packet starts right after the Ethernet header,
198 * with a signature of two bytes of 0xFF (which is
199 * LLCSAP_GLOBAL).
200 *
201 * (It might also have been an Ethernet_802.3 IPX at
202 * one time, but got bridged onto another network,
203 * such as an 802.11 network; this has appeared in at
204 * least one capture file.)
205 */
206
207 if (eflag)
208 printf("IPX 802.3: ");
209
210 ipx_print(p, length);
211 return (1);
212 }
213
214 dsap = dsap_field & ~LLC_IG;
215 ssap = ssap_field & ~LLC_GSAP;
216
217 if (eflag) {
218 printf("LLC, dsap %s (0x%02x) %s, ssap %s (0x%02x) %s",
219 tok2str(llc_values, "Unknown", dsap),
220 dsap,
221 tok2str(llc_ig_flag_values, "Unknown", dsap_field & LLC_IG),
222 tok2str(llc_values, "Unknown", ssap),
223 ssap,
224 tok2str(llc_flag_values, "Unknown", ssap_field & LLC_GSAP));
225
226 if (is_u) {
227 printf(", ctrl 0x%02x: ", control);
228 } else {
229 printf(", ctrl 0x%04x: ", control);
230 }
231 }
232
233 if (ssap == LLCSAP_8021D && dsap == LLCSAP_8021D &&
234 control == LLC_UI) {
235 stp_print(p+3, length-3);
236 return (1);
237 }
238
239 if (ssap == LLCSAP_IP && dsap == LLCSAP_IP &&
240 control == LLC_UI) {
241 ip_print(gndo, p+4, length-4);
242 return (1);
243 }
244
245 if (ssap == LLCSAP_IPX && dsap == LLCSAP_IPX &&
246 control == LLC_UI) {
247 /*
248 * This is an Ethernet_802.2 IPX frame, with an 802.3
249 * header and an 802.2 LLC header with the source and
250 * destination SAPs being the IPX SAP.
251 *
252 * Skip DSAP, LSAP, and control field.
253 */
254 if (eflag)
255 printf("IPX 802.2: ");
256
257 ipx_print(p+3, length-3);
258 return (1);
259 }
260
261 #ifdef TCPDUMP_DO_SMB
262 if (ssap == LLCSAP_NETBEUI && dsap == LLCSAP_NETBEUI
263 && (!(control & LLC_S_FMT) || control == LLC_U_FMT)) {
264 /*
265 * we don't actually have a full netbeui parser yet, but the
266 * smb parser can handle many smb-in-netbeui packets, which
267 * is very useful, so we call that
268 *
269 * We don't call it for S frames, however, just I frames
270 * (which are frames that don't have the low-order bit,
271 * LLC_S_FMT, set in the first byte of the control field)
272 * and UI frames (whose control field is just 3, LLC_U_FMT).
273 */
274
275 /*
276 * Skip the LLC header.
277 */
278 if (is_u) {
279 p += 3;
280 length -= 3;
281 caplen -= 3;
282 } else {
283 p += 4;
284 length -= 4;
285 caplen -= 4;
286 }
287 netbeui_print(control, p, length);
288 return (1);
289 }
290 #endif
291 if (ssap == LLCSAP_ISONS && dsap == LLCSAP_ISONS
292 && control == LLC_UI) {
293 isoclns_print(p + 3, length - 3, caplen - 3);
294 return (1);
295 }
296
297 if (ssap == LLCSAP_SNAP && dsap == LLCSAP_SNAP
298 && control == LLC_UI) {
299 /*
300 * XXX - what *is* the right bridge pad value here?
301 * Does anybody ever bridge one form of LAN traffic
302 * over a networking type that uses 802.2 LLC?
303 */
304 ret = snap_print(p+3, length-3, caplen-3, extracted_ethertype,
305 2);
306 if (ret)
307 return (ret);
308 }
309
310 if (!eflag) {
311 if (ssap == dsap) {
312 if (esrc == NULL || edst == NULL)
313 (void)printf("%s ", tok2str(llc_values, "Unknown DSAP 0x%02x", dsap));
314 else
315 (void)printf("%s > %s %s ",
316 etheraddr_string(esrc),
317 etheraddr_string(edst),
318 tok2str(llc_values, "Unknown DSAP 0x%02x", dsap));
319 } else {
320 if (esrc == NULL || edst == NULL)
321 (void)printf("%s > %s ",
322 tok2str(llc_values, "Unknown SSAP 0x%02x", ssap),
323 tok2str(llc_values, "Unknown DSAP 0x%02x", dsap));
324 else
325 (void)printf("%s %s > %s %s ",
326 etheraddr_string(esrc),
327 tok2str(llc_values, "Unknown SSAP 0x%02x", ssap),
328 etheraddr_string(edst),
329 tok2str(llc_values, "Unknown DSAP 0x%02x", dsap));
330 }
331 }
332
333 if (is_u) {
334 printf("Unnumbered, %s, Flags [%s], length %u",
335 tok2str(llc_cmd_values, "%02x", LLC_U_CMD(control)),
336 tok2str(llc_flag_values,"?",(ssap_field & LLC_GSAP) | (control & LLC_U_POLL)),
337 length);
338
339 p += 3;
340 length -= 3;
341 caplen -= 3;
342
343 if ((control & ~LLC_U_POLL) == LLC_XID) {
344 if (*p == LLC_XID_FI) {
345 printf(": %02x %02x", p[1], p[2]);
346 p += 3;
347 length -= 3;
348 caplen -= 3;
349 }
350 }
351 } else {
352 if ((control & LLC_S_FMT) == LLC_S_FMT) {
353 (void)printf("Supervisory, %s, rcv seq %u, Flags [%s], length %u",
354 tok2str(llc_supervisory_values,"?",LLC_S_CMD(control)),
355 LLC_IS_NR(control),
356 tok2str(llc_flag_values,"?",(ssap_field & LLC_GSAP) | (control & LLC_IS_POLL)),
357 length);
358 } else {
359 (void)printf("Information, send seq %u, rcv seq %u, Flags [%s], length %u",
360 LLC_I_NS(control),
361 LLC_IS_NR(control),
362 tok2str(llc_flag_values,"?",(ssap_field & LLC_GSAP) | (control & LLC_IS_POLL)),
363 length);
364 }
365 p += 4;
366 length -= 4;
367 caplen -= 4;
368 }
369 return(1);
370 }
371
372 int
373 snap_print(const u_char *p, u_int length, u_int caplen,
374 u_short *extracted_ethertype, u_int bridge_pad)
375 {
376 u_int32_t orgcode;
377 register u_short et;
378 register int ret;
379
380 TCHECK2(*p, 5);
381 orgcode = EXTRACT_24BITS(p);
382 et = EXTRACT_16BITS(p + 3);
383
384 if (eflag) {
385 const struct tok *tok = NULL;
386 const struct oui_tok *otp;
387
388 for (otp = &oui_to_tok[0]; otp->tok != NULL; otp++) {
389 if (otp->oui == orgcode) {
390 tok = otp->tok;
391 break;
392 }
393 }
394 (void)printf("oui %s (0x%06x), %s %s (0x%04x): ",
395 tok2str(oui_values, "Unknown", orgcode),
396 orgcode,
397 (orgcode == 0x000000 ? "ethertype" : "pid"),
398 tok2str(tok, "Unknown", et),
399 et);
400 }
401 p += 5;
402 length -= 5;
403 caplen -= 5;
404
405 switch (orgcode) {
406 case OUI_ENCAP_ETHER:
407 case OUI_CISCO_90:
408 /*
409 * This is an encapsulated Ethernet packet,
410 * or a packet bridged by some piece of
411 * Cisco hardware; the protocol ID is
412 * an Ethernet protocol type.
413 */
414 ret = ether_encap_print(et, p, length, caplen,
415 extracted_ethertype);
416 if (ret)
417 return (ret);
418 break;
419
420 case OUI_APPLETALK:
421 if (et == ETHERTYPE_ATALK) {
422 /*
423 * No, I have no idea why Apple used one
424 * of their own OUIs, rather than
425 * 0x000000, and an Ethernet packet
426 * type, for Appletalk data packets,
427 * but used 0x000000 and an Ethernet
428 * packet type for AARP packets.
429 */
430 ret = ether_encap_print(et, p, length, caplen,
431 extracted_ethertype);
432 if (ret)
433 return (ret);
434 }
435 break;
436
437 case OUI_CISCO:
438 if (et == PID_CISCO_CDP) {
439 cdp_print(p, length, caplen);
440 return (1);
441 }
442 break;
443
444 case OUI_RFC2684:
445 switch (et) {
446
447 case PID_RFC2684_ETH_FCS:
448 case PID_RFC2684_ETH_NOFCS:
449 /*
450 * XXX - remove the last two bytes for
451 * PID_RFC2684_ETH_FCS?
452 */
453 /*
454 * Skip the padding.
455 */
456 TCHECK2(*p, bridge_pad);
457 caplen -= bridge_pad;
458 length -= bridge_pad;
459 p += bridge_pad;
460
461 /*
462 * What remains is an Ethernet packet.
463 */
464 ether_print(p, length, caplen);
465 return (1);
466
467 case PID_RFC2684_802_5_FCS:
468 case PID_RFC2684_802_5_NOFCS:
469 /*
470 * XXX - remove the last two bytes for
471 * PID_RFC2684_ETH_FCS?
472 */
473 /*
474 * Skip the padding, but not the Access
475 * Control field.
476 */
477 TCHECK2(*p, bridge_pad);
478 caplen -= bridge_pad;
479 length -= bridge_pad;
480 p += bridge_pad;
481
482 /*
483 * What remains is an 802.5 Token Ring
484 * packet.
485 */
486 token_print(p, length, caplen);
487 return (1);
488
489 case PID_RFC2684_FDDI_FCS:
490 case PID_RFC2684_FDDI_NOFCS:
491 /*
492 * XXX - remove the last two bytes for
493 * PID_RFC2684_ETH_FCS?
494 */
495 /*
496 * Skip the padding.
497 */
498 TCHECK2(*p, bridge_pad + 1);
499 caplen -= bridge_pad + 1;
500 length -= bridge_pad + 1;
501 p += bridge_pad + 1;
502
503 /*
504 * What remains is an FDDI packet.
505 */
506 fddi_print(p, length, caplen);
507 return (1);
508
509 case PID_RFC2684_BPDU:
510 stp_print(p, length);
511 return (1);
512 }
513 }
514 return (0);
515
516 trunc:
517 (void)printf("[|snap]");
518 return (1);
519 }
520
521
522 /*
523 * Local Variables:
524 * c-style: whitesmith
525 * c-basic-offset: 8
526 * End:
527 */