Explicitly request literal mode after .Xr.
[netbsd-mini2440.git] / dist / tcpdump / print-ppp.c
blob3d0b2d5be0a121f8c1fcedcfff403b555f3c4071
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 1990, 1991, 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 * Extensively modified by Motonori Shindo (mshindo@mshindo.net) for more
24 * complete PPP support.
28 * TODO:
29 * o resolve XXX as much as possible
30 * o MP support
31 * o BAP support
34 #include <sys/cdefs.h>
35 #ifndef lint
36 #if 0
37 static const char rcsid[] _U_ =
38 "@(#) Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.108.2.6 2005/12/05 11:40:36 hannes Exp (LBL)";
39 #else
40 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
41 #endif
42 #endif
44 #ifdef HAVE_CONFIG_H
45 #include "config.h"
46 #endif
48 #include <tcpdump-stdinc.h>
50 #ifdef __bsdi__
51 #include <net/slcompress.h>
52 #include <net/if_ppp.h>
53 #endif
55 #include <pcap.h>
56 #include <stdio.h>
57 #include <stdlib.h>
59 #include "interface.h"
60 #include "extract.h"
61 #include "addrtoname.h"
62 #include "ppp.h"
63 #include "chdlc.h"
64 #include "ethertype.h"
65 #include "oui.h"
68 * The following constatns are defined by IANA. Please refer to
69 * http://www.isi.edu/in-notes/iana/assignments/ppp-numbers
70 * for the up-to-date information.
73 /* Protocol Codes defined in ppp.h */
75 struct tok ppptype2str[] = {
76 { PPP_IP, "IP" },
77 { PPP_OSI, "OSI" },
78 { PPP_NS, "NS" },
79 { PPP_DECNET, "DECNET" },
80 { PPP_APPLE, "APPLE" },
81 { PPP_IPX, "IPX" },
82 { PPP_VJC, "VJC IP" },
83 { PPP_VJNC, "VJNC IP" },
84 { PPP_BRPDU, "BRPDU" },
85 { PPP_STII, "STII" },
86 { PPP_VINES, "VINES" },
87 { PPP_MPLS_UCAST, "MPLS" },
88 { PPP_MPLS_MCAST, "MPLS" },
89 { PPP_COMP, "Compressed"},
90 { PPP_ML, "MLPPP"},
91 { PPP_IPV6, "IP6"},
93 { PPP_HELLO, "HELLO" },
94 { PPP_LUXCOM, "LUXCOM" },
95 { PPP_SNS, "SNS" },
96 { PPP_IPCP, "IPCP" },
97 { PPP_OSICP, "OSICP" },
98 { PPP_NSCP, "NSCP" },
99 { PPP_DECNETCP, "DECNETCP" },
100 { PPP_APPLECP, "APPLECP" },
101 { PPP_IPXCP, "IPXCP" },
102 { PPP_STIICP, "STIICP" },
103 { PPP_VINESCP, "VINESCP" },
104 { PPP_IPV6CP, "IP6CP" },
105 { PPP_MPLSCP, "MPLSCP" },
107 { PPP_LCP, "LCP" },
108 { PPP_PAP, "PAP" },
109 { PPP_LQM, "LQM" },
110 { PPP_CHAP, "CHAP" },
111 { PPP_EAP, "EAP" },
112 { PPP_SPAP, "SPAP" },
113 { PPP_SPAP_OLD, "Old-SPAP" },
114 { PPP_BACP, "BACP" },
115 { PPP_BAP, "BAP" },
116 { PPP_MPCP, "MLPPP-CP" },
117 { 0, NULL }
120 /* Control Protocols (LCP/IPCP/CCP etc.) Codes defined in RFC 1661 */
122 #define CPCODES_VEXT 0 /* Vendor-Specific (RFC2153) */
123 #define CPCODES_CONF_REQ 1 /* Configure-Request */
124 #define CPCODES_CONF_ACK 2 /* Configure-Ack */
125 #define CPCODES_CONF_NAK 3 /* Configure-Nak */
126 #define CPCODES_CONF_REJ 4 /* Configure-Reject */
127 #define CPCODES_TERM_REQ 5 /* Terminate-Request */
128 #define CPCODES_TERM_ACK 6 /* Terminate-Ack */
129 #define CPCODES_CODE_REJ 7 /* Code-Reject */
130 #define CPCODES_PROT_REJ 8 /* Protocol-Reject (LCP only) */
131 #define CPCODES_ECHO_REQ 9 /* Echo-Request (LCP only) */
132 #define CPCODES_ECHO_RPL 10 /* Echo-Reply (LCP only) */
133 #define CPCODES_DISC_REQ 11 /* Discard-Request (LCP only) */
134 #define CPCODES_ID 12 /* Identification (LCP only) RFC1570 */
135 #define CPCODES_TIME_REM 13 /* Time-Remaining (LCP only) RFC1570 */
136 #define CPCODES_RESET_REQ 14 /* Reset-Request (CCP only) RFC1962 */
137 #define CPCODES_RESET_REP 15 /* Reset-Reply (CCP only) */
139 struct tok cpcodes[] = {
140 {CPCODES_VEXT, "Vendor-Extension"}, /* RFC2153 */
141 {CPCODES_CONF_REQ, "Conf-Request"},
142 {CPCODES_CONF_ACK, "Conf-Ack"},
143 {CPCODES_CONF_NAK, "Conf-Nack"},
144 {CPCODES_CONF_REJ, "Conf-Reject"},
145 {CPCODES_TERM_REQ, "Term-Request"},
146 {CPCODES_TERM_ACK, "Term-Ack"},
147 {CPCODES_CODE_REJ, "Code-Reject"},
148 {CPCODES_PROT_REJ, "Prot-Reject"},
149 {CPCODES_ECHO_REQ, "Echo-Request"},
150 {CPCODES_ECHO_RPL, "Echo-Reply"},
151 {CPCODES_DISC_REQ, "Disc-Req"},
152 {CPCODES_ID, "Ident"}, /* RFC1570 */
153 {CPCODES_TIME_REM, "Time-Rem"}, /* RFC1570 */
154 {CPCODES_RESET_REQ, "Reset-Req"}, /* RFC1962 */
155 {CPCODES_RESET_REP, "Reset-Ack"}, /* RFC1962 */
156 {0, NULL}
159 /* LCP Config Options */
161 #define LCPOPT_VEXT 0
162 #define LCPOPT_MRU 1
163 #define LCPOPT_ACCM 2
164 #define LCPOPT_AP 3
165 #define LCPOPT_QP 4
166 #define LCPOPT_MN 5
167 #define LCPOPT_DEP6 6
168 #define LCPOPT_PFC 7
169 #define LCPOPT_ACFC 8
170 #define LCPOPT_FCSALT 9
171 #define LCPOPT_SDP 10
172 #define LCPOPT_NUMMODE 11
173 #define LCPOPT_DEP12 12
174 #define LCPOPT_CBACK 13
175 #define LCPOPT_DEP14 14
176 #define LCPOPT_DEP15 15
177 #define LCPOPT_DEP16 16
178 #define LCPOPT_MLMRRU 17
179 #define LCPOPT_MLSSNHF 18
180 #define LCPOPT_MLED 19
181 #define LCPOPT_PROP 20
182 #define LCPOPT_DCEID 21
183 #define LCPOPT_MPP 22
184 #define LCPOPT_LD 23
185 #define LCPOPT_LCPAOPT 24
186 #define LCPOPT_COBS 25
187 #define LCPOPT_PE 26
188 #define LCPOPT_MLHF 27
189 #define LCPOPT_I18N 28
190 #define LCPOPT_SDLOS 29
191 #define LCPOPT_PPPMUX 30
193 #define LCPOPT_MIN LCPOPT_VEXT
194 #define LCPOPT_MAX LCPOPT_PPPMUX
196 static const char *lcpconfopts[] = {
197 "Vend-Ext", /* (0) */
198 "MRU", /* (1) */
199 "ACCM", /* (2) */
200 "Auth-Prot", /* (3) */
201 "Qual-Prot", /* (4) */
202 "Magic-Num", /* (5) */
203 "deprecated(6)", /* used to be a Quality Protocol */
204 "PFC", /* (7) */
205 "ACFC", /* (8) */
206 "FCS-Alt", /* (9) */
207 "SDP", /* (10) */
208 "Num-Mode", /* (11) */
209 "deprecated(12)", /* used to be a Multi-Link-Procedure*/
210 "Call-Back", /* (13) */
211 "deprecated(14)", /* used to be a Connect-Time */
212 "deprecated(15)", /* used to be a Compund-Frames */
213 "deprecated(16)", /* used to be a Nominal-Data-Encap */
214 "MRRU", /* (17) */
215 "12-Bit seq #", /* (18) */
216 "End-Disc", /* (19) */
217 "Proprietary", /* (20) */
218 "DCE-Id", /* (21) */
219 "MP+", /* (22) */
220 "Link-Disc", /* (23) */
221 "LCP-Auth-Opt", /* (24) */
222 "COBS", /* (25) */
223 "Prefix-elision", /* (26) */
224 "Multilink-header-Form",/* (27) */
225 "I18N", /* (28) */
226 "SDL-over-SONET/SDH", /* (29) */
227 "PPP-Muxing", /* (30) */
230 /* ECP - to be supported */
232 /* CCP Config Options */
234 #define CCPOPT_OUI 0 /* RFC1962 */
235 #define CCPOPT_PRED1 1 /* RFC1962 */
236 #define CCPOPT_PRED2 2 /* RFC1962 */
237 #define CCPOPT_PJUMP 3 /* RFC1962 */
238 /* 4-15 unassigned */
239 #define CCPOPT_HPPPC 16 /* RFC1962 */
240 #define CCPOPT_STACLZS 17 /* RFC1974 */
241 #define CCPOPT_MPPC 18 /* RFC2118 */
242 #define CCPOPT_GFZA 19 /* RFC1962 */
243 #define CCPOPT_V42BIS 20 /* RFC1962 */
244 #define CCPOPT_BSDCOMP 21 /* RFC1977 */
245 /* 22 unassigned */
246 #define CCPOPT_LZSDCP 23 /* RFC1967 */
247 #define CCPOPT_MVRCA 24 /* RFC1975 */
248 #define CCPOPT_DEC 25 /* RFC1976 */
249 #define CCPOPT_DEFLATE 26 /* RFC1979 */
250 /* 27-254 unassigned */
251 #define CCPOPT_RESV 255 /* RFC1962 */
253 const struct tok ccpconfopts_values[] = {
254 { CCPOPT_OUI, "OUI" },
255 { CCPOPT_PRED1, "Pred-1" },
256 { CCPOPT_PRED2, "Pred-2" },
257 { CCPOPT_PJUMP, "Puddle" },
258 { CCPOPT_HPPPC, "HP-PPC" },
259 { CCPOPT_STACLZS, "Stac-LZS" },
260 { CCPOPT_MPPC, "MPPC" },
261 { CCPOPT_GFZA, "Gand-FZA" },
262 { CCPOPT_V42BIS, "V.42bis" },
263 { CCPOPT_BSDCOMP, "BSD-Comp" },
264 { CCPOPT_LZSDCP, "LZS-DCP" },
265 { CCPOPT_MVRCA, "MVRCA" },
266 { CCPOPT_DEC, "DEC" },
267 { CCPOPT_DEFLATE, "Deflate" },
268 { CCPOPT_RESV, "Reserved"},
269 {0, NULL}
272 /* BACP Config Options */
274 #define BACPOPT_FPEER 1 /* RFC2125 */
276 const struct tok bacconfopts_values[] = {
277 { BACPOPT_FPEER, "Favored-Peer" },
278 {0, NULL}
282 /* SDCP - to be supported */
284 /* IPCP Config Options */
285 #define IPCPOPT_2ADDR 1 /* RFC1172, RFC1332 (deprecated) */
286 #define IPCPOPT_IPCOMP 2 /* RFC1332 */
287 #define IPCPOPT_ADDR 3 /* RFC1332 */
288 #define IPCPOPT_MOBILE4 4 /* RFC2290 */
289 #define IPCPOPT_PRIDNS 129 /* RFC1877 */
290 #define IPCPOPT_PRINBNS 130 /* RFC1877 */
291 #define IPCPOPT_SECDNS 131 /* RFC1877 */
292 #define IPCPOPT_SECNBNS 132 /* RFC1877 */
294 struct tok ipcpopt_values[] = {
295 { IPCPOPT_2ADDR, "IP-Addrs" },
296 { IPCPOPT_IPCOMP, "IP-Comp" },
297 { IPCPOPT_ADDR, "IP-Addr" },
298 { IPCPOPT_MOBILE4, "Home-Addr" },
299 { IPCPOPT_PRIDNS, "Pri-DNS" },
300 { IPCPOPT_PRINBNS, "Pri-NBNS" },
301 { IPCPOPT_SECDNS, "Sec-DNS" },
302 { IPCPOPT_SECNBNS, "Sec-NBNS" },
303 { 0, NULL }
306 #define IPCPOPT_IPCOMP_HDRCOMP 0x61 /* rfc3544 */
307 #define IPCPOPT_IPCOMP_MINLEN 14
309 struct tok ipcpopt_compproto_values[] = {
310 { PPP_VJC, "VJ-Comp" },
311 { IPCPOPT_IPCOMP_HDRCOMP, "IP Header Compression" },
312 { 0, NULL }
315 struct tok ipcpopt_compproto_subopt_values[] = {
316 { 1, "RTP-Compression" },
317 { 2, "Enhanced RTP-Compression" },
318 { 0, NULL }
321 /* IP6CP Config Options */
322 #define IP6CP_IFID 1
324 struct tok ip6cpopt_values[] = {
325 { IP6CP_IFID, "Interface-ID" },
326 { 0, NULL }
329 /* ATCP - to be supported */
330 /* OSINLCP - to be supported */
331 /* BVCP - to be supported */
332 /* BCP - to be supported */
333 /* IPXCP - to be supported */
334 /* MPLSCP - to be supported */
336 /* Auth Algorithms */
338 /* 0-4 Reserved (RFC1994) */
339 #define AUTHALG_CHAPMD5 5 /* RFC1994 */
340 #define AUTHALG_MSCHAP1 128 /* RFC2433 */
341 #define AUTHALG_MSCHAP2 129 /* RFC2795 */
343 struct tok authalg_values[] = {
344 { AUTHALG_CHAPMD5, "MD5" },
345 { AUTHALG_MSCHAP1, "MS-CHAPv1" },
346 { AUTHALG_MSCHAP2, "MS-CHAPv2" },
347 { 0, NULL }
350 /* FCS Alternatives - to be supported */
352 /* Multilink Endpoint Discriminator (RFC1717) */
353 #define MEDCLASS_NULL 0 /* Null Class */
354 #define MEDCLASS_LOCAL 1 /* Locally Assigned */
355 #define MEDCLASS_IPV4 2 /* Internet Protocol (IPv4) */
356 #define MEDCLASS_MAC 3 /* IEEE 802.1 global MAC address */
357 #define MEDCLASS_MNB 4 /* PPP Magic Number Block */
358 #define MEDCLASS_PSNDN 5 /* Public Switched Network Director Number */
360 /* PPP LCP Callback */
361 #define CALLBACK_AUTH 0 /* Location determined by user auth */
362 #define CALLBACK_DSTR 1 /* Dialing string */
363 #define CALLBACK_LID 2 /* Location identifier */
364 #define CALLBACK_E164 3 /* E.164 number */
365 #define CALLBACK_X500 4 /* X.500 distinguished name */
366 #define CALLBACK_CBCP 6 /* Location is determined during CBCP nego */
368 struct tok ppp_callback_values[] = {
369 { CALLBACK_AUTH, "UserAuth" },
370 { CALLBACK_DSTR, "DialString" },
371 { CALLBACK_LID, "LocalID" },
372 { CALLBACK_E164, "E.164" },
373 { CALLBACK_X500, "X.500" },
374 { CALLBACK_CBCP, "CBCP" },
375 { 0, NULL }
378 /* CHAP */
380 #define CHAP_CHAL 1
381 #define CHAP_RESP 2
382 #define CHAP_SUCC 3
383 #define CHAP_FAIL 4
385 struct tok chapcode_values[] = {
386 { CHAP_CHAL, "Challenge" },
387 { CHAP_RESP, "Response" },
388 { CHAP_SUCC, "Success" },
389 { CHAP_FAIL, "Fail" },
390 { 0, NULL}
393 /* PAP */
395 #define PAP_AREQ 1
396 #define PAP_AACK 2
397 #define PAP_ANAK 3
399 struct tok papcode_values[] = {
400 { PAP_AREQ, "Auth-Req" },
401 { PAP_AACK, "Auth-ACK" },
402 { PAP_ANAK, "Auth-NACK" },
403 { 0, NULL }
406 /* BAP */
407 #define BAP_CALLREQ 1
408 #define BAP_CALLRES 2
409 #define BAP_CBREQ 3
410 #define BAP_CBRES 4
411 #define BAP_LDQREQ 5
412 #define BAP_LDQRES 6
413 #define BAP_CSIND 7
414 #define BAP_CSRES 8
416 static void handle_ctrl_proto (u_int proto,const u_char *p, int length);
417 static void handle_chap (const u_char *p, int length);
418 static void handle_pap (const u_char *p, int length);
419 static void handle_bap (const u_char *p, int length);
420 static void handle_mlppp(const u_char *p, int length);
421 static int print_lcp_config_options (const u_char *p, int);
422 static int print_ipcp_config_options (const u_char *p, int);
423 static int print_ip6cp_config_options (const u_char *p, int);
424 static int print_ccp_config_options (const u_char *p, int);
425 static int print_bacp_config_options (const u_char *p, int);
426 static void handle_ppp (u_int proto, const u_char *p, int length);
427 static void ppp_hdlc(const u_char *p, int length);
429 /* generic Control Protocol (e.g. LCP, IPCP, CCP, etc.) handler */
430 static void
431 handle_ctrl_proto(u_int proto, const u_char *pptr, int length)
433 const char *typestr;
434 u_int code, len;
435 int (*pfunc)(const u_char *, int);
436 int x, j;
437 const u_char *tptr;
439 tptr=pptr;
441 typestr = tok2str(ppptype2str, "unknown ctrl-proto (0x%04x)", proto);
442 printf("%s, ",typestr);
444 if (length < 4) /* FIXME weak boundary checking */
445 goto trunc;
446 TCHECK2(*tptr, 2);
448 code = *tptr++;
450 printf("%s (0x%02x), id %u, length %u",
451 tok2str(cpcodes, "Unknown Opcode",code),
452 code,
453 *tptr++, /* ID */
454 length+2);
456 if (!vflag)
457 return;
459 if (length <= 4)
460 return; /* there may be a NULL confreq etc. */
462 TCHECK2(*tptr, 2);
463 len = EXTRACT_16BITS(tptr);
464 tptr += 2;
466 printf("\n\tencoded length %u (=Option(s) length %u)",len,len-4);
468 if (vflag>1)
469 print_unknown_data(pptr-2,"\n\t",6);
472 switch (code) {
473 case CPCODES_VEXT:
474 if (length < 11)
475 break;
476 TCHECK2(*tptr, 4);
477 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr));
478 tptr += 4;
479 TCHECK2(*tptr, 3);
480 printf(" Vendor: %s (%u)",
481 tok2str(oui_values,"Unknown",EXTRACT_24BITS(tptr)),
482 EXTRACT_24BITS(tptr));
483 /* XXX: need to decode Kind and Value(s)? */
484 break;
485 case CPCODES_CONF_REQ:
486 case CPCODES_CONF_ACK:
487 case CPCODES_CONF_NAK:
488 case CPCODES_CONF_REJ:
489 x = len - 4; /* Code(1), Identifier(1) and Length(2) */
490 do {
491 switch (proto) {
492 case PPP_LCP:
493 pfunc = print_lcp_config_options;
494 break;
495 case PPP_IPCP:
496 pfunc = print_ipcp_config_options;
497 break;
498 case PPP_IPV6CP:
499 pfunc = print_ip6cp_config_options;
500 break;
501 case PPP_CCP:
502 pfunc = print_ccp_config_options;
503 break;
504 case PPP_BACP:
505 pfunc = print_bacp_config_options;
506 break;
507 default:
509 * No print routine for the options for
510 * this protocol.
512 pfunc = NULL;
513 break;
516 if (pfunc == NULL) /* catch the above null pointer if unknown CP */
517 break;
519 if ((j = (*pfunc)(tptr, len)) == 0)
520 break;
521 x -= j;
522 tptr += j;
523 } while (x > 0);
524 break;
526 case CPCODES_TERM_REQ:
527 case CPCODES_TERM_ACK:
528 /* XXX: need to decode Data? */
529 break;
530 case CPCODES_CODE_REJ:
531 /* XXX: need to decode Rejected-Packet? */
532 break;
533 case CPCODES_PROT_REJ:
534 if (length < 6)
535 break;
536 TCHECK2(*tptr, 2);
537 printf("\n\t Rejected %s Protocol (0x%04x)",
538 tok2str(ppptype2str,"unknown", EXTRACT_16BITS(tptr)),
539 EXTRACT_16BITS(tptr));
540 /* XXX: need to decode Rejected-Information? - hexdump for now */
541 if (len > 6) {
542 printf("\n\t Rejected Packet");
543 print_unknown_data(tptr+2,"\n\t ",len-2);
545 break;
546 case CPCODES_ECHO_REQ:
547 case CPCODES_ECHO_RPL:
548 case CPCODES_DISC_REQ:
549 if (length < 8)
550 break;
551 TCHECK2(*tptr, 4);
552 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr));
553 /* XXX: need to decode Data? - hexdump for now */
554 if (len > 8) {
555 printf("\n\t -----trailing data-----");
556 TCHECK2(tptr[4], len-8);
557 print_unknown_data(tptr+4,"\n\t ",len-8);
559 break;
560 case CPCODES_ID:
561 if (length < 8)
562 break;
563 TCHECK2(*tptr, 4);
564 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr));
565 /* RFC 1661 says this is intended to be human readable */
566 if (len > 8) {
567 printf("\n\t Message\n\t ");
568 fn_printn(tptr+4,len-4,snapend);
570 break;
571 case CPCODES_TIME_REM:
572 if (length < 12)
573 break;
574 TCHECK2(*tptr, 4);
575 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr));
576 TCHECK2(*(tptr + 4), 4);
577 printf(", Seconds-Remaining %us", EXTRACT_32BITS(tptr + 4));
578 /* XXX: need to decode Message? */
579 break;
580 default:
581 /* XXX this is dirty but we do not get the
582 * original pointer passed to the begin
583 * the PPP packet */
584 if (vflag <= 1)
585 print_unknown_data(pptr-2,"\n\t ",length+2);
586 break;
588 return;
590 trunc:
591 printf("[|%s]", typestr);
594 /* LCP config options */
595 static int
596 print_lcp_config_options(const u_char *p, int length)
598 int len, opt;
600 if (length < 2)
601 return 0;
602 TCHECK2(*p, 2);
603 len = p[1];
604 opt = p[0];
605 if (length < len)
606 return 0;
607 if (len < 2) {
608 if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX))
609 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)", lcpconfopts[opt],opt,len);
610 else
611 printf("\n\tunknown LCP option 0x%02x", opt);
612 return 0;
614 if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX))
615 printf("\n\t %s Option (0x%02x), length %u: ", lcpconfopts[opt],opt,len);
616 else {
617 printf("\n\tunknown LCP option 0x%02x", opt);
618 return len;
621 switch (opt) {
622 case LCPOPT_VEXT:
623 if (len >= 6) {
624 TCHECK2(*(p + 2), 3);
625 printf("Vendor: %s (%u)",
626 tok2str(oui_values,"Unknown",EXTRACT_24BITS(p+2)),
627 EXTRACT_24BITS(p+2));
628 #if 0
629 TCHECK(p[5]);
630 printf(", kind: 0x%02x", p[5]);
631 printf(", Value: 0x")
632 for (i = 0; i < len - 6; i++) {
633 TCHECK(p[6 + i]);
634 printf("%02x", p[6 + i]);
636 #endif
638 break;
639 case LCPOPT_MRU:
640 if (len == 4) {
641 TCHECK2(*(p + 2), 2);
642 printf("%u", EXTRACT_16BITS(p + 2));
644 break;
645 case LCPOPT_ACCM:
646 if (len == 6) {
647 TCHECK2(*(p + 2), 4);
648 printf("0x%08x", EXTRACT_32BITS(p + 2));
650 break;
651 case LCPOPT_AP:
652 if (len >= 4) {
653 TCHECK2(*(p + 2), 2);
654 printf("%s", tok2str(ppptype2str,"Unknown Auth Proto (0x04x)",EXTRACT_16BITS(p+2)));
656 switch (EXTRACT_16BITS(p+2)) {
657 case PPP_CHAP:
658 TCHECK(p[4]);
659 printf(", %s",tok2str(authalg_values,"Unknown Auth Alg %u",p[4]));
660 break;
661 case PPP_PAP: /* fall through */
662 case PPP_EAP:
663 case PPP_SPAP:
664 case PPP_SPAP_OLD:
665 break;
666 default:
667 print_unknown_data(p,"\n\t",len);
670 break;
671 case LCPOPT_QP:
672 if (len >= 4) {
673 TCHECK2(*(p + 2), 2);
674 if (EXTRACT_16BITS(p+2) == PPP_LQM)
675 printf(" LQR");
676 else
677 printf(" unknown");
679 break;
680 case LCPOPT_MN:
681 if (len == 6) {
682 TCHECK2(*(p + 2), 4);
683 printf("0x%08x", EXTRACT_32BITS(p + 2));
685 break;
686 case LCPOPT_PFC:
687 break;
688 case LCPOPT_ACFC:
689 break;
690 case LCPOPT_LD:
691 if (len == 4) {
692 TCHECK2(*(p + 2), 2);
693 printf("0x%04x", EXTRACT_16BITS(p + 2));
695 break;
696 case LCPOPT_CBACK:
697 if (len < 3)
698 break;
699 TCHECK(p[2]);
700 printf("Callback Operation %s (%u)",
701 tok2str(ppp_callback_values,"Unknown",p[2]),
702 p[2]);
703 break;
704 case LCPOPT_MLMRRU:
705 if (len == 4) {
706 TCHECK2(*(p + 2), 2);
707 printf("%u", EXTRACT_16BITS(p + 2));
709 break;
710 case LCPOPT_MLED:
711 if (len < 3)
712 break;
713 TCHECK(p[2]);
714 switch (p[2]) { /* class */
715 case MEDCLASS_NULL:
716 printf("Null");
717 break;
718 case MEDCLASS_LOCAL:
719 printf("Local"); /* XXX */
720 break;
721 case MEDCLASS_IPV4:
722 if (len != 7)
723 break;
724 TCHECK2(*(p + 3), 4);
725 printf("IPv4 %s", ipaddr_string(p + 3));
726 break;
727 case MEDCLASS_MAC:
728 if (len != 9)
729 break;
730 TCHECK(p[8]);
731 printf("MAC %02x:%02x:%02x:%02x:%02x:%02x",
732 p[3], p[4], p[5], p[6], p[7], p[8]);
733 break;
734 case MEDCLASS_MNB:
735 printf("Magic-Num-Block"); /* XXX */
736 break;
737 case MEDCLASS_PSNDN:
738 printf("PSNDN"); /* XXX */
739 break;
741 break;
743 /* XXX: to be supported */
744 #if 0
745 case LCPOPT_DEP6:
746 case LCPOPT_FCSALT:
747 case LCPOPT_SDP:
748 case LCPOPT_NUMMODE:
749 case LCPOPT_DEP12:
750 case LCPOPT_DEP14:
751 case LCPOPT_DEP15:
752 case LCPOPT_DEP16:
753 case LCPOPT_MLSSNHF:
754 case LCPOPT_PROP:
755 case LCPOPT_DCEID:
756 case LCPOPT_MPP:
757 case LCPOPT_LCPAOPT:
758 case LCPOPT_COBS:
759 case LCPOPT_PE:
760 case LCPOPT_MLHF:
761 case LCPOPT_I18N:
762 case LCPOPT_SDLOS:
763 case LCPOPT_PPPMUX:
764 break;
765 #endif
766 default:
767 if(vflag<2)
768 print_unknown_data(&p[2],"\n\t ",len-2);
769 break;
772 if (vflag>1)
773 print_unknown_data(&p[2],"\n\t ",len-2); /* exclude TLV header */
775 return len;
777 trunc:
778 printf("[|lcp]");
779 return 0;
782 /* ML-PPP*/
783 struct tok ppp_ml_flag_values[] = {
784 { 0x80, "begin" },
785 { 0x40, "end" },
786 { 0, NULL }
789 static void
790 handle_mlppp(const u_char *p, int length) {
792 if (!eflag)
793 printf("MLPPP, ");
795 printf("seq 0x%03x, Flags [%s], length %u",
796 (EXTRACT_16BITS(p))&0x0fff, /* only support 12-Bit sequence space for now */
797 bittok2str(ppp_ml_flag_values, "none", *p & 0xc0),
798 length);
800 return;
803 /* CHAP */
804 static void
805 handle_chap(const u_char *p, int length)
807 u_int code, len;
808 int val_size, name_size, msg_size;
809 const u_char *p0;
810 int i;
812 p0 = p;
813 if (length < 1) {
814 printf("[|chap]");
815 return;
816 } else if (length < 4) {
817 TCHECK(*p);
818 printf("[|chap 0x%02x]", *p);
819 return;
822 TCHECK(*p);
823 code = *p;
824 printf("CHAP, %s (0x%02x)",
825 tok2str(chapcode_values,"unknown",code),
826 code);
827 p++;
829 TCHECK(*p);
830 printf(", id %u", *p); /* ID */
831 p++;
833 TCHECK2(*p, 2);
834 len = EXTRACT_16BITS(p);
835 p += 2;
838 * Note that this is a generic CHAP decoding routine. Since we
839 * don't know which flavor of CHAP (i.e. CHAP-MD5, MS-CHAPv1,
840 * MS-CHAPv2) is used at this point, we can't decode packet
841 * specifically to each algorithms. Instead, we simply decode
842 * the GCD (Gratest Common Denominator) for all algorithms.
844 switch (code) {
845 case CHAP_CHAL:
846 case CHAP_RESP:
847 if (length - (p - p0) < 1)
848 return;
849 TCHECK(*p);
850 val_size = *p; /* value size */
851 p++;
852 if (length - (p - p0) < val_size)
853 return;
854 printf(", Value ");
855 for (i = 0; i < val_size; i++) {
856 TCHECK(*p);
857 printf("%02x", *p++);
859 name_size = len - (p - p0);
860 printf(", Name ");
861 for (i = 0; i < name_size; i++) {
862 TCHECK(*p);
863 safeputchar(*p++);
865 break;
866 case CHAP_SUCC:
867 case CHAP_FAIL:
868 msg_size = len - (p - p0);
869 printf(", Msg ");
870 for (i = 0; i< msg_size; i++) {
871 TCHECK(*p);
872 safeputchar(*p++);
874 break;
876 return;
878 trunc:
879 printf("[|chap]");
882 /* PAP (see RFC 1334) */
883 static void
884 handle_pap(const u_char *p, int length)
886 u_int code, len;
887 int peerid_len, passwd_len, msg_len;
888 const u_char *p0;
889 int i;
891 p0 = p;
892 if (length < 1) {
893 printf("[|pap]");
894 return;
895 } else if (length < 4) {
896 TCHECK(*p);
897 printf("[|pap 0x%02x]", *p);
898 return;
901 TCHECK(*p);
902 code = *p;
903 printf("PAP, %s (0x%02x)",
904 tok2str(papcode_values,"unknown",code),
905 code);
906 p++;
908 TCHECK(*p);
909 printf(", id %u", *p); /* ID */
910 p++;
912 TCHECK2(*p, 2);
913 len = EXTRACT_16BITS(p);
914 p += 2;
916 if ((int)len > length) {
917 printf(", length %u > packet size", len);
918 return;
920 length = len;
921 if (length < (p - p0)) {
922 printf(", length %u < PAP header length", length);
923 return;
926 switch (code) {
927 case PAP_AREQ:
928 if (length - (p - p0) < 1)
929 return;
930 TCHECK(*p);
931 peerid_len = *p; /* Peer-ID Length */
932 p++;
933 if (length - (p - p0) < peerid_len)
934 return;
935 printf(", Peer ");
936 for (i = 0; i < peerid_len; i++) {
937 TCHECK(*p);
938 safeputchar(*p++);
941 if (length - (p - p0) < 1)
942 return;
943 TCHECK(*p);
944 passwd_len = *p; /* Password Length */
945 p++;
946 if (length - (p - p0) < passwd_len)
947 return;
948 printf(", Name ");
949 for (i = 0; i < passwd_len; i++) {
950 TCHECK(*p);
951 safeputchar(*p++);
953 break;
954 case PAP_AACK:
955 case PAP_ANAK:
956 if (length - (p - p0) < 1)
957 return;
958 TCHECK(*p);
959 msg_len = *p; /* Msg-Length */
960 p++;
961 if (length - (p - p0) < msg_len)
962 return;
963 printf(", Msg ");
964 for (i = 0; i< msg_len; i++) {
965 TCHECK(*p);
966 safeputchar(*p++);
968 break;
970 return;
972 trunc:
973 printf("[|pap]");
976 /* BAP */
977 static void
978 handle_bap(const u_char *p _U_, int length _U_)
980 /* XXX: to be supported!! */
984 /* IPCP config options */
985 static int
986 print_ipcp_config_options(const u_char *p, int length)
988 int len, opt;
989 u_int compproto, ipcomp_subopttotallen, ipcomp_subopt, ipcomp_suboptlen;
991 if (length < 2)
992 return 0;
993 TCHECK2(*p, 2);
994 len = p[1];
995 opt = p[0];
996 if (length < len)
997 return 0;
998 if (len < 2) {
999 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1000 tok2str(ipcpopt_values,"unknown",opt),
1001 opt,
1002 len);
1003 return 0;
1006 printf("\n\t %s Option (0x%02x), length %u: ",
1007 tok2str(ipcpopt_values,"unknown",opt),
1008 opt,
1009 len);
1011 switch (opt) {
1012 case IPCPOPT_2ADDR: /* deprecated */
1013 if (len != 10)
1014 goto invlen;
1015 TCHECK2(*(p + 6), 4);
1016 printf("src %s, dst %s",
1017 ipaddr_string(p + 2),
1018 ipaddr_string(p + 6));
1019 break;
1020 case IPCPOPT_IPCOMP:
1021 if (len < 4)
1022 goto invlen;
1023 TCHECK2(*(p + 2), 2);
1024 compproto = EXTRACT_16BITS(p+2);
1026 printf("%s (0x%02x):",
1027 tok2str(ipcpopt_compproto_values,"Unknown",compproto),
1028 compproto);
1030 switch (compproto) {
1031 case PPP_VJC:
1032 /* XXX: VJ-Comp parameters should be decoded */
1033 break;
1034 case IPCPOPT_IPCOMP_HDRCOMP:
1035 if (len < IPCPOPT_IPCOMP_MINLEN)
1036 goto invlen;
1038 TCHECK2(*(p + 2), IPCPOPT_IPCOMP_MINLEN);
1039 printf("\n\t TCP Space %u, non-TCP Space %u" \
1040 ", maxPeriod %u, maxTime %u, maxHdr %u",
1041 EXTRACT_16BITS(p+4),
1042 EXTRACT_16BITS(p+6),
1043 EXTRACT_16BITS(p+8),
1044 EXTRACT_16BITS(p+10),
1045 EXTRACT_16BITS(p+12));
1047 /* suboptions present ? */
1048 if (len > IPCPOPT_IPCOMP_MINLEN) {
1049 ipcomp_subopttotallen = len - IPCPOPT_IPCOMP_MINLEN;
1050 p += IPCPOPT_IPCOMP_MINLEN;
1052 printf("\n\t Suboptions, length %u", ipcomp_subopttotallen);
1054 while (ipcomp_subopttotallen >= 2) {
1055 TCHECK2(*p, 2);
1056 ipcomp_subopt = *p;
1057 ipcomp_suboptlen = *(p+1);
1059 /* sanity check */
1060 if (ipcomp_subopt == 0 ||
1061 ipcomp_suboptlen == 0 )
1062 break;
1064 /* XXX: just display the suboptions for now */
1065 printf("\n\t\t%s Suboption #%u, length %u",
1066 tok2str(ipcpopt_compproto_subopt_values,
1067 "Unknown",
1068 ipcomp_subopt),
1069 ipcomp_subopt,
1070 ipcomp_suboptlen);
1072 ipcomp_subopttotallen -= ipcomp_suboptlen;
1073 p += ipcomp_suboptlen;
1076 break;
1077 default:
1078 break;
1080 break;
1082 case IPCPOPT_ADDR: /* those options share the same format - fall through */
1083 case IPCPOPT_MOBILE4:
1084 case IPCPOPT_PRIDNS:
1085 case IPCPOPT_PRINBNS:
1086 case IPCPOPT_SECDNS:
1087 case IPCPOPT_SECNBNS:
1088 if (len != 6)
1089 goto invlen;
1090 TCHECK2(*(p + 2), 4);
1091 printf("%s", ipaddr_string(p + 2));
1092 break;
1093 default:
1094 if(vflag<2)
1095 print_unknown_data(&p[2],"\n\t ",len-2);
1096 break;
1098 if (vflag>1)
1099 print_unknown_data(&p[2],"\n\t ",len-2); /* exclude TLV header */
1100 return len;
1102 invlen:
1103 printf(", invalid-length-%d", opt);
1104 return 0;
1106 trunc:
1107 printf("[|ipcp]");
1108 return 0;
1111 /* IP6CP config options */
1112 static int
1113 print_ip6cp_config_options(const u_char *p, int length)
1115 int len, opt;
1117 if (length < 2)
1118 return 0;
1119 TCHECK2(*p, 2);
1120 len = p[1];
1121 opt = p[0];
1122 if (length < len)
1123 return 0;
1124 if (len < 2) {
1125 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1126 tok2str(ip6cpopt_values,"unknown",opt),
1127 opt,
1128 len);
1129 return 0;
1132 printf("\n\t %s Option (0x%02x), length %u: ",
1133 tok2str(ip6cpopt_values,"unknown",opt),
1134 opt,
1135 len);
1137 switch (opt) {
1138 case IP6CP_IFID:
1139 if (len != 10)
1140 goto invlen;
1141 TCHECK2(*(p + 2), 8);
1142 printf("%04x:%04x:%04x:%04x",
1143 EXTRACT_16BITS(p + 2),
1144 EXTRACT_16BITS(p + 4),
1145 EXTRACT_16BITS(p + 6),
1146 EXTRACT_16BITS(p + 8));
1147 break;
1148 default:
1149 if(vflag<2)
1150 print_unknown_data(&p[2],"\n\t ",len-2);
1151 break;
1153 if (vflag>1)
1154 print_unknown_data(&p[2],"\n\t ",len-2); /* exclude TLV header */
1156 return len;
1158 invlen:
1159 printf(", invalid-length-%d", opt);
1160 return 0;
1162 trunc:
1163 printf("[|ip6cp]");
1164 return 0;
1168 /* CCP config options */
1169 static int
1170 print_ccp_config_options(const u_char *p, int length)
1172 int len, opt;
1174 if (length < 2)
1175 return 0;
1176 TCHECK2(*p, 2);
1177 len = p[1];
1178 opt = p[0];
1179 if (length < len)
1180 return 0;
1181 if (len < 2) {
1182 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1183 tok2str(ccpconfopts_values, "Unknown", opt),
1184 opt,
1185 len);
1186 return 0;
1189 printf("\n\t %s Option (0x%02x), length %u:",
1190 tok2str(ccpconfopts_values, "Unknown", opt),
1191 opt,
1192 len);
1194 switch (opt) {
1195 /* fall through --> default: nothing supported yet */
1196 case CCPOPT_OUI:
1197 case CCPOPT_PRED1:
1198 case CCPOPT_PRED2:
1199 case CCPOPT_PJUMP:
1200 case CCPOPT_HPPPC:
1201 case CCPOPT_STACLZS:
1202 case CCPOPT_MPPC:
1203 case CCPOPT_GFZA:
1204 case CCPOPT_V42BIS:
1205 case CCPOPT_BSDCOMP:
1206 case CCPOPT_LZSDCP:
1207 case CCPOPT_MVRCA:
1208 case CCPOPT_DEC:
1209 case CCPOPT_DEFLATE:
1210 case CCPOPT_RESV:
1211 default:
1212 if(vflag<2)
1213 print_unknown_data(&p[2],"\n\t ",len-2);
1214 break;
1216 if (vflag>1)
1217 print_unknown_data(&p[2],"\n\t ",len-2); /* exclude TLV header */
1219 return len;
1221 trunc:
1222 printf("[|ccp]");
1223 return 0;
1226 /* BACP config options */
1227 static int
1228 print_bacp_config_options(const u_char *p, int length)
1230 int len, opt;
1232 if (length < 2)
1233 return 0;
1234 TCHECK2(*p, 2);
1235 len = p[1];
1236 opt = p[0];
1237 if (length < len)
1238 return 0;
1239 if (len < 2) {
1240 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1241 tok2str(bacconfopts_values, "Unknown", opt),
1242 opt,
1243 len);
1244 return 0;
1247 printf("\n\t %s Option (0x%02x), length %u:",
1248 tok2str(bacconfopts_values, "Unknown", opt),
1249 opt,
1250 len);
1252 switch (opt) {
1253 case BACPOPT_FPEER:
1254 TCHECK2(*(p + 2), 4);
1255 printf(", Magic-Num 0x%08x", EXTRACT_32BITS(p + 2));
1256 break;
1257 default:
1258 if(vflag<2)
1259 print_unknown_data(&p[2],"\n\t ",len-2);
1260 break;
1262 if (vflag>1)
1263 print_unknown_data(&p[2],"\n\t ",len-2); /* exclude TLV header */
1265 return len;
1267 trunc:
1268 printf("[|bacp]");
1269 return 0;
1273 static void
1274 ppp_hdlc(const u_char *p, int length)
1276 u_char *b, *s, *t, c;
1277 int i, proto;
1278 const void *se;
1280 b = (u_int8_t *)malloc(length);
1281 if (b == NULL)
1282 return;
1285 * Unescape all the data into a temporary, private, buffer.
1286 * Do this so that we dont overwrite the original packet
1287 * contents.
1289 for (s = (u_char *)p, t = b, i = length; i > 0; i--) {
1290 c = *s++;
1291 if (c == 0x7d) {
1292 if (i > 1) {
1293 i--;
1294 c = *s++ ^ 0x20;
1295 } else
1296 continue;
1298 *t++ = c;
1301 se = snapend;
1302 snapend = t;
1304 /* now lets guess about the payload codepoint format */
1305 proto = *b; /* start with a one-octet codepoint guess */
1307 switch (proto) {
1308 case PPP_IP:
1309 ip_print(gndo, b+1, t - b - 1);
1310 goto cleanup;
1311 #ifdef INET6
1312 case PPP_IPV6:
1313 ip6_print(b+1, t - b - 1);
1314 goto cleanup;
1315 #endif
1316 default: /* no luck - try next guess */
1317 break;
1320 proto = EXTRACT_16BITS(b); /* next guess - load two octets */
1322 switch (proto) {
1323 case (PPP_ADDRESS << 8 | PPP_CONTROL): /* looks like a PPP frame */
1324 proto = EXTRACT_16BITS(b+2); /* load the PPP proto-id */
1325 handle_ppp(proto, b+4, t - b - 4);
1326 break;
1327 default: /* last guess - proto must be a PPP proto-id */
1328 handle_ppp(proto, b+2, t - b - 2);
1329 break;
1332 cleanup:
1333 snapend = se;
1334 free(b);
1335 return;
1339 /* PPP */
1340 static void
1341 handle_ppp(u_int proto, const u_char *p, int length)
1343 if ((proto & 0xff00) == 0x7e00) {/* is this an escape code ? */
1344 ppp_hdlc(p-1, length);
1345 return;
1348 switch (proto) {
1349 case PPP_LCP: /* fall through */
1350 case PPP_IPCP:
1351 case PPP_OSICP:
1352 case PPP_MPLSCP:
1353 case PPP_IPV6CP:
1354 case PPP_CCP:
1355 case PPP_BACP:
1356 handle_ctrl_proto(proto, p, length);
1357 break;
1358 case PPP_ML:
1359 handle_mlppp(p, length);
1360 break;
1361 case PPP_CHAP:
1362 handle_chap(p, length);
1363 break;
1364 case PPP_PAP:
1365 handle_pap(p, length);
1366 break;
1367 case PPP_BAP: /* XXX: not yet completed */
1368 handle_bap(p, length);
1369 break;
1370 case ETHERTYPE_IP: /*XXX*/
1371 case PPP_VJNC:
1372 case PPP_IP:
1373 ip_print(gndo, p, length);
1374 break;
1375 #ifdef INET6
1376 case ETHERTYPE_IPV6: /*XXX*/
1377 case PPP_IPV6:
1378 ip6_print(p, length);
1379 break;
1380 #endif
1381 case ETHERTYPE_IPX: /*XXX*/
1382 case PPP_IPX:
1383 ipx_print(p, length);
1384 break;
1385 case PPP_OSI:
1386 isoclns_print(p, length, length);
1387 break;
1388 case PPP_MPLS_UCAST:
1389 case PPP_MPLS_MCAST:
1390 mpls_print(p, length);
1391 break;
1392 case PPP_COMP:
1393 printf("compressed PPP data");
1394 break;
1395 default:
1396 printf("%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto));
1397 print_unknown_data(p,"\n\t",length);
1398 break;
1402 /* Standard PPP printer */
1403 u_int
1404 ppp_print(register const u_char *p, u_int length)
1406 u_int proto,ppp_header;
1407 u_int olen = length; /* _o_riginal length */
1408 u_int hdr_len = 0;
1411 * Here, we assume that p points to the Address and Control
1412 * field (if they present).
1414 if (length < 2)
1415 goto trunc;
1416 TCHECK2(*p, 2);
1417 ppp_header = EXTRACT_16BITS(p);
1419 switch(ppp_header) {
1420 case (PPP_WITHDIRECTION_IN << 8 | PPP_CONTROL):
1421 if (eflag) printf("In ");
1422 p += 2;
1423 length -= 2;
1424 hdr_len += 2;
1425 break;
1426 case (PPP_WITHDIRECTION_OUT << 8 | PPP_CONTROL):
1427 if (eflag) printf("Out ");
1428 p += 2;
1429 length -= 2;
1430 hdr_len += 2;
1431 break;
1432 case (PPP_ADDRESS << 8 | PPP_CONTROL):
1433 p += 2; /* ACFC not used */
1434 length -= 2;
1435 hdr_len += 2;
1436 break;
1438 default:
1439 break;
1442 if (length < 2)
1443 goto trunc;
1444 TCHECK(*p);
1445 if (*p % 2) {
1446 proto = *p; /* PFC is used */
1447 p++;
1448 length--;
1449 hdr_len++;
1450 } else {
1451 TCHECK2(*p, 2);
1452 proto = EXTRACT_16BITS(p);
1453 p += 2;
1454 length -= 2;
1455 hdr_len += 2;
1458 if (eflag)
1459 printf("%s (0x%04x), length %u: ",
1460 tok2str(ppptype2str, "unknown", proto),
1461 proto,
1462 olen);
1464 handle_ppp(proto, p, length);
1465 return (hdr_len);
1466 trunc:
1467 printf("[|ppp]");
1468 return (0);
1472 /* PPP I/F printer */
1473 u_int
1474 ppp_if_print(const struct pcap_pkthdr *h, register const u_char *p)
1476 register u_int length = h->len;
1477 register u_int caplen = h->caplen;
1479 if (caplen < PPP_HDRLEN) {
1480 printf("[|ppp]");
1481 return (caplen);
1484 #if 0
1486 * XXX: seems to assume that there are 2 octets prepended to an
1487 * actual PPP frame. The 1st octet looks like Input/Output flag
1488 * while 2nd octet is unknown, at least to me
1489 * (mshindo@mshindo.net).
1491 * That was what the original tcpdump code did.
1493 * FreeBSD's "if_ppp.c" *does* set the first octet to 1 for outbound
1494 * packets and 0 for inbound packets - but only if the
1495 * protocol field has the 0x8000 bit set (i.e., it's a network
1496 * control protocol); it does so before running the packet through
1497 * "bpf_filter" to see if it should be discarded, and to see
1498 * if we should update the time we sent the most recent packet...
1500 * ...but it puts the original address field back after doing
1501 * so.
1503 * NetBSD's "if_ppp.c" doesn't set the first octet in that fashion.
1505 * I don't know if any PPP implementation handed up to a BPF
1506 * device packets with the first octet being 1 for outbound and
1507 * 0 for inbound packets, so I (guy@alum.mit.edu) don't know
1508 * whether that ever needs to be checked or not.
1510 * Note that NetBSD has a DLT_PPP_SERIAL, which it uses for PPP,
1511 * and its tcpdump appears to assume that the frame always
1512 * begins with an address field and a control field, and that
1513 * the address field might be 0x0f or 0x8f, for Cisco
1514 * point-to-point with HDLC framing as per section 4.3.1 of RFC
1515 * 1547, as well as 0xff, for PPP in HDLC-like framing as per
1516 * RFC 1662.
1518 * (Is the Cisco framing in question what DLT_C_HDLC, in
1519 * BSD/OS, is?)
1521 if (eflag)
1522 printf("%c %4d %02x ", p[0] ? 'O' : 'I', length, p[1]);
1523 #endif
1525 ppp_print(p, length);
1527 return (0);
1531 * PPP I/F printer to use if we know that RFC 1662-style PPP in HDLC-like
1532 * framing, or Cisco PPP with HDLC framing as per section 4.3.1 of RFC 1547,
1533 * is being used (i.e., we don't check for PPP_ADDRESS and PPP_CONTROL,
1534 * discard them *if* those are the first two octets, and parse the remaining
1535 * packet as a PPP packet, as "ppp_print()" does).
1537 * This handles, for example, DLT_PPP_SERIAL in NetBSD.
1539 u_int
1540 ppp_hdlc_if_print(const struct pcap_pkthdr *h, register const u_char *p)
1542 register u_int length = h->len;
1543 register u_int caplen = h->caplen;
1544 u_int proto;
1545 u_int hdrlen = 0;
1547 if (caplen < 2) {
1548 printf("[|ppp]");
1549 return (caplen);
1552 switch (p[0]) {
1554 case PPP_ADDRESS:
1555 if (caplen < 4) {
1556 printf("[|ppp]");
1557 return (caplen);
1560 if (eflag)
1561 printf("%02x %02x %d ", p[0], p[1], length);
1562 p += 2;
1563 length -= 2;
1564 hdrlen += 2;
1566 proto = EXTRACT_16BITS(p);
1567 p += 2;
1568 length -= 2;
1569 hdrlen += 2;
1570 printf("%s: ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto));
1572 handle_ppp(proto, p, length);
1573 break;
1575 case CHDLC_UNICAST:
1576 case CHDLC_BCAST:
1577 return (chdlc_if_print(h, p));
1579 default:
1580 if (eflag)
1581 printf("%02x %02x %d ", p[0], p[1], length);
1582 p += 2;
1583 length -= 2;
1584 hdrlen += 2;
1587 * XXX - NetBSD's "ppp_netbsd_serial_if_print()" treats
1588 * the next two octets as an Ethernet type; does that
1589 * ever happen?
1591 printf("unknown addr %02x; ctrl %02x", p[0], p[1]);
1592 break;
1595 return (hdrlen);
1598 #define PPP_BSDI_HDRLEN 24
1600 /* BSD/OS specific PPP printer */
1601 u_int
1602 ppp_bsdos_if_print(const struct pcap_pkthdr *h _U_, register const u_char *p _U_)
1604 register int hdrlength;
1605 #ifdef __bsdi__
1606 register u_int length = h->len;
1607 register u_int caplen = h->caplen;
1608 u_int16_t ptype;
1609 const u_char *q;
1610 int i;
1612 if (caplen < PPP_BSDI_HDRLEN) {
1613 printf("[|ppp]");
1614 return (caplen)
1617 hdrlength = 0;
1619 #if 0
1620 if (p[0] == PPP_ADDRESS && p[1] == PPP_CONTROL) {
1621 if (eflag)
1622 printf("%02x %02x ", p[0], p[1]);
1623 p += 2;
1624 hdrlength = 2;
1627 if (eflag)
1628 printf("%d ", length);
1629 /* Retrieve the protocol type */
1630 if (*p & 01) {
1631 /* Compressed protocol field */
1632 ptype = *p;
1633 if (eflag)
1634 printf("%02x ", ptype);
1635 p++;
1636 hdrlength += 1;
1637 } else {
1638 /* Un-compressed protocol field */
1639 ptype = ntohs(*(u_int16_t *)p);
1640 if (eflag)
1641 printf("%04x ", ptype);
1642 p += 2;
1643 hdrlength += 2;
1645 #else
1646 ptype = 0; /*XXX*/
1647 if (eflag)
1648 printf("%c ", p[SLC_DIR] ? 'O' : 'I');
1649 if (p[SLC_LLHL]) {
1650 /* link level header */
1651 struct ppp_header *ph;
1653 q = p + SLC_BPFHDRLEN;
1654 ph = (struct ppp_header *)q;
1655 if (ph->phdr_addr == PPP_ADDRESS
1656 && ph->phdr_ctl == PPP_CONTROL) {
1657 if (eflag)
1658 printf("%02x %02x ", q[0], q[1]);
1659 ptype = ntohs(ph->phdr_type);
1660 if (eflag && (ptype == PPP_VJC || ptype == PPP_VJNC)) {
1661 printf("%s ", tok2str(ppptype2str,
1662 "proto-#%d", ptype));
1664 } else {
1665 if (eflag) {
1666 printf("LLH=[");
1667 for (i = 0; i < p[SLC_LLHL]; i++)
1668 printf("%02x", q[i]);
1669 printf("] ");
1673 if (eflag)
1674 printf("%d ", length);
1675 if (p[SLC_CHL]) {
1676 q = p + SLC_BPFHDRLEN + p[SLC_LLHL];
1678 switch (ptype) {
1679 case PPP_VJC:
1680 ptype = vjc_print(q, ptype);
1681 hdrlength = PPP_BSDI_HDRLEN;
1682 p += hdrlength;
1683 switch (ptype) {
1684 case PPP_IP:
1685 ip_print(p, length);
1686 break;
1687 #ifdef INET6
1688 case PPP_IPV6:
1689 ip6_print(p, length);
1690 break;
1691 #endif
1692 case PPP_MPLS_UCAST:
1693 case PPP_MPLS_MCAST:
1694 mpls_print(p, length);
1695 break;
1697 goto printx;
1698 case PPP_VJNC:
1699 ptype = vjc_print(q, ptype);
1700 hdrlength = PPP_BSDI_HDRLEN;
1701 p += hdrlength;
1702 switch (ptype) {
1703 case PPP_IP:
1704 ip_print(p, length);
1705 break;
1706 #ifdef INET6
1707 case PPP_IPV6:
1708 ip6_print(p, length);
1709 break;
1710 #endif
1711 case PPP_MPLS_UCAST:
1712 case PPP_MPLS_MCAST:
1713 mpls_print(p, length);
1714 break;
1716 goto printx;
1717 default:
1718 if (eflag) {
1719 printf("CH=[");
1720 for (i = 0; i < p[SLC_LLHL]; i++)
1721 printf("%02x", q[i]);
1722 printf("] ");
1724 break;
1728 hdrlength = PPP_BSDI_HDRLEN;
1729 #endif
1731 length -= hdrlength;
1732 p += hdrlength;
1734 switch (ptype) {
1735 case PPP_IP:
1736 ip_print(p, length);
1737 break;
1738 #ifdef INET6
1739 case PPP_IPV6:
1740 ip6_print(p, length);
1741 break;
1742 #endif
1743 case PPP_MPLS_UCAST:
1744 case PPP_MPLS_MCAST:
1745 mpls_print(p, length);
1746 break;
1747 default:
1748 printf("%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", ptype));
1751 printx:
1752 #else /* __bsdi */
1753 hdrlength = 0;
1754 #endif /* __bsdi__ */
1755 return (hdrlength);
1760 * Local Variables:
1761 * c-style: whitesmith
1762 * c-basic-offset: 8
1763 * End: