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 nd_printjn(ndo
, p
, name_size
);
878 msg_size
= len
- (u_int
)(p
- p0
);
880 nd_printjn(ndo
, p
, msg_size
);
885 /* PAP (see RFC 1334) */
887 handle_pap(netdissect_options
*ndo
,
888 const u_char
*p
, u_int length
)
891 u_int peerid_len
, passwd_len
, msg_len
;
898 } else if (length
< 4) {
899 ND_PRINT("[|pap 0x%02x]", GET_U_1(p
));
904 ND_PRINT("PAP, %s (0x%02x)",
905 tok2str(papcode_values
, "unknown", code
),
909 ND_PRINT(", id %u", GET_U_1(p
)); /* ID */
916 ND_PRINT(", length %u > packet size", len
);
920 if (length
< (size_t)(p
- p0
)) {
921 ND_PRINT(", length %u < PAP header length", length
);
927 /* A valid Authenticate-Request is 6 or more octets long. */
930 if (length
- (p
- p0
) < 1)
932 peerid_len
= GET_U_1(p
); /* Peer-ID Length */
934 if (length
- (p
- p0
) < peerid_len
)
937 nd_printjn(ndo
, p
, peerid_len
);
940 if (length
- (p
- p0
) < 1)
942 passwd_len
= GET_U_1(p
); /* Password Length */
944 if (length
- (p
- p0
) < passwd_len
)
947 nd_printjn(ndo
, p
, passwd_len
);
951 /* Although some implementations ignore truncation at
952 * this point and at least one generates a truncated
953 * packet, RFC 1334 section 2.2.2 clearly states that
954 * both AACK and ANAK are at least 5 bytes long.
958 if (length
- (p
- p0
) < 1)
960 msg_len
= GET_U_1(p
); /* Msg-Length */
962 if (length
- (p
- p0
) < msg_len
)
965 nd_printjn(ndo
, p
, msg_len
);
976 handle_bap(netdissect_options
*ndo _U_
,
977 const u_char
*p _U_
, u_int length _U_
)
979 /* XXX: to be supported!! */
983 /* IPCP config options */
985 print_ipcp_config_options(netdissect_options
*ndo
,
986 const u_char
*p
, u_int length
)
989 u_int compproto
, ipcomp_subopttotallen
, ipcomp_subopt
, ipcomp_suboptlen
;
995 len
= GET_U_1(p
+ 1);
999 ND_PRINT("\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1000 tok2str(ipcpopt_values
,"unknown",opt
),
1006 ND_PRINT("\n\t %s Option (0x%02x), length %u",
1007 tok2str(ipcpopt_values
,"unknown",opt
),
1012 case IPCPOPT_2ADDR
: /* deprecated */
1014 ND_PRINT(" (length bogus, should be = 10)");
1017 ND_PRINT(": src %s, dst %s",
1018 GET_IPADDR_STRING(p
+ 2),
1019 GET_IPADDR_STRING(p
+ 6));
1021 case IPCPOPT_IPCOMP
:
1023 ND_PRINT(" (length bogus, should be >= 4)");
1026 compproto
= GET_BE_U_2(p
+ 2);
1028 ND_PRINT(": %s (0x%02x):",
1029 tok2str(ipcpopt_compproto_values
, "Unknown", compproto
),
1032 switch (compproto
) {
1034 /* XXX: VJ-Comp parameters should be decoded */
1036 case IPCPOPT_IPCOMP_HDRCOMP
:
1037 if (len
< IPCPOPT_IPCOMP_MINLEN
) {
1038 ND_PRINT(" (length bogus, should be >= %u)",
1039 IPCPOPT_IPCOMP_MINLEN
);
1043 ND_TCHECK_LEN(p
+ 2, IPCPOPT_IPCOMP_MINLEN
);
1044 ND_PRINT("\n\t TCP Space %u, non-TCP Space %u"
1045 ", maxPeriod %u, maxTime %u, maxHdr %u",
1050 GET_BE_U_2(p
+ 12));
1052 /* suboptions present ? */
1053 if (len
> IPCPOPT_IPCOMP_MINLEN
) {
1054 ipcomp_subopttotallen
= len
- IPCPOPT_IPCOMP_MINLEN
;
1055 p
+= IPCPOPT_IPCOMP_MINLEN
;
1057 ND_PRINT("\n\t Suboptions, length %u", ipcomp_subopttotallen
);
1059 while (ipcomp_subopttotallen
>= 2) {
1061 ipcomp_subopt
= GET_U_1(p
);
1062 ipcomp_suboptlen
= GET_U_1(p
+ 1);
1065 if (ipcomp_subopt
== 0 ||
1066 ipcomp_suboptlen
== 0 )
1069 /* XXX: just display the suboptions for now */
1070 ND_PRINT("\n\t\t%s Suboption #%u, length %u",
1071 tok2str(ipcpopt_compproto_subopt_values
,
1076 if (ipcomp_subopttotallen
< ipcomp_suboptlen
) {
1077 ND_PRINT(" [remaining suboptions length %u < %u]",
1078 ipcomp_subopttotallen
, ipcomp_suboptlen
);
1079 nd_print_invalid(ndo
);
1082 ipcomp_subopttotallen
-= ipcomp_suboptlen
;
1083 p
+= ipcomp_suboptlen
;
1092 case IPCPOPT_ADDR
: /* those options share the same format - fall through */
1093 case IPCPOPT_MOBILE4
:
1094 case IPCPOPT_PRIDNS
:
1095 case IPCPOPT_PRINBNS
:
1096 case IPCPOPT_SECDNS
:
1097 case IPCPOPT_SECNBNS
:
1099 ND_PRINT(" (length bogus, should be = 6)");
1102 ND_PRINT(": %s", GET_IPADDR_STRING(p
+ 2));
1106 * Unknown option; dump it as raw bytes now if we're
1107 * not going to do so below.
1109 if (ndo
->ndo_vflag
< 2)
1110 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2);
1113 if (ndo
->ndo_vflag
> 1 && ND_TTEST_LEN(p
+ 2, len
- 2))
1114 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2); /* exclude TLV header */
1118 ND_PRINT("[|ipcp]");
1122 /* IP6CP config options */
1124 print_ip6cp_config_options(netdissect_options
*ndo
,
1125 const u_char
*p
, u_int length
)
1133 len
= GET_U_1(p
+ 1);
1137 ND_PRINT("\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1138 tok2str(ip6cpopt_values
,"unknown",opt
),
1144 ND_PRINT("\n\t %s Option (0x%02x), length %u",
1145 tok2str(ip6cpopt_values
,"unknown",opt
),
1152 ND_PRINT(" (length bogus, should be = 10)");
1156 ND_PRINT(": %04x:%04x:%04x:%04x",
1164 * Unknown option; dump it as raw bytes now if we're
1165 * not going to do so below.
1167 if (ndo
->ndo_vflag
< 2)
1168 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2);
1171 if (ndo
->ndo_vflag
> 1)
1172 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2); /* exclude TLV header */
1177 ND_PRINT("[|ip6cp]");
1182 /* CCP config options */
1184 print_ccp_config_options(netdissect_options
*ndo
,
1185 const u_char
*p
, u_int length
)
1193 len
= GET_U_1(p
+ 1);
1197 ND_PRINT("\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1198 tok2str(ccpconfopts_values
, "Unknown", opt
),
1204 ND_PRINT("\n\t %s Option (0x%02x), length %u",
1205 tok2str(ccpconfopts_values
, "Unknown", opt
),
1210 case CCPOPT_BSDCOMP
:
1212 ND_PRINT(" (length bogus, should be >= 3)");
1215 ND_PRINT(": Version: %u, Dictionary Bits: %u",
1216 GET_U_1(p
+ 2) >> 5,
1217 GET_U_1(p
+ 2) & 0x1f);
1221 ND_PRINT(" (length bogus, should be >= 4)");
1224 ND_PRINT(": Features: %u, PxP: %s, History: %u, #CTX-ID: %u",
1225 (GET_U_1(p
+ 2) & 0xc0) >> 6,
1226 (GET_U_1(p
+ 2) & 0x20) ? "Enabled" : "Disabled",
1227 GET_U_1(p
+ 2) & 0x1f,
1230 case CCPOPT_DEFLATE
:
1232 ND_PRINT(" (length bogus, should be >= 4)");
1235 ND_PRINT(": Window: %uK, Method: %s (0x%x), MBZ: %u, CHK: %u",
1236 (GET_U_1(p
+ 2) & 0xf0) >> 4,
1237 ((GET_U_1(p
+ 2) & 0x0f) == 8) ? "zlib" : "unknown",
1238 GET_U_1(p
+ 2) & 0x0f,
1239 (GET_U_1(p
+ 3) & 0xfc) >> 2,
1240 GET_U_1(p
+ 3) & 0x03);
1243 /* XXX: to be supported */
1250 case CCPOPT_STACLZS
:
1261 * Unknown option; dump it as raw bytes now if we're
1262 * not going to do so below.
1264 if (ndo
->ndo_vflag
< 2)
1265 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2);
1268 if (ndo
->ndo_vflag
> 1)
1269 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2); /* exclude TLV header */
1278 /* BACP config options */
1280 print_bacp_config_options(netdissect_options
*ndo
,
1281 const u_char
*p
, u_int length
)
1289 len
= GET_U_1(p
+ 1);
1293 ND_PRINT("\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1294 tok2str(bacconfopts_values
, "Unknown", opt
),
1300 ND_PRINT("\n\t %s Option (0x%02x), length %u",
1301 tok2str(bacconfopts_values
, "Unknown", opt
),
1308 ND_PRINT(" (length bogus, should be = 6)");
1311 ND_PRINT(": Magic-Num 0x%08x", GET_BE_U_4(p
+ 2));
1315 * Unknown option; dump it as raw bytes now if we're
1316 * not going to do so below.
1318 if (ndo
->ndo_vflag
< 2)
1319 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2);
1322 if (ndo
->ndo_vflag
> 1)
1323 print_unknown_data(ndo
, p
+ 2, "\n\t ", len
- 2); /* exclude TLV header */
1328 ND_PRINT("[|bacp]");
1333 * Un-escape RFC 1662 PPP in HDLC-like framing, with octet escapes.
1334 * The length argument is the on-the-wire length, not the captured
1335 * length; we can only un-escape the captured part.
1338 ppp_hdlc(netdissect_options
*ndo
,
1339 const u_char
*p
, u_int length
)
1341 u_int caplen
= ND_BYTES_AVAILABLE_AFTER(p
);
1352 b
= (u_char
*)malloc(caplen
);
1354 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
1355 "%s: malloc", __func__
);
1359 * Unescape all the data into a temporary, private, buffer.
1360 * Do this so that we don't overwrite the original packet
1363 for (s
= p
, t
= b
, i
= caplen
; i
!= 0; i
--) {
1370 c
= GET_U_1(s
) ^ 0x20;
1377 * Switch to the output buffer for dissection, and save it
1378 * on the buffer stack so it can be freed; our caller must
1381 if (!nd_push_buffer(ndo
, b
, b
, (u_int
)(t
- b
))) {
1383 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
1384 "%s: can't push buffer on buffer stack", __func__
);
1386 length
= ND_BYTES_AVAILABLE_AFTER(b
);
1388 /* now lets guess about the payload codepoint format */
1391 proto
= GET_U_1(b
); /* start with a one-octet codepoint guess */
1395 ip_print(ndo
, b
+ 1, length
- 1);
1398 ip6_print(ndo
, b
+ 1, length
- 1);
1400 default: /* no luck - try next guess */
1406 proto
= GET_BE_U_2(b
); /* next guess - load two octets */
1409 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
): /* looks like a PPP frame */
1412 proto
= GET_BE_U_2(b
+ 2); /* load the PPP proto-id */
1413 if ((proto
& 0xff00) == 0x7e00)
1414 ND_PRINT("(protocol 0x%04x invalid)", proto
);
1416 handle_ppp(ndo
, proto
, b
+ 4, length
- 4);
1418 default: /* last guess - proto must be a PPP proto-id */
1419 if ((proto
& 0xff00) == 0x7e00)
1420 ND_PRINT("(protocol 0x%04x invalid)", proto
);
1422 handle_ppp(ndo
, proto
, b
+ 2, length
- 2);
1427 nd_pop_packet_info(ndo
);
1431 nd_pop_packet_info(ndo
);
1432 nd_print_trunc(ndo
);
1438 handle_ppp(netdissect_options
*ndo
,
1439 u_int proto
, const u_char
*p
, u_int length
)
1441 if ((proto
& 0xff00) == 0x7e00) { /* is this an escape code ? */
1442 ppp_hdlc(ndo
, p
- 1, length
);
1447 case PPP_LCP
: /* fall through */
1454 handle_ctrl_proto(ndo
, proto
, p
, length
);
1457 handle_mlppp(ndo
, p
, length
);
1460 handle_chap(ndo
, p
, length
);
1463 handle_pap(ndo
, p
, length
);
1465 case PPP_BAP
: /* XXX: not yet completed */
1466 handle_bap(ndo
, p
, length
);
1468 case ETHERTYPE_IP
: /*XXX*/
1471 ip_print(ndo
, p
, length
);
1473 case ETHERTYPE_IPV6
: /*XXX*/
1475 ip6_print(ndo
, p
, length
);
1477 case ETHERTYPE_IPX
: /*XXX*/
1479 ipx_print(ndo
, p
, length
);
1482 isoclns_print(ndo
, p
, length
);
1484 case PPP_MPLS_UCAST
:
1485 case PPP_MPLS_MCAST
:
1486 mpls_print(ndo
, p
, length
);
1489 ND_PRINT("compressed PPP data");
1492 ND_PRINT("%s ", tok2str(ppptype2str
, "unknown PPP protocol (0x%04x)", proto
));
1493 print_unknown_data(ndo
, p
, "\n\t", length
);
1498 /* Standard PPP printer */
1500 ppp_print(netdissect_options
*ndo
,
1501 const u_char
*p
, u_int length
)
1503 u_int proto
,ppp_header
;
1504 u_int olen
= length
; /* _o_riginal length */
1507 ndo
->ndo_protocol
= "ppp";
1509 * Here, we assume that p points to the Address and Control
1510 * field (if they present).
1514 ppp_header
= GET_BE_U_2(p
);
1516 switch(ppp_header
) {
1517 case (PPP_PPPD_IN
<< 8 | PPP_CONTROL
):
1518 if (ndo
->ndo_eflag
) ND_PRINT("In ");
1523 case (PPP_PPPD_OUT
<< 8 | PPP_CONTROL
):
1524 if (ndo
->ndo_eflag
) ND_PRINT("Out ");
1529 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
):
1530 p
+= 2; /* ACFC not used */
1541 if (GET_U_1(p
) % 2) {
1542 proto
= GET_U_1(p
); /* PFC is used */
1547 proto
= GET_BE_U_2(p
);
1553 if (ndo
->ndo_eflag
) {
1554 const char *typestr
;
1555 typestr
= tok2str(ppptype2str
, "unknown", proto
);
1556 ND_PRINT("%s (0x%04x), length %u",
1560 if (*typestr
== 'u') /* "unknown" */
1566 handle_ppp(ndo
, proto
, p
, length
);
1569 nd_print_trunc(ndo
);
1574 /* PPP I/F printer */
1576 ppp_if_print(netdissect_options
*ndo
,
1577 const struct pcap_pkthdr
*h
, const u_char
*p
)
1579 u_int length
= h
->len
;
1580 u_int caplen
= h
->caplen
;
1582 ndo
->ndo_protocol
= "ppp";
1583 if (caplen
< PPP_HDRLEN
) {
1584 nd_print_trunc(ndo
);
1585 ndo
->ndo_ll_hdr_len
+= caplen
;
1588 ndo
->ndo_ll_hdr_len
+= PPP_HDRLEN
;
1592 * XXX: seems to assume that there are 2 octets prepended to an
1593 * actual PPP frame. The 1st octet looks like Input/Output flag
1594 * while 2nd octet is unknown, at least to me
1595 * (mshindo@mshindo.net).
1597 * That was what the original tcpdump code did.
1599 * FreeBSD's "if_ppp.c" *does* set the first octet to 1 for outbound
1600 * packets and 0 for inbound packets - but only if the
1601 * protocol field has the 0x8000 bit set (i.e., it's a network
1602 * control protocol); it does so before running the packet through
1603 * "bpf_filter" to see if it should be discarded, and to see
1604 * if we should update the time we sent the most recent packet...
1606 * ...but it puts the original address field back after doing
1609 * NetBSD's "if_ppp.c" doesn't set the first octet in that fashion.
1611 * I don't know if any PPP implementation handed up to a BPF
1612 * device packets with the first octet being 1 for outbound and
1613 * 0 for inbound packets, so I (guy@alum.mit.edu) don't know
1614 * whether that ever needs to be checked or not.
1616 * Note that NetBSD has a DLT_PPP_SERIAL, which it uses for PPP,
1617 * and its tcpdump appears to assume that the frame always
1618 * begins with an address field and a control field, and that
1619 * the address field might be 0x0f or 0x8f, for Cisco
1620 * point-to-point with HDLC framing as per section 4.3.1 of RFC
1621 * 1547, as well as 0xff, for PPP in HDLC-like framing as per
1624 * (Is the Cisco framing in question what DLT_C_HDLC, in
1628 ND_PRINT("%c %4d %02x ", GET_U_1(p
) ? 'O' : 'I',
1629 length
, GET_U_1(p
+ 1));
1632 ppp_print(ndo
, p
, length
);
1636 * PPP I/F printer to use if we know that RFC 1662-style PPP in HDLC-like
1637 * framing, or Cisco PPP with HDLC framing as per section 4.3.1 of RFC 1547,
1638 * is being used (i.e., we don't check for PPP_ADDRESS and PPP_CONTROL,
1639 * discard them *if* those are the first two octets, and parse the remaining
1640 * packet as a PPP packet, as "ppp_print()" does).
1642 * This handles, for example, DLT_PPP_SERIAL in NetBSD.
1645 ppp_hdlc_if_print(netdissect_options
*ndo
,
1646 const struct pcap_pkthdr
*h
, const u_char
*p
)
1648 u_int length
= h
->len
;
1649 u_int caplen
= h
->caplen
;
1653 ndo
->ndo_protocol
= "ppp_hdlc";
1655 nd_print_trunc(ndo
);
1656 ndo
->ndo_ll_hdr_len
+= caplen
;
1660 switch (GET_U_1(p
)) {
1664 nd_print_trunc(ndo
);
1665 ndo
->ndo_ll_hdr_len
+= caplen
;
1670 ND_PRINT("%02x %02x %u ", GET_U_1(p
),
1671 GET_U_1(p
+ 1), length
);
1676 proto
= GET_BE_U_2(p
);
1680 ND_PRINT("%s: ", tok2str(ppptype2str
, "unknown PPP protocol (0x%04x)", proto
));
1682 handle_ppp(ndo
, proto
, p
, length
);
1687 chdlc_if_print(ndo
, h
, p
);
1692 nd_print_trunc(ndo
);
1693 ndo
->ndo_ll_hdr_len
+= caplen
;
1698 ND_PRINT("%02x %02x %u ", GET_U_1(p
),
1699 GET_U_1(p
+ 1), length
);
1704 * XXX - NetBSD's "ppp_netbsd_serial_if_print()" treats
1705 * the next two octets as an Ethernet type; does that
1708 ND_PRINT("unknown addr %02x; ctrl %02x", GET_U_1(p
),
1713 ndo
->ndo_ll_hdr_len
+= hdrlen
;