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
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.
29 * o resolve XXX as much as possible
34 #include <sys/cdefs.h>
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)";
40 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
48 #include <tcpdump-stdinc.h>
51 #include <net/slcompress.h>
52 #include <net/if_ppp.h>
59 #include "interface.h"
61 #include "addrtoname.h"
64 #include "ethertype.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
[] = {
79 { PPP_DECNET
, "DECNET" },
80 { PPP_APPLE
, "APPLE" },
82 { PPP_VJC
, "VJC IP" },
83 { PPP_VJNC
, "VJNC IP" },
84 { PPP_BRPDU
, "BRPDU" },
86 { PPP_VINES
, "VINES" },
87 { PPP_MPLS_UCAST
, "MPLS" },
88 { PPP_MPLS_MCAST
, "MPLS" },
89 { PPP_COMP
, "Compressed"},
93 { PPP_HELLO
, "HELLO" },
94 { PPP_LUXCOM
, "LUXCOM" },
97 { PPP_OSICP
, "OSICP" },
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" },
110 { PPP_CHAP
, "CHAP" },
112 { PPP_SPAP
, "SPAP" },
113 { PPP_SPAP_OLD
, "Old-SPAP" },
114 { PPP_BACP
, "BACP" },
116 { PPP_MPCP
, "MLPPP-CP" },
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 */
159 /* LCP Config Options */
161 #define LCPOPT_VEXT 0
163 #define LCPOPT_ACCM 2
167 #define LCPOPT_DEP6 6
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
185 #define LCPOPT_LCPAOPT 24
186 #define LCPOPT_COBS 25
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) */
200 "Auth-Prot", /* (3) */
201 "Qual-Prot", /* (4) */
202 "Magic-Num", /* (5) */
203 "deprecated(6)", /* used to be a Quality Protocol */
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 */
215 "12-Bit seq #", /* (18) */
216 "End-Disc", /* (19) */
217 "Proprietary", /* (20) */
220 "Link-Disc", /* (23) */
221 "LCP-Auth-Opt", /* (24) */
223 "Prefix-elision", /* (26) */
224 "Multilink-header-Form",/* (27) */
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 */
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"},
272 /* BACP Config Options */
274 #define BACPOPT_FPEER 1 /* RFC2125 */
276 const struct tok bacconfopts_values
[] = {
277 { BACPOPT_FPEER
, "Favored-Peer" },
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" },
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" },
315 struct tok ipcpopt_compproto_subopt_values
[] = {
316 { 1, "RTP-Compression" },
317 { 2, "Enhanced RTP-Compression" },
321 /* IP6CP Config Options */
324 struct tok ip6cpopt_values
[] = {
325 { IP6CP_IFID
, "Interface-ID" },
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" },
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" },
385 struct tok chapcode_values
[] = {
386 { CHAP_CHAL
, "Challenge" },
387 { CHAP_RESP
, "Response" },
388 { CHAP_SUCC
, "Success" },
389 { CHAP_FAIL
, "Fail" },
399 struct tok papcode_values
[] = {
400 { PAP_AREQ
, "Auth-Req" },
401 { PAP_AACK
, "Auth-ACK" },
402 { PAP_ANAK
, "Auth-NACK" },
407 #define BAP_CALLREQ 1
408 #define BAP_CALLRES 2
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 */
431 handle_ctrl_proto(u_int proto
, const u_char
*pptr
, int length
)
435 int (*pfunc
)(const u_char
*, int);
441 typestr
= tok2str(ppptype2str
, "unknown ctrl-proto (0x%04x)", proto
);
442 printf("%s, ",typestr
);
444 if (length
< 4) /* FIXME weak boundary checking */
450 printf("%s (0x%02x), id %u, length %u",
451 tok2str(cpcodes
, "Unknown Opcode",code
),
460 return; /* there may be a NULL confreq etc. */
463 len
= EXTRACT_16BITS(tptr
);
466 printf("\n\tencoded length %u (=Option(s) length %u)",len
,len
-4);
469 print_unknown_data(pptr
-2,"\n\t",6);
477 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr
));
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)? */
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) */
493 pfunc
= print_lcp_config_options
;
496 pfunc
= print_ipcp_config_options
;
499 pfunc
= print_ip6cp_config_options
;
502 pfunc
= print_ccp_config_options
;
505 pfunc
= print_bacp_config_options
;
509 * No print routine for the options for
516 if (pfunc
== NULL
) /* catch the above null pointer if unknown CP */
519 if ((j
= (*pfunc
)(tptr
, len
)) == 0)
526 case CPCODES_TERM_REQ
:
527 case CPCODES_TERM_ACK
:
528 /* XXX: need to decode Data? */
530 case CPCODES_CODE_REJ
:
531 /* XXX: need to decode Rejected-Packet? */
533 case CPCODES_PROT_REJ
:
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 */
542 printf("\n\t Rejected Packet");
543 print_unknown_data(tptr
+2,"\n\t ",len
-2);
546 case CPCODES_ECHO_REQ
:
547 case CPCODES_ECHO_RPL
:
548 case CPCODES_DISC_REQ
:
552 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr
));
553 /* XXX: need to decode Data? - hexdump for now */
555 printf("\n\t -----trailing data-----");
556 TCHECK2(tptr
[4], len
-8);
557 print_unknown_data(tptr
+4,"\n\t ",len
-8);
564 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr
));
565 /* RFC 1661 says this is intended to be human readable */
567 printf("\n\t Message\n\t ");
568 fn_printn(tptr
+4,len
-4,snapend
);
571 case CPCODES_TIME_REM
:
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? */
581 /* XXX this is dirty but we do not get the
582 * original pointer passed to the begin
585 print_unknown_data(pptr
-2,"\n\t ",length
+2);
591 printf("[|%s]", typestr
);
594 /* LCP config options */
596 print_lcp_config_options(const u_char
*p
, int length
)
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
);
611 printf("\n\tunknown LCP option 0x%02x", opt
);
614 if ((opt
>= LCPOPT_MIN
) && (opt
<= LCPOPT_MAX
))
615 printf("\n\t %s Option (0x%02x), length %u: ", lcpconfopts
[opt
],opt
,len
);
617 printf("\n\tunknown LCP option 0x%02x", opt
);
624 TCHECK2(*(p
+ 2), 3);
625 printf("Vendor: %s (%u)",
626 tok2str(oui_values
,"Unknown",EXTRACT_24BITS(p
+2)),
627 EXTRACT_24BITS(p
+2));
630 printf(", kind: 0x%02x", p
[5]);
631 printf(", Value: 0x")
632 for (i
= 0; i
< len
- 6; i
++) {
634 printf("%02x", p
[6 + i
]);
641 TCHECK2(*(p
+ 2), 2);
642 printf("%u", EXTRACT_16BITS(p
+ 2));
647 TCHECK2(*(p
+ 2), 4);
648 printf("0x%08x", EXTRACT_32BITS(p
+ 2));
653 TCHECK2(*(p
+ 2), 2);
654 printf("%s", tok2str(ppptype2str
,"Unknown Auth Proto (0x04x)",EXTRACT_16BITS(p
+2)));
656 switch (EXTRACT_16BITS(p
+2)) {
659 printf(", %s",tok2str(authalg_values
,"Unknown Auth Alg %u",p
[4]));
661 case PPP_PAP
: /* fall through */
667 print_unknown_data(p
,"\n\t",len
);
673 TCHECK2(*(p
+ 2), 2);
674 if (EXTRACT_16BITS(p
+2) == PPP_LQM
)
682 TCHECK2(*(p
+ 2), 4);
683 printf("0x%08x", EXTRACT_32BITS(p
+ 2));
692 TCHECK2(*(p
+ 2), 2);
693 printf("0x%04x", EXTRACT_16BITS(p
+ 2));
700 printf("Callback Operation %s (%u)",
701 tok2str(ppp_callback_values
,"Unknown",p
[2]),
706 TCHECK2(*(p
+ 2), 2);
707 printf("%u", EXTRACT_16BITS(p
+ 2));
714 switch (p
[2]) { /* class */
719 printf("Local"); /* XXX */
724 TCHECK2(*(p
+ 3), 4);
725 printf("IPv4 %s", ipaddr_string(p
+ 3));
731 printf("MAC %02x:%02x:%02x:%02x:%02x:%02x",
732 p
[3], p
[4], p
[5], p
[6], p
[7], p
[8]);
735 printf("Magic-Num-Block"); /* XXX */
738 printf("PSNDN"); /* XXX */
743 /* XXX: to be supported */
768 print_unknown_data(&p
[2],"\n\t ",len
-2);
773 print_unknown_data(&p
[2],"\n\t ",len
-2); /* exclude TLV header */
783 struct tok ppp_ml_flag_values
[] = {
790 handle_mlppp(const u_char
*p
, int length
) {
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),
805 handle_chap(const u_char
*p
, int length
)
808 int val_size
, name_size
, msg_size
;
816 } else if (length
< 4) {
818 printf("[|chap 0x%02x]", *p
);
824 printf("CHAP, %s (0x%02x)",
825 tok2str(chapcode_values
,"unknown",code
),
830 printf(", id %u", *p
); /* ID */
834 len
= EXTRACT_16BITS(p
);
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.
847 if (length
- (p
- p0
) < 1)
850 val_size
= *p
; /* value size */
852 if (length
- (p
- p0
) < val_size
)
855 for (i
= 0; i
< val_size
; i
++) {
857 printf("%02x", *p
++);
859 name_size
= len
- (p
- p0
);
861 for (i
= 0; i
< name_size
; i
++) {
868 msg_size
= len
- (p
- p0
);
870 for (i
= 0; i
< msg_size
; i
++) {
882 /* PAP (see RFC 1334) */
884 handle_pap(const u_char
*p
, int length
)
887 int peerid_len
, passwd_len
, msg_len
;
895 } else if (length
< 4) {
897 printf("[|pap 0x%02x]", *p
);
903 printf("PAP, %s (0x%02x)",
904 tok2str(papcode_values
,"unknown",code
),
909 printf(", id %u", *p
); /* ID */
913 len
= EXTRACT_16BITS(p
);
916 if ((int)len
> length
) {
917 printf(", length %u > packet size", len
);
921 if (length
< (p
- p0
)) {
922 printf(", length %u < PAP header length", length
);
928 if (length
- (p
- p0
) < 1)
931 peerid_len
= *p
; /* Peer-ID Length */
933 if (length
- (p
- p0
) < peerid_len
)
936 for (i
= 0; i
< peerid_len
; i
++) {
941 if (length
- (p
- p0
) < 1)
944 passwd_len
= *p
; /* Password Length */
946 if (length
- (p
- p0
) < passwd_len
)
949 for (i
= 0; i
< passwd_len
; i
++) {
956 if (length
- (p
- p0
) < 1)
959 msg_len
= *p
; /* Msg-Length */
961 if (length
- (p
- p0
) < msg_len
)
964 for (i
= 0; i
< msg_len
; i
++) {
978 handle_bap(const u_char
*p _U_
, int length _U_
)
980 /* XXX: to be supported!! */
984 /* IPCP config options */
986 print_ipcp_config_options(const u_char
*p
, int length
)
989 u_int compproto
, ipcomp_subopttotallen
, ipcomp_subopt
, ipcomp_suboptlen
;
999 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1000 tok2str(ipcpopt_values
,"unknown",opt
),
1006 printf("\n\t %s Option (0x%02x), length %u: ",
1007 tok2str(ipcpopt_values
,"unknown",opt
),
1012 case IPCPOPT_2ADDR
: /* deprecated */
1015 TCHECK2(*(p
+ 6), 4);
1016 printf("src %s, dst %s",
1017 ipaddr_string(p
+ 2),
1018 ipaddr_string(p
+ 6));
1020 case IPCPOPT_IPCOMP
:
1023 TCHECK2(*(p
+ 2), 2);
1024 compproto
= EXTRACT_16BITS(p
+2);
1026 printf("%s (0x%02x):",
1027 tok2str(ipcpopt_compproto_values
,"Unknown",compproto
),
1030 switch (compproto
) {
1032 /* XXX: VJ-Comp parameters should be decoded */
1034 case IPCPOPT_IPCOMP_HDRCOMP
:
1035 if (len
< IPCPOPT_IPCOMP_MINLEN
)
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) {
1057 ipcomp_suboptlen
= *(p
+1);
1060 if (ipcomp_subopt
== 0 ||
1061 ipcomp_suboptlen
== 0 )
1064 /* XXX: just display the suboptions for now */
1065 printf("\n\t\t%s Suboption #%u, length %u",
1066 tok2str(ipcpopt_compproto_subopt_values
,
1072 ipcomp_subopttotallen
-= ipcomp_suboptlen
;
1073 p
+= ipcomp_suboptlen
;
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
:
1090 TCHECK2(*(p
+ 2), 4);
1091 printf("%s", ipaddr_string(p
+ 2));
1095 print_unknown_data(&p
[2],"\n\t ",len
-2);
1099 print_unknown_data(&p
[2],"\n\t ",len
-2); /* exclude TLV header */
1103 printf(", invalid-length-%d", opt
);
1111 /* IP6CP config options */
1113 print_ip6cp_config_options(const u_char
*p
, int length
)
1125 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1126 tok2str(ip6cpopt_values
,"unknown",opt
),
1132 printf("\n\t %s Option (0x%02x), length %u: ",
1133 tok2str(ip6cpopt_values
,"unknown",opt
),
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));
1150 print_unknown_data(&p
[2],"\n\t ",len
-2);
1154 print_unknown_data(&p
[2],"\n\t ",len
-2); /* exclude TLV header */
1159 printf(", invalid-length-%d", opt
);
1168 /* CCP config options */
1170 print_ccp_config_options(const u_char
*p
, int length
)
1182 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1183 tok2str(ccpconfopts_values
, "Unknown", opt
),
1189 printf("\n\t %s Option (0x%02x), length %u:",
1190 tok2str(ccpconfopts_values
, "Unknown", opt
),
1195 /* fall through --> default: nothing supported yet */
1201 case CCPOPT_STACLZS
:
1205 case CCPOPT_BSDCOMP
:
1209 case CCPOPT_DEFLATE
:
1213 print_unknown_data(&p
[2],"\n\t ",len
-2);
1217 print_unknown_data(&p
[2],"\n\t ",len
-2); /* exclude TLV header */
1226 /* BACP config options */
1228 print_bacp_config_options(const u_char
*p
, int length
)
1240 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1241 tok2str(bacconfopts_values
, "Unknown", opt
),
1247 printf("\n\t %s Option (0x%02x), length %u:",
1248 tok2str(bacconfopts_values
, "Unknown", opt
),
1254 TCHECK2(*(p
+ 2), 4);
1255 printf(", Magic-Num 0x%08x", EXTRACT_32BITS(p
+ 2));
1259 print_unknown_data(&p
[2],"\n\t ",len
-2);
1263 print_unknown_data(&p
[2],"\n\t ",len
-2); /* exclude TLV header */
1274 ppp_hdlc(const u_char
*p
, int length
)
1276 u_char
*b
, *s
, *t
, c
;
1280 b
= (u_int8_t
*)malloc(length
);
1285 * Unescape all the data into a temporary, private, buffer.
1286 * Do this so that we dont overwrite the original packet
1289 for (s
= (u_char
*)p
, t
= b
, i
= length
; i
> 0; i
--) {
1304 /* now lets guess about the payload codepoint format */
1305 proto
= *b
; /* start with a one-octet codepoint guess */
1309 ip_print(gndo
, b
+1, t
- b
- 1);
1313 ip6_print(b
+1, t
- b
- 1);
1316 default: /* no luck - try next guess */
1320 proto
= EXTRACT_16BITS(b
); /* next guess - load two octets */
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);
1327 default: /* last guess - proto must be a PPP proto-id */
1328 handle_ppp(proto
, b
+2, t
- b
- 2);
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
);
1349 case PPP_LCP
: /* fall through */
1356 handle_ctrl_proto(proto
, p
, length
);
1359 handle_mlppp(p
, length
);
1362 handle_chap(p
, length
);
1365 handle_pap(p
, length
);
1367 case PPP_BAP
: /* XXX: not yet completed */
1368 handle_bap(p
, length
);
1370 case ETHERTYPE_IP
: /*XXX*/
1373 ip_print(gndo
, p
, length
);
1376 case ETHERTYPE_IPV6
: /*XXX*/
1378 ip6_print(p
, length
);
1381 case ETHERTYPE_IPX
: /*XXX*/
1383 ipx_print(p
, length
);
1386 isoclns_print(p
, length
, length
);
1388 case PPP_MPLS_UCAST
:
1389 case PPP_MPLS_MCAST
:
1390 mpls_print(p
, length
);
1393 printf("compressed PPP data");
1396 printf("%s ", tok2str(ppptype2str
, "unknown PPP protocol (0x%04x)", proto
));
1397 print_unknown_data(p
,"\n\t",length
);
1402 /* Standard PPP printer */
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 */
1411 * Here, we assume that p points to the Address and Control
1412 * field (if they present).
1417 ppp_header
= EXTRACT_16BITS(p
);
1419 switch(ppp_header
) {
1420 case (PPP_WITHDIRECTION_IN
<< 8 | PPP_CONTROL
):
1421 if (eflag
) printf("In ");
1426 case (PPP_WITHDIRECTION_OUT
<< 8 | PPP_CONTROL
):
1427 if (eflag
) printf("Out ");
1432 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
):
1433 p
+= 2; /* ACFC not used */
1446 proto
= *p
; /* PFC is used */
1452 proto
= EXTRACT_16BITS(p
);
1459 printf("%s (0x%04x), length %u: ",
1460 tok2str(ppptype2str
, "unknown", proto
),
1464 handle_ppp(proto
, p
, length
);
1472 /* PPP I/F printer */
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
) {
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
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
1518 * (Is the Cisco framing in question what DLT_C_HDLC, in
1522 printf("%c %4d %02x ", p
[0] ? 'O' : 'I', length
, p
[1]);
1525 ppp_print(p
, length
);
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.
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
;
1561 printf("%02x %02x %d ", p
[0], p
[1], length
);
1566 proto
= EXTRACT_16BITS(p
);
1570 printf("%s: ", tok2str(ppptype2str
, "unknown PPP protocol (0x%04x)", proto
));
1572 handle_ppp(proto
, p
, length
);
1577 return (chdlc_if_print(h
, p
));
1581 printf("%02x %02x %d ", p
[0], p
[1], length
);
1587 * XXX - NetBSD's "ppp_netbsd_serial_if_print()" treats
1588 * the next two octets as an Ethernet type; does that
1591 printf("unknown addr %02x; ctrl %02x", p
[0], p
[1]);
1598 #define PPP_BSDI_HDRLEN 24
1600 /* BSD/OS specific PPP printer */
1602 ppp_bsdos_if_print(const struct pcap_pkthdr
*h _U_
, register const u_char
*p _U_
)
1604 register int hdrlength
;
1606 register u_int length
= h
->len
;
1607 register u_int caplen
= h
->caplen
;
1612 if (caplen
< PPP_BSDI_HDRLEN
) {
1620 if (p
[0] == PPP_ADDRESS
&& p
[1] == PPP_CONTROL
) {
1622 printf("%02x %02x ", p
[0], p
[1]);
1628 printf("%d ", length
);
1629 /* Retrieve the protocol type */
1631 /* Compressed protocol field */
1634 printf("%02x ", ptype
);
1638 /* Un-compressed protocol field */
1639 ptype
= ntohs(*(u_int16_t
*)p
);
1641 printf("%04x ", ptype
);
1648 printf("%c ", p
[SLC_DIR
] ? 'O' : 'I');
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
) {
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
));
1667 for (i
= 0; i
< p
[SLC_LLHL
]; i
++)
1668 printf("%02x", q
[i
]);
1674 printf("%d ", length
);
1676 q
= p
+ SLC_BPFHDRLEN
+ p
[SLC_LLHL
];
1680 ptype
= vjc_print(q
, ptype
);
1681 hdrlength
= PPP_BSDI_HDRLEN
;
1685 ip_print(p
, length
);
1689 ip6_print(p
, length
);
1692 case PPP_MPLS_UCAST
:
1693 case PPP_MPLS_MCAST
:
1694 mpls_print(p
, length
);
1699 ptype
= vjc_print(q
, ptype
);
1700 hdrlength
= PPP_BSDI_HDRLEN
;
1704 ip_print(p
, length
);
1708 ip6_print(p
, length
);
1711 case PPP_MPLS_UCAST
:
1712 case PPP_MPLS_MCAST
:
1713 mpls_print(p
, length
);
1720 for (i
= 0; i
< p
[SLC_LLHL
]; i
++)
1721 printf("%02x", q
[i
]);
1728 hdrlength
= PPP_BSDI_HDRLEN
;
1731 length
-= hdrlength
;
1736 ip_print(p
, length
);
1740 ip6_print(p
, length
);
1743 case PPP_MPLS_UCAST
:
1744 case PPP_MPLS_MCAST
:
1745 mpls_print(p
, length
);
1748 printf("%s ", tok2str(ppptype2str
, "unknown PPP protocol (0x%04x)", ptype
));
1754 #endif /* __bsdi__ */
1761 * c-style: whitesmith