]> The Tcpdump Group git mirrors - tcpdump/blob - print-ppp.c
display cosmetics: remove the PPP- string from proto output
[tcpdump] / print-ppp.c
1 /*
2 * Copyright (c) 1990, 1991, 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 * Extensively modified by Motonori Shindo (mshindo@mshindo.net) for more
22 * complete PPP support.
23 */
24
25 /*
26 * TODO:
27 * o resolve XXX as much as possible
28 * o MP support
29 * o BAP support
30 */
31
32 #ifndef lint
33 static const char rcsid[] _U_ =
34 "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.93 2004-03-18 10:59:15 hannes Exp $ (LBL)";
35 #endif
36
37 #ifdef HAVE_CONFIG_H
38 #include "config.h"
39 #endif
40
41 #include <tcpdump-stdinc.h>
42
43 #ifdef __bsdi__
44 #include <net/slcompress.h>
45 #include <net/if_ppp.h>
46 #endif
47
48 #include <pcap.h>
49 #include <stdio.h>
50
51 #include "interface.h"
52 #include "extract.h"
53 #include "addrtoname.h"
54 #include "ppp.h"
55 #include "chdlc.h"
56 #include "ethertype.h"
57 #include "oui.h"
58
59 /*
60 * The following constatns are defined by IANA. Please refer to
61 * http://www.isi.edu/in-notes/iana/assignments/ppp-numbers
62 * for the up-to-date information.
63 */
64
65 /* Protocol Codes defined in ppp.h */
66
67 struct tok ppptype2str[] = {
68 { PPP_IP, "IP" },
69 { PPP_OSI, "OSI" },
70 { PPP_NS, "NS" },
71 { PPP_DECNET, "DECNET" },
72 { PPP_APPLE, "APPLE" },
73 { PPP_IPX, "IPX" },
74 { PPP_VJC, "VJC" },
75 { PPP_VJNC, "VJNC" },
76 { PPP_BRPDU, "BRPDU" },
77 { PPP_STII, "STII" },
78 { PPP_VINES, "VINES" },
79 { PPP_MPLS_UCAST, "MPLS" },
80 { PPP_MPLS_MCAST, "MPLS" },
81
82 { PPP_HELLO, "HELLO" },
83 { PPP_LUXCOM, "LUXCOM" },
84 { PPP_SNS, "SNS" },
85 { PPP_IPCP, "IPCP" },
86 { PPP_OSICP, "OSICP" },
87 { PPP_NSCP, "NSCP" },
88 { PPP_DECNETCP, "DECNETCP" },
89 { PPP_APPLECP, "APPLECP" },
90 { PPP_IPXCP, "IPXCP" },
91 { PPP_STIICP, "STIICP" },
92 { PPP_VINESCP, "VINESCP" },
93 { PPP_MPLSCP, "MPLSCP" },
94
95 { PPP_LCP, "LCP" },
96 { PPP_PAP, "PAP" },
97 { PPP_LQM, "LQM" },
98 { PPP_CHAP, "CHAP" },
99 { PPP_BACP, "BACP" },
100 { PPP_BAP, "BAP" },
101 { PPP_MP, "ML" },
102 { 0, NULL }
103 };
104
105 /* Control Protocols (LCP/IPCP/CCP etc.) Codes defined in RFC 1661 */
106
107 #define CPCODES_VEXT 0 /* Vendor-Specific (RFC2153) */
108 #define CPCODES_CONF_REQ 1 /* Configure-Request */
109 #define CPCODES_CONF_ACK 2 /* Configure-Ack */
110 #define CPCODES_CONF_NAK 3 /* Configure-Nak */
111 #define CPCODES_CONF_REJ 4 /* Configure-Reject */
112 #define CPCODES_TERM_REQ 5 /* Terminate-Request */
113 #define CPCODES_TERM_ACK 6 /* Terminate-Ack */
114 #define CPCODES_CODE_REJ 7 /* Code-Reject */
115 #define CPCODES_PROT_REJ 8 /* Protocol-Reject (LCP only) */
116 #define CPCODES_ECHO_REQ 9 /* Echo-Request (LCP only) */
117 #define CPCODES_ECHO_RPL 10 /* Echo-Reply (LCP only) */
118 #define CPCODES_DISC_REQ 11 /* Discard-Request (LCP only) */
119 #define CPCODES_ID 12 /* Identification (LCP only) RFC1570 */
120 #define CPCODES_TIME_REM 13 /* Time-Remaining (LCP only) RFC1570 */
121 #define CPCODES_RESET_REQ 14 /* Reset-Request (CCP only) RFC1962 */
122 #define CPCODES_RESET_REP 15 /* Reset-Reply (CCP only) */
123
124 struct tok cpcodes[] = {
125 {CPCODES_VEXT, "Vendor-Extension"}, /* RFC2153 */
126 {CPCODES_CONF_REQ, "Conf-Request"},
127 {CPCODES_CONF_ACK, "Conf-Ack"},
128 {CPCODES_CONF_NAK, "Conf-Nack"},
129 {CPCODES_CONF_REJ, "Conf-Reject"},
130 {CPCODES_TERM_REQ, "Term-Request"},
131 {CPCODES_TERM_ACK, "Term-Ack"},
132 {CPCODES_CODE_REJ, "Code-Reject"},
133 {CPCODES_PROT_REJ, "Prot-Reject"},
134 {CPCODES_ECHO_REQ, "Echo-Request"},
135 {CPCODES_ECHO_RPL, "Echo-Reply"},
136 {CPCODES_DISC_REQ, "Disc-Req"},
137 {CPCODES_ID, "Ident"}, /* RFC1570 */
138 {CPCODES_TIME_REM, "Time-Rem"}, /* RFC1570 */
139 {CPCODES_RESET_REQ, "Reset-Req"}, /* RFC1962 */
140 {CPCODES_RESET_REP, "Reset-Ack"}, /* RFC1962 */
141 {0, NULL}
142 };
143
144 /* LCP Config Options */
145
146 #define LCPOPT_VEXT 0
147 #define LCPOPT_MRU 1
148 #define LCPOPT_ACCM 2
149 #define LCPOPT_AP 3
150 #define LCPOPT_QP 4
151 #define LCPOPT_MN 5
152 #define LCPOPT_DEP6 6
153 #define LCPOPT_PFC 7
154 #define LCPOPT_ACFC 8
155 #define LCPOPT_FCSALT 9
156 #define LCPOPT_SDP 10
157 #define LCPOPT_NUMMODE 11
158 #define LCPOPT_DEP12 12
159 #define LCPOPT_CBACK 13
160 #define LCPOPT_DEP14 14
161 #define LCPOPT_DEP15 15
162 #define LCPOPT_DEP16 16
163 #define LCPOPT_MLMRRU 17
164 #define LCPOPT_MLSSNHF 18
165 #define LCPOPT_MLED 19
166 #define LCPOPT_PROP 20
167 #define LCPOPT_DCEID 21
168 #define LCPOPT_MPP 22
169 #define LCPOPT_LD 23
170 #define LCPOPT_LCPAOPT 24
171 #define LCPOPT_COBS 25
172 #define LCPOPT_PE 26
173 #define LCPOPT_MLHF 27
174 #define LCPOPT_I18N 28
175 #define LCPOPT_SDLOS 29
176 #define LCPOPT_PPPMUX 30
177
178 #define LCPOPT_MIN LCPOPT_VEXT
179 #define LCPOPT_MAX LCPOPT_PPPMUX
180
181 static const char *lcpconfopts[] = {
182 "Vend-Ext", /* (0) */
183 "MRU", /* (1) */
184 "ACCM", /* (2) */
185 "Auth-Prot", /* (3) */
186 "Qual-Prot", /* (4) */
187 "Magic-Num", /* (5) */
188 "deprecated(6)", /* used to be a Quality Protocol */
189 "PFC", /* (7) */
190 "ACFC", /* (8) */
191 "FCS-Alt", /* (9) */
192 "SDP", /* (10) */
193 "Num-Mode", /* (11) */
194 "deprecated(12)", /* used to be a Multi-Link-Procedure*/
195 "Call-Back", /* (13) */
196 "deprecated(14)", /* used to be a Connect-Time */
197 "deprecated(15)", /* used to be a Compund-Frames */
198 "deprecated(16)", /* used to be a Nominal-Data-Encap */
199 "MRRU", /* (17) */
200 "SSNHF", /* (18) */
201 "End-Disc", /* (19) */
202 "Proprietary", /* (20) */
203 "DCE-Id", /* (21) */
204 "MP+", /* (22) */
205 "Link-Disc", /* (23) */
206 "LCP-Auth-Opt", /* (24) */
207 "COBS", /* (25) */
208 "Prefix-elision", /* (26) */
209 "Multilink-header-Form",/* (27) */
210 "I18N", /* (28) */
211 "SDL-over-SONET/SDH", /* (29) */
212 "PPP-Muxing", /* (30) */
213 };
214
215 /* IPV6CP - to be supported */
216 /* ECP - to be supported */
217
218 /* CCP Config Options */
219
220 #define CCPOPT_OUI 0 /* RFC1962 */
221 #define CCPOPT_PRED1 1 /* RFC1962 */
222 #define CCPOPT_PRED2 2 /* RFC1962 */
223 #define CCPOPT_PJUMP 3 /* RFC1962 */
224 /* 4-15 unassigned */
225 #define CCPOPT_HPPPC 16 /* RFC1962 */
226 #define CCPOPT_STACLZS 17 /* RFC1974 */
227 #define CCPOPT_MPPC 18 /* RFC2118 */
228 #define CCPOPT_GFZA 19 /* RFC1962 */
229 #define CCPOPT_V42BIS 20 /* RFC1962 */
230 #define CCPOPT_BSDCOMP 21 /* RFC1977 */
231 /* 22 unassigned */
232 #define CCPOPT_LZSDCP 23 /* RFC1967 */
233 #define CCPOPT_MVRCA 24 /* RFC1975 */
234 #define CCPOPT_DEC 25 /* RFC1976 */
235 #define CCPOPT_DEFLATE 26 /* RFC1979 */
236 /* 27-254 unassigned */
237 #define CCPOPT_RESV 255 /* RFC1962 */
238
239 #define CCPOPT_MIN CCPOPT_OUI
240 #define CCPOPT_MAX CCPOPT_DEFLATE /* XXX: should be CCPOPT_RESV but... */
241
242 static const char *ccpconfopts[] = {
243 "OUI", /* (0) */
244 "Pred-1", /* (1) */
245 "Pred-2", /* (2) */
246 "Puddle", /* (3) */
247 "unassigned(4)", /* (4) */
248 "unassigned(5)", /* (5) */
249 "unassigned(6)", /* (6) */
250 "unassigned(7)", /* (7) */
251 "unassigned(8)", /* (8) */
252 "unassigned(9)", /* (9) */
253 "unassigned(10)", /* (10) */
254 "unassigned(11)", /* (11) */
255 "unassigned(12)", /* (12) */
256 "unassigned(13)", /* (13) */
257 "unassigned(14)", /* (14) */
258 "unassigned(15)", /* (15) */
259 "HP-PPC", /* (16) */
260 "Stac-LZS", /* (17) */
261 "MPPC", /* (18) */
262 "Gand-FZA", /* (19) */
263 "V.42bis", /* (20) */
264 "BSD-Comp", /* (21) */
265 "unassigned(22)", /* (22) */
266 "LZS-DCP", /* (23) */
267 "MVRCA", /* (24) */
268 "DEC", /* (25) */
269 "Deflate", /* (26) */
270 };
271
272 /* BACP Config Options */
273
274 #define BACPOPT_FPEER 1 /* RFC2125 */
275
276 /* SDCP - to be supported */
277
278 /* IPCP Config Options */
279
280 #define IPCPOPT_2ADDR 1 /* RFC1172, RFC1332 (deprecated) */
281 #define IPCPOPT_IPCOMP 2 /* RFC1332 */
282 #define IPCPOPT_ADDR 3 /* RFC1332 */
283 #define IPCPOPT_MOBILE4 4 /* RFC2290 */
284
285 #define IPCPOPT_PRIDNS 129 /* RFC1877 */
286 #define IPCPOPT_PRINBNS 130 /* RFC1877 */
287 #define IPCPOPT_SECDNS 131 /* RFC1877 */
288 #define IPCPOPT_SECNBNS 132 /* RFC1877 */
289
290 /* ATCP - to be supported */
291 /* OSINLCP - to be supported */
292 /* BVCP - to be supported */
293 /* BCP - to be supported */
294 /* IPXCP - to be supported */
295 /* MPLSCP - to be supported */
296
297 /* Auth Algorithms */
298
299 /* 0-4 Reserved (RFC1994) */
300 #define AUTHALG_CHAPMD5 5 /* RFC1994 */
301 #define AUTHALG_MSCHAP1 128 /* RFC2433 */
302 #define AUTHALG_MSCHAP2 129 /* RFC2795 */
303
304 /* FCS Alternatives - to be supported */
305
306 /* Multilink Endpoint Discriminator (RFC1717) */
307 #define MEDCLASS_NULL 0 /* Null Class */
308 #define MEDCLASS_LOCAL 1 /* Locally Assigned */
309 #define MEDCLASS_IPV4 2 /* Internet Protocol (IPv4) */
310 #define MEDCLASS_MAC 3 /* IEEE 802.1 global MAC address */
311 #define MEDCLASS_MNB 4 /* PPP Magic Number Block */
312 #define MEDCLASS_PSNDN 5 /* Public Switched Network Director Number */
313
314 /* PPP LCP Callback */
315 #define CALLBACK_AUTH 0 /* Location determined by user auth */
316 #define CALLBACK_DSTR 1 /* Dialing string */
317 #define CALLBACK_LID 2 /* Location identifier */
318 #define CALLBACK_E164 3 /* E.164 number */
319 #define CALLBACK_X500 4 /* X.500 distinguished name */
320 #define CALLBACK_CBCP 6 /* Location is determined during CBCP nego */
321
322 /* CHAP */
323
324 #define CHAP_CHAL 1
325 #define CHAP_RESP 2
326 #define CHAP_SUCC 3
327 #define CHAP_FAIL 4
328
329 #define CHAP_CODEMIN CHAP_CHAL
330 #define CHAP_CODEMAX CHAP_FAIL
331
332 static const char *chapcode[] = {
333 "Chal", /* (1) */
334 "Resp", /* (2) */
335 "Succ", /* (3) */
336 "Fail", /* (4) */
337 };
338
339 /* PAP */
340
341 #define PAP_AREQ 1
342 #define PAP_AACK 2
343 #define PAP_ANAK 3
344
345 #define PAP_CODEMIN PAP_AREQ
346 #define PAP_CODEMAX PAP_ANAK
347
348 static const char *papcode[] = {
349 "Auth-Req", /* (1) */
350 "Auth-Ack", /* (2) */
351 "Auth-Nak", /* (3) */
352 };
353
354 /* BAP */
355 #define BAP_CALLREQ 1
356 #define BAP_CALLRES 2
357 #define BAP_CBREQ 3
358 #define BAP_CBRES 4
359 #define BAP_LDQREQ 5
360 #define BAP_LDQRES 6
361 #define BAP_CSIND 7
362 #define BAP_CSRES 8
363
364 static void handle_ctrl_proto (u_int proto,const u_char *p, int length);
365 static void handle_chap (const u_char *p, int length);
366 static void handle_pap (const u_char *p, int length);
367 static void handle_bap (const u_char *p, int length);
368 static int print_lcp_config_options (const u_char *p, int);
369 static int print_ipcp_config_options (const u_char *p, int);
370 static int print_ccp_config_options (const u_char *p, int);
371 static int print_bacp_config_options (const u_char *p, int);
372 static void handle_ppp (u_int proto, const u_char *p, int length);
373
374 /* generic Control Protocol (e.g. LCP, IPCP, CCP, etc.) handler */
375 static void
376 handle_ctrl_proto(u_int proto, const u_char *pptr, int length)
377 {
378 u_int code, len;
379 int (*pfunc)(const u_char *, int);
380 int x, j;
381 const u_char *tptr;
382
383 tptr=pptr;
384
385 printf("%s, ",tok2str(ppptype2str, "unknown", proto));
386
387 if (length < 4) /* FIXME weak boundary checking */
388 return;
389
390 code = *tptr++;
391
392 printf("%s (0x%02x), id %u",
393 tok2str(cpcodes, "Unknown Opcode",code),
394 code,
395 *tptr++); /* ID */
396
397 len = EXTRACT_16BITS(tptr);
398 tptr += 2;
399
400 if (length <= 4)
401 return; /* there may be a NULL confreq etc. */
402
403 switch (code) {
404 case CPCODES_VEXT:
405 if (length < 11)
406 break;
407 printf(", Magic-Num 0x%08x", EXTRACT_32BITS(tptr));
408 tptr += 4;
409 printf(" Vendor: %s (%u)",
410 tok2str(oui_values,"Unknown",EXTRACT_24BITS(tptr)),
411 EXTRACT_24BITS(tptr));
412 /* XXX: need to decode Kind and Value(s)? */
413 break;
414 case CPCODES_CONF_REQ:
415 case CPCODES_CONF_ACK:
416 case CPCODES_CONF_NAK:
417 case CPCODES_CONF_REJ:
418 x = len - 4; /* Code(1), Identifier(1) and Length(2) */
419 do {
420 switch (proto) {
421 case PPP_LCP:
422 pfunc = print_lcp_config_options;
423 break;
424 case PPP_IPCP:
425 pfunc = print_ipcp_config_options;
426 break;
427 case PPP_CCP:
428 pfunc = print_ccp_config_options;
429 break;
430 case PPP_BACP:
431 pfunc = print_bacp_config_options;
432 break;
433 default:
434 /*
435 * This should never happen, but we set
436 * "pfunc" to squelch uninitialized
437 * variable warnings from compilers.
438 */
439 pfunc = NULL;
440 break;
441 }
442 if ((j = (*pfunc)(tptr, len)) == 0)
443 break;
444 x -= j;
445 tptr += j;
446 } while (x > 0);
447 break;
448
449 case CPCODES_TERM_REQ:
450 case CPCODES_TERM_ACK:
451 /* XXX: need to decode Data? */
452 break;
453 case CPCODES_CODE_REJ:
454 /* XXX: need to decode Rejected-Packet? */
455 break;
456 case CPCODES_PROT_REJ:
457 if (length < 6)
458 break;
459 printf(", Rejected %s Protocol (0x%04x)",
460 tok2str(ppptype2str,"unknown", EXTRACT_16BITS(tptr)),
461 EXTRACT_16BITS(tptr));
462 /* XXX: need to decode Rejected-Information? */
463 break;
464 case CPCODES_ECHO_REQ:
465 case CPCODES_ECHO_RPL:
466 case CPCODES_DISC_REQ:
467 case CPCODES_ID:
468 if (length < 8)
469 break;
470 printf(", Magic-Num 0x%08x", EXTRACT_32BITS(tptr));
471 /* XXX: need to decode Data? */
472 break;
473 case CPCODES_TIME_REM:
474 if (length < 12)
475 break;
476 printf(", Magic-Num 0x%08x", EXTRACT_32BITS(tptr));
477 printf(", Seconds-Remaining %us", EXTRACT_32BITS(tptr + 4));
478 /* XXX: need to decode Message? */
479 break;
480 default:
481 /* XXX this is dirty but we do not get the
482 * original pointer passed to the begin
483 * the PPP packet */
484 if (vflag <= 1)
485 print_unknown_data(pptr-2,"\n\t",length+2);
486 break;
487 }
488 printf(", length %u", length);
489
490 if (vflag >1)
491 print_unknown_data(pptr-2,"\n\t",length+2);
492 }
493
494 /* LCP config options */
495 static int
496 print_lcp_config_options(const u_char *p, int length)
497 {
498 int len, opt;
499
500 if (length < 2)
501 return 0;
502 len = p[1];
503 opt = p[0];
504 if (length < len)
505 return 0;
506 if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX))
507 printf(", %s (%u)", lcpconfopts[opt],opt);
508 else {
509 printf(", unknown LCP option 0x%02x", opt);
510 return len;
511 }
512
513 switch (opt) {
514 case LCPOPT_VEXT:
515 if (len >= 6) {
516 printf(" Vendor: %s (%u)",
517 tok2str(oui_values,"Unknown",EXTRACT_24BITS(p+2)),
518 EXTRACT_24BITS(p+2));
519 #if 0
520 printf(", kind: 0x%02x", p[5]);
521 printf(", Value: 0x")
522 for (i = 0; i < len - 6; i++) {
523 printf("%02x", p[6 + i]);
524 }
525 #endif
526 }
527 break;
528 case LCPOPT_MRU:
529 if (len == 4)
530 printf(" %u", EXTRACT_16BITS(p + 2));
531 break;
532 case LCPOPT_ACCM:
533 if (len == 6)
534 printf(" 0x%08x", EXTRACT_32BITS(p + 2));
535 break;
536 case LCPOPT_AP:
537 if (len >= 4) {
538 switch (EXTRACT_16BITS(p+2)) {
539 case PPP_PAP:
540 printf(" PAP");
541 break;
542 case PPP_CHAP:
543 printf(" CHAP");
544 switch (p[4]) {
545 default:
546 printf(", unknown-algorithm-%u", p[4]);
547 break;
548 case AUTHALG_CHAPMD5:
549 printf(", MD5");
550 break;
551 case AUTHALG_MSCHAP1:
552 printf(", MSCHAPv1");
553 break;
554 case AUTHALG_MSCHAP2:
555 printf(", MSCHAPv2");
556 break;
557 }
558 break;
559 case PPP_EAP:
560 printf(" EAP");
561 break;
562 case PPP_SPAP:
563 printf(" SPAP");
564 break;
565 case PPP_SPAP_OLD:
566 printf(" Old-SPAP");
567 break;
568 default:
569 printf("unknown");
570 }
571 }
572 break;
573 case LCPOPT_QP:
574 if (len >= 4) {
575 if (EXTRACT_16BITS(p+2) == PPP_LQM)
576 printf(" LQR");
577 else
578 printf(" unknown");
579 }
580 break;
581 case LCPOPT_MN:
582 if (len == 6)
583 printf(" 0x%08x", EXTRACT_32BITS(p + 2));
584 break;
585 case LCPOPT_PFC:
586 break;
587 case LCPOPT_ACFC:
588 break;
589 case LCPOPT_LD:
590 if (len == 4)
591 printf(" 0x%04x", EXTRACT_16BITS(p + 2));
592 break;
593 case LCPOPT_CBACK:
594 if (len < 3)
595 break;
596 switch (p[2]) { /* Operation */
597 case CALLBACK_AUTH:
598 printf(" UserAuth");
599 break;
600 case CALLBACK_DSTR:
601 printf(" DialString");
602 break;
603 case CALLBACK_LID:
604 printf(" LocalID");
605 break;
606 case CALLBACK_E164:
607 printf(" E.164");
608 break;
609 case CALLBACK_X500:
610 printf(" X.500");
611 break;
612 case CALLBACK_CBCP:
613 printf(" CBCP");
614 break;
615 default:
616 printf(" unknown-operation=%u", p[2]);
617 break;
618 }
619 break;
620 case LCPOPT_MLMRRU:
621 if (len == 4)
622 printf(" %u", EXTRACT_16BITS(p + 2));
623 break;
624 case LCPOPT_MLED:
625 if (len < 3)
626 break;
627 switch (p[2]) { /* class */
628 case MEDCLASS_NULL:
629 printf(" Null");
630 break;
631 case MEDCLASS_LOCAL:
632 printf(" Local"); /* XXX */
633 break;
634 case MEDCLASS_IPV4:
635 if (len != 7)
636 break;
637 printf(" IPv4 %s", ipaddr_string(p + 3));
638 break;
639 case MEDCLASS_MAC:
640 if (len != 9)
641 break;
642 printf(" MAC %02x:%02x:%02x:%02x:%02x:%02x",
643 p[3], p[4], p[5], p[6], p[7], p[8]);
644 break;
645 case MEDCLASS_MNB:
646 printf(" Magic-Num-Block"); /* XXX */
647 break;
648 case MEDCLASS_PSNDN:
649 printf(" PSNDN"); /* XXX */
650 break;
651 }
652 break;
653
654 /* XXX: to be supported */
655 #if 0
656 case LCPOPT_DEP6:
657 case LCPOPT_FCSALT:
658 case LCPOPT_SDP:
659 case LCPOPT_NUMMODE:
660 case LCPOPT_DEP12:
661 case LCPOPT_DEP14:
662 case LCPOPT_DEP15:
663 case LCPOPT_DEP16:
664 case LCPOPT_MLSSNHF:
665 case LCPOPT_PROP:
666 case LCPOPT_DCEID:
667 case LCPOPT_MPP:
668 case LCPOPT_LCPAOPT:
669 case LCPOPT_COBS:
670 case LCPOPT_PE:
671 case LCPOPT_MLHF:
672 case LCPOPT_I18N:
673 case LCPOPT_SDLOS:
674 case LCPOPT_PPPMUX:
675 break;
676 #endif
677 }
678 return len;
679 }
680
681 /* CHAP */
682 static void
683 handle_chap(const u_char *p, int length)
684 {
685 u_int code, len;
686 int val_size, name_size, msg_size;
687 const u_char *p0;
688 int i;
689
690 p0 = p;
691 if (length < 1) {
692 printf("[|chap]");
693 return;
694 } else if (length < 4) {
695 printf("[|chap 0x%02x]", *p);
696 return;
697 }
698
699 code = *p;
700 if ((code >= CHAP_CODEMIN) && (code <= CHAP_CODEMAX))
701 printf("%s", chapcode[code - 1]);
702 else {
703 printf("0x%02x", code);
704 return;
705 }
706 p++;
707
708 printf("(%u)", *p); /* ID */
709 p++;
710
711 len = EXTRACT_16BITS(p);
712 p += 2;
713
714 /*
715 * Note that this is a generic CHAP decoding routine. Since we
716 * don't know which flavor of CHAP (i.e. CHAP-MD5, MS-CHAPv1,
717 * MS-CHAPv2) is used at this point, we can't decode packet
718 * specifically to each algorithms. Instead, we simply decode
719 * the GCD (Gratest Common Denominator) for all algorithms.
720 */
721 switch (code) {
722 case CHAP_CHAL:
723 case CHAP_RESP:
724 if (length - (p - p0) < 1)
725 return;
726 val_size = *p; /* value size */
727 p++;
728 if (length - (p - p0) < val_size)
729 return;
730 printf(", Value ");
731 for (i = 0; i < val_size; i++)
732 printf("%02x", *p++);
733 name_size = len - (p - p0);
734 printf(", Name ");
735 for (i = 0; i < name_size; i++)
736 safeputchar(*p++);
737 break;
738 case CHAP_SUCC:
739 case CHAP_FAIL:
740 msg_size = len - (p - p0);
741 printf(", Msg ");
742 for (i = 0; i< msg_size; i++)
743 safeputchar(*p++);
744 break;
745 }
746 }
747
748 /* PAP (see RFC 1334) */
749 static void
750 handle_pap(const u_char *p, int length)
751 {
752 u_int code, len;
753 int peerid_len, passwd_len, msg_len;
754 const u_char *p0;
755 int i;
756
757 p0 = p;
758 if (length < 1) {
759 printf("[|pap]");
760 return;
761 } else if (length < 4) {
762 printf("[|pap 0x%02x]", *p);
763 return;
764 }
765
766 code = *p;
767 if ((code >= PAP_CODEMIN) && (code <= PAP_CODEMAX))
768 printf("%s", papcode[code - 1]);
769 else {
770 printf("0x%02x", code);
771 return;
772 }
773 p++;
774
775 printf("(%u)", *p); /* ID */
776 p++;
777
778 len = EXTRACT_16BITS(p);
779 p += 2;
780
781 switch (code) {
782 case PAP_AREQ:
783 if (length - (p - p0) < 1)
784 return;
785 peerid_len = *p; /* Peer-ID Length */
786 p++;
787 if (length - (p - p0) < peerid_len)
788 return;
789 printf(", Peer ");
790 for (i = 0; i < peerid_len; i++)
791 safeputchar(*p++);
792
793 if (length - (p - p0) < 1)
794 return;
795 passwd_len = *p; /* Password Length */
796 p++;
797 if (length - (p - p0) < passwd_len)
798 return;
799 printf(", Name ");
800 for (i = 0; i < passwd_len; i++)
801 safeputchar(*p++);
802 break;
803 case PAP_AACK:
804 case PAP_ANAK:
805 if (length - (p - p0) < 1)
806 return;
807 msg_len = *p; /* Msg-Length */
808 p++;
809 if (length - (p - p0) < msg_len)
810 return;
811 printf(", Msg ");
812 for (i = 0; i< msg_len; i++)
813 safeputchar(*p++);
814 break;
815 }
816 return;
817 }
818
819 /* BAP */
820 static void
821 handle_bap(const u_char *p _U_, int length _U_)
822 {
823 /* XXX: to be supported!! */
824 }
825
826
827 /* IPCP config options */
828 static int
829 print_ipcp_config_options(const u_char *p, int length)
830 {
831 int len, opt;
832
833 if (length < 2)
834 return 0;
835 len = p[1];
836 opt = p[0];
837 if (length < len)
838 return 0;
839 switch (opt) {
840 case IPCPOPT_2ADDR: /* deprecated */
841 if (len != 10)
842 goto invlen;
843 printf(", IP-Addrs src %s, dst %s",
844 ipaddr_string(p + 2),
845 ipaddr_string(p + 6));
846 break;
847 case IPCPOPT_IPCOMP:
848 if (len < 4)
849 goto invlen;
850 printf(", IP-Comp");
851 if (EXTRACT_16BITS(p + 2) == PPP_VJC) {
852 printf(" VJ-Comp");
853 /* XXX: VJ-Comp parameters should be decoded */
854 } else
855 printf(" unknown-comp-proto=%04x", EXTRACT_16BITS(p + 2));
856 break;
857 case IPCPOPT_ADDR:
858 if (len != 6)
859 goto invlen;
860 printf(", IP-Addr %s", ipaddr_string(p + 2));
861 break;
862 case IPCPOPT_MOBILE4:
863 if (len != 6)
864 goto invlen;
865 printf(", Home-Addr %s", ipaddr_string(p + 2));
866 break;
867 case IPCPOPT_PRIDNS:
868 if (len != 6)
869 goto invlen;
870 printf(", Pri-DNS %s", ipaddr_string(p + 2));
871 break;
872 case IPCPOPT_PRINBNS:
873 if (len != 6)
874 goto invlen;
875 printf(", Pri-NBNS %s", ipaddr_string(p + 2));
876 break;
877 case IPCPOPT_SECDNS:
878 if (len != 6)
879 goto invlen;
880 printf(", Sec-DNS %s", ipaddr_string(p + 2));
881 break;
882 case IPCPOPT_SECNBNS:
883 if (len != 6)
884 goto invlen;
885 printf(", Sec-NBNS %s", ipaddr_string(p + 2));
886 break;
887 default:
888 printf(", unknown-%d", opt);
889 break;
890 }
891 return len;
892
893 invlen:
894 printf(", invalid-length-%d", opt);
895 return 0;
896 }
897
898 /* CCP config options */
899 static int
900 print_ccp_config_options(const u_char *p, int length)
901 {
902 int len, opt;
903
904 if (length < 2)
905 return 0;
906 len = p[1];
907 opt = p[0];
908 if (length < len)
909 return 0;
910 if ((opt >= CCPOPT_MIN) && (opt <= CCPOPT_MAX))
911 printf(", %s", ccpconfopts[opt]);
912 #if 0 /* XXX */
913 switch (opt) {
914 case CCPOPT_OUI:
915 case CCPOPT_PRED1:
916 case CCPOPT_PRED2:
917 case CCPOPT_PJUMP:
918 case CCPOPT_HPPPC:
919 case CCPOPT_STACLZS:
920 case CCPOPT_MPPC:
921 case CCPOPT_GFZA:
922 case CCPOPT_V42BIS:
923 case CCPOPT_BSDCOMP:
924 case CCPOPT_LZSDCP:
925 case CCPOPT_MVRCA:
926 case CCPOPT_DEC:
927 case CCPOPT_DEFLATE:
928 case CCPOPT_RESV:
929 break;
930
931 default:
932 printf(", unknown-%d", opt);
933 break;
934 }
935 #endif
936 return len;
937 }
938
939 /* BACP config options */
940 static int
941 print_bacp_config_options(const u_char *p, int length)
942 {
943 int len, opt;
944
945 if (length < 2)
946 return 0;
947 len = p[1];
948 opt = p[0];
949 if (length < len)
950 return 0;
951 if (opt == BACPOPT_FPEER) {
952 printf(", Favored-Peer");
953 printf(", Magic-Num 0x%08x", EXTRACT_32BITS(p + 2));
954 } else {
955 printf(", unknown-option-%d", opt);
956 }
957 return len;
958 }
959
960
961 /* PPP */
962 static void
963 handle_ppp(u_int proto, const u_char *p, int length)
964 {
965 switch (proto) {
966 case PPP_LCP:
967 case PPP_IPCP:
968 case PPP_OSICP:
969 case PPP_MPLSCP:
970 case PPP_IPV6CP:
971 case PPP_CCP:
972 case PPP_BACP:
973 handle_ctrl_proto(proto, p, length);
974 break;
975 case PPP_CHAP:
976 handle_chap(p, length);
977 break;
978 case PPP_PAP:
979 handle_pap(p, length);
980 break;
981 case PPP_BAP: /* XXX: not yet completed */
982 handle_bap(p, length);
983 break;
984 case ETHERTYPE_IP: /*XXX*/
985 case PPP_IP:
986 ip_print(p, length);
987 break;
988 #ifdef INET6
989 case ETHERTYPE_IPV6: /*XXX*/
990 case PPP_IPV6:
991 ip6_print(p, length);
992 break;
993 #endif
994 case ETHERTYPE_IPX: /*XXX*/
995 case PPP_IPX:
996 ipx_print(p, length);
997 break;
998 case PPP_OSI:
999 isoclns_print(p, length, length);
1000 break;
1001 case PPP_MPLS_UCAST:
1002 case PPP_MPLS_MCAST:
1003 mpls_print(p, length);
1004 break;
1005 default:
1006 printf("unknown PPP protocol (0x%04x)", proto);
1007 print_unknown_data(p,"\n\t",length);
1008 break;
1009 }
1010 }
1011
1012 /* Standard PPP printer */
1013 u_int
1014 ppp_print(register const u_char *p, u_int length)
1015 {
1016 u_int proto;
1017 u_int olen = length; /* _o_riginal length */
1018 u_int hdr_len = 0;
1019
1020 /*
1021 * Here, we assume that p points to the Address and Control
1022 * field (if they present).
1023 */
1024 if (length < 2)
1025 goto trunc;
1026 if (*p == PPP_ADDRESS && *(p + 1) == PPP_CONTROL) {
1027 p += 2; /* ACFC not used */
1028 length -= 2;
1029 hdr_len += 2;
1030 }
1031
1032 if (length < 2)
1033 goto trunc;
1034 if (*p % 2) {
1035 proto = *p; /* PFC is used */
1036 p++;
1037 length--;
1038 hdr_len++;
1039 } else {
1040 proto = EXTRACT_16BITS(p);
1041 p += 2;
1042 length -= 2;
1043 hdr_len += 2;
1044 }
1045
1046 if (eflag)
1047 printf("%s (0x%04x), length %u: ",
1048 tok2str(ppptype2str, "unknown", proto),
1049 proto,
1050 olen);
1051
1052 handle_ppp(proto, p, length);
1053 return (hdr_len);
1054 trunc:
1055 printf("[|ppp]");
1056 return (0);
1057 }
1058
1059
1060 /* PPP I/F printer */
1061 u_int
1062 ppp_if_print(const struct pcap_pkthdr *h, register const u_char *p)
1063 {
1064 register u_int length = h->len;
1065 register u_int caplen = h->caplen;
1066
1067 if (caplen < PPP_HDRLEN) {
1068 printf("[|ppp]");
1069 return (caplen);
1070 }
1071
1072 #if 0
1073 /*
1074 * XXX: seems to assume that there are 2 octets prepended to an
1075 * actual PPP frame. The 1st octet looks like Input/Output flag
1076 * while 2nd octet is unknown, at least to me
1077 * (mshindo@mshindo.net).
1078 *
1079 * That was what the original tcpdump code did.
1080 *
1081 * FreeBSD's "if_ppp.c" *does* set the first octet to 1 for outbound
1082 * packets and 0 for inbound packets - but only if the
1083 * protocol field has the 0x8000 bit set (i.e., it's a network
1084 * control protocol); it does so before running the packet through
1085 * "bpf_filter" to see if it should be discarded, and to see
1086 * if we should update the time we sent the most recent packet...
1087 *
1088 * ...but it puts the original address field back after doing
1089 * so.
1090 *
1091 * NetBSD's "if_ppp.c" doesn't set the first octet in that fashion.
1092 *
1093 * I don't know if any PPP implementation handed up to a BPF
1094 * device packets with the first octet being 1 for outbound and
1095 * 0 for inbound packets, so I (guy@alum.mit.edu) don't know
1096 * whether that ever needs to be checked or not.
1097 *
1098 * Note that NetBSD has a DLT_PPP_SERIAL, which it uses for PPP,
1099 * and its tcpdump appears to assume that the frame always
1100 * begins with an address field and a control field, and that
1101 * the address field might be 0x0f or 0x8f, for Cisco
1102 * point-to-point with HDLC framing as per section 4.3.1 of RFC
1103 * 1547, as well as 0xff, for PPP in HDLC-like framing as per
1104 * RFC 1662.
1105 *
1106 * (Is the Cisco framing in question what DLT_C_HDLC, in
1107 * BSD/OS, is?)
1108 */
1109 if (eflag)
1110 printf("%c %4d %02x ", p[0] ? 'O' : 'I', length, p[1]);
1111 #endif
1112
1113 ppp_print(p, length);
1114
1115 return (0);
1116 }
1117
1118 /*
1119 * PPP I/F printer to use if we know that RFC 1662-style PPP in HDLC-like
1120 * framing, or Cisco PPP with HDLC framing as per section 4.3.1 of RFC 1547,
1121 * is being used (i.e., we don't check for PPP_ADDRESS and PPP_CONTROL,
1122 * discard them *if* those are the first two octets, and parse the remaining
1123 * packet as a PPP packet, as "ppp_print()" does).
1124 *
1125 * This handles, for example, DLT_PPP_SERIAL in NetBSD.
1126 */
1127 u_int
1128 ppp_hdlc_if_print(const struct pcap_pkthdr *h, register const u_char *p)
1129 {
1130 register u_int length = h->len;
1131 register u_int caplen = h->caplen;
1132 u_int proto;
1133 u_int hdrlen = 0;
1134
1135 if (caplen < 2) {
1136 printf("[|ppp]");
1137 return (caplen);
1138 }
1139
1140 switch (p[0]) {
1141
1142 case PPP_ADDRESS:
1143 if (caplen < 4) {
1144 printf("[|ppp]");
1145 return (caplen);
1146 }
1147
1148 if (eflag)
1149 printf("%02x %02x %d ", p[0], p[1], length);
1150 p += 2;
1151 length -= 2;
1152 hdrlen += 2;
1153
1154 proto = EXTRACT_16BITS(p);
1155 p += 2;
1156 length -= 2;
1157 hdrlen += 2;
1158 printf("%s: ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto));
1159
1160 handle_ppp(proto, p, length);
1161 break;
1162
1163 case CHDLC_UNICAST:
1164 case CHDLC_BCAST:
1165 return (chdlc_if_print(h, p));
1166
1167 default:
1168 if (eflag)
1169 printf("%02x %02x %d ", p[0], p[1], length);
1170 p += 2;
1171 length -= 2;
1172 hdrlen += 2;
1173
1174 /*
1175 * XXX - NetBSD's "ppp_netbsd_serial_if_print()" treats
1176 * the next two octets as an Ethernet type; does that
1177 * ever happen?
1178 */
1179 printf("unknown addr %02x; ctrl %02x", p[0], p[1]);
1180 break;
1181 }
1182
1183 return (hdrlen);
1184 }
1185
1186 #define PPP_BSDI_HDRLEN 24
1187
1188 /* BSD/OS specific PPP printer */
1189 u_int
1190 ppp_bsdos_if_print(const struct pcap_pkthdr *h _U_, register const u_char *p _U_)
1191 {
1192 register int hdrlength;
1193 #ifdef __bsdi__
1194 register u_int length = h->len;
1195 register u_int caplen = h->caplen;
1196 u_int16_t ptype;
1197 const u_char *q;
1198 int i;
1199
1200 if (caplen < PPP_BSDI_HDRLEN) {
1201 printf("[|ppp]");
1202 return (caplen)
1203 }
1204
1205 hdrlength = 0;
1206
1207 #if 0
1208 if (p[0] == PPP_ADDRESS && p[1] == PPP_CONTROL) {
1209 if (eflag)
1210 printf("%02x %02x ", p[0], p[1]);
1211 p += 2;
1212 hdrlength = 2;
1213 }
1214
1215 if (eflag)
1216 printf("%d ", length);
1217 /* Retrieve the protocol type */
1218 if (*p & 01) {
1219 /* Compressed protocol field */
1220 ptype = *p;
1221 if (eflag)
1222 printf("%02x ", ptype);
1223 p++;
1224 hdrlength += 1;
1225 } else {
1226 /* Un-compressed protocol field */
1227 ptype = ntohs(*(u_int16_t *)p);
1228 if (eflag)
1229 printf("%04x ", ptype);
1230 p += 2;
1231 hdrlength += 2;
1232 }
1233 #else
1234 ptype = 0; /*XXX*/
1235 if (eflag)
1236 printf("%c ", p[SLC_DIR] ? 'O' : 'I');
1237 if (p[SLC_LLHL]) {
1238 /* link level header */
1239 struct ppp_header *ph;
1240
1241 q = p + SLC_BPFHDRLEN;
1242 ph = (struct ppp_header *)q;
1243 if (ph->phdr_addr == PPP_ADDRESS
1244 && ph->phdr_ctl == PPP_CONTROL) {
1245 if (eflag)
1246 printf("%02x %02x ", q[0], q[1]);
1247 ptype = ntohs(ph->phdr_type);
1248 if (eflag && (ptype == PPP_VJC || ptype == PPP_VJNC)) {
1249 printf("%s ", tok2str(ppptype2str,
1250 "proto-#%d", ptype));
1251 }
1252 } else {
1253 if (eflag) {
1254 printf("LLH=[");
1255 for (i = 0; i < p[SLC_LLHL]; i++)
1256 printf("%02x", q[i]);
1257 printf("] ");
1258 }
1259 }
1260 }
1261 if (eflag)
1262 printf("%d ", length);
1263 if (p[SLC_CHL]) {
1264 q = p + SLC_BPFHDRLEN + p[SLC_LLHL];
1265
1266 switch (ptype) {
1267 case PPP_VJC:
1268 ptype = vjc_print(q, ptype);
1269 hdrlength = PPP_BSDI_HDRLEN;
1270 p += hdrlength;
1271 switch (ptype) {
1272 case PPP_IP:
1273 ip_print(p, length);
1274 break;
1275 #ifdef INET6
1276 case PPP_IPV6:
1277 ip6_print(p, length);
1278 break;
1279 #endif
1280 case PPP_MPLS_UCAST:
1281 case PPP_MPLS_MCAST:
1282 mpls_print(p, length);
1283 break;
1284 }
1285 goto printx;
1286 case PPP_VJNC:
1287 ptype = vjc_print(q, ptype);
1288 hdrlength = PPP_BSDI_HDRLEN;
1289 p += hdrlength;
1290 switch (ptype) {
1291 case PPP_IP:
1292 ip_print(p, length);
1293 break;
1294 #ifdef INET6
1295 case PPP_IPV6:
1296 ip6_print(p, length);
1297 break;
1298 #endif
1299 case PPP_MPLS_UCAST:
1300 case PPP_MPLS_MCAST:
1301 mpls_print(p, length);
1302 break;
1303 }
1304 goto printx;
1305 default:
1306 if (eflag) {
1307 printf("CH=[");
1308 for (i = 0; i < p[SLC_LLHL]; i++)
1309 printf("%02x", q[i]);
1310 printf("] ");
1311 }
1312 break;
1313 }
1314 }
1315
1316 hdrlength = PPP_BSDI_HDRLEN;
1317 #endif
1318
1319 length -= hdrlength;
1320 p += hdrlength;
1321
1322 switch (ptype) {
1323 case PPP_IP:
1324 ip_print(p, length);
1325 break;
1326 #ifdef INET6
1327 case PPP_IPV6:
1328 ip6_print(p, length);
1329 break;
1330 #endif
1331 case PPP_MPLS_UCAST:
1332 case PPP_MPLS_MCAST:
1333 mpls_print(p, length);
1334 break;
1335 default:
1336 printf("%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", ptype));
1337 }
1338
1339 printx:
1340 #else /* __bsdi */
1341 hdrlength = 0;
1342 #endif /* __bsdi__ */
1343 return (hdrlength);
1344 }