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
36 #include <tcpdump-stdinc.h>
39 #include <net/slcompress.h>
40 #include <net/if_ppp.h>
46 #include "interface.h"
48 #include "addrtoname.h"
51 #include "ethertype.h"
55 * The following constatns are defined by IANA. Please refer to
56 * http://www.isi.edu/in-notes/iana/assignments/ppp-numbers
57 * for the up-to-date information.
60 /* Protocol Codes defined in ppp.h */
62 static const struct tok ppptype2str
[] = {
66 { PPP_DECNET
, "DECNET" },
67 { PPP_APPLE
, "APPLE" },
69 { PPP_VJC
, "VJC IP" },
70 { PPP_VJNC
, "VJNC IP" },
71 { PPP_BRPDU
, "BRPDU" },
73 { PPP_VINES
, "VINES" },
74 { PPP_MPLS_UCAST
, "MPLS" },
75 { PPP_MPLS_MCAST
, "MPLS" },
76 { PPP_COMP
, "Compressed"},
80 { PPP_HELLO
, "HELLO" },
81 { PPP_LUXCOM
, "LUXCOM" },
84 { PPP_OSICP
, "OSICP" },
86 { PPP_DECNETCP
, "DECNETCP" },
87 { PPP_APPLECP
, "APPLECP" },
88 { PPP_IPXCP
, "IPXCP" },
89 { PPP_STIICP
, "STIICP" },
90 { PPP_VINESCP
, "VINESCP" },
91 { PPP_IPV6CP
, "IP6CP" },
92 { PPP_MPLSCP
, "MPLSCP" },
100 { PPP_SPAP_OLD
, "Old-SPAP" },
101 { PPP_BACP
, "BACP" },
103 { PPP_MPCP
, "MLPPP-CP" },
107 /* Control Protocols (LCP/IPCP/CCP etc.) Codes defined in RFC 1661 */
109 #define CPCODES_VEXT 0 /* Vendor-Specific (RFC2153) */
110 #define CPCODES_CONF_REQ 1 /* Configure-Request */
111 #define CPCODES_CONF_ACK 2 /* Configure-Ack */
112 #define CPCODES_CONF_NAK 3 /* Configure-Nak */
113 #define CPCODES_CONF_REJ 4 /* Configure-Reject */
114 #define CPCODES_TERM_REQ 5 /* Terminate-Request */
115 #define CPCODES_TERM_ACK 6 /* Terminate-Ack */
116 #define CPCODES_CODE_REJ 7 /* Code-Reject */
117 #define CPCODES_PROT_REJ 8 /* Protocol-Reject (LCP only) */
118 #define CPCODES_ECHO_REQ 9 /* Echo-Request (LCP only) */
119 #define CPCODES_ECHO_RPL 10 /* Echo-Reply (LCP only) */
120 #define CPCODES_DISC_REQ 11 /* Discard-Request (LCP only) */
121 #define CPCODES_ID 12 /* Identification (LCP only) RFC1570 */
122 #define CPCODES_TIME_REM 13 /* Time-Remaining (LCP only) RFC1570 */
123 #define CPCODES_RESET_REQ 14 /* Reset-Request (CCP only) RFC1962 */
124 #define CPCODES_RESET_REP 15 /* Reset-Reply (CCP only) */
126 static const struct tok cpcodes
[] = {
127 {CPCODES_VEXT
, "Vendor-Extension"}, /* RFC2153 */
128 {CPCODES_CONF_REQ
, "Conf-Request"},
129 {CPCODES_CONF_ACK
, "Conf-Ack"},
130 {CPCODES_CONF_NAK
, "Conf-Nack"},
131 {CPCODES_CONF_REJ
, "Conf-Reject"},
132 {CPCODES_TERM_REQ
, "Term-Request"},
133 {CPCODES_TERM_ACK
, "Term-Ack"},
134 {CPCODES_CODE_REJ
, "Code-Reject"},
135 {CPCODES_PROT_REJ
, "Prot-Reject"},
136 {CPCODES_ECHO_REQ
, "Echo-Request"},
137 {CPCODES_ECHO_RPL
, "Echo-Reply"},
138 {CPCODES_DISC_REQ
, "Disc-Req"},
139 {CPCODES_ID
, "Ident"}, /* RFC1570 */
140 {CPCODES_TIME_REM
, "Time-Rem"}, /* RFC1570 */
141 {CPCODES_RESET_REQ
, "Reset-Req"}, /* RFC1962 */
142 {CPCODES_RESET_REP
, "Reset-Ack"}, /* RFC1962 */
146 /* LCP Config Options */
148 #define LCPOPT_VEXT 0
150 #define LCPOPT_ACCM 2
154 #define LCPOPT_DEP6 6
156 #define LCPOPT_ACFC 8
157 #define LCPOPT_FCSALT 9
158 #define LCPOPT_SDP 10
159 #define LCPOPT_NUMMODE 11
160 #define LCPOPT_DEP12 12
161 #define LCPOPT_CBACK 13
162 #define LCPOPT_DEP14 14
163 #define LCPOPT_DEP15 15
164 #define LCPOPT_DEP16 16
165 #define LCPOPT_MLMRRU 17
166 #define LCPOPT_MLSSNHF 18
167 #define LCPOPT_MLED 19
168 #define LCPOPT_PROP 20
169 #define LCPOPT_DCEID 21
170 #define LCPOPT_MPP 22
172 #define LCPOPT_LCPAOPT 24
173 #define LCPOPT_COBS 25
175 #define LCPOPT_MLHF 27
176 #define LCPOPT_I18N 28
177 #define LCPOPT_SDLOS 29
178 #define LCPOPT_PPPMUX 30
180 #define LCPOPT_MIN LCPOPT_VEXT
181 #define LCPOPT_MAX LCPOPT_PPPMUX
183 static const char *lcpconfopts
[] = {
184 "Vend-Ext", /* (0) */
187 "Auth-Prot", /* (3) */
188 "Qual-Prot", /* (4) */
189 "Magic-Num", /* (5) */
190 "deprecated(6)", /* used to be a Quality Protocol */
195 "Num-Mode", /* (11) */
196 "deprecated(12)", /* used to be a Multi-Link-Procedure*/
197 "Call-Back", /* (13) */
198 "deprecated(14)", /* used to be a Connect-Time */
199 "deprecated(15)", /* used to be a Compund-Frames */
200 "deprecated(16)", /* used to be a Nominal-Data-Encap */
202 "12-Bit seq #", /* (18) */
203 "End-Disc", /* (19) */
204 "Proprietary", /* (20) */
207 "Link-Disc", /* (23) */
208 "LCP-Auth-Opt", /* (24) */
210 "Prefix-elision", /* (26) */
211 "Multilink-header-Form",/* (27) */
213 "SDL-over-SONET/SDH", /* (29) */
214 "PPP-Muxing", /* (30) */
217 /* ECP - to be supported */
219 /* CCP Config Options */
221 #define CCPOPT_OUI 0 /* RFC1962 */
222 #define CCPOPT_PRED1 1 /* RFC1962 */
223 #define CCPOPT_PRED2 2 /* RFC1962 */
224 #define CCPOPT_PJUMP 3 /* RFC1962 */
225 /* 4-15 unassigned */
226 #define CCPOPT_HPPPC 16 /* RFC1962 */
227 #define CCPOPT_STACLZS 17 /* RFC1974 */
228 #define CCPOPT_MPPC 18 /* RFC2118 */
229 #define CCPOPT_GFZA 19 /* RFC1962 */
230 #define CCPOPT_V42BIS 20 /* RFC1962 */
231 #define CCPOPT_BSDCOMP 21 /* RFC1977 */
233 #define CCPOPT_LZSDCP 23 /* RFC1967 */
234 #define CCPOPT_MVRCA 24 /* RFC1975 */
235 #define CCPOPT_DEC 25 /* RFC1976 */
236 #define CCPOPT_DEFLATE 26 /* RFC1979 */
237 /* 27-254 unassigned */
238 #define CCPOPT_RESV 255 /* RFC1962 */
240 static const struct tok ccpconfopts_values
[] = {
241 { CCPOPT_OUI
, "OUI" },
242 { CCPOPT_PRED1
, "Pred-1" },
243 { CCPOPT_PRED2
, "Pred-2" },
244 { CCPOPT_PJUMP
, "Puddle" },
245 { CCPOPT_HPPPC
, "HP-PPC" },
246 { CCPOPT_STACLZS
, "Stac-LZS" },
247 { CCPOPT_MPPC
, "MPPC" },
248 { CCPOPT_GFZA
, "Gand-FZA" },
249 { CCPOPT_V42BIS
, "V.42bis" },
250 { CCPOPT_BSDCOMP
, "BSD-Comp" },
251 { CCPOPT_LZSDCP
, "LZS-DCP" },
252 { CCPOPT_MVRCA
, "MVRCA" },
253 { CCPOPT_DEC
, "DEC" },
254 { CCPOPT_DEFLATE
, "Deflate" },
255 { CCPOPT_RESV
, "Reserved"},
259 /* BACP Config Options */
261 #define BACPOPT_FPEER 1 /* RFC2125 */
263 static const struct tok bacconfopts_values
[] = {
264 { BACPOPT_FPEER
, "Favored-Peer" },
269 /* SDCP - to be supported */
271 /* IPCP Config Options */
272 #define IPCPOPT_2ADDR 1 /* RFC1172, RFC1332 (deprecated) */
273 #define IPCPOPT_IPCOMP 2 /* RFC1332 */
274 #define IPCPOPT_ADDR 3 /* RFC1332 */
275 #define IPCPOPT_MOBILE4 4 /* RFC2290 */
276 #define IPCPOPT_PRIDNS 129 /* RFC1877 */
277 #define IPCPOPT_PRINBNS 130 /* RFC1877 */
278 #define IPCPOPT_SECDNS 131 /* RFC1877 */
279 #define IPCPOPT_SECNBNS 132 /* RFC1877 */
281 static const struct tok ipcpopt_values
[] = {
282 { IPCPOPT_2ADDR
, "IP-Addrs" },
283 { IPCPOPT_IPCOMP
, "IP-Comp" },
284 { IPCPOPT_ADDR
, "IP-Addr" },
285 { IPCPOPT_MOBILE4
, "Home-Addr" },
286 { IPCPOPT_PRIDNS
, "Pri-DNS" },
287 { IPCPOPT_PRINBNS
, "Pri-NBNS" },
288 { IPCPOPT_SECDNS
, "Sec-DNS" },
289 { IPCPOPT_SECNBNS
, "Sec-NBNS" },
293 #define IPCPOPT_IPCOMP_HDRCOMP 0x61 /* rfc3544 */
294 #define IPCPOPT_IPCOMP_MINLEN 14
296 static const struct tok ipcpopt_compproto_values
[] = {
297 { PPP_VJC
, "VJ-Comp" },
298 { IPCPOPT_IPCOMP_HDRCOMP
, "IP Header Compression" },
302 static const struct tok ipcpopt_compproto_subopt_values
[] = {
303 { 1, "RTP-Compression" },
304 { 2, "Enhanced RTP-Compression" },
308 /* IP6CP Config Options */
311 static const struct tok ip6cpopt_values
[] = {
312 { IP6CP_IFID
, "Interface-ID" },
316 /* ATCP - to be supported */
317 /* OSINLCP - to be supported */
318 /* BVCP - to be supported */
319 /* BCP - to be supported */
320 /* IPXCP - to be supported */
321 /* MPLSCP - to be supported */
323 /* Auth Algorithms */
325 /* 0-4 Reserved (RFC1994) */
326 #define AUTHALG_CHAPMD5 5 /* RFC1994 */
327 #define AUTHALG_MSCHAP1 128 /* RFC2433 */
328 #define AUTHALG_MSCHAP2 129 /* RFC2795 */
330 static const struct tok authalg_values
[] = {
331 { AUTHALG_CHAPMD5
, "MD5" },
332 { AUTHALG_MSCHAP1
, "MS-CHAPv1" },
333 { AUTHALG_MSCHAP2
, "MS-CHAPv2" },
337 /* FCS Alternatives - to be supported */
339 /* Multilink Endpoint Discriminator (RFC1717) */
340 #define MEDCLASS_NULL 0 /* Null Class */
341 #define MEDCLASS_LOCAL 1 /* Locally Assigned */
342 #define MEDCLASS_IPV4 2 /* Internet Protocol (IPv4) */
343 #define MEDCLASS_MAC 3 /* IEEE 802.1 global MAC address */
344 #define MEDCLASS_MNB 4 /* PPP Magic Number Block */
345 #define MEDCLASS_PSNDN 5 /* Public Switched Network Director Number */
347 /* PPP LCP Callback */
348 #define CALLBACK_AUTH 0 /* Location determined by user auth */
349 #define CALLBACK_DSTR 1 /* Dialing string */
350 #define CALLBACK_LID 2 /* Location identifier */
351 #define CALLBACK_E164 3 /* E.164 number */
352 #define CALLBACK_X500 4 /* X.500 distinguished name */
353 #define CALLBACK_CBCP 6 /* Location is determined during CBCP nego */
355 static const struct tok ppp_callback_values
[] = {
356 { CALLBACK_AUTH
, "UserAuth" },
357 { CALLBACK_DSTR
, "DialString" },
358 { CALLBACK_LID
, "LocalID" },
359 { CALLBACK_E164
, "E.164" },
360 { CALLBACK_X500
, "X.500" },
361 { CALLBACK_CBCP
, "CBCP" },
372 static const struct tok chapcode_values
[] = {
373 { CHAP_CHAL
, "Challenge" },
374 { CHAP_RESP
, "Response" },
375 { CHAP_SUCC
, "Success" },
376 { CHAP_FAIL
, "Fail" },
386 static const struct tok papcode_values
[] = {
387 { PAP_AREQ
, "Auth-Req" },
388 { PAP_AACK
, "Auth-ACK" },
389 { PAP_ANAK
, "Auth-NACK" },
394 #define BAP_CALLREQ 1
395 #define BAP_CALLRES 2
403 static void handle_ctrl_proto (u_int proto
,const u_char
*p
, int length
);
404 static void handle_chap (const u_char
*p
, int length
);
405 static void handle_pap (const u_char
*p
, int length
);
406 static void handle_bap (const u_char
*p
, int length
);
407 static void handle_mlppp(const u_char
*p
, int length
);
408 static int print_lcp_config_options (const u_char
*p
, int);
409 static int print_ipcp_config_options (const u_char
*p
, int);
410 static int print_ip6cp_config_options (const u_char
*p
, int);
411 static int print_ccp_config_options (const u_char
*p
, int);
412 static int print_bacp_config_options (const u_char
*p
, int);
413 static void handle_ppp (u_int proto
, const u_char
*p
, int length
);
414 static void ppp_hdlc(const u_char
*p
, int length
);
416 /* generic Control Protocol (e.g. LCP, IPCP, CCP, etc.) handler */
418 handle_ctrl_proto(u_int proto
, const u_char
*pptr
, int length
)
422 int (*pfunc
)(const u_char
*, int);
428 typestr
= tok2str(ppptype2str
, "unknown ctrl-proto (0x%04x)", proto
);
429 printf("%s, ",typestr
);
431 if (length
< 4) /* FIXME weak boundary checking */
437 printf("%s (0x%02x), id %u, length %u",
438 tok2str(cpcodes
, "Unknown Opcode",code
),
447 return; /* there may be a NULL confreq etc. */
450 len
= EXTRACT_16BITS(tptr
);
453 printf("\n\tencoded length %u (=Option(s) length %u)",len
,len
-4);
456 print_unknown_data(gndo
,pptr
-2,"\n\t",6);
464 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr
));
467 printf(" Vendor: %s (%u)",
468 tok2str(oui_values
,"Unknown",EXTRACT_24BITS(tptr
)),
469 EXTRACT_24BITS(tptr
));
470 /* XXX: need to decode Kind and Value(s)? */
472 case CPCODES_CONF_REQ
:
473 case CPCODES_CONF_ACK
:
474 case CPCODES_CONF_NAK
:
475 case CPCODES_CONF_REJ
:
476 x
= len
- 4; /* Code(1), Identifier(1) and Length(2) */
480 pfunc
= print_lcp_config_options
;
483 pfunc
= print_ipcp_config_options
;
486 pfunc
= print_ip6cp_config_options
;
489 pfunc
= print_ccp_config_options
;
492 pfunc
= print_bacp_config_options
;
496 * No print routine for the options for
503 if (pfunc
== NULL
) /* catch the above null pointer if unknown CP */
506 if ((j
= (*pfunc
)(tptr
, len
)) == 0)
513 case CPCODES_TERM_REQ
:
514 case CPCODES_TERM_ACK
:
515 /* XXX: need to decode Data? */
517 case CPCODES_CODE_REJ
:
518 /* XXX: need to decode Rejected-Packet? */
520 case CPCODES_PROT_REJ
:
524 printf("\n\t Rejected %s Protocol (0x%04x)",
525 tok2str(ppptype2str
,"unknown", EXTRACT_16BITS(tptr
)),
526 EXTRACT_16BITS(tptr
));
527 /* XXX: need to decode Rejected-Information? - hexdump for now */
529 printf("\n\t Rejected Packet");
530 print_unknown_data(gndo
,tptr
+2,"\n\t ",len
-2);
533 case CPCODES_ECHO_REQ
:
534 case CPCODES_ECHO_RPL
:
535 case CPCODES_DISC_REQ
:
539 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr
));
540 /* XXX: need to decode Data? - hexdump for now */
542 printf("\n\t -----trailing data-----");
543 TCHECK2(tptr
[4], len
-8);
544 print_unknown_data(gndo
,tptr
+4,"\n\t ",len
-8);
551 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr
));
552 /* RFC 1661 says this is intended to be human readable */
554 printf("\n\t Message\n\t ");
555 fn_printn(tptr
+4,len
-4,snapend
);
558 case CPCODES_TIME_REM
:
562 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr
));
563 TCHECK2(*(tptr
+ 4), 4);
564 printf(", Seconds-Remaining %us", EXTRACT_32BITS(tptr
+ 4));
565 /* XXX: need to decode Message? */
568 /* XXX this is dirty but we do not get the
569 * original pointer passed to the begin
572 print_unknown_data(gndo
,pptr
-2,"\n\t ",length
+2);
578 printf("[|%s]", typestr
);
581 /* LCP config options */
583 print_lcp_config_options(const u_char
*p
, int length
)
595 if ((opt
>= LCPOPT_MIN
) && (opt
<= LCPOPT_MAX
))
596 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)", lcpconfopts
[opt
],opt
,len
);
598 printf("\n\tunknown LCP option 0x%02x", opt
);
601 if ((opt
>= LCPOPT_MIN
) && (opt
<= LCPOPT_MAX
))
602 printf("\n\t %s Option (0x%02x), length %u: ", lcpconfopts
[opt
],opt
,len
);
604 printf("\n\tunknown LCP option 0x%02x", opt
);
611 TCHECK2(*(p
+ 2), 3);
612 printf("Vendor: %s (%u)",
613 tok2str(oui_values
,"Unknown",EXTRACT_24BITS(p
+2)),
614 EXTRACT_24BITS(p
+2));
617 printf(", kind: 0x%02x", p
[5]);
618 printf(", Value: 0x")
619 for (i
= 0; i
< len
- 6; i
++) {
621 printf("%02x", p
[6 + i
]);
628 TCHECK2(*(p
+ 2), 2);
629 printf("%u", EXTRACT_16BITS(p
+ 2));
634 TCHECK2(*(p
+ 2), 4);
635 printf("0x%08x", EXTRACT_32BITS(p
+ 2));
640 TCHECK2(*(p
+ 2), 2);
641 printf("%s", tok2str(ppptype2str
,"Unknown Auth Proto (0x04x)",EXTRACT_16BITS(p
+2)));
643 switch (EXTRACT_16BITS(p
+2)) {
646 printf(", %s",tok2str(authalg_values
,"Unknown Auth Alg %u",p
[4]));
648 case PPP_PAP
: /* fall through */
654 print_unknown_data(gndo
,p
,"\n\t",len
);
660 TCHECK2(*(p
+ 2), 2);
661 if (EXTRACT_16BITS(p
+2) == PPP_LQM
)
669 TCHECK2(*(p
+ 2), 4);
670 printf("0x%08x", EXTRACT_32BITS(p
+ 2));
679 TCHECK2(*(p
+ 2), 2);
680 printf("0x%04x", EXTRACT_16BITS(p
+ 2));
687 printf("Callback Operation %s (%u)",
688 tok2str(ppp_callback_values
,"Unknown",p
[2]),
693 TCHECK2(*(p
+ 2), 2);
694 printf("%u", EXTRACT_16BITS(p
+ 2));
701 switch (p
[2]) { /* class */
706 printf("Local"); /* XXX */
711 TCHECK2(*(p
+ 3), 4);
712 printf("IPv4 %s", ipaddr_string(p
+ 3));
718 printf("MAC %02x:%02x:%02x:%02x:%02x:%02x",
719 p
[3], p
[4], p
[5], p
[6], p
[7], p
[8]);
722 printf("Magic-Num-Block"); /* XXX */
725 printf("PSNDN"); /* XXX */
730 /* XXX: to be supported */
755 print_unknown_data(gndo
,&p
[2],"\n\t ",len
-2);
760 print_unknown_data(gndo
,&p
[2],"\n\t ",len
-2); /* exclude TLV header */
770 static const struct tok ppp_ml_flag_values
[] = {
777 handle_mlppp(const u_char
*p
, int length
) {
782 printf("seq 0x%03x, Flags [%s], length %u",
783 (EXTRACT_16BITS(p
))&0x0fff, /* only support 12-Bit sequence space for now */
784 bittok2str(ppp_ml_flag_values
, "none", *p
& 0xc0),
792 handle_chap(const u_char
*p
, int length
)
795 int val_size
, name_size
, msg_size
;
803 } else if (length
< 4) {
805 printf("[|chap 0x%02x]", *p
);
811 printf("CHAP, %s (0x%02x)",
812 tok2str(chapcode_values
,"unknown",code
),
817 printf(", id %u", *p
); /* ID */
821 len
= EXTRACT_16BITS(p
);
825 * Note that this is a generic CHAP decoding routine. Since we
826 * don't know which flavor of CHAP (i.e. CHAP-MD5, MS-CHAPv1,
827 * MS-CHAPv2) is used at this point, we can't decode packet
828 * specifically to each algorithms. Instead, we simply decode
829 * the GCD (Gratest Common Denominator) for all algorithms.
834 if (length
- (p
- p0
) < 1)
837 val_size
= *p
; /* value size */
839 if (length
- (p
- p0
) < val_size
)
842 for (i
= 0; i
< val_size
; i
++) {
844 printf("%02x", *p
++);
846 name_size
= len
- (p
- p0
);
848 for (i
= 0; i
< name_size
; i
++) {
855 msg_size
= len
- (p
- p0
);
857 for (i
= 0; i
< msg_size
; i
++) {
869 /* PAP (see RFC 1334) */
871 handle_pap(const u_char
*p
, int length
)
874 int peerid_len
, passwd_len
, msg_len
;
882 } else if (length
< 4) {
884 printf("[|pap 0x%02x]", *p
);
890 printf("PAP, %s (0x%02x)",
891 tok2str(papcode_values
,"unknown",code
),
896 printf(", id %u", *p
); /* ID */
900 len
= EXTRACT_16BITS(p
);
903 if ((int)len
> length
) {
904 printf(", length %u > packet size", len
);
908 if (length
< (p
- p0
)) {
909 printf(", length %u < PAP header length", length
);
915 if (length
- (p
- p0
) < 1)
918 peerid_len
= *p
; /* Peer-ID Length */
920 if (length
- (p
- p0
) < peerid_len
)
923 for (i
= 0; i
< peerid_len
; i
++) {
928 if (length
- (p
- p0
) < 1)
931 passwd_len
= *p
; /* Password Length */
933 if (length
- (p
- p0
) < passwd_len
)
936 for (i
= 0; i
< passwd_len
; i
++) {
943 if (length
- (p
- p0
) < 1)
946 msg_len
= *p
; /* Msg-Length */
948 if (length
- (p
- p0
) < msg_len
)
951 for (i
= 0; i
< msg_len
; i
++) {
965 handle_bap(const u_char
*p _U_
, int length _U_
)
967 /* XXX: to be supported!! */
971 /* IPCP config options */
973 print_ipcp_config_options(const u_char
*p
, int length
)
976 u_int compproto
, ipcomp_subopttotallen
, ipcomp_subopt
, ipcomp_suboptlen
;
986 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
987 tok2str(ipcpopt_values
,"unknown",opt
),
993 printf("\n\t %s Option (0x%02x), length %u: ",
994 tok2str(ipcpopt_values
,"unknown",opt
),
999 case IPCPOPT_2ADDR
: /* deprecated */
1002 TCHECK2(*(p
+ 6), 4);
1003 printf("src %s, dst %s",
1004 ipaddr_string(p
+ 2),
1005 ipaddr_string(p
+ 6));
1007 case IPCPOPT_IPCOMP
:
1010 TCHECK2(*(p
+ 2), 2);
1011 compproto
= EXTRACT_16BITS(p
+2);
1013 printf("%s (0x%02x):",
1014 tok2str(ipcpopt_compproto_values
,"Unknown",compproto
),
1017 switch (compproto
) {
1019 /* XXX: VJ-Comp parameters should be decoded */
1021 case IPCPOPT_IPCOMP_HDRCOMP
:
1022 if (len
< IPCPOPT_IPCOMP_MINLEN
)
1025 TCHECK2(*(p
+ 2), IPCPOPT_IPCOMP_MINLEN
);
1026 printf("\n\t TCP Space %u, non-TCP Space %u" \
1027 ", maxPeriod %u, maxTime %u, maxHdr %u",
1028 EXTRACT_16BITS(p
+4),
1029 EXTRACT_16BITS(p
+6),
1030 EXTRACT_16BITS(p
+8),
1031 EXTRACT_16BITS(p
+10),
1032 EXTRACT_16BITS(p
+12));
1034 /* suboptions present ? */
1035 if (len
> IPCPOPT_IPCOMP_MINLEN
) {
1036 ipcomp_subopttotallen
= len
- IPCPOPT_IPCOMP_MINLEN
;
1037 p
+= IPCPOPT_IPCOMP_MINLEN
;
1039 printf("\n\t Suboptions, length %u", ipcomp_subopttotallen
);
1041 while (ipcomp_subopttotallen
>= 2) {
1044 ipcomp_suboptlen
= *(p
+1);
1047 if (ipcomp_subopt
== 0 ||
1048 ipcomp_suboptlen
== 0 )
1051 /* XXX: just display the suboptions for now */
1052 printf("\n\t\t%s Suboption #%u, length %u",
1053 tok2str(ipcpopt_compproto_subopt_values
,
1059 ipcomp_subopttotallen
-= ipcomp_suboptlen
;
1060 p
+= ipcomp_suboptlen
;
1069 case IPCPOPT_ADDR
: /* those options share the same format - fall through */
1070 case IPCPOPT_MOBILE4
:
1071 case IPCPOPT_PRIDNS
:
1072 case IPCPOPT_PRINBNS
:
1073 case IPCPOPT_SECDNS
:
1074 case IPCPOPT_SECNBNS
:
1077 TCHECK2(*(p
+ 2), 4);
1078 printf("%s", ipaddr_string(p
+ 2));
1082 print_unknown_data(gndo
,&p
[2],"\n\t ",len
-2);
1086 print_unknown_data(gndo
,&p
[2],"\n\t ",len
-2); /* exclude TLV header */
1090 printf(", invalid-length-%d", opt
);
1098 /* IP6CP config options */
1100 print_ip6cp_config_options(const u_char
*p
, int length
)
1112 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1113 tok2str(ip6cpopt_values
,"unknown",opt
),
1119 printf("\n\t %s Option (0x%02x), length %u: ",
1120 tok2str(ip6cpopt_values
,"unknown",opt
),
1128 TCHECK2(*(p
+ 2), 8);
1129 printf("%04x:%04x:%04x:%04x",
1130 EXTRACT_16BITS(p
+ 2),
1131 EXTRACT_16BITS(p
+ 4),
1132 EXTRACT_16BITS(p
+ 6),
1133 EXTRACT_16BITS(p
+ 8));
1137 print_unknown_data(gndo
,&p
[2],"\n\t ",len
-2);
1141 print_unknown_data(gndo
,&p
[2],"\n\t ",len
-2); /* exclude TLV header */
1146 printf(", invalid-length-%d", opt
);
1155 /* CCP config options */
1157 print_ccp_config_options(const u_char
*p
, int length
)
1169 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1170 tok2str(ccpconfopts_values
, "Unknown", opt
),
1176 printf("\n\t %s Option (0x%02x), length %u:",
1177 tok2str(ccpconfopts_values
, "Unknown", opt
),
1182 /* fall through --> default: nothing supported yet */
1188 case CCPOPT_STACLZS
:
1192 case CCPOPT_BSDCOMP
:
1196 case CCPOPT_DEFLATE
:
1200 print_unknown_data(gndo
,&p
[2],"\n\t ",len
-2);
1204 print_unknown_data(gndo
,&p
[2],"\n\t ",len
-2); /* exclude TLV header */
1213 /* BACP config options */
1215 print_bacp_config_options(const u_char
*p
, int length
)
1227 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1228 tok2str(bacconfopts_values
, "Unknown", opt
),
1234 printf("\n\t %s Option (0x%02x), length %u:",
1235 tok2str(bacconfopts_values
, "Unknown", opt
),
1241 TCHECK2(*(p
+ 2), 4);
1242 printf(", Magic-Num 0x%08x", EXTRACT_32BITS(p
+ 2));
1246 print_unknown_data(gndo
,&p
[2],"\n\t ",len
-2);
1250 print_unknown_data(gndo
,&p
[2],"\n\t ",len
-2); /* exclude TLV header */
1261 ppp_hdlc(const u_char
*p
, int length
)
1263 u_char
*b
, *s
, *t
, c
;
1270 b
= (u_int8_t
*)malloc(length
);
1275 * Unescape all the data into a temporary, private, buffer.
1276 * Do this so that we dont overwrite the original packet
1279 for (s
= (u_char
*)p
, t
= b
, i
= length
; i
> 0; i
--) {
1295 /* now lets guess about the payload codepoint format */
1298 proto
= *b
; /* start with a one-octet codepoint guess */
1302 ip_print(gndo
, b
+1, length
- 1);
1306 ip6_print(gndo
, b
+1, length
- 1);
1309 default: /* no luck - try next guess */
1315 proto
= EXTRACT_16BITS(b
); /* next guess - load two octets */
1318 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
): /* looks like a PPP frame */
1321 proto
= EXTRACT_16BITS(b
+2); /* load the PPP proto-id */
1322 handle_ppp(proto
, b
+4, length
- 4);
1324 default: /* last guess - proto must be a PPP proto-id */
1325 handle_ppp(proto
, b
+2, length
- 2);
1344 handle_ppp(u_int proto
, const u_char
*p
, int length
)
1346 if ((proto
& 0xff00) == 0x7e00) {/* is this an escape code ? */
1347 ppp_hdlc(p
-1, length
);
1352 case PPP_LCP
: /* fall through */
1359 handle_ctrl_proto(proto
, p
, length
);
1362 handle_mlppp(p
, length
);
1365 handle_chap(p
, length
);
1368 handle_pap(p
, length
);
1370 case PPP_BAP
: /* XXX: not yet completed */
1371 handle_bap(p
, length
);
1373 case ETHERTYPE_IP
: /*XXX*/
1376 ip_print(gndo
, p
, length
);
1379 case ETHERTYPE_IPV6
: /*XXX*/
1381 ip6_print(gndo
, p
, length
);
1384 case ETHERTYPE_IPX
: /*XXX*/
1386 ipx_print(p
, length
);
1389 isoclns_print(p
, length
, length
);
1391 case PPP_MPLS_UCAST
:
1392 case PPP_MPLS_MCAST
:
1393 mpls_print(p
, length
);
1396 printf("compressed PPP data");
1399 printf("%s ", tok2str(ppptype2str
, "unknown PPP protocol (0x%04x)", proto
));
1400 print_unknown_data(gndo
,p
,"\n\t",length
);
1405 /* Standard PPP printer */
1407 ppp_print(register const u_char
*p
, u_int length
)
1409 u_int proto
,ppp_header
;
1410 u_int olen
= length
; /* _o_riginal length */
1414 * Here, we assume that p points to the Address and Control
1415 * field (if they present).
1420 ppp_header
= EXTRACT_16BITS(p
);
1422 switch(ppp_header
) {
1423 case (PPP_WITHDIRECTION_IN
<< 8 | PPP_CONTROL
):
1424 if (eflag
) printf("In ");
1429 case (PPP_WITHDIRECTION_OUT
<< 8 | PPP_CONTROL
):
1430 if (eflag
) printf("Out ");
1435 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
):
1436 p
+= 2; /* ACFC not used */
1449 proto
= *p
; /* PFC is used */
1455 proto
= EXTRACT_16BITS(p
);
1462 printf("%s (0x%04x), length %u: ",
1463 tok2str(ppptype2str
, "unknown", proto
),
1467 handle_ppp(proto
, p
, length
);
1475 /* PPP I/F printer */
1477 ppp_if_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
1479 register u_int length
= h
->len
;
1480 register u_int caplen
= h
->caplen
;
1482 if (caplen
< PPP_HDRLEN
) {
1489 * XXX: seems to assume that there are 2 octets prepended to an
1490 * actual PPP frame. The 1st octet looks like Input/Output flag
1491 * while 2nd octet is unknown, at least to me
1492 * (mshindo@mshindo.net).
1494 * That was what the original tcpdump code did.
1496 * FreeBSD's "if_ppp.c" *does* set the first octet to 1 for outbound
1497 * packets and 0 for inbound packets - but only if the
1498 * protocol field has the 0x8000 bit set (i.e., it's a network
1499 * control protocol); it does so before running the packet through
1500 * "bpf_filter" to see if it should be discarded, and to see
1501 * if we should update the time we sent the most recent packet...
1503 * ...but it puts the original address field back after doing
1506 * NetBSD's "if_ppp.c" doesn't set the first octet in that fashion.
1508 * I don't know if any PPP implementation handed up to a BPF
1509 * device packets with the first octet being 1 for outbound and
1510 * 0 for inbound packets, so I (guy@alum.mit.edu) don't know
1511 * whether that ever needs to be checked or not.
1513 * Note that NetBSD has a DLT_PPP_SERIAL, which it uses for PPP,
1514 * and its tcpdump appears to assume that the frame always
1515 * begins with an address field and a control field, and that
1516 * the address field might be 0x0f or 0x8f, for Cisco
1517 * point-to-point with HDLC framing as per section 4.3.1 of RFC
1518 * 1547, as well as 0xff, for PPP in HDLC-like framing as per
1521 * (Is the Cisco framing in question what DLT_C_HDLC, in
1525 printf("%c %4d %02x ", p
[0] ? 'O' : 'I', length
, p
[1]);
1528 ppp_print(p
, length
);
1534 * PPP I/F printer to use if we know that RFC 1662-style PPP in HDLC-like
1535 * framing, or Cisco PPP with HDLC framing as per section 4.3.1 of RFC 1547,
1536 * is being used (i.e., we don't check for PPP_ADDRESS and PPP_CONTROL,
1537 * discard them *if* those are the first two octets, and parse the remaining
1538 * packet as a PPP packet, as "ppp_print()" does).
1540 * This handles, for example, DLT_PPP_SERIAL in NetBSD.
1543 ppp_hdlc_if_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
1545 register u_int length
= h
->len
;
1546 register u_int caplen
= h
->caplen
;
1564 printf("%02x %02x %d ", p
[0], p
[1], length
);
1569 proto
= EXTRACT_16BITS(p
);
1573 printf("%s: ", tok2str(ppptype2str
, "unknown PPP protocol (0x%04x)", proto
));
1575 handle_ppp(proto
, p
, length
);
1580 return (chdlc_if_print(h
, p
));
1584 printf("%02x %02x %d ", p
[0], p
[1], length
);
1590 * XXX - NetBSD's "ppp_netbsd_serial_if_print()" treats
1591 * the next two octets as an Ethernet type; does that
1594 printf("unknown addr %02x; ctrl %02x", p
[0], p
[1]);
1601 #define PPP_BSDI_HDRLEN 24
1603 /* BSD/OS specific PPP printer */
1605 ppp_bsdos_if_print(const struct pcap_pkthdr
*h _U_
, register const u_char
*p _U_
)
1607 register int hdrlength
;
1609 register u_int length
= h
->len
;
1610 register u_int caplen
= h
->caplen
;
1615 if (caplen
< PPP_BSDI_HDRLEN
) {
1623 if (p
[0] == PPP_ADDRESS
&& p
[1] == PPP_CONTROL
) {
1625 printf("%02x %02x ", p
[0], p
[1]);
1631 printf("%d ", length
);
1632 /* Retrieve the protocol type */
1634 /* Compressed protocol field */
1637 printf("%02x ", ptype
);
1641 /* Un-compressed protocol field */
1642 ptype
= EXTRACT_16BITS(p
);
1644 printf("%04x ", ptype
);
1651 printf("%c ", p
[SLC_DIR
] ? 'O' : 'I');
1653 /* link level header */
1654 struct ppp_header
*ph
;
1656 q
= p
+ SLC_BPFHDRLEN
;
1657 ph
= (struct ppp_header
*)q
;
1658 if (ph
->phdr_addr
== PPP_ADDRESS
1659 && ph
->phdr_ctl
== PPP_CONTROL
) {
1661 printf("%02x %02x ", q
[0], q
[1]);
1662 ptype
= EXTRACT_16BITS(&ph
->phdr_type
);
1663 if (eflag
&& (ptype
== PPP_VJC
|| ptype
== PPP_VJNC
)) {
1664 printf("%s ", tok2str(ppptype2str
,
1665 "proto-#%d", ptype
));
1670 for (i
= 0; i
< p
[SLC_LLHL
]; i
++)
1671 printf("%02x", q
[i
]);
1677 printf("%d ", length
);
1679 q
= p
+ SLC_BPFHDRLEN
+ p
[SLC_LLHL
];
1683 ptype
= vjc_print(q
, ptype
);
1684 hdrlength
= PPP_BSDI_HDRLEN
;
1688 ip_print(gndo
, p
, length
);
1692 ip6_print(gndo
, p
, length
);
1695 case PPP_MPLS_UCAST
:
1696 case PPP_MPLS_MCAST
:
1697 mpls_print(p
, length
);
1702 ptype
= vjc_print(q
, ptype
);
1703 hdrlength
= PPP_BSDI_HDRLEN
;
1707 ip_print(gndo
, p
, length
);
1711 ip6_print(gndo
, p
, length
);
1714 case PPP_MPLS_UCAST
:
1715 case PPP_MPLS_MCAST
:
1716 mpls_print(p
, length
);
1723 for (i
= 0; i
< p
[SLC_LLHL
]; i
++)
1724 printf("%02x", q
[i
]);
1731 hdrlength
= PPP_BSDI_HDRLEN
;
1734 length
-= hdrlength
;
1739 ip_print(p
, length
);
1743 ip6_print(gndo
, p
, length
);
1746 case PPP_MPLS_UCAST
:
1747 case PPP_MPLS_MCAST
:
1748 mpls_print(gndo
, p
, length
);
1751 printf("%s ", tok2str(ppptype2str
, "unknown PPP protocol (0x%04x)", ptype
));
1757 #endif /* __bsdi__ */
1764 * c-style: whitesmith