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.
25 /* \summary: Point to Point Protocol (PPP) printer */
29 * o resolve XXX as much as possible
36 #include "netdissect-stdinc.h"
40 #include "netdissect.h"
42 #include "addrtoname.h"
45 #include "ethertype.h"
47 #include "netdissect-alloc.h"
50 * The following constants are defined by IANA. Please refer to
51 * https://www.isi.edu/in-notes/iana/assignments/ppp-numbers
52 * for the up-to-date information.
55 /* Protocol Codes defined in ppp.h */
57 static const struct tok ppptype2str
[] = {
61 { PPP_DECNET
, "DECNET" },
62 { PPP_APPLE
, "APPLE" },
64 { PPP_VJC
, "VJC IP" },
65 { PPP_VJNC
, "VJNC IP" },
66 { PPP_BRPDU
, "BRPDU" },
68 { PPP_VINES
, "VINES" },
69 { PPP_MPLS_UCAST
, "MPLS" },
70 { PPP_MPLS_MCAST
, "MPLS" },
71 { PPP_COMP
, "Compressed"},
75 { PPP_HELLO
, "HELLO" },
76 { PPP_LUXCOM
, "LUXCOM" },
79 { PPP_OSICP
, "OSICP" },
81 { PPP_DECNETCP
, "DECNETCP" },
82 { PPP_APPLECP
, "APPLECP" },
83 { PPP_IPXCP
, "IPXCP" },
84 { PPP_STIICP
, "STIICP" },
85 { PPP_VINESCP
, "VINESCP" },
86 { PPP_IPV6CP
, "IP6CP" },
87 { PPP_MPLSCP
, "MPLSCP" },
95 { PPP_SPAP_OLD
, "Old-SPAP" },
98 { PPP_MPCP
, "MLPPP-CP" },
103 /* Control Protocols (LCP/IPCP/CCP etc.) Codes defined in RFC 1661 */
105 #define CPCODES_VEXT 0 /* Vendor-Specific (RFC2153) */
106 #define CPCODES_CONF_REQ 1 /* Configure-Request */
107 #define CPCODES_CONF_ACK 2 /* Configure-Ack */
108 #define CPCODES_CONF_NAK 3 /* Configure-Nak */
109 #define CPCODES_CONF_REJ 4 /* Configure-Reject */
110 #define CPCODES_TERM_REQ 5 /* Terminate-Request */
111 #define CPCODES_TERM_ACK 6 /* Terminate-Ack */
112 #define CPCODES_CODE_REJ 7 /* Code-Reject */
113 #define CPCODES_PROT_REJ 8 /* Protocol-Reject (LCP only) */
114 #define CPCODES_ECHO_REQ 9 /* Echo-Request (LCP only) */
115 #define CPCODES_ECHO_RPL 10 /* Echo-Reply (LCP only) */
116 #define CPCODES_DISC_REQ 11 /* Discard-Request (LCP only) */
117 #define CPCODES_ID 12 /* Identification (LCP only) RFC1570 */
118 #define CPCODES_TIME_REM 13 /* Time-Remaining (LCP only) RFC1570 */
119 #define CPCODES_RESET_REQ 14 /* Reset-Request (CCP only) RFC1962 */
120 #define CPCODES_RESET_REP 15 /* Reset-Reply (CCP only) */
122 static const struct tok cpcodes
[] = {
123 {CPCODES_VEXT
, "Vendor-Extension"}, /* RFC2153 */
124 {CPCODES_CONF_REQ
, "Conf-Request"},
125 {CPCODES_CONF_ACK
, "Conf-Ack"},
126 {CPCODES_CONF_NAK
, "Conf-Nack"},
127 {CPCODES_CONF_REJ
, "Conf-Reject"},
128 {CPCODES_TERM_REQ
, "Term-Request"},
129 {CPCODES_TERM_ACK
, "Term-Ack"},
130 {CPCODES_CODE_REJ
, "Code-Reject"},
131 {CPCODES_PROT_REJ
, "Prot-Reject"},
132 {CPCODES_ECHO_REQ
, "Echo-Request"},
133 {CPCODES_ECHO_RPL
, "Echo-Reply"},
134 {CPCODES_DISC_REQ
, "Disc-Req"},
135 {CPCODES_ID
, "Ident"}, /* RFC1570 */
136 {CPCODES_TIME_REM
, "Time-Rem"}, /* RFC1570 */
137 {CPCODES_RESET_REQ
, "Reset-Req"}, /* RFC1962 */
138 {CPCODES_RESET_REP
, "Reset-Ack"}, /* RFC1962 */
142 /* LCP Config Options */
144 #define LCPOPT_VEXT 0
146 #define LCPOPT_ACCM 2
150 #define LCPOPT_DEP6 6
152 #define LCPOPT_ACFC 8
153 #define LCPOPT_FCSALT 9
154 #define LCPOPT_SDP 10
155 #define LCPOPT_NUMMODE 11
156 #define LCPOPT_DEP12 12
157 #define LCPOPT_CBACK 13
158 #define LCPOPT_DEP14 14
159 #define LCPOPT_DEP15 15
160 #define LCPOPT_DEP16 16
161 #define LCPOPT_MLMRRU 17
162 #define LCPOPT_MLSSNHF 18
163 #define LCPOPT_MLED 19
164 #define LCPOPT_PROP 20
165 #define LCPOPT_DCEID 21
166 #define LCPOPT_MPP 22
168 #define LCPOPT_LCPAOPT 24
169 #define LCPOPT_COBS 25
171 #define LCPOPT_MLHF 27
172 #define LCPOPT_I18N 28
173 #define LCPOPT_SDLOS 29
174 #define LCPOPT_PPPMUX 30
176 static const char *lcpconfopts
[] = {
177 "Vend-Ext", /* (0) */
180 "Auth-Prot", /* (3) */
181 "Qual-Prot", /* (4) */
182 "Magic-Num", /* (5) */
183 "deprecated(6)", /* used to be a Quality Protocol */
188 "Num-Mode", /* (11) */
189 "deprecated(12)", /* used to be a Multi-Link-Procedure*/
190 "Call-Back", /* (13) */
191 "deprecated(14)", /* used to be a Connect-Time */
192 "deprecated(15)", /* used to be a Compound-Frames */
193 "deprecated(16)", /* used to be a Nominal-Data-Encap */
195 "12-Bit seq #", /* (18) */
196 "End-Disc", /* (19) */
197 "Proprietary", /* (20) */
200 "Link-Disc", /* (23) */
201 "LCP-Auth-Opt", /* (24) */
203 "Prefix-elision", /* (26) */
204 "Multilink-header-Form",/* (27) */
206 "SDL-over-SONET/SDH", /* (29) */
207 "PPP-Muxing", /* (30) */
210 #define NUM_LCPOPTS (sizeof(lcpconfopts) / sizeof(lcpconfopts[0]))
212 /* ECP - to be supported */
214 /* CCP Config Options */
216 #define CCPOPT_OUI 0 /* RFC1962 */
217 #define CCPOPT_PRED1 1 /* RFC1962 */
218 #define CCPOPT_PRED2 2 /* RFC1962 */
219 #define CCPOPT_PJUMP 3 /* RFC1962 */
220 /* 4-15 unassigned */
221 #define CCPOPT_HPPPC 16 /* RFC1962 */
222 #define CCPOPT_STACLZS 17 /* RFC1974 */
223 #define CCPOPT_MPPC 18 /* RFC2118 */
224 #define CCPOPT_GFZA 19 /* RFC1962 */
225 #define CCPOPT_V42BIS 20 /* RFC1962 */
226 #define CCPOPT_BSDCOMP 21 /* RFC1977 */
228 #define CCPOPT_LZSDCP 23 /* RFC1967 */
229 #define CCPOPT_MVRCA 24 /* RFC1975 */
230 #define CCPOPT_DEC 25 /* RFC1976 */
231 #define CCPOPT_DEFLATE 26 /* RFC1979 */
232 /* 27-254 unassigned */
233 #define CCPOPT_RESV 255 /* RFC1962 */
235 static const struct tok ccpconfopts_values
[] = {
236 { CCPOPT_OUI
, "OUI" },
237 { CCPOPT_PRED1
, "Pred-1" },
238 { CCPOPT_PRED2
, "Pred-2" },
239 { CCPOPT_PJUMP
, "Puddle" },
240 { CCPOPT_HPPPC
, "HP-PPC" },
241 { CCPOPT_STACLZS
, "Stac-LZS" },
242 { CCPOPT_MPPC
, "MPPC" },
243 { CCPOPT_GFZA
, "Gand-FZA" },
244 { CCPOPT_V42BIS
, "V.42bis" },
245 { CCPOPT_BSDCOMP
, "BSD-Comp" },
246 { CCPOPT_LZSDCP
, "LZS-DCP" },
247 { CCPOPT_MVRCA
, "MVRCA" },
248 { CCPOPT_DEC
, "DEC" },
249 { CCPOPT_DEFLATE
, "Deflate" },
250 { CCPOPT_RESV
, "Reserved"},
254 /* BACP Config Options */
256 #define BACPOPT_FPEER 1 /* RFC2125 */
258 static const struct tok bacconfopts_values
[] = {
259 { BACPOPT_FPEER
, "Favored-Peer" },
264 /* SDCP - to be supported */
266 /* IPCP Config Options */
267 #define IPCPOPT_2ADDR 1 /* RFC1172, RFC1332 (deprecated) */
268 #define IPCPOPT_IPCOMP 2 /* RFC1332 */
269 #define IPCPOPT_ADDR 3 /* RFC1332 */
270 #define IPCPOPT_MOBILE4 4 /* RFC2290 */
271 #define IPCPOPT_PRIDNS 129 /* RFC1877 */
272 #define IPCPOPT_PRINBNS 130 /* RFC1877 */
273 #define IPCPOPT_SECDNS 131 /* RFC1877 */
274 #define IPCPOPT_SECNBNS 132 /* RFC1877 */
276 static const struct tok ipcpopt_values
[] = {
277 { IPCPOPT_2ADDR
, "IP-Addrs" },
278 { IPCPOPT_IPCOMP
, "IP-Comp" },
279 { IPCPOPT_ADDR
, "IP-Addr" },
280 { IPCPOPT_MOBILE4
, "Home-Addr" },
281 { IPCPOPT_PRIDNS
, "Pri-DNS" },
282 { IPCPOPT_PRINBNS
, "Pri-NBNS" },
283 { IPCPOPT_SECDNS
, "Sec-DNS" },
284 { IPCPOPT_SECNBNS
, "Sec-NBNS" },
288 #define IPCPOPT_IPCOMP_HDRCOMP 0x61 /* rfc3544 */
289 #define IPCPOPT_IPCOMP_MINLEN 14
291 static const struct tok ipcpopt_compproto_values
[] = {
292 { PPP_VJC
, "VJ-Comp" },
293 { IPCPOPT_IPCOMP_HDRCOMP
, "IP Header Compression" },
297 static const struct tok ipcpopt_compproto_subopt_values
[] = {
298 { 1, "RTP-Compression" },
299 { 2, "Enhanced RTP-Compression" },
303 /* IP6CP Config Options */
306 static const struct tok ip6cpopt_values
[] = {
307 { IP6CP_IFID
, "Interface-ID" },
311 /* ATCP - to be supported */
312 /* OSINLCP - to be supported */
313 /* BVCP - to be supported */
314 /* BCP - to be supported */
315 /* IPXCP - to be supported */
316 /* MPLSCP - to be supported */
318 /* Auth Algorithms */
320 /* 0-4 Reserved (RFC1994) */
321 #define AUTHALG_CHAPMD5 5 /* RFC1994 */
322 #define AUTHALG_MSCHAP1 128 /* RFC2433 */
323 #define AUTHALG_MSCHAP2 129 /* RFC2795 */
325 static const struct tok authalg_values
[] = {
326 { AUTHALG_CHAPMD5
, "MD5" },
327 { AUTHALG_MSCHAP1
, "MS-CHAPv1" },
328 { AUTHALG_MSCHAP2
, "MS-CHAPv2" },
332 /* FCS Alternatives - to be supported */
334 /* Multilink Endpoint Discriminator (RFC1717) */
335 #define MEDCLASS_NULL 0 /* Null Class */
336 #define MEDCLASS_LOCAL 1 /* Locally Assigned */
337 #define MEDCLASS_IPV4 2 /* Internet Protocol (IPv4) */
338 #define MEDCLASS_MAC 3 /* IEEE 802.1 global MAC address */
339 #define MEDCLASS_MNB 4 /* PPP Magic Number Block */
340 #define MEDCLASS_PSNDN 5 /* Public Switched Network Director Number */
342 /* PPP LCP Callback */
343 #define CALLBACK_AUTH 0 /* Location determined by user auth */
344 #define CALLBACK_DSTR 1 /* Dialing string */
345 #define CALLBACK_LID 2 /* Location identifier */
346 #define CALLBACK_E164 3 /* E.164 number */
347 #define CALLBACK_X500 4 /* X.500 distinguished name */
348 #define CALLBACK_CBCP 6 /* Location is determined during CBCP nego */
350 static const struct tok ppp_callback_values
[] = {
351 { CALLBACK_AUTH
, "UserAuth" },
352 { CALLBACK_DSTR
, "DialString" },
353 { CALLBACK_LID
, "LocalID" },
354 { CALLBACK_E164
, "E.164" },
355 { CALLBACK_X500
, "X.500" },
356 { CALLBACK_CBCP
, "CBCP" },
367 static const struct tok chapcode_values
[] = {
368 { CHAP_CHAL
, "Challenge" },
369 { CHAP_RESP
, "Response" },
370 { CHAP_SUCC
, "Success" },
371 { CHAP_FAIL
, "Fail" },
381 static const struct tok papcode_values
[] = {
382 { PAP_AREQ
, "Auth-Req" },
383 { PAP_AACK
, "Auth-ACK" },
384 { PAP_ANAK
, "Auth-NACK" },
389 #define BAP_CALLREQ 1
390 #define BAP_CALLRES 2
398 static u_int
print_lcp_config_options(netdissect_options
*, const u_char
*p
, u_int
);
399 static u_int
print_ipcp_config_options(netdissect_options
*, const u_char
*p
, u_int
);
400 static u_int
print_ip6cp_config_options(netdissect_options
*, const u_char
*p
, u_int
);
401 static u_int
print_ccp_config_options(netdissect_options
*, const u_char
*p
, u_int
);
402 static u_int
print_bacp_config_options(netdissect_options
*, const u_char
*p
, u_int
);
403 static void handle_ppp(netdissect_options
*, u_int proto
, const u_char
*p
, u_int length
);
405 /* generic Control Protocol (e.g. LCP, IPCP, CCP, etc.) handler */
407 handle_ctrl_proto(netdissect_options
*ndo
,
408 u_int proto
, const u_char
*pptr
, u_int length
)
412 u_int (*pfunc
)(netdissect_options
*, const u_char
*, u_int
);
418 typestr
= tok2str(ppptype2str
, "unknown ctrl-proto (0x%04x)", proto
);
419 ND_PRINT("%s, ", typestr
);
421 if (length
< 4) /* FIXME weak boundary checking */
425 code
= GET_U_1(tptr
);
428 ND_PRINT("%s (0x%02x), id %u, length %u",
429 tok2str(cpcodes
, "Unknown Opcode",code
),
431 GET_U_1(tptr
), /* ID */
438 len
= GET_BE_U_2(tptr
);
442 ND_PRINT("\n\tencoded length %u (< 4))", len
);
447 ND_PRINT("\n\tencoded length %u (> packet length %u))", len
, length
);
452 ND_PRINT("\n\tencoded length %u (=Option(s) length %u)", len
, len
- 4);
455 return; /* there may be a NULL confreq etc. */
457 if (ndo
->ndo_vflag
> 1)
458 print_unknown_data(ndo
, pptr
- 2, "\n\t", 6);
465 ND_PRINT("\n\t Magic-Num 0x%08x", GET_BE_U_4(tptr
));
467 ND_PRINT(" Vendor: %s (%u)",
468 tok2str(oui_values
,"Unknown",GET_BE_U_3(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 tlen
= 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 ((advance
= (*pfunc
)(ndo
, tptr
, len
)) == 0)
508 if (tlen
< advance
) {
509 ND_PRINT(" [remaining options length %u < %u]",
511 nd_print_invalid(ndo
);
519 case CPCODES_TERM_REQ
:
520 case CPCODES_TERM_ACK
:
521 /* XXX: need to decode Data? */
523 case CPCODES_CODE_REJ
:
524 /* XXX: need to decode Rejected-Packet? */
526 case CPCODES_PROT_REJ
:
529 ND_PRINT("\n\t Rejected %s Protocol (0x%04x)",
530 tok2str(ppptype2str
,"unknown", GET_BE_U_2(tptr
)),
532 /* XXX: need to decode Rejected-Information? - hexdump for now */
534 ND_PRINT("\n\t Rejected Packet");
535 print_unknown_data(ndo
, tptr
+ 2, "\n\t ", len
- 2);
538 case CPCODES_ECHO_REQ
:
539 case CPCODES_ECHO_RPL
:
540 case CPCODES_DISC_REQ
:
543 ND_PRINT("\n\t Magic-Num 0x%08x", GET_BE_U_4(tptr
));
544 /* XXX: need to decode Data? - hexdump for now */
546 ND_PRINT("\n\t -----trailing data-----");
547 ND_TCHECK_LEN(tptr
+ 4, len
- 8);
548 print_unknown_data(ndo
, tptr
+ 4, "\n\t ", len
- 8);
554 ND_PRINT("\n\t Magic-Num 0x%08x", GET_BE_U_4(tptr
));
555 /* RFC 1661 says this is intended to be human readable */
557 ND_PRINT("\n\t Message\n\t ");
558 if (nd_printn(ndo
, tptr
+ 4, len
- 4, ndo
->ndo_snapend
))
562 case CPCODES_TIME_REM
:
565 ND_PRINT("\n\t Magic-Num 0x%08x", GET_BE_U_4(tptr
));
566 ND_PRINT(", Seconds-Remaining %us", GET_BE_U_4(tptr
+ 4));
567 /* XXX: need to decode Message? */
570 /* XXX this is dirty but we do not get the
571 * original pointer passed to the begin
573 if (ndo
->ndo_vflag
<= 1)
574 print_unknown_data(ndo
, pptr
- 2, "\n\t ", length
+ 2);
580 ND_PRINT("[|%s]", typestr
);
583 /* LCP config options */
585 print_lcp_config_options(netdissect_options
*ndo
,
586 const u_char
*p
, u_int length
)
594 len
= GET_U_1(p
+ 1);
598 if (opt
< NUM_LCPOPTS
)
599 ND_PRINT("\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
600 lcpconfopts
[opt
], opt
, len
);
602 ND_PRINT("\n\tunknown LCP option 0x%02x", opt
);
605 if (opt
< NUM_LCPOPTS
)
606 ND_PRINT("\n\t %s Option (0x%02x), length %u", lcpconfopts
[opt
], opt
, len
);
608 ND_PRINT("\n\tunknown LCP option 0x%02x", opt
);
615 ND_PRINT(" (length bogus, should be >= 6)");
618 ND_PRINT(": Vendor: %s (%u)",
619 tok2str(oui_values
,"Unknown",GET_BE_U_3(p
+ 2)),
622 ND_PRINT(", kind: 0x%02x", GET_U_1(p
+ 5));
623 ND_PRINT(", Value: 0x");
624 for (i
= 0; i
< len
- 6; i
++) {
625 ND_PRINT("%02x", GET_U_1(p
+ 6 + i
));
631 ND_PRINT(" (length bogus, should be = 4)");
634 ND_PRINT(": %u", GET_BE_U_2(p
+ 2));
638 ND_PRINT(" (length bogus, should be = 6)");
641 ND_PRINT(": 0x%08x", GET_BE_U_4(p
+ 2));
645 ND_PRINT(" (length bogus, should be >= 4)");
649 tok2str(ppptype2str
, "Unknown Auth Proto (0x04x)", GET_BE_U_2(p
+ 2)));
651 switch (GET_BE_U_2(p
+ 2)) {
654 tok2str(authalg_values
, "Unknown Auth Alg %u", GET_U_1(p
+ 4)));
656 case PPP_PAP
: /* fall through */
662 print_unknown_data(ndo
, p
, "\n\t", len
);
667 ND_PRINT(" (length bogus, should be >= 4)");
670 if (GET_BE_U_2(p
+ 2) == PPP_LQM
)
673 ND_PRINT(": unknown");
677 ND_PRINT(" (length bogus, should be = 6)");
680 ND_PRINT(": 0x%08x", GET_BE_U_4(p
+ 2));
688 ND_PRINT(" (length bogus, should be = 4)");
691 ND_PRINT(": 0x%04x", GET_BE_U_2(p
+ 2));
695 ND_PRINT(" (length bogus, should be >= 3)");
698 ND_PRINT(": Callback Operation %s (%u)",
699 tok2str(ppp_callback_values
, "Unknown", GET_U_1(p
+ 2)),
704 ND_PRINT(" (length bogus, should be = 4)");
707 ND_PRINT(": %u", GET_BE_U_2(p
+ 2));
711 ND_PRINT(" (length bogus, should be >= 3)");
714 switch (GET_U_1(p
+ 2)) { /* class */
719 ND_PRINT(": Local"); /* XXX */
723 ND_PRINT(" (length bogus, should be = 7)");
726 ND_PRINT(": IPv4 %s", GET_IPADDR_STRING(p
+ 3));
730 ND_PRINT(" (length bogus, should be = 9)");
733 ND_PRINT(": MAC %s", GET_MAC48_STRING(p
+ 3));
736 ND_PRINT(": Magic-Num-Block"); /* XXX */
739 ND_PRINT(": PSNDN"); /* XXX */
742 ND_PRINT(": Unknown class %u", GET_U_1(p
+ 2));
747 /* XXX: to be supported */
772 * Unknown option; dump it as raw bytes now if we're
773 * not going to do so below.
775 if (ndo
->ndo_vflag
< 2)
776 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2);
780 if (ndo
->ndo_vflag
> 1)
781 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2); /* exclude TLV header */
791 static const struct tok ppp_ml_flag_values
[] = {
798 handle_mlppp(netdissect_options
*ndo
,
799 const u_char
*p
, u_int length
)
805 ND_PRINT("[|mlppp]");
808 if (!ND_TTEST_2(p
)) {
809 ND_PRINT("[|mlppp]");
813 ND_PRINT("seq 0x%03x, Flags [%s], length %u",
814 (GET_BE_U_2(p
))&0x0fff,
815 /* only support 12-Bit sequence space for now */
816 bittok2str(ppp_ml_flag_values
, "none", GET_U_1(p
) & 0xc0),
822 handle_chap(netdissect_options
*ndo
,
823 const u_char
*p
, u_int length
)
826 u_int val_size
, name_size
, msg_size
;
834 } else if (length
< 4) {
835 ND_PRINT("[|chap 0x%02x]", GET_U_1(p
));
840 ND_PRINT("CHAP, %s (0x%02x)",
841 tok2str(chapcode_values
,"unknown",code
),
845 ND_PRINT(", id %u", GET_U_1(p
)); /* ID */
852 * Note that this is a generic CHAP decoding routine. Since we
853 * don't know which flavor of CHAP (i.e. CHAP-MD5, MS-CHAPv1,
854 * MS-CHAPv2) is used at this point, we can't decode packet
855 * specifically to each algorithms. Instead, we simply decode
856 * the GCD (Greatest Common Denominator) for all algorithms.
861 if (length
- (p
- p0
) < 1)
863 val_size
= GET_U_1(p
); /* value size */
865 if (length
- (p
- p0
) < val_size
)
867 ND_PRINT(", Value ");
868 for (i
= 0; i
< val_size
; i
++) {
869 ND_PRINT("%02x", GET_U_1(p
));
872 name_size
= len
- (u_int
)(p
- p0
);
874 for (i
= 0; i
< name_size
; i
++) {
875 fn_print_char(ndo
, GET_U_1(p
));
881 msg_size
= len
- (u_int
)(p
- p0
);
883 for (i
= 0; i
< msg_size
; i
++) {
884 fn_print_char(ndo
, GET_U_1(p
));
891 /* PAP (see RFC 1334) */
893 handle_pap(netdissect_options
*ndo
,
894 const u_char
*p
, u_int length
)
897 u_int peerid_len
, passwd_len
, msg_len
;
905 } else if (length
< 4) {
906 ND_PRINT("[|pap 0x%02x]", GET_U_1(p
));
911 ND_PRINT("PAP, %s (0x%02x)",
912 tok2str(papcode_values
, "unknown", code
),
916 ND_PRINT(", id %u", GET_U_1(p
)); /* ID */
923 ND_PRINT(", length %u > packet size", len
);
927 if (length
< (size_t)(p
- p0
)) {
928 ND_PRINT(", length %u < PAP header length", length
);
934 /* A valid Authenticate-Request is 6 or more octets long. */
937 if (length
- (p
- p0
) < 1)
939 peerid_len
= GET_U_1(p
); /* Peer-ID Length */
941 if (length
- (p
- p0
) < peerid_len
)
944 for (i
= 0; i
< peerid_len
; i
++) {
945 fn_print_char(ndo
, GET_U_1(p
));
949 if (length
- (p
- p0
) < 1)
951 passwd_len
= GET_U_1(p
); /* Password Length */
953 if (length
- (p
- p0
) < passwd_len
)
956 for (i
= 0; i
< passwd_len
; i
++) {
957 fn_print_char(ndo
, GET_U_1(p
));
963 /* Although some implementations ignore truncation at
964 * this point and at least one generates a truncated
965 * packet, RFC 1334 section 2.2.2 clearly states that
966 * both AACK and ANAK are at least 5 bytes long.
970 if (length
- (p
- p0
) < 1)
972 msg_len
= GET_U_1(p
); /* Msg-Length */
974 if (length
- (p
- p0
) < msg_len
)
977 for (i
= 0; i
< msg_len
; i
++) {
978 fn_print_char(ndo
, GET_U_1(p
));
991 handle_bap(netdissect_options
*ndo _U_
,
992 const u_char
*p _U_
, u_int length _U_
)
994 /* XXX: to be supported!! */
998 /* IPCP config options */
1000 print_ipcp_config_options(netdissect_options
*ndo
,
1001 const u_char
*p
, u_int length
)
1004 u_int compproto
, ipcomp_subopttotallen
, ipcomp_subopt
, ipcomp_suboptlen
;
1010 len
= GET_U_1(p
+ 1);
1014 ND_PRINT("\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1015 tok2str(ipcpopt_values
,"unknown",opt
),
1021 ND_PRINT("\n\t %s Option (0x%02x), length %u",
1022 tok2str(ipcpopt_values
,"unknown",opt
),
1027 case IPCPOPT_2ADDR
: /* deprecated */
1029 ND_PRINT(" (length bogus, should be = 10)");
1032 ND_PRINT(": src %s, dst %s",
1033 GET_IPADDR_STRING(p
+ 2),
1034 GET_IPADDR_STRING(p
+ 6));
1036 case IPCPOPT_IPCOMP
:
1038 ND_PRINT(" (length bogus, should be >= 4)");
1041 compproto
= GET_BE_U_2(p
+ 2);
1043 ND_PRINT(": %s (0x%02x):",
1044 tok2str(ipcpopt_compproto_values
, "Unknown", compproto
),
1047 switch (compproto
) {
1049 /* XXX: VJ-Comp parameters should be decoded */
1051 case IPCPOPT_IPCOMP_HDRCOMP
:
1052 if (len
< IPCPOPT_IPCOMP_MINLEN
) {
1053 ND_PRINT(" (length bogus, should be >= %u)",
1054 IPCPOPT_IPCOMP_MINLEN
);
1058 ND_TCHECK_LEN(p
+ 2, IPCPOPT_IPCOMP_MINLEN
);
1059 ND_PRINT("\n\t TCP Space %u, non-TCP Space %u"
1060 ", maxPeriod %u, maxTime %u, maxHdr %u",
1065 GET_BE_U_2(p
+ 12));
1067 /* suboptions present ? */
1068 if (len
> IPCPOPT_IPCOMP_MINLEN
) {
1069 ipcomp_subopttotallen
= len
- IPCPOPT_IPCOMP_MINLEN
;
1070 p
+= IPCPOPT_IPCOMP_MINLEN
;
1072 ND_PRINT("\n\t Suboptions, length %u", ipcomp_subopttotallen
);
1074 while (ipcomp_subopttotallen
>= 2) {
1076 ipcomp_subopt
= GET_U_1(p
);
1077 ipcomp_suboptlen
= GET_U_1(p
+ 1);
1080 if (ipcomp_subopt
== 0 ||
1081 ipcomp_suboptlen
== 0 )
1084 /* XXX: just display the suboptions for now */
1085 ND_PRINT("\n\t\t%s Suboption #%u, length %u",
1086 tok2str(ipcpopt_compproto_subopt_values
,
1091 if (ipcomp_subopttotallen
< ipcomp_suboptlen
) {
1092 ND_PRINT(" [remaining suboptions length %u < %u]",
1093 ipcomp_subopttotallen
, ipcomp_suboptlen
);
1094 nd_print_invalid(ndo
);
1097 ipcomp_subopttotallen
-= ipcomp_suboptlen
;
1098 p
+= ipcomp_suboptlen
;
1107 case IPCPOPT_ADDR
: /* those options share the same format - fall through */
1108 case IPCPOPT_MOBILE4
:
1109 case IPCPOPT_PRIDNS
:
1110 case IPCPOPT_PRINBNS
:
1111 case IPCPOPT_SECDNS
:
1112 case IPCPOPT_SECNBNS
:
1114 ND_PRINT(" (length bogus, should be = 6)");
1117 ND_PRINT(": %s", GET_IPADDR_STRING(p
+ 2));
1121 * Unknown option; dump it as raw bytes now if we're
1122 * not going to do so below.
1124 if (ndo
->ndo_vflag
< 2)
1125 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2);
1128 if (ndo
->ndo_vflag
> 1 && ND_TTEST_LEN(p
+ 2, len
- 2))
1129 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2); /* exclude TLV header */
1133 ND_PRINT("[|ipcp]");
1137 /* IP6CP config options */
1139 print_ip6cp_config_options(netdissect_options
*ndo
,
1140 const u_char
*p
, u_int length
)
1148 len
= GET_U_1(p
+ 1);
1152 ND_PRINT("\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1153 tok2str(ip6cpopt_values
,"unknown",opt
),
1159 ND_PRINT("\n\t %s Option (0x%02x), length %u",
1160 tok2str(ip6cpopt_values
,"unknown",opt
),
1167 ND_PRINT(" (length bogus, should be = 10)");
1171 ND_PRINT(": %04x:%04x:%04x:%04x",
1179 * Unknown option; dump it as raw bytes now if we're
1180 * not going to do so below.
1182 if (ndo
->ndo_vflag
< 2)
1183 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2);
1186 if (ndo
->ndo_vflag
> 1)
1187 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2); /* exclude TLV header */
1192 ND_PRINT("[|ip6cp]");
1197 /* CCP config options */
1199 print_ccp_config_options(netdissect_options
*ndo
,
1200 const u_char
*p
, u_int length
)
1208 len
= GET_U_1(p
+ 1);
1212 ND_PRINT("\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1213 tok2str(ccpconfopts_values
, "Unknown", opt
),
1219 ND_PRINT("\n\t %s Option (0x%02x), length %u",
1220 tok2str(ccpconfopts_values
, "Unknown", opt
),
1225 case CCPOPT_BSDCOMP
:
1227 ND_PRINT(" (length bogus, should be >= 3)");
1230 ND_PRINT(": Version: %u, Dictionary Bits: %u",
1231 GET_U_1(p
+ 2) >> 5,
1232 GET_U_1(p
+ 2) & 0x1f);
1236 ND_PRINT(" (length bogus, should be >= 4)");
1239 ND_PRINT(": Features: %u, PxP: %s, History: %u, #CTX-ID: %u",
1240 (GET_U_1(p
+ 2) & 0xc0) >> 6,
1241 (GET_U_1(p
+ 2) & 0x20) ? "Enabled" : "Disabled",
1242 GET_U_1(p
+ 2) & 0x1f,
1245 case CCPOPT_DEFLATE
:
1247 ND_PRINT(" (length bogus, should be >= 4)");
1250 ND_PRINT(": Window: %uK, Method: %s (0x%x), MBZ: %u, CHK: %u",
1251 (GET_U_1(p
+ 2) & 0xf0) >> 4,
1252 ((GET_U_1(p
+ 2) & 0x0f) == 8) ? "zlib" : "unknown",
1253 GET_U_1(p
+ 2) & 0x0f,
1254 (GET_U_1(p
+ 3) & 0xfc) >> 2,
1255 GET_U_1(p
+ 3) & 0x03);
1258 /* XXX: to be supported */
1265 case CCPOPT_STACLZS
:
1276 * Unknown option; dump it as raw bytes now if we're
1277 * not going to do so below.
1279 if (ndo
->ndo_vflag
< 2)
1280 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2);
1283 if (ndo
->ndo_vflag
> 1)
1284 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2); /* exclude TLV header */
1293 /* BACP config options */
1295 print_bacp_config_options(netdissect_options
*ndo
,
1296 const u_char
*p
, u_int length
)
1304 len
= GET_U_1(p
+ 1);
1308 ND_PRINT("\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1309 tok2str(bacconfopts_values
, "Unknown", opt
),
1315 ND_PRINT("\n\t %s Option (0x%02x), length %u",
1316 tok2str(bacconfopts_values
, "Unknown", opt
),
1323 ND_PRINT(" (length bogus, should be = 6)");
1326 ND_PRINT(": Magic-Num 0x%08x", GET_BE_U_4(p
+ 2));
1330 * Unknown option; dump it as raw bytes now if we're
1331 * not going to do so below.
1333 if (ndo
->ndo_vflag
< 2)
1334 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2);
1337 if (ndo
->ndo_vflag
> 1)
1338 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2); /* exclude TLV header */
1343 ND_PRINT("[|bacp]");
1348 * Un-escape RFC 1662 PPP in HDLC-like framing, with octet escapes.
1349 * The length argument is the on-the-wire length, not the captured
1350 * length; we can only un-escape the captured part.
1353 ppp_hdlc(netdissect_options
*ndo
,
1354 const u_char
*p
, u_int length
)
1356 u_int caplen
= ND_BYTES_AVAILABLE_AFTER(p
);
1367 b
= (u_char
*)malloc(caplen
);
1369 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
1370 "%s: malloc", __func__
);
1374 * Unescape all the data into a temporary, private, buffer.
1375 * Do this so that we don't overwrite the original packet
1378 for (s
= p
, t
= b
, i
= caplen
; i
!= 0; i
--) {
1385 c
= GET_U_1(s
) ^ 0x20;
1392 * Switch to the output buffer for dissection, and save it
1393 * on the buffer stack so it can be freed; our caller must
1396 if (!nd_push_buffer(ndo
, b
, b
, (u_int
)(t
- b
))) {
1398 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
1399 "%s: can't push buffer on buffer stack", __func__
);
1401 length
= ND_BYTES_AVAILABLE_AFTER(b
);
1403 /* now lets guess about the payload codepoint format */
1406 proto
= GET_U_1(b
); /* start with a one-octet codepoint guess */
1410 ip_print(ndo
, b
+ 1, length
- 1);
1413 ip6_print(ndo
, b
+ 1, length
- 1);
1415 default: /* no luck - try next guess */
1421 proto
= GET_BE_U_2(b
); /* next guess - load two octets */
1424 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
): /* looks like a PPP frame */
1427 proto
= GET_BE_U_2(b
+ 2); /* load the PPP proto-id */
1428 if ((proto
& 0xff00) == 0x7e00)
1429 ND_PRINT("(protocol 0x%04x invalid)", proto
);
1431 handle_ppp(ndo
, proto
, b
+ 4, length
- 4);
1433 default: /* last guess - proto must be a PPP proto-id */
1434 if ((proto
& 0xff00) == 0x7e00)
1435 ND_PRINT("(protocol 0x%04x invalid)", proto
);
1437 handle_ppp(ndo
, proto
, b
+ 2, length
- 2);
1442 nd_pop_packet_info(ndo
);
1446 nd_pop_packet_info(ndo
);
1447 nd_print_trunc(ndo
);
1453 handle_ppp(netdissect_options
*ndo
,
1454 u_int proto
, const u_char
*p
, u_int length
)
1456 if ((proto
& 0xff00) == 0x7e00) { /* is this an escape code ? */
1457 ppp_hdlc(ndo
, p
- 1, length
);
1462 case PPP_LCP
: /* fall through */
1469 handle_ctrl_proto(ndo
, proto
, p
, length
);
1472 handle_mlppp(ndo
, p
, length
);
1475 handle_chap(ndo
, p
, length
);
1478 handle_pap(ndo
, p
, length
);
1480 case PPP_BAP
: /* XXX: not yet completed */
1481 handle_bap(ndo
, p
, length
);
1483 case ETHERTYPE_IP
: /*XXX*/
1486 ip_print(ndo
, p
, length
);
1488 case ETHERTYPE_IPV6
: /*XXX*/
1490 ip6_print(ndo
, p
, length
);
1492 case ETHERTYPE_IPX
: /*XXX*/
1494 ipx_print(ndo
, p
, length
);
1497 isoclns_print(ndo
, p
, length
);
1499 case PPP_MPLS_UCAST
:
1500 case PPP_MPLS_MCAST
:
1501 mpls_print(ndo
, p
, length
);
1504 ND_PRINT("compressed PPP data");
1507 ND_PRINT("%s ", tok2str(ppptype2str
, "unknown PPP protocol (0x%04x)", proto
));
1508 print_unknown_data(ndo
, p
, "\n\t", length
);
1513 /* Standard PPP printer */
1515 ppp_print(netdissect_options
*ndo
,
1516 const u_char
*p
, u_int length
)
1518 u_int proto
,ppp_header
;
1519 u_int olen
= length
; /* _o_riginal length */
1522 ndo
->ndo_protocol
= "ppp";
1524 * Here, we assume that p points to the Address and Control
1525 * field (if they present).
1529 ppp_header
= GET_BE_U_2(p
);
1531 switch(ppp_header
) {
1532 case (PPP_PPPD_IN
<< 8 | PPP_CONTROL
):
1533 if (ndo
->ndo_eflag
) ND_PRINT("In ");
1538 case (PPP_PPPD_OUT
<< 8 | PPP_CONTROL
):
1539 if (ndo
->ndo_eflag
) ND_PRINT("Out ");
1544 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
):
1545 p
+= 2; /* ACFC not used */
1556 if (GET_U_1(p
) % 2) {
1557 proto
= GET_U_1(p
); /* PFC is used */
1562 proto
= GET_BE_U_2(p
);
1568 if (ndo
->ndo_eflag
) {
1569 const char *typestr
;
1570 typestr
= tok2str(ppptype2str
, "unknown", proto
);
1571 ND_PRINT("%s (0x%04x), length %u",
1575 if (*typestr
== 'u') /* "unknown" */
1581 handle_ppp(ndo
, proto
, p
, length
);
1584 nd_print_trunc(ndo
);
1589 /* PPP I/F printer */
1591 ppp_if_print(netdissect_options
*ndo
,
1592 const struct pcap_pkthdr
*h
, const u_char
*p
)
1594 u_int length
= h
->len
;
1595 u_int caplen
= h
->caplen
;
1597 ndo
->ndo_protocol
= "ppp";
1598 if (caplen
< PPP_HDRLEN
) {
1599 nd_print_trunc(ndo
);
1600 ndo
->ndo_ll_hdr_len
+= caplen
;
1603 ndo
->ndo_ll_hdr_len
+= PPP_HDRLEN
;
1607 * XXX: seems to assume that there are 2 octets prepended to an
1608 * actual PPP frame. The 1st octet looks like Input/Output flag
1609 * while 2nd octet is unknown, at least to me
1610 * (mshindo@mshindo.net).
1612 * That was what the original tcpdump code did.
1614 * FreeBSD's "if_ppp.c" *does* set the first octet to 1 for outbound
1615 * packets and 0 for inbound packets - but only if the
1616 * protocol field has the 0x8000 bit set (i.e., it's a network
1617 * control protocol); it does so before running the packet through
1618 * "bpf_filter" to see if it should be discarded, and to see
1619 * if we should update the time we sent the most recent packet...
1621 * ...but it puts the original address field back after doing
1624 * NetBSD's "if_ppp.c" doesn't set the first octet in that fashion.
1626 * I don't know if any PPP implementation handed up to a BPF
1627 * device packets with the first octet being 1 for outbound and
1628 * 0 for inbound packets, so I (guy@alum.mit.edu) don't know
1629 * whether that ever needs to be checked or not.
1631 * Note that NetBSD has a DLT_PPP_SERIAL, which it uses for PPP,
1632 * and its tcpdump appears to assume that the frame always
1633 * begins with an address field and a control field, and that
1634 * the address field might be 0x0f or 0x8f, for Cisco
1635 * point-to-point with HDLC framing as per section 4.3.1 of RFC
1636 * 1547, as well as 0xff, for PPP in HDLC-like framing as per
1639 * (Is the Cisco framing in question what DLT_C_HDLC, in
1643 ND_PRINT("%c %4d %02x ", GET_U_1(p
) ? 'O' : 'I',
1644 length
, GET_U_1(p
+ 1));
1647 ppp_print(ndo
, p
, length
);
1651 * PPP I/F printer to use if we know that RFC 1662-style PPP in HDLC-like
1652 * framing, or Cisco PPP with HDLC framing as per section 4.3.1 of RFC 1547,
1653 * is being used (i.e., we don't check for PPP_ADDRESS and PPP_CONTROL,
1654 * discard them *if* those are the first two octets, and parse the remaining
1655 * packet as a PPP packet, as "ppp_print()" does).
1657 * This handles, for example, DLT_PPP_SERIAL in NetBSD.
1660 ppp_hdlc_if_print(netdissect_options
*ndo
,
1661 const struct pcap_pkthdr
*h
, const u_char
*p
)
1663 u_int length
= h
->len
;
1664 u_int caplen
= h
->caplen
;
1668 ndo
->ndo_protocol
= "ppp_hdlc";
1670 nd_print_trunc(ndo
);
1671 ndo
->ndo_ll_hdr_len
+= caplen
;
1675 switch (GET_U_1(p
)) {
1679 nd_print_trunc(ndo
);
1680 ndo
->ndo_ll_hdr_len
+= caplen
;
1685 ND_PRINT("%02x %02x %u ", GET_U_1(p
),
1686 GET_U_1(p
+ 1), length
);
1691 proto
= GET_BE_U_2(p
);
1695 ND_PRINT("%s: ", tok2str(ppptype2str
, "unknown PPP protocol (0x%04x)", proto
));
1697 handle_ppp(ndo
, proto
, p
, length
);
1702 chdlc_if_print(ndo
, h
, p
);
1707 nd_print_trunc(ndo
);
1708 ndo
->ndo_ll_hdr_len
+= caplen
;
1713 ND_PRINT("%02x %02x %u ", GET_U_1(p
),
1714 GET_U_1(p
+ 1), length
);
1719 * XXX - NetBSD's "ppp_netbsd_serial_if_print()" treats
1720 * the next two octets as an Ethernet type; does that
1723 ND_PRINT("unknown addr %02x; ctrl %02x", GET_U_1(p
),
1728 ndo
->ndo_ll_hdr_len
+= hdrlen
;