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