2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
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
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.
21 * Extensively modified by Motonori Shindo (mshindo@mshindo.net) for more
22 * complete PPP support.
27 * o resolve XXX as much as possible
33 static const char rcsid
[] _U_
=
34 "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.113 2005-11-03 07:30:25 hannes Exp $ (LBL)";
41 #include <tcpdump-stdinc.h>
44 #include <net/slcompress.h>
45 #include <net/if_ppp.h>
52 #include "interface.h"
54 #include "addrtoname.h"
57 #include "ethertype.h"
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.
66 /* Protocol Codes defined in ppp.h */
68 struct tok ppptype2str
[] = {
72 { PPP_DECNET
, "DECNET" },
73 { PPP_APPLE
, "APPLE" },
75 { PPP_VJC
, "VJC IP" },
76 { PPP_VJNC
, "VJNC IP" },
77 { PPP_BRPDU
, "BRPDU" },
79 { PPP_VINES
, "VINES" },
80 { PPP_MPLS_UCAST
, "MPLS" },
81 { PPP_MPLS_MCAST
, "MPLS" },
82 { PPP_COMP
, "Compressed"},
86 { PPP_HELLO
, "HELLO" },
87 { PPP_LUXCOM
, "LUXCOM" },
90 { PPP_OSICP
, "OSICP" },
92 { PPP_DECNETCP
, "DECNETCP" },
93 { PPP_APPLECP
, "APPLECP" },
94 { PPP_IPXCP
, "IPXCP" },
95 { PPP_STIICP
, "STIICP" },
96 { PPP_VINESCP
, "VINESCP" },
97 { PPP_IPV6CP
, "IP6CP" },
98 { PPP_MPLSCP
, "MPLSCP" },
103 { PPP_CHAP
, "CHAP" },
105 { PPP_SPAP
, "SPAP" },
106 { PPP_SPAP_OLD
, "Old-SPAP" },
107 { PPP_BACP
, "BACP" },
109 { PPP_MPCP
, "MLPPP-CP" },
113 /* Control Protocols (LCP/IPCP/CCP etc.) Codes defined in RFC 1661 */
115 #define CPCODES_VEXT 0 /* Vendor-Specific (RFC2153) */
116 #define CPCODES_CONF_REQ 1 /* Configure-Request */
117 #define CPCODES_CONF_ACK 2 /* Configure-Ack */
118 #define CPCODES_CONF_NAK 3 /* Configure-Nak */
119 #define CPCODES_CONF_REJ 4 /* Configure-Reject */
120 #define CPCODES_TERM_REQ 5 /* Terminate-Request */
121 #define CPCODES_TERM_ACK 6 /* Terminate-Ack */
122 #define CPCODES_CODE_REJ 7 /* Code-Reject */
123 #define CPCODES_PROT_REJ 8 /* Protocol-Reject (LCP only) */
124 #define CPCODES_ECHO_REQ 9 /* Echo-Request (LCP only) */
125 #define CPCODES_ECHO_RPL 10 /* Echo-Reply (LCP only) */
126 #define CPCODES_DISC_REQ 11 /* Discard-Request (LCP only) */
127 #define CPCODES_ID 12 /* Identification (LCP only) RFC1570 */
128 #define CPCODES_TIME_REM 13 /* Time-Remaining (LCP only) RFC1570 */
129 #define CPCODES_RESET_REQ 14 /* Reset-Request (CCP only) RFC1962 */
130 #define CPCODES_RESET_REP 15 /* Reset-Reply (CCP only) */
132 struct tok cpcodes
[] = {
133 {CPCODES_VEXT
, "Vendor-Extension"}, /* RFC2153 */
134 {CPCODES_CONF_REQ
, "Conf-Request"},
135 {CPCODES_CONF_ACK
, "Conf-Ack"},
136 {CPCODES_CONF_NAK
, "Conf-Nack"},
137 {CPCODES_CONF_REJ
, "Conf-Reject"},
138 {CPCODES_TERM_REQ
, "Term-Request"},
139 {CPCODES_TERM_ACK
, "Term-Ack"},
140 {CPCODES_CODE_REJ
, "Code-Reject"},
141 {CPCODES_PROT_REJ
, "Prot-Reject"},
142 {CPCODES_ECHO_REQ
, "Echo-Request"},
143 {CPCODES_ECHO_RPL
, "Echo-Reply"},
144 {CPCODES_DISC_REQ
, "Disc-Req"},
145 {CPCODES_ID
, "Ident"}, /* RFC1570 */
146 {CPCODES_TIME_REM
, "Time-Rem"}, /* RFC1570 */
147 {CPCODES_RESET_REQ
, "Reset-Req"}, /* RFC1962 */
148 {CPCODES_RESET_REP
, "Reset-Ack"}, /* RFC1962 */
152 /* LCP Config Options */
154 #define LCPOPT_VEXT 0
156 #define LCPOPT_ACCM 2
160 #define LCPOPT_DEP6 6
162 #define LCPOPT_ACFC 8
163 #define LCPOPT_FCSALT 9
164 #define LCPOPT_SDP 10
165 #define LCPOPT_NUMMODE 11
166 #define LCPOPT_DEP12 12
167 #define LCPOPT_CBACK 13
168 #define LCPOPT_DEP14 14
169 #define LCPOPT_DEP15 15
170 #define LCPOPT_DEP16 16
171 #define LCPOPT_MLMRRU 17
172 #define LCPOPT_MLSSNHF 18
173 #define LCPOPT_MLED 19
174 #define LCPOPT_PROP 20
175 #define LCPOPT_DCEID 21
176 #define LCPOPT_MPP 22
178 #define LCPOPT_LCPAOPT 24
179 #define LCPOPT_COBS 25
181 #define LCPOPT_MLHF 27
182 #define LCPOPT_I18N 28
183 #define LCPOPT_SDLOS 29
184 #define LCPOPT_PPPMUX 30
186 #define LCPOPT_MIN LCPOPT_VEXT
187 #define LCPOPT_MAX LCPOPT_PPPMUX
189 static const char *lcpconfopts
[] = {
190 "Vend-Ext", /* (0) */
193 "Auth-Prot", /* (3) */
194 "Qual-Prot", /* (4) */
195 "Magic-Num", /* (5) */
196 "deprecated(6)", /* used to be a Quality Protocol */
201 "Num-Mode", /* (11) */
202 "deprecated(12)", /* used to be a Multi-Link-Procedure*/
203 "Call-Back", /* (13) */
204 "deprecated(14)", /* used to be a Connect-Time */
205 "deprecated(15)", /* used to be a Compund-Frames */
206 "deprecated(16)", /* used to be a Nominal-Data-Encap */
208 "12-Bit seq #", /* (18) */
209 "End-Disc", /* (19) */
210 "Proprietary", /* (20) */
213 "Link-Disc", /* (23) */
214 "LCP-Auth-Opt", /* (24) */
216 "Prefix-elision", /* (26) */
217 "Multilink-header-Form",/* (27) */
219 "SDL-over-SONET/SDH", /* (29) */
220 "PPP-Muxing", /* (30) */
223 /* ECP - to be supported */
225 /* CCP Config Options */
227 #define CCPOPT_OUI 0 /* RFC1962 */
228 #define CCPOPT_PRED1 1 /* RFC1962 */
229 #define CCPOPT_PRED2 2 /* RFC1962 */
230 #define CCPOPT_PJUMP 3 /* RFC1962 */
231 /* 4-15 unassigned */
232 #define CCPOPT_HPPPC 16 /* RFC1962 */
233 #define CCPOPT_STACLZS 17 /* RFC1974 */
234 #define CCPOPT_MPPC 18 /* RFC2118 */
235 #define CCPOPT_GFZA 19 /* RFC1962 */
236 #define CCPOPT_V42BIS 20 /* RFC1962 */
237 #define CCPOPT_BSDCOMP 21 /* RFC1977 */
239 #define CCPOPT_LZSDCP 23 /* RFC1967 */
240 #define CCPOPT_MVRCA 24 /* RFC1975 */
241 #define CCPOPT_DEC 25 /* RFC1976 */
242 #define CCPOPT_DEFLATE 26 /* RFC1979 */
243 /* 27-254 unassigned */
244 #define CCPOPT_RESV 255 /* RFC1962 */
246 const struct tok ccpconfopts_values
[] = {
247 { CCPOPT_OUI
, "OUI" },
248 { CCPOPT_PRED1
, "Pred-1" },
249 { CCPOPT_PRED2
, "Pred-2" },
250 { CCPOPT_PJUMP
, "Puddle" },
251 { CCPOPT_HPPPC
, "HP-PPC" },
252 { CCPOPT_STACLZS
, "Stac-LZS" },
253 { CCPOPT_MPPC
, "MPPC" },
254 { CCPOPT_GFZA
, "Gand-FZA" },
255 { CCPOPT_V42BIS
, "V.42bis" },
256 { CCPOPT_BSDCOMP
, "BSD-Comp" },
257 { CCPOPT_LZSDCP
, "LZS-DCP" },
258 { CCPOPT_MVRCA
, "MVRCA" },
259 { CCPOPT_DEC
, "DEC" },
260 { CCPOPT_DEFLATE
, "Deflate" },
261 { CCPOPT_RESV
, "Reserved"},
265 /* BACP Config Options */
267 #define BACPOPT_FPEER 1 /* RFC2125 */
269 const struct tok bacconfopts_values
[] = {
270 { BACPOPT_FPEER
, "Favored-Peer" },
275 /* SDCP - to be supported */
277 /* IPCP Config Options */
278 #define IPCPOPT_2ADDR 1 /* RFC1172, RFC1332 (deprecated) */
279 #define IPCPOPT_IPCOMP 2 /* RFC1332 */
280 #define IPCPOPT_ADDR 3 /* RFC1332 */
281 #define IPCPOPT_MOBILE4 4 /* RFC2290 */
282 #define IPCPOPT_PRIDNS 129 /* RFC1877 */
283 #define IPCPOPT_PRINBNS 130 /* RFC1877 */
284 #define IPCPOPT_SECDNS 131 /* RFC1877 */
285 #define IPCPOPT_SECNBNS 132 /* RFC1877 */
287 struct tok ipcpopt_values
[] = {
288 { IPCPOPT_2ADDR
, "IP-Addrs" },
289 { IPCPOPT_IPCOMP
, "IP-Comp" },
290 { IPCPOPT_ADDR
, "IP-Addr" },
291 { IPCPOPT_MOBILE4
, "Home-Addr" },
292 { IPCPOPT_PRIDNS
, "Pri-DNS" },
293 { IPCPOPT_PRINBNS
, "Pri-NBNS" },
294 { IPCPOPT_SECDNS
, "Sec-DNS" },
295 { IPCPOPT_SECNBNS
, "Sec-NBNS" },
300 /* IP6CP Config Options */
303 struct tok ip6cpopt_values
[] = {
304 { IP6CP_IFID
, "Interface-ID" },
308 /* ATCP - to be supported */
309 /* OSINLCP - to be supported */
310 /* BVCP - to be supported */
311 /* BCP - to be supported */
312 /* IPXCP - to be supported */
313 /* MPLSCP - to be supported */
315 /* Auth Algorithms */
317 /* 0-4 Reserved (RFC1994) */
318 #define AUTHALG_CHAPMD5 5 /* RFC1994 */
319 #define AUTHALG_MSCHAP1 128 /* RFC2433 */
320 #define AUTHALG_MSCHAP2 129 /* RFC2795 */
322 struct tok authalg_values
[] = {
323 { AUTHALG_CHAPMD5
, "MD5" },
324 { AUTHALG_MSCHAP1
, "MS-CHAPv1" },
325 { AUTHALG_MSCHAP2
, "MS-CHAPv2" },
329 /* FCS Alternatives - to be supported */
331 /* Multilink Endpoint Discriminator (RFC1717) */
332 #define MEDCLASS_NULL 0 /* Null Class */
333 #define MEDCLASS_LOCAL 1 /* Locally Assigned */
334 #define MEDCLASS_IPV4 2 /* Internet Protocol (IPv4) */
335 #define MEDCLASS_MAC 3 /* IEEE 802.1 global MAC address */
336 #define MEDCLASS_MNB 4 /* PPP Magic Number Block */
337 #define MEDCLASS_PSNDN 5 /* Public Switched Network Director Number */
339 /* PPP LCP Callback */
340 #define CALLBACK_AUTH 0 /* Location determined by user auth */
341 #define CALLBACK_DSTR 1 /* Dialing string */
342 #define CALLBACK_LID 2 /* Location identifier */
343 #define CALLBACK_E164 3 /* E.164 number */
344 #define CALLBACK_X500 4 /* X.500 distinguished name */
345 #define CALLBACK_CBCP 6 /* Location is determined during CBCP nego */
347 struct tok ppp_callback_values
[] = {
348 { CALLBACK_AUTH
, "UserAuth" },
349 { CALLBACK_DSTR
, "DialString" },
350 { CALLBACK_LID
, "LocalID" },
351 { CALLBACK_E164
, "E.164" },
352 { CALLBACK_X500
, "X.500" },
353 { CALLBACK_CBCP
, "CBCP" },
364 struct tok chapcode_values
[] = {
365 { CHAP_CHAL
, "Challenge" },
366 { CHAP_RESP
, "Response" },
367 { CHAP_SUCC
, "Success" },
368 { CHAP_FAIL
, "Fail" },
378 struct tok papcode_values
[] = {
379 { PAP_AREQ
, "Auth-Req" },
380 { PAP_AACK
, "Auth-ACK" },
381 { PAP_ANAK
, "Auth-NACK" },
386 #define BAP_CALLREQ 1
387 #define BAP_CALLRES 2
395 static void handle_ctrl_proto (u_int proto
,const u_char
*p
, int length
);
396 static void handle_chap (const u_char
*p
, int length
);
397 static void handle_pap (const u_char
*p
, int length
);
398 static void handle_bap (const u_char
*p
, int length
);
399 static void handle_mlppp(const u_char
*p
, int length
);
400 static int print_lcp_config_options (const u_char
*p
, int);
401 static int print_ipcp_config_options (const u_char
*p
, int);
402 static int print_ip6cp_config_options (const u_char
*p
, int);
403 static int print_ccp_config_options (const u_char
*p
, int);
404 static int print_bacp_config_options (const u_char
*p
, int);
405 static void handle_ppp (u_int proto
, const u_char
*p
, int length
);
406 static void ppp_hdlc(const u_char
*p
, int length
);
408 /* generic Control Protocol (e.g. LCP, IPCP, CCP, etc.) handler */
410 handle_ctrl_proto(u_int proto
, const u_char
*pptr
, int length
)
414 int (*pfunc
)(const u_char
*, int);
420 typestr
= tok2str(ppptype2str
, "unknown ctrl-proto (0x%04x)", proto
);
421 printf("%s, ",typestr
);
423 if (length
< 4) /* FIXME weak boundary checking */
429 printf("%s (0x%02x), id %u, length %u",
430 tok2str(cpcodes
, "Unknown Opcode",code
),
439 return; /* there may be a NULL confreq etc. */
442 len
= EXTRACT_16BITS(tptr
);
445 printf("\n\tencoded length %u (=Option(s) length %u)",len
,len
-4);
448 print_unknown_data(pptr
-2,"\n\t",6);
456 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr
));
459 printf(" Vendor: %s (%u)",
460 tok2str(oui_values
,"Unknown",EXTRACT_24BITS(tptr
)),
461 EXTRACT_24BITS(tptr
));
462 /* XXX: need to decode Kind and Value(s)? */
464 case CPCODES_CONF_REQ
:
465 case CPCODES_CONF_ACK
:
466 case CPCODES_CONF_NAK
:
467 case CPCODES_CONF_REJ
:
468 x
= len
- 4; /* Code(1), Identifier(1) and Length(2) */
472 pfunc
= print_lcp_config_options
;
475 pfunc
= print_ipcp_config_options
;
478 pfunc
= print_ip6cp_config_options
;
481 pfunc
= print_ccp_config_options
;
484 pfunc
= print_bacp_config_options
;
488 * No print routine for the options for
495 if (pfunc
== NULL
) /* catch the above null pointer if unknown CP */
498 if ((j
= (*pfunc
)(tptr
, len
)) == 0)
505 case CPCODES_TERM_REQ
:
506 case CPCODES_TERM_ACK
:
507 /* XXX: need to decode Data? */
509 case CPCODES_CODE_REJ
:
510 /* XXX: need to decode Rejected-Packet? */
512 case CPCODES_PROT_REJ
:
516 printf("\n\t Rejected %s Protocol (0x%04x)",
517 tok2str(ppptype2str
,"unknown", EXTRACT_16BITS(tptr
)),
518 EXTRACT_16BITS(tptr
));
519 /* XXX: need to decode Rejected-Information? - hexdump for now */
521 printf("\n\t Rejected Packet");
522 print_unknown_data(tptr
+2,"\n\t ",len
-2);
525 case CPCODES_ECHO_REQ
:
526 case CPCODES_ECHO_RPL
:
527 case CPCODES_DISC_REQ
:
531 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr
));
532 /* XXX: need to decode Data? - hexdump for now */
534 printf("\n\t -----trailing data-----");
535 TCHECK2(tptr
[4], len
-8);
536 print_unknown_data(tptr
+4,"\n\t ",len
-8);
543 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr
));
544 /* RFC 1661 says this is intended to be human readable */
546 printf("\n\t Message\n\t ");
547 fn_printn(tptr
+4,len
-4,snapend
);
550 case CPCODES_TIME_REM
:
554 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr
));
555 TCHECK2(*(tptr
+ 4), 4);
556 printf(", Seconds-Remaining %us", EXTRACT_32BITS(tptr
+ 4));
557 /* XXX: need to decode Message? */
560 /* XXX this is dirty but we do not get the
561 * original pointer passed to the begin
564 print_unknown_data(pptr
-2,"\n\t ",length
+2);
570 printf("[|%s]", typestr
);
573 /* LCP config options */
575 print_lcp_config_options(const u_char
*p
, int length
)
587 if ((opt
>= LCPOPT_MIN
) && (opt
<= LCPOPT_MAX
))
588 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)", lcpconfopts
[opt
],opt
,len
);
590 printf("\n\tunknown LCP option 0x%02x", opt
);
593 if ((opt
>= LCPOPT_MIN
) && (opt
<= LCPOPT_MAX
))
594 printf("\n\t %s Option (0x%02x), length %u: ", lcpconfopts
[opt
],opt
,len
);
596 printf("\n\tunknown LCP option 0x%02x", opt
);
603 TCHECK2(*(p
+ 2), 3);
604 printf("Vendor: %s (%u)",
605 tok2str(oui_values
,"Unknown",EXTRACT_24BITS(p
+2)),
606 EXTRACT_24BITS(p
+2));
609 printf(", kind: 0x%02x", p
[5]);
610 printf(", Value: 0x")
611 for (i
= 0; i
< len
- 6; i
++) {
613 printf("%02x", p
[6 + i
]);
620 TCHECK2(*(p
+ 2), 2);
621 printf("%u", EXTRACT_16BITS(p
+ 2));
626 TCHECK2(*(p
+ 2), 4);
627 printf("0x%08x", EXTRACT_32BITS(p
+ 2));
632 TCHECK2(*(p
+ 2), 2);
633 printf("%s", tok2str(ppptype2str
,"Unknown Auth Proto (0x04x)",EXTRACT_16BITS(p
+2)));
635 switch (EXTRACT_16BITS(p
+2)) {
638 printf(", %s",tok2str(authalg_values
,"Unknown Auth Alg %u",p
[4]));
640 case PPP_PAP
: /* fall through */
646 print_unknown_data(p
,"\n\t",len
);
652 TCHECK2(*(p
+ 2), 2);
653 if (EXTRACT_16BITS(p
+2) == PPP_LQM
)
661 TCHECK2(*(p
+ 2), 4);
662 printf("0x%08x", EXTRACT_32BITS(p
+ 2));
671 TCHECK2(*(p
+ 2), 2);
672 printf("0x%04x", EXTRACT_16BITS(p
+ 2));
679 printf("Callback Operation %s (%u)",
680 tok2str(ppp_callback_values
,"Unknown",p
[2]),
685 TCHECK2(*(p
+ 2), 2);
686 printf("%u", EXTRACT_16BITS(p
+ 2));
693 switch (p
[2]) { /* class */
698 printf("Local"); /* XXX */
703 TCHECK2(*(p
+ 3), 4);
704 printf("IPv4 %s", ipaddr_string(p
+ 3));
710 printf("MAC %02x:%02x:%02x:%02x:%02x:%02x",
711 p
[3], p
[4], p
[5], p
[6], p
[7], p
[8]);
714 printf("Magic-Num-Block"); /* XXX */
717 printf("PSNDN"); /* XXX */
722 /* XXX: to be supported */
747 print_unknown_data(&p
[2],"\n\t ",len
-2);
752 print_unknown_data(&p
[2],"\n\t ",len
-2); /* exclude TLV header */
762 struct tok ppp_ml_flag_values
[] = {
769 handle_mlppp(const u_char
*p
, int length
) {
774 printf("seq 0x%03x, Flags [%s], length %u",
775 (EXTRACT_16BITS(p
))&0x0fff, /* only support 12-Bit sequence space for now */
776 bittok2str(ppp_ml_flag_values
, "none", *p
& 0xc0),
784 handle_chap(const u_char
*p
, int length
)
787 int val_size
, name_size
, msg_size
;
795 } else if (length
< 4) {
797 printf("[|chap 0x%02x]", *p
);
803 printf("CHAP, %s (0x%02x)",
804 tok2str(chapcode_values
,"unknown",code
),
809 printf(", id %u", *p
); /* ID */
813 len
= EXTRACT_16BITS(p
);
817 * Note that this is a generic CHAP decoding routine. Since we
818 * don't know which flavor of CHAP (i.e. CHAP-MD5, MS-CHAPv1,
819 * MS-CHAPv2) is used at this point, we can't decode packet
820 * specifically to each algorithms. Instead, we simply decode
821 * the GCD (Gratest Common Denominator) for all algorithms.
826 if (length
- (p
- p0
) < 1)
829 val_size
= *p
; /* value size */
831 if (length
- (p
- p0
) < val_size
)
834 for (i
= 0; i
< val_size
; i
++) {
836 printf("%02x", *p
++);
838 name_size
= len
- (p
- p0
);
840 for (i
= 0; i
< name_size
; i
++) {
847 msg_size
= len
- (p
- p0
);
849 for (i
= 0; i
< msg_size
; i
++) {
861 /* PAP (see RFC 1334) */
863 handle_pap(const u_char
*p
, int length
)
866 int peerid_len
, passwd_len
, msg_len
;
874 } else if (length
< 4) {
876 printf("[|pap 0x%02x]", *p
);
882 printf("PAP, %s (0x%02x)",
883 tok2str(papcode_values
,"unknown",code
),
888 printf(", id %u", *p
); /* ID */
892 len
= EXTRACT_16BITS(p
);
895 if ((int)len
> length
) {
896 printf(", length %u > packet size", len
);
900 if (length
< (p
- p0
)) {
901 printf(", length %u < PAP header length", length
);
907 if (length
- (p
- p0
) < 1)
910 peerid_len
= *p
; /* Peer-ID Length */
912 if (length
- (p
- p0
) < peerid_len
)
915 for (i
= 0; i
< peerid_len
; i
++) {
920 if (length
- (p
- p0
) < 1)
923 passwd_len
= *p
; /* Password Length */
925 if (length
- (p
- p0
) < passwd_len
)
928 for (i
= 0; i
< passwd_len
; i
++) {
935 if (length
- (p
- p0
) < 1)
938 msg_len
= *p
; /* Msg-Length */
940 if (length
- (p
- p0
) < msg_len
)
943 for (i
= 0; i
< msg_len
; i
++) {
957 handle_bap(const u_char
*p _U_
, int length _U_
)
959 /* XXX: to be supported!! */
963 /* IPCP config options */
965 print_ipcp_config_options(const u_char
*p
, int length
)
977 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
978 tok2str(ipcpopt_values
,"unknown",opt
),
984 printf("\n\t %s Option (0x%02x), length %u: ",
985 tok2str(ipcpopt_values
,"unknown",opt
),
990 case IPCPOPT_2ADDR
: /* deprecated */
993 TCHECK2(*(p
+ 6), 4);
994 printf("src %s, dst %s",
995 ipaddr_string(p
+ 2),
996 ipaddr_string(p
+ 6));
1001 TCHECK2(*(p
+ 2), 2);
1002 if (EXTRACT_16BITS(p
+ 2) == PPP_VJC
) {
1004 /* XXX: VJ-Comp parameters should be decoded */
1006 printf("unknown-comp-proto %04x", EXTRACT_16BITS(p
+ 2));
1009 case IPCPOPT_ADDR
: /* those options share the same format - fall through */
1010 case IPCPOPT_MOBILE4
:
1011 case IPCPOPT_PRIDNS
:
1012 case IPCPOPT_PRINBNS
:
1013 case IPCPOPT_SECDNS
:
1014 case IPCPOPT_SECNBNS
:
1017 TCHECK2(*(p
+ 2), 4);
1018 printf("%s", ipaddr_string(p
+ 2));
1022 print_unknown_data(&p
[2],"\n\t ",len
-2);
1026 print_unknown_data(&p
[2],"\n\t ",len
-2); /* exclude TLV header */
1030 printf(", invalid-length-%d", opt
);
1038 /* IP6CP config options */
1040 print_ip6cp_config_options(const u_char
*p
, int length
)
1052 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1053 tok2str(ip6cpopt_values
,"unknown",opt
),
1059 printf("\n\t %s Option (0x%02x), length %u: ",
1060 tok2str(ip6cpopt_values
,"unknown",opt
),
1068 TCHECK2(*(p
+ 2), 8);
1069 printf("%04x:%04x:%04x:%04x",
1070 EXTRACT_16BITS(p
+ 2),
1071 EXTRACT_16BITS(p
+ 4),
1072 EXTRACT_16BITS(p
+ 6),
1073 EXTRACT_16BITS(p
+ 8));
1077 print_unknown_data(&p
[2],"\n\t ",len
-2);
1081 print_unknown_data(&p
[2],"\n\t ",len
-2); /* exclude TLV header */
1086 printf(", invalid-length-%d", opt
);
1095 /* CCP config options */
1097 print_ccp_config_options(const u_char
*p
, int length
)
1109 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1110 tok2str(ccpconfopts_values
, "Unknown", opt
),
1116 printf("\n\t %s Option (0x%02x), length %u:",
1117 tok2str(ccpconfopts_values
, "Unknown", opt
),
1122 /* fall through --> default: nothing supported yet */
1128 case CCPOPT_STACLZS
:
1132 case CCPOPT_BSDCOMP
:
1136 case CCPOPT_DEFLATE
:
1140 print_unknown_data(&p
[2],"\n\t ",len
-2);
1144 print_unknown_data(&p
[2],"\n\t ",len
-2); /* exclude TLV header */
1153 /* BACP config options */
1155 print_bacp_config_options(const u_char
*p
, int length
)
1167 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1168 tok2str(bacconfopts_values
, "Unknown", opt
),
1174 printf("\n\t %s Option (0x%02x), length %u:",
1175 tok2str(bacconfopts_values
, "Unknown", opt
),
1181 TCHECK2(*(p
+ 2), 4);
1182 printf(", Magic-Num 0x%08x", EXTRACT_32BITS(p
+ 2));
1186 print_unknown_data(&p
[2],"\n\t ",len
-2);
1190 print_unknown_data(&p
[2],"\n\t ",len
-2); /* exclude TLV header */
1201 ppp_hdlc(const u_char
*p
, int length
)
1203 u_char
*b
, *s
, *t
, c
;
1207 b
= (u_int8_t
*)malloc(length
);
1212 * Unescape all the data into a temporary, private, buffer.
1213 * Do this so that we dont overwrite the original packet
1216 for (s
= (u_char
*)p
, t
= b
, i
= length
; i
> 0; i
--) {
1231 /* now lets guess about the payload codepoint format */
1232 proto
= *b
; /* start with a one-octet codepoint guess */
1236 ip_print(gndo
, b
+1, t
- b
- 1);
1240 ip6_print(b
+1, t
- b
- 1);
1243 default: /* no luck - try next guess */
1247 proto
= EXTRACT_16BITS(b
); /* next guess - load two octets */
1250 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
): /* looks like a PPP frame */
1251 proto
= EXTRACT_16BITS(b
+2); /* load the PPP proto-id */
1252 handle_ppp(proto
, b
+4, t
- b
- 4);
1254 default: /* last guess - proto must be a PPP proto-id */
1255 handle_ppp(proto
, b
+2, t
- b
- 2);
1268 handle_ppp(u_int proto
, const u_char
*p
, int length
)
1270 if ((proto
& 0xff00) == 0x7e00) {/* is this an escape code ? */
1271 ppp_hdlc(p
-1, length
);
1276 case PPP_LCP
: /* fall through */
1283 handle_ctrl_proto(proto
, p
, length
);
1286 handle_mlppp(p
, length
);
1289 handle_chap(p
, length
);
1292 handle_pap(p
, length
);
1294 case PPP_BAP
: /* XXX: not yet completed */
1295 handle_bap(p
, length
);
1297 case ETHERTYPE_IP
: /*XXX*/
1300 ip_print(gndo
, p
, length
);
1303 case ETHERTYPE_IPV6
: /*XXX*/
1305 ip6_print(p
, length
);
1308 case ETHERTYPE_IPX
: /*XXX*/
1310 ipx_print(p
, length
);
1313 isoclns_print(p
, length
, length
);
1315 case PPP_MPLS_UCAST
:
1316 case PPP_MPLS_MCAST
:
1317 mpls_print(p
, length
);
1320 printf("compressed PPP data");
1323 printf("%s ", tok2str(ppptype2str
, "unknown PPP protocol (0x%04x)", proto
));
1324 print_unknown_data(p
,"\n\t",length
);
1329 /* Standard PPP printer */
1331 ppp_print(register const u_char
*p
, u_int length
)
1333 u_int proto
,ppp_header
;
1334 u_int olen
= length
; /* _o_riginal length */
1338 * Here, we assume that p points to the Address and Control
1339 * field (if they present).
1344 ppp_header
= EXTRACT_16BITS(p
);
1346 switch(ppp_header
) {
1347 case (PPP_WITHDIRECTION_IN
<< 8 | PPP_CONTROL
):
1348 if (eflag
) printf("In ");
1353 case (PPP_WITHDIRECTION_OUT
<< 8 | PPP_CONTROL
):
1354 if (eflag
) printf("Out ");
1359 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
):
1360 p
+= 2; /* ACFC not used */
1373 proto
= *p
; /* PFC is used */
1379 proto
= EXTRACT_16BITS(p
);
1386 printf("%s (0x%04x), length %u: ",
1387 tok2str(ppptype2str
, "unknown", proto
),
1391 handle_ppp(proto
, p
, length
);
1399 /* PPP I/F printer */
1401 ppp_if_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
1403 register u_int length
= h
->len
;
1404 register u_int caplen
= h
->caplen
;
1406 if (caplen
< PPP_HDRLEN
) {
1413 * XXX: seems to assume that there are 2 octets prepended to an
1414 * actual PPP frame. The 1st octet looks like Input/Output flag
1415 * while 2nd octet is unknown, at least to me
1416 * (mshindo@mshindo.net).
1418 * That was what the original tcpdump code did.
1420 * FreeBSD's "if_ppp.c" *does* set the first octet to 1 for outbound
1421 * packets and 0 for inbound packets - but only if the
1422 * protocol field has the 0x8000 bit set (i.e., it's a network
1423 * control protocol); it does so before running the packet through
1424 * "bpf_filter" to see if it should be discarded, and to see
1425 * if we should update the time we sent the most recent packet...
1427 * ...but it puts the original address field back after doing
1430 * NetBSD's "if_ppp.c" doesn't set the first octet in that fashion.
1432 * I don't know if any PPP implementation handed up to a BPF
1433 * device packets with the first octet being 1 for outbound and
1434 * 0 for inbound packets, so I (guy@alum.mit.edu) don't know
1435 * whether that ever needs to be checked or not.
1437 * Note that NetBSD has a DLT_PPP_SERIAL, which it uses for PPP,
1438 * and its tcpdump appears to assume that the frame always
1439 * begins with an address field and a control field, and that
1440 * the address field might be 0x0f or 0x8f, for Cisco
1441 * point-to-point with HDLC framing as per section 4.3.1 of RFC
1442 * 1547, as well as 0xff, for PPP in HDLC-like framing as per
1445 * (Is the Cisco framing in question what DLT_C_HDLC, in
1449 printf("%c %4d %02x ", p
[0] ? 'O' : 'I', length
, p
[1]);
1452 ppp_print(p
, length
);
1458 * PPP I/F printer to use if we know that RFC 1662-style PPP in HDLC-like
1459 * framing, or Cisco PPP with HDLC framing as per section 4.3.1 of RFC 1547,
1460 * is being used (i.e., we don't check for PPP_ADDRESS and PPP_CONTROL,
1461 * discard them *if* those are the first two octets, and parse the remaining
1462 * packet as a PPP packet, as "ppp_print()" does).
1464 * This handles, for example, DLT_PPP_SERIAL in NetBSD.
1467 ppp_hdlc_if_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
1469 register u_int length
= h
->len
;
1470 register u_int caplen
= h
->caplen
;
1488 printf("%02x %02x %d ", p
[0], p
[1], length
);
1493 proto
= EXTRACT_16BITS(p
);
1497 printf("%s: ", tok2str(ppptype2str
, "unknown PPP protocol (0x%04x)", proto
));
1499 handle_ppp(proto
, p
, length
);
1504 return (chdlc_if_print(h
, p
));
1508 printf("%02x %02x %d ", p
[0], p
[1], length
);
1514 * XXX - NetBSD's "ppp_netbsd_serial_if_print()" treats
1515 * the next two octets as an Ethernet type; does that
1518 printf("unknown addr %02x; ctrl %02x", p
[0], p
[1]);
1525 #define PPP_BSDI_HDRLEN 24
1527 /* BSD/OS specific PPP printer */
1529 ppp_bsdos_if_print(const struct pcap_pkthdr
*h _U_
, register const u_char
*p _U_
)
1531 register int hdrlength
;
1533 register u_int length
= h
->len
;
1534 register u_int caplen
= h
->caplen
;
1539 if (caplen
< PPP_BSDI_HDRLEN
) {
1547 if (p
[0] == PPP_ADDRESS
&& p
[1] == PPP_CONTROL
) {
1549 printf("%02x %02x ", p
[0], p
[1]);
1555 printf("%d ", length
);
1556 /* Retrieve the protocol type */
1558 /* Compressed protocol field */
1561 printf("%02x ", ptype
);
1565 /* Un-compressed protocol field */
1566 ptype
= ntohs(*(u_int16_t
*)p
);
1568 printf("%04x ", ptype
);
1575 printf("%c ", p
[SLC_DIR
] ? 'O' : 'I');
1577 /* link level header */
1578 struct ppp_header
*ph
;
1580 q
= p
+ SLC_BPFHDRLEN
;
1581 ph
= (struct ppp_header
*)q
;
1582 if (ph
->phdr_addr
== PPP_ADDRESS
1583 && ph
->phdr_ctl
== PPP_CONTROL
) {
1585 printf("%02x %02x ", q
[0], q
[1]);
1586 ptype
= ntohs(ph
->phdr_type
);
1587 if (eflag
&& (ptype
== PPP_VJC
|| ptype
== PPP_VJNC
)) {
1588 printf("%s ", tok2str(ppptype2str
,
1589 "proto-#%d", ptype
));
1594 for (i
= 0; i
< p
[SLC_LLHL
]; i
++)
1595 printf("%02x", q
[i
]);
1601 printf("%d ", length
);
1603 q
= p
+ SLC_BPFHDRLEN
+ p
[SLC_LLHL
];
1607 ptype
= vjc_print(q
, ptype
);
1608 hdrlength
= PPP_BSDI_HDRLEN
;
1612 ip_print(p
, length
);
1616 ip6_print(p
, length
);
1619 case PPP_MPLS_UCAST
:
1620 case PPP_MPLS_MCAST
:
1621 mpls_print(p
, length
);
1626 ptype
= vjc_print(q
, ptype
);
1627 hdrlength
= PPP_BSDI_HDRLEN
;
1631 ip_print(p
, length
);
1635 ip6_print(p
, length
);
1638 case PPP_MPLS_UCAST
:
1639 case PPP_MPLS_MCAST
:
1640 mpls_print(p
, length
);
1647 for (i
= 0; i
< p
[SLC_LLHL
]; i
++)
1648 printf("%02x", q
[i
]);
1655 hdrlength
= PPP_BSDI_HDRLEN
;
1658 length
-= hdrlength
;
1663 ip_print(p
, length
);
1667 ip6_print(p
, length
);
1670 case PPP_MPLS_UCAST
:
1671 case PPP_MPLS_MCAST
:
1672 mpls_print(p
, length
);
1675 printf("%s ", tok2str(ppptype2str
, "unknown PPP protocol (0x%04x)", ptype
));
1681 #endif /* __bsdi__ */
1688 * c-style: whitesmith