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.
29 * o resolve XXX as much as possible
35 static const char rcsid[] _U_ =
36 "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.114 2005-12-05 11:35:58 hannes Exp $ (LBL)";
43 #include <tcpdump-stdinc.h>
46 #include <net/slcompress.h>
47 #include <net/if_ppp.h>
54 #include "interface.h"
56 #include "addrtoname.h"
59 #include "ethertype.h"
63 * The following constatns are defined by IANA. Please refer to
64 * http://www.isi.edu/in-notes/iana/assignments/ppp-numbers
65 * for the up-to-date information.
68 /* Protocol Codes defined in ppp.h */
70 struct tok ppptype2str[] = {
74 { PPP_DECNET, "DECNET" },
75 { PPP_APPLE, "APPLE" },
77 { PPP_VJC, "VJC IP" },
78 { PPP_VJNC, "VJNC IP" },
79 { PPP_BRPDU, "BRPDU" },
81 { PPP_VINES, "VINES" },
82 { PPP_MPLS_UCAST, "MPLS" },
83 { PPP_MPLS_MCAST, "MPLS" },
84 { PPP_COMP, "Compressed"},
88 { PPP_HELLO, "HELLO" },
89 { PPP_LUXCOM, "LUXCOM" },
92 { PPP_OSICP, "OSICP" },
94 { PPP_DECNETCP, "DECNETCP" },
95 { PPP_APPLECP, "APPLECP" },
96 { PPP_IPXCP, "IPXCP" },
97 { PPP_STIICP, "STIICP" },
98 { PPP_VINESCP, "VINESCP" },
99 { PPP_IPV6CP, "IP6CP" },
100 { PPP_MPLSCP, "MPLSCP" },
105 { PPP_CHAP, "CHAP" },
107 { PPP_SPAP, "SPAP" },
108 { PPP_SPAP_OLD, "Old-SPAP" },
109 { PPP_BACP, "BACP" },
111 { PPP_MPCP, "MLPPP-CP" },
115 /* Control Protocols (LCP/IPCP/CCP etc.) Codes defined in RFC 1661 */
117 #define CPCODES_VEXT 0 /* Vendor-Specific (RFC2153) */
118 #define CPCODES_CONF_REQ 1 /* Configure-Request */
119 #define CPCODES_CONF_ACK 2 /* Configure-Ack */
120 #define CPCODES_CONF_NAK 3 /* Configure-Nak */
121 #define CPCODES_CONF_REJ 4 /* Configure-Reject */
122 #define CPCODES_TERM_REQ 5 /* Terminate-Request */
123 #define CPCODES_TERM_ACK 6 /* Terminate-Ack */
124 #define CPCODES_CODE_REJ 7 /* Code-Reject */
125 #define CPCODES_PROT_REJ 8 /* Protocol-Reject (LCP only) */
126 #define CPCODES_ECHO_REQ 9 /* Echo-Request (LCP only) */
127 #define CPCODES_ECHO_RPL 10 /* Echo-Reply (LCP only) */
128 #define CPCODES_DISC_REQ 11 /* Discard-Request (LCP only) */
129 #define CPCODES_ID 12 /* Identification (LCP only) RFC1570 */
130 #define CPCODES_TIME_REM 13 /* Time-Remaining (LCP only) RFC1570 */
131 #define CPCODES_RESET_REQ 14 /* Reset-Request (CCP only) RFC1962 */
132 #define CPCODES_RESET_REP 15 /* Reset-Reply (CCP only) */
134 struct tok cpcodes[] = {
135 {CPCODES_VEXT, "Vendor-Extension"}, /* RFC2153 */
136 {CPCODES_CONF_REQ, "Conf-Request"},
137 {CPCODES_CONF_ACK, "Conf-Ack"},
138 {CPCODES_CONF_NAK, "Conf-Nack"},
139 {CPCODES_CONF_REJ, "Conf-Reject"},
140 {CPCODES_TERM_REQ, "Term-Request"},
141 {CPCODES_TERM_ACK, "Term-Ack"},
142 {CPCODES_CODE_REJ, "Code-Reject"},
143 {CPCODES_PROT_REJ, "Prot-Reject"},
144 {CPCODES_ECHO_REQ, "Echo-Request"},
145 {CPCODES_ECHO_RPL, "Echo-Reply"},
146 {CPCODES_DISC_REQ, "Disc-Req"},
147 {CPCODES_ID, "Ident"}, /* RFC1570 */
148 {CPCODES_TIME_REM, "Time-Rem"}, /* RFC1570 */
149 {CPCODES_RESET_REQ, "Reset-Req"}, /* RFC1962 */
150 {CPCODES_RESET_REP, "Reset-Ack"}, /* RFC1962 */
154 /* LCP Config Options */
156 #define LCPOPT_VEXT 0
158 #define LCPOPT_ACCM 2
162 #define LCPOPT_DEP6 6
164 #define LCPOPT_ACFC 8
165 #define LCPOPT_FCSALT 9
166 #define LCPOPT_SDP 10
167 #define LCPOPT_NUMMODE 11
168 #define LCPOPT_DEP12 12
169 #define LCPOPT_CBACK 13
170 #define LCPOPT_DEP14 14
171 #define LCPOPT_DEP15 15
172 #define LCPOPT_DEP16 16
173 #define LCPOPT_MLMRRU 17
174 #define LCPOPT_MLSSNHF 18
175 #define LCPOPT_MLED 19
176 #define LCPOPT_PROP 20
177 #define LCPOPT_DCEID 21
178 #define LCPOPT_MPP 22
180 #define LCPOPT_LCPAOPT 24
181 #define LCPOPT_COBS 25
183 #define LCPOPT_MLHF 27
184 #define LCPOPT_I18N 28
185 #define LCPOPT_SDLOS 29
186 #define LCPOPT_PPPMUX 30
188 #define LCPOPT_MIN LCPOPT_VEXT
189 #define LCPOPT_MAX LCPOPT_PPPMUX
191 static const char *lcpconfopts[] = {
192 "Vend-Ext", /* (0) */
195 "Auth-Prot", /* (3) */
196 "Qual-Prot", /* (4) */
197 "Magic-Num", /* (5) */
198 "deprecated(6)", /* used to be a Quality Protocol */
203 "Num-Mode", /* (11) */
204 "deprecated(12)", /* used to be a Multi-Link-Procedure*/
205 "Call-Back", /* (13) */
206 "deprecated(14)", /* used to be a Connect-Time */
207 "deprecated(15)", /* used to be a Compund-Frames */
208 "deprecated(16)", /* used to be a Nominal-Data-Encap */
210 "12-Bit seq #", /* (18) */
211 "End-Disc", /* (19) */
212 "Proprietary", /* (20) */
215 "Link-Disc", /* (23) */
216 "LCP-Auth-Opt", /* (24) */
218 "Prefix-elision", /* (26) */
219 "Multilink-header-Form",/* (27) */
221 "SDL-over-SONET/SDH", /* (29) */
222 "PPP-Muxing", /* (30) */
225 /* ECP - to be supported */
227 /* CCP Config Options */
229 #define CCPOPT_OUI 0 /* RFC1962 */
230 #define CCPOPT_PRED1 1 /* RFC1962 */
231 #define CCPOPT_PRED2 2 /* RFC1962 */
232 #define CCPOPT_PJUMP 3 /* RFC1962 */
233 /* 4-15 unassigned */
234 #define CCPOPT_HPPPC 16 /* RFC1962 */
235 #define CCPOPT_STACLZS 17 /* RFC1974 */
236 #define CCPOPT_MPPC 18 /* RFC2118 */
237 #define CCPOPT_GFZA 19 /* RFC1962 */
238 #define CCPOPT_V42BIS 20 /* RFC1962 */
239 #define CCPOPT_BSDCOMP 21 /* RFC1977 */
241 #define CCPOPT_LZSDCP 23 /* RFC1967 */
242 #define CCPOPT_MVRCA 24 /* RFC1975 */
243 #define CCPOPT_DEC 25 /* RFC1976 */
244 #define CCPOPT_DEFLATE 26 /* RFC1979 */
245 /* 27-254 unassigned */
246 #define CCPOPT_RESV 255 /* RFC1962 */
248 const struct tok ccpconfopts_values[] = {
249 { CCPOPT_OUI, "OUI" },
250 { CCPOPT_PRED1, "Pred-1" },
251 { CCPOPT_PRED2, "Pred-2" },
252 { CCPOPT_PJUMP, "Puddle" },
253 { CCPOPT_HPPPC, "HP-PPC" },
254 { CCPOPT_STACLZS, "Stac-LZS" },
255 { CCPOPT_MPPC, "MPPC" },
256 { CCPOPT_GFZA, "Gand-FZA" },
257 { CCPOPT_V42BIS, "V.42bis" },
258 { CCPOPT_BSDCOMP, "BSD-Comp" },
259 { CCPOPT_LZSDCP, "LZS-DCP" },
260 { CCPOPT_MVRCA, "MVRCA" },
261 { CCPOPT_DEC, "DEC" },
262 { CCPOPT_DEFLATE, "Deflate" },
263 { CCPOPT_RESV, "Reserved"},
267 /* BACP Config Options */
269 #define BACPOPT_FPEER 1 /* RFC2125 */
271 const struct tok bacconfopts_values[] = {
272 { BACPOPT_FPEER, "Favored-Peer" },
277 /* SDCP - to be supported */
279 /* IPCP Config Options */
280 #define IPCPOPT_2ADDR 1 /* RFC1172, RFC1332 (deprecated) */
281 #define IPCPOPT_IPCOMP 2 /* RFC1332 */
282 #define IPCPOPT_ADDR 3 /* RFC1332 */
283 #define IPCPOPT_MOBILE4 4 /* RFC2290 */
284 #define IPCPOPT_PRIDNS 129 /* RFC1877 */
285 #define IPCPOPT_PRINBNS 130 /* RFC1877 */
286 #define IPCPOPT_SECDNS 131 /* RFC1877 */
287 #define IPCPOPT_SECNBNS 132 /* RFC1877 */
289 struct tok ipcpopt_values[] = {
290 { IPCPOPT_2ADDR, "IP-Addrs" },
291 { IPCPOPT_IPCOMP, "IP-Comp" },
292 { IPCPOPT_ADDR, "IP-Addr" },
293 { IPCPOPT_MOBILE4, "Home-Addr" },
294 { IPCPOPT_PRIDNS, "Pri-DNS" },
295 { IPCPOPT_PRINBNS, "Pri-NBNS" },
296 { IPCPOPT_SECDNS, "Sec-DNS" },
297 { IPCPOPT_SECNBNS, "Sec-NBNS" },
301 #define IPCPOPT_IPCOMP_HDRCOMP 0x61 /* rfc3544 */
302 #define IPCPOPT_IPCOMP_MINLEN 14
304 struct tok ipcpopt_compproto_values[] = {
305 { PPP_VJC, "VJ-Comp" },
306 { IPCPOPT_IPCOMP_HDRCOMP, "IP Header Compression" },
310 struct tok ipcpopt_compproto_subopt_values[] = {
311 { 1, "RTP-Compression" },
312 { 2, "Enhanced RTP-Compression" },
316 /* IP6CP Config Options */
319 struct tok ip6cpopt_values[] = {
320 { IP6CP_IFID, "Interface-ID" },
324 /* ATCP - to be supported */
325 /* OSINLCP - to be supported */
326 /* BVCP - to be supported */
327 /* BCP - to be supported */
328 /* IPXCP - to be supported */
329 /* MPLSCP - to be supported */
331 /* Auth Algorithms */
333 /* 0-4 Reserved (RFC1994) */
334 #define AUTHALG_CHAPMD5 5 /* RFC1994 */
335 #define AUTHALG_MSCHAP1 128 /* RFC2433 */
336 #define AUTHALG_MSCHAP2 129 /* RFC2795 */
338 struct tok authalg_values[] = {
339 { AUTHALG_CHAPMD5, "MD5" },
340 { AUTHALG_MSCHAP1, "MS-CHAPv1" },
341 { AUTHALG_MSCHAP2, "MS-CHAPv2" },
345 /* FCS Alternatives - to be supported */
347 /* Multilink Endpoint Discriminator (RFC1717) */
348 #define MEDCLASS_NULL 0 /* Null Class */
349 #define MEDCLASS_LOCAL 1 /* Locally Assigned */
350 #define MEDCLASS_IPV4 2 /* Internet Protocol (IPv4) */
351 #define MEDCLASS_MAC 3 /* IEEE 802.1 global MAC address */
352 #define MEDCLASS_MNB 4 /* PPP Magic Number Block */
353 #define MEDCLASS_PSNDN 5 /* Public Switched Network Director Number */
355 /* PPP LCP Callback */
356 #define CALLBACK_AUTH 0 /* Location determined by user auth */
357 #define CALLBACK_DSTR 1 /* Dialing string */
358 #define CALLBACK_LID 2 /* Location identifier */
359 #define CALLBACK_E164 3 /* E.164 number */
360 #define CALLBACK_X500 4 /* X.500 distinguished name */
361 #define CALLBACK_CBCP 6 /* Location is determined during CBCP nego */
363 struct tok ppp_callback_values[] = {
364 { CALLBACK_AUTH, "UserAuth" },
365 { CALLBACK_DSTR, "DialString" },
366 { CALLBACK_LID, "LocalID" },
367 { CALLBACK_E164, "E.164" },
368 { CALLBACK_X500, "X.500" },
369 { CALLBACK_CBCP, "CBCP" },
380 struct tok chapcode_values[] = {
381 { CHAP_CHAL, "Challenge" },
382 { CHAP_RESP, "Response" },
383 { CHAP_SUCC, "Success" },
384 { CHAP_FAIL, "Fail" },
394 struct tok papcode_values[] = {
395 { PAP_AREQ, "Auth-Req" },
396 { PAP_AACK, "Auth-ACK" },
397 { PAP_ANAK, "Auth-NACK" },
402 #define BAP_CALLREQ 1
403 #define BAP_CALLRES 2
411 static void handle_ctrl_proto (u_int proto,const u_char *p, int length);
412 static void handle_chap (const u_char *p, int length);
413 static void handle_pap (const u_char *p, int length);
414 static void handle_bap (const u_char *p, int length);
415 static void handle_mlppp(const u_char *p, int length);
416 static int print_lcp_config_options (const u_char *p, int);
417 static int print_ipcp_config_options (const u_char *p, int);
418 static int print_ip6cp_config_options (const u_char *p, int);
419 static int print_ccp_config_options (const u_char *p, int);
420 static int print_bacp_config_options (const u_char *p, int);
421 static void handle_ppp (u_int proto, const u_char *p, int length);
422 static void ppp_hdlc(const u_char *p, int length);
424 /* generic Control Protocol (e.g. LCP, IPCP, CCP, etc.) handler */
426 handle_ctrl_proto(u_int proto, const u_char *pptr, int length)
430 int (*pfunc)(const u_char *, int);
436 typestr = tok2str(ppptype2str, "unknown ctrl-proto (0x%04x)", proto);
437 printf("%s, ",typestr);
439 if (length < 4) /* FIXME weak boundary checking */
445 printf("%s (0x%02x), id %u, length %u",
446 tok2str(cpcodes, "Unknown Opcode",code),
455 return; /* there may be a NULL confreq etc. */
458 len = EXTRACT_16BITS(tptr);
461 printf("\n\tencoded length %u (=Option(s) length %u)",len,len-4);
464 print_unknown_data(pptr-2,"\n\t",6);
472 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr));
475 printf(" Vendor: %s (%u)",
476 tok2str(oui_values,"Unknown",EXTRACT_24BITS(tptr)),
477 EXTRACT_24BITS(tptr));
478 /* XXX: need to decode Kind and Value(s)? */
480 case CPCODES_CONF_REQ:
481 case CPCODES_CONF_ACK:
482 case CPCODES_CONF_NAK:
483 case CPCODES_CONF_REJ:
484 x = len - 4; /* Code(1), Identifier(1) and Length(2) */
488 pfunc = print_lcp_config_options;
491 pfunc = print_ipcp_config_options;
494 pfunc = print_ip6cp_config_options;
497 pfunc = print_ccp_config_options;
500 pfunc = print_bacp_config_options;
504 * No print routine for the options for
511 if (pfunc == NULL) /* catch the above null pointer if unknown CP */
514 if ((j = (*pfunc)(tptr, len)) == 0)
521 case CPCODES_TERM_REQ:
522 case CPCODES_TERM_ACK:
523 /* XXX: need to decode Data? */
525 case CPCODES_CODE_REJ:
526 /* XXX: need to decode Rejected-Packet? */
528 case CPCODES_PROT_REJ:
532 printf("\n\t Rejected %s Protocol (0x%04x)",
533 tok2str(ppptype2str,"unknown", EXTRACT_16BITS(tptr)),
534 EXTRACT_16BITS(tptr));
535 /* XXX: need to decode Rejected-Information? - hexdump for now */
537 printf("\n\t Rejected Packet");
538 print_unknown_data(tptr+2,"\n\t ",len-2);
541 case CPCODES_ECHO_REQ:
542 case CPCODES_ECHO_RPL:
543 case CPCODES_DISC_REQ:
547 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr));
548 /* XXX: need to decode Data? - hexdump for now */
550 printf("\n\t -----trailing data-----");
551 TCHECK2(tptr[4], len-8);
552 print_unknown_data(tptr+4,"\n\t ",len-8);
559 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr));
560 /* RFC 1661 says this is intended to be human readable */
562 printf("\n\t Message\n\t ");
563 fn_printn(tptr+4,len-4,snapend);
566 case CPCODES_TIME_REM:
570 printf("\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr));
571 TCHECK2(*(tptr + 4), 4);
572 printf(", Seconds-Remaining %us", EXTRACT_32BITS(tptr + 4));
573 /* XXX: need to decode Message? */
576 /* XXX this is dirty but we do not get the
577 * original pointer passed to the begin
580 print_unknown_data(pptr-2,"\n\t ",length+2);
586 printf("[|%s]", typestr);
589 /* LCP config options */
591 print_lcp_config_options(const u_char *p, int length)
603 if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX))
604 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)", lcpconfopts[opt],opt,len);
606 printf("\n\tunknown LCP option 0x%02x", opt);
609 if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX))
610 printf("\n\t %s Option (0x%02x), length %u: ", lcpconfopts[opt],opt,len);
612 printf("\n\tunknown LCP option 0x%02x", opt);
619 TCHECK2(*(p + 2), 3);
620 printf("Vendor: %s (%u)",
621 tok2str(oui_values,"Unknown",EXTRACT_24BITS(p+2)),
622 EXTRACT_24BITS(p+2));
625 printf(", kind: 0x%02x", p[5]);
626 printf(", Value: 0x")
627 for (i = 0; i < len - 6; i++) {
629 printf("%02x", p[6 + i]);
636 TCHECK2(*(p + 2), 2);
637 printf("%u", EXTRACT_16BITS(p + 2));
642 TCHECK2(*(p + 2), 4);
643 printf("0x%08x", EXTRACT_32BITS(p + 2));
648 TCHECK2(*(p + 2), 2);
649 printf("%s", tok2str(ppptype2str,"Unknown Auth Proto (0x04x)",EXTRACT_16BITS(p+2)));
651 switch (EXTRACT_16BITS(p+2)) {
654 printf(", %s",tok2str(authalg_values,"Unknown Auth Alg %u",p[4]));
656 case PPP_PAP: /* fall through */
662 print_unknown_data(p,"\n\t",len);
668 TCHECK2(*(p + 2), 2);
669 if (EXTRACT_16BITS(p+2) == PPP_LQM)
677 TCHECK2(*(p + 2), 4);
678 printf("0x%08x", EXTRACT_32BITS(p + 2));
687 TCHECK2(*(p + 2), 2);
688 printf("0x%04x", EXTRACT_16BITS(p + 2));
695 printf("Callback Operation %s (%u)",
696 tok2str(ppp_callback_values,"Unknown",p[2]),
701 TCHECK2(*(p + 2), 2);
702 printf("%u", EXTRACT_16BITS(p + 2));
709 switch (p[2]) { /* class */
714 printf("Local"); /* XXX */
719 TCHECK2(*(p + 3), 4);
720 printf("IPv4 %s", ipaddr_string(p + 3));
726 printf("MAC %02x:%02x:%02x:%02x:%02x:%02x",
727 p[3], p[4], p[5], p[6], p[7], p[8]);
730 printf("Magic-Num-Block"); /* XXX */
733 printf("PSNDN"); /* XXX */
738 /* XXX: to be supported */
763 print_unknown_data(&p[2],"\n\t ",len-2);
768 print_unknown_data(&p[2],"\n\t ",len-2); /* exclude TLV header */
778 struct tok ppp_ml_flag_values[] = {
785 handle_mlppp(const u_char *p, int length) {
790 printf("seq 0x%03x, Flags [%s], length %u",
791 (EXTRACT_16BITS(p))&0x0fff, /* only support 12-Bit sequence space for now */
792 bittok2str(ppp_ml_flag_values, "none", *p & 0xc0),
800 handle_chap(const u_char *p, int length)
803 int val_size, name_size, msg_size;
811 } else if (length < 4) {
813 printf("[|chap 0x%02x]", *p);
819 printf("CHAP, %s (0x%02x)",
820 tok2str(chapcode_values,"unknown",code),
825 printf(", id %u", *p); /* ID */
829 len = EXTRACT_16BITS(p);
833 * Note that this is a generic CHAP decoding routine. Since we
834 * don't know which flavor of CHAP (i.e. CHAP-MD5, MS-CHAPv1,
835 * MS-CHAPv2) is used at this point, we can't decode packet
836 * specifically to each algorithms. Instead, we simply decode
837 * the GCD (Gratest Common Denominator) for all algorithms.
842 if (length - (p - p0) < 1)
845 val_size = *p; /* value size */
847 if (length - (p - p0) < val_size)
850 for (i = 0; i < val_size; i++) {
852 printf("%02x", *p++);
854 name_size = len - (p - p0);
856 for (i = 0; i < name_size; i++) {
863 msg_size = len - (p - p0);
865 for (i = 0; i< msg_size; i++) {
877 /* PAP (see RFC 1334) */
879 handle_pap(const u_char *p, int length)
882 int peerid_len, passwd_len, msg_len;
890 } else if (length < 4) {
892 printf("[|pap 0x%02x]", *p);
898 printf("PAP, %s (0x%02x)",
899 tok2str(papcode_values,"unknown",code),
904 printf(", id %u", *p); /* ID */
908 len = EXTRACT_16BITS(p);
911 if ((int)len > length) {
912 printf(", length %u > packet size", len);
916 if (length < (p - p0)) {
917 printf(", length %u < PAP header length", length);
923 if (length - (p - p0) < 1)
926 peerid_len = *p; /* Peer-ID Length */
928 if (length - (p - p0) < peerid_len)
931 for (i = 0; i < peerid_len; i++) {
936 if (length - (p - p0) < 1)
939 passwd_len = *p; /* Password Length */
941 if (length - (p - p0) < passwd_len)
944 for (i = 0; i < passwd_len; i++) {
951 if (length - (p - p0) < 1)
954 msg_len = *p; /* Msg-Length */
956 if (length - (p - p0) < msg_len)
959 for (i = 0; i< msg_len; i++) {
973 handle_bap(const u_char *p _U_, int length _U_)
975 /* XXX: to be supported!! */
979 /* IPCP config options */
981 print_ipcp_config_options(const u_char *p, int length)
984 u_int compproto, ipcomp_subopttotallen, ipcomp_subopt, ipcomp_suboptlen;
994 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
995 tok2str(ipcpopt_values,"unknown",opt),
1001 printf("\n\t %s Option (0x%02x), length %u: ",
1002 tok2str(ipcpopt_values,"unknown",opt),
1007 case IPCPOPT_2ADDR: /* deprecated */
1010 TCHECK2(*(p + 6), 4);
1011 printf("src %s, dst %s",
1012 ipaddr_string(p + 2),
1013 ipaddr_string(p + 6));
1015 case IPCPOPT_IPCOMP:
1018 TCHECK2(*(p + 2), 2);
1019 compproto = EXTRACT_16BITS(p+2);
1021 printf("%s (0x%02x):",
1022 tok2str(ipcpopt_compproto_values,"Unknown",compproto),
1025 switch (compproto) {
1027 /* XXX: VJ-Comp parameters should be decoded */
1029 case IPCPOPT_IPCOMP_HDRCOMP:
1030 if (len < IPCPOPT_IPCOMP_MINLEN)
1033 TCHECK2(*(p + 2), IPCPOPT_IPCOMP_MINLEN);
1034 printf("\n\t TCP Space %u, non-TCP Space %u" \
1035 ", maxPeriod %u, maxTime %u, maxHdr %u",
1036 EXTRACT_16BITS(p+4),
1037 EXTRACT_16BITS(p+6),
1038 EXTRACT_16BITS(p+8),
1039 EXTRACT_16BITS(p+10),
1040 EXTRACT_16BITS(p+12));
1042 /* suboptions present ? */
1043 if (len > IPCPOPT_IPCOMP_MINLEN) {
1044 ipcomp_subopttotallen = len - IPCPOPT_IPCOMP_MINLEN;
1045 p += IPCPOPT_IPCOMP_MINLEN;
1047 printf("\n\t Suboptions, length %u", ipcomp_subopttotallen);
1049 while (ipcomp_subopttotallen >= 2) {
1052 ipcomp_suboptlen = *(p+1);
1055 if (ipcomp_subopt == 0 ||
1056 ipcomp_suboptlen == 0 )
1059 /* XXX: just display the suboptions for now */
1060 printf("\n\t\t%s Suboption #%u, length %u",
1061 tok2str(ipcpopt_compproto_subopt_values,
1067 ipcomp_subopttotallen -= ipcomp_suboptlen;
1068 p += ipcomp_suboptlen;
1077 case IPCPOPT_ADDR: /* those options share the same format - fall through */
1078 case IPCPOPT_MOBILE4:
1079 case IPCPOPT_PRIDNS:
1080 case IPCPOPT_PRINBNS:
1081 case IPCPOPT_SECDNS:
1082 case IPCPOPT_SECNBNS:
1085 TCHECK2(*(p + 2), 4);
1086 printf("%s", ipaddr_string(p + 2));
1090 print_unknown_data(&p[2],"\n\t ",len-2);
1094 print_unknown_data(&p[2],"\n\t ",len-2); /* exclude TLV header */
1098 printf(", invalid-length-%d", opt);
1106 /* IP6CP config options */
1108 print_ip6cp_config_options(const u_char *p, int length)
1120 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1121 tok2str(ip6cpopt_values,"unknown",opt),
1127 printf("\n\t %s Option (0x%02x), length %u: ",
1128 tok2str(ip6cpopt_values,"unknown",opt),
1136 TCHECK2(*(p + 2), 8);
1137 printf("%04x:%04x:%04x:%04x",
1138 EXTRACT_16BITS(p + 2),
1139 EXTRACT_16BITS(p + 4),
1140 EXTRACT_16BITS(p + 6),
1141 EXTRACT_16BITS(p + 8));
1145 print_unknown_data(&p[2],"\n\t ",len-2);
1149 print_unknown_data(&p[2],"\n\t ",len-2); /* exclude TLV header */
1154 printf(", invalid-length-%d", opt);
1163 /* CCP config options */
1165 print_ccp_config_options(const u_char *p, int length)
1177 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1178 tok2str(ccpconfopts_values, "Unknown", opt),
1184 printf("\n\t %s Option (0x%02x), length %u:",
1185 tok2str(ccpconfopts_values, "Unknown", opt),
1190 /* fall through --> default: nothing supported yet */
1196 case CCPOPT_STACLZS:
1200 case CCPOPT_BSDCOMP:
1204 case CCPOPT_DEFLATE:
1208 print_unknown_data(&p[2],"\n\t ",len-2);
1212 print_unknown_data(&p[2],"\n\t ",len-2); /* exclude TLV header */
1221 /* BACP config options */
1223 print_bacp_config_options(const u_char *p, int length)
1235 printf("\n\t %s Option (0x%02x), length %u (bogus, should be >= 2)",
1236 tok2str(bacconfopts_values, "Unknown", opt),
1242 printf("\n\t %s Option (0x%02x), length %u:",
1243 tok2str(bacconfopts_values, "Unknown", opt),
1249 TCHECK2(*(p + 2), 4);
1250 printf(", Magic-Num 0x%08x", EXTRACT_32BITS(p + 2));
1254 print_unknown_data(&p[2],"\n\t ",len-2);
1258 print_unknown_data(&p[2],"\n\t ",len-2); /* exclude TLV header */
1269 ppp_hdlc(const u_char *p, int length)
1271 u_char *b, *s, *t, c;
1275 b = (u_int8_t *)malloc(length);
1280 * Unescape all the data into a temporary, private, buffer.
1281 * Do this so that we dont overwrite the original packet
1284 for (s = (u_char *)p, t = b, i = length; i > 0; i--) {
1299 /* now lets guess about the payload codepoint format */
1300 proto = *b; /* start with a one-octet codepoint guess */
1304 ip_print(gndo, b+1, t - b - 1);
1308 ip6_print(gndo, b+1, t - b - 1);
1311 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 */
1319 proto = EXTRACT_16BITS(b+2); /* load the PPP proto-id */
1320 handle_ppp(proto, b+4, t - b - 4);
1322 default: /* last guess - proto must be a PPP proto-id */
1323 handle_ppp(proto, b+2, t - b - 2);
1336 handle_ppp(u_int proto, const u_char *p, int length)
1338 if ((proto & 0xff00) == 0x7e00) {/* is this an escape code ? */
1339 ppp_hdlc(p-1, length);
1344 case PPP_LCP: /* fall through */
1351 handle_ctrl_proto(proto, p, length);
1354 handle_mlppp(p, length);
1357 handle_chap(p, length);
1360 handle_pap(p, length);
1362 case PPP_BAP: /* XXX: not yet completed */
1363 handle_bap(p, length);
1365 case ETHERTYPE_IP: /*XXX*/
1368 ip_print(gndo, p, length);
1371 case ETHERTYPE_IPV6: /*XXX*/
1373 ip6_print(gndo, p, length);
1376 case ETHERTYPE_IPX: /*XXX*/
1378 ipx_print(p, length);
1381 isoclns_print(p, length, length);
1383 case PPP_MPLS_UCAST:
1384 case PPP_MPLS_MCAST:
1385 mpls_print(p, length);
1388 printf("compressed PPP data");
1391 printf("%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto));
1392 print_unknown_data(p,"\n\t",length);
1397 /* Standard PPP printer */
1399 ppp_print(register const u_char *p, u_int length)
1401 u_int proto,ppp_header;
1402 u_int olen = length; /* _o_riginal length */
1406 * Here, we assume that p points to the Address and Control
1407 * field (if they present).
1412 ppp_header = EXTRACT_16BITS(p);
1414 switch(ppp_header) {
1415 case (PPP_WITHDIRECTION_IN << 8 | PPP_CONTROL):
1416 if (eflag) printf("In ");
1421 case (PPP_WITHDIRECTION_OUT << 8 | PPP_CONTROL):
1422 if (eflag) printf("Out ");
1427 case (PPP_ADDRESS << 8 | PPP_CONTROL):
1428 p += 2; /* ACFC not used */
1441 proto = *p; /* PFC is used */
1447 proto = EXTRACT_16BITS(p);
1454 printf("%s (0x%04x), length %u: ",
1455 tok2str(ppptype2str, "unknown", proto),
1459 handle_ppp(proto, p, length);
1467 /* PPP I/F printer */
1469 ppp_if_print(const struct pcap_pkthdr *h, register const u_char *p)
1471 register u_int length = h->len;
1472 register u_int caplen = h->caplen;
1474 if (caplen < PPP_HDRLEN) {
1481 * XXX: seems to assume that there are 2 octets prepended to an
1482 * actual PPP frame. The 1st octet looks like Input/Output flag
1483 * while 2nd octet is unknown, at least to me
1484 * (mshindo@mshindo.net).
1486 * That was what the original tcpdump code did.
1488 * FreeBSD's "if_ppp.c" *does* set the first octet to 1 for outbound
1489 * packets and 0 for inbound packets - but only if the
1490 * protocol field has the 0x8000 bit set (i.e., it's a network
1491 * control protocol); it does so before running the packet through
1492 * "bpf_filter" to see if it should be discarded, and to see
1493 * if we should update the time we sent the most recent packet...
1495 * ...but it puts the original address field back after doing
1498 * NetBSD's "if_ppp.c" doesn't set the first octet in that fashion.
1500 * I don't know if any PPP implementation handed up to a BPF
1501 * device packets with the first octet being 1 for outbound and
1502 * 0 for inbound packets, so I (guy@alum.mit.edu) don't know
1503 * whether that ever needs to be checked or not.
1505 * Note that NetBSD has a DLT_PPP_SERIAL, which it uses for PPP,
1506 * and its tcpdump appears to assume that the frame always
1507 * begins with an address field and a control field, and that
1508 * the address field might be 0x0f or 0x8f, for Cisco
1509 * point-to-point with HDLC framing as per section 4.3.1 of RFC
1510 * 1547, as well as 0xff, for PPP in HDLC-like framing as per
1513 * (Is the Cisco framing in question what DLT_C_HDLC, in
1517 printf("%c %4d %02x ", p[0] ? 'O' : 'I', length, p[1]);
1520 ppp_print(p, length);
1526 * PPP I/F printer to use if we know that RFC 1662-style PPP in HDLC-like
1527 * framing, or Cisco PPP with HDLC framing as per section 4.3.1 of RFC 1547,
1528 * is being used (i.e., we don't check for PPP_ADDRESS and PPP_CONTROL,
1529 * discard them *if* those are the first two octets, and parse the remaining
1530 * packet as a PPP packet, as "ppp_print()" does).
1532 * This handles, for example, DLT_PPP_SERIAL in NetBSD.
1535 ppp_hdlc_if_print(const struct pcap_pkthdr *h, register const u_char *p)
1537 register u_int length = h->len;
1538 register u_int caplen = h->caplen;
1556 printf("%02x %02x %d ", p[0], p[1], length);
1561 proto = EXTRACT_16BITS(p);
1565 printf("%s: ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto));
1567 handle_ppp(proto, p, length);
1572 return (chdlc_if_print(h, p));
1576 printf("%02x %02x %d ", p[0], p[1], length);
1582 * XXX - NetBSD's "ppp_netbsd_serial_if_print()" treats
1583 * the next two octets as an Ethernet type; does that
1586 printf("unknown addr %02x; ctrl %02x", p[0], p[1]);
1593 #define PPP_BSDI_HDRLEN 24
1595 /* BSD/OS specific PPP printer */
1597 ppp_bsdos_if_print(const struct pcap_pkthdr *h _U_, register const u_char *p _U_)
1599 register int hdrlength;
1601 register u_int length = h->len;
1602 register u_int caplen = h->caplen;
1607 if (caplen < PPP_BSDI_HDRLEN) {
1615 if (p[0] == PPP_ADDRESS && p[1] == PPP_CONTROL) {
1617 printf("%02x %02x ", p[0], p[1]);
1623 printf("%d ", length);
1624 /* Retrieve the protocol type */
1626 /* Compressed protocol field */
1629 printf("%02x ", ptype);
1633 /* Un-compressed protocol field */
1634 ptype = EXTRACT_16BITS(p);
1636 printf("%04x ", ptype);
1643 printf("%c ", p[SLC_DIR] ? 'O' : 'I');
1645 /* link level header */
1646 struct ppp_header *ph;
1648 q = p + SLC_BPFHDRLEN;
1649 ph = (struct ppp_header *)q;
1650 if (ph->phdr_addr == PPP_ADDRESS
1651 && ph->phdr_ctl == PPP_CONTROL) {
1653 printf("%02x %02x ", q[0], q[1]);
1654 ptype = EXTRACT_16BITS(&ph->phdr_type);
1655 if (eflag && (ptype == PPP_VJC || ptype == PPP_VJNC)) {
1656 printf("%s ", tok2str(ppptype2str,
1657 "proto-#%d", ptype));
1662 for (i = 0; i < p[SLC_LLHL]; i++)
1663 printf("%02x", q[i]);
1669 printf("%d ", length);
1671 q = p + SLC_BPFHDRLEN + p[SLC_LLHL];
1675 ptype = vjc_print(q, ptype);
1676 hdrlength = PPP_BSDI_HDRLEN;
1680 ip_print(gndo, p, length);
1684 ip6_print(gndo, p, length);
1687 case PPP_MPLS_UCAST:
1688 case PPP_MPLS_MCAST:
1689 mpls_print(p, length);
1694 ptype = vjc_print(q, ptype);
1695 hdrlength = PPP_BSDI_HDRLEN;
1699 ip_print(gndo, p, length);
1703 ip6_print(gndo, p, length);
1706 case PPP_MPLS_UCAST:
1707 case PPP_MPLS_MCAST:
1708 mpls_print(p, length);
1715 for (i = 0; i < p[SLC_LLHL]; i++)
1716 printf("%02x", q[i]);
1723 hdrlength = PPP_BSDI_HDRLEN;
1726 length -= hdrlength;
1731 ip_print(p, length);
1735 ip6_print(gndo, p, length);
1738 case PPP_MPLS_UCAST:
1739 case PPP_MPLS_MCAST:
1740 mpls_print(gndo, p, length);
1743 printf("%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", ptype));
1749 #endif /* __bsdi__ */
1756 * c-style: whitesmith