blob: edc03c021c4e27a43eccad12b6475f6f7e62c9b8 [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
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
16 * written permission.
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.
20 *
21 * Extensively modified by Motonori Shindo (mshindo@mshindo.net) for more
22 * complete PPP support.
23 */
24
25/*
26 * TODO:
27 * o resolve XXX as much as possible
28 * o MP support
29 * o BAP support
30 */
31
Elliott Hughes892a68b2015-10-19 14:43:53 -070032#define NETDISSECT_REWORKED
The Android Open Source Project2949f582009-03-03 19:30:46 -080033#ifdef HAVE_CONFIG_H
34#include "config.h"
35#endif
36
37#include <tcpdump-stdinc.h>
38
39#ifdef __bsdi__
40#include <net/slcompress.h>
41#include <net/if_ppp.h>
42#endif
43
The Android Open Source Project2949f582009-03-03 19:30:46 -080044#include <stdlib.h>
45
46#include "interface.h"
47#include "extract.h"
48#include "addrtoname.h"
49#include "ppp.h"
50#include "chdlc.h"
51#include "ethertype.h"
52#include "oui.h"
53
54/*
55 * The following constatns are defined by IANA. Please refer to
56 * http://www.isi.edu/in-notes/iana/assignments/ppp-numbers
57 * for the up-to-date information.
58 */
59
60/* Protocol Codes defined in ppp.h */
61
JP Abgrall53f17a92014-02-12 14:02:41 -080062static const struct tok ppptype2str[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080063 { PPP_IP, "IP" },
64 { PPP_OSI, "OSI" },
65 { PPP_NS, "NS" },
66 { PPP_DECNET, "DECNET" },
67 { PPP_APPLE, "APPLE" },
68 { PPP_IPX, "IPX" },
69 { PPP_VJC, "VJC IP" },
70 { PPP_VJNC, "VJNC IP" },
71 { PPP_BRPDU, "BRPDU" },
72 { PPP_STII, "STII" },
73 { PPP_VINES, "VINES" },
74 { PPP_MPLS_UCAST, "MPLS" },
75 { PPP_MPLS_MCAST, "MPLS" },
76 { PPP_COMP, "Compressed"},
77 { PPP_ML, "MLPPP"},
78 { PPP_IPV6, "IP6"},
79
80 { PPP_HELLO, "HELLO" },
81 { PPP_LUXCOM, "LUXCOM" },
82 { PPP_SNS, "SNS" },
83 { PPP_IPCP, "IPCP" },
84 { PPP_OSICP, "OSICP" },
85 { PPP_NSCP, "NSCP" },
86 { PPP_DECNETCP, "DECNETCP" },
87 { PPP_APPLECP, "APPLECP" },
88 { PPP_IPXCP, "IPXCP" },
89 { PPP_STIICP, "STIICP" },
90 { PPP_VINESCP, "VINESCP" },
91 { PPP_IPV6CP, "IP6CP" },
92 { PPP_MPLSCP, "MPLSCP" },
93
94 { PPP_LCP, "LCP" },
95 { PPP_PAP, "PAP" },
96 { PPP_LQM, "LQM" },
97 { PPP_CHAP, "CHAP" },
98 { PPP_EAP, "EAP" },
99 { PPP_SPAP, "SPAP" },
100 { PPP_SPAP_OLD, "Old-SPAP" },
101 { PPP_BACP, "BACP" },
102 { PPP_BAP, "BAP" },
103 { PPP_MPCP, "MLPPP-CP" },
Elliott Hughes892a68b2015-10-19 14:43:53 -0700104 { PPP_CCP, "CCP" },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800105 { 0, NULL }
106};
107
108/* Control Protocols (LCP/IPCP/CCP etc.) Codes defined in RFC 1661 */
109
110#define CPCODES_VEXT 0 /* Vendor-Specific (RFC2153) */
111#define CPCODES_CONF_REQ 1 /* Configure-Request */
112#define CPCODES_CONF_ACK 2 /* Configure-Ack */
113#define CPCODES_CONF_NAK 3 /* Configure-Nak */
114#define CPCODES_CONF_REJ 4 /* Configure-Reject */
115#define CPCODES_TERM_REQ 5 /* Terminate-Request */
116#define CPCODES_TERM_ACK 6 /* Terminate-Ack */
117#define CPCODES_CODE_REJ 7 /* Code-Reject */
118#define CPCODES_PROT_REJ 8 /* Protocol-Reject (LCP only) */
119#define CPCODES_ECHO_REQ 9 /* Echo-Request (LCP only) */
120#define CPCODES_ECHO_RPL 10 /* Echo-Reply (LCP only) */
121#define CPCODES_DISC_REQ 11 /* Discard-Request (LCP only) */
122#define CPCODES_ID 12 /* Identification (LCP only) RFC1570 */
123#define CPCODES_TIME_REM 13 /* Time-Remaining (LCP only) RFC1570 */
124#define CPCODES_RESET_REQ 14 /* Reset-Request (CCP only) RFC1962 */
125#define CPCODES_RESET_REP 15 /* Reset-Reply (CCP only) */
126
JP Abgrall53f17a92014-02-12 14:02:41 -0800127static const struct tok cpcodes[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800128 {CPCODES_VEXT, "Vendor-Extension"}, /* RFC2153 */
129 {CPCODES_CONF_REQ, "Conf-Request"},
130 {CPCODES_CONF_ACK, "Conf-Ack"},
131 {CPCODES_CONF_NAK, "Conf-Nack"},
132 {CPCODES_CONF_REJ, "Conf-Reject"},
133 {CPCODES_TERM_REQ, "Term-Request"},
134 {CPCODES_TERM_ACK, "Term-Ack"},
135 {CPCODES_CODE_REJ, "Code-Reject"},
136 {CPCODES_PROT_REJ, "Prot-Reject"},
137 {CPCODES_ECHO_REQ, "Echo-Request"},
138 {CPCODES_ECHO_RPL, "Echo-Reply"},
139 {CPCODES_DISC_REQ, "Disc-Req"},
140 {CPCODES_ID, "Ident"}, /* RFC1570 */
141 {CPCODES_TIME_REM, "Time-Rem"}, /* RFC1570 */
142 {CPCODES_RESET_REQ, "Reset-Req"}, /* RFC1962 */
143 {CPCODES_RESET_REP, "Reset-Ack"}, /* RFC1962 */
144 {0, NULL}
145};
146
147/* LCP Config Options */
148
149#define LCPOPT_VEXT 0
150#define LCPOPT_MRU 1
151#define LCPOPT_ACCM 2
152#define LCPOPT_AP 3
153#define LCPOPT_QP 4
154#define LCPOPT_MN 5
155#define LCPOPT_DEP6 6
156#define LCPOPT_PFC 7
157#define LCPOPT_ACFC 8
158#define LCPOPT_FCSALT 9
159#define LCPOPT_SDP 10
160#define LCPOPT_NUMMODE 11
161#define LCPOPT_DEP12 12
162#define LCPOPT_CBACK 13
163#define LCPOPT_DEP14 14
164#define LCPOPT_DEP15 15
165#define LCPOPT_DEP16 16
166#define LCPOPT_MLMRRU 17
167#define LCPOPT_MLSSNHF 18
168#define LCPOPT_MLED 19
169#define LCPOPT_PROP 20
170#define LCPOPT_DCEID 21
171#define LCPOPT_MPP 22
172#define LCPOPT_LD 23
173#define LCPOPT_LCPAOPT 24
174#define LCPOPT_COBS 25
175#define LCPOPT_PE 26
176#define LCPOPT_MLHF 27
177#define LCPOPT_I18N 28
178#define LCPOPT_SDLOS 29
179#define LCPOPT_PPPMUX 30
180
181#define LCPOPT_MIN LCPOPT_VEXT
182#define LCPOPT_MAX LCPOPT_PPPMUX
183
184static const char *lcpconfopts[] = {
185 "Vend-Ext", /* (0) */
186 "MRU", /* (1) */
187 "ACCM", /* (2) */
188 "Auth-Prot", /* (3) */
189 "Qual-Prot", /* (4) */
190 "Magic-Num", /* (5) */
191 "deprecated(6)", /* used to be a Quality Protocol */
192 "PFC", /* (7) */
193 "ACFC", /* (8) */
194 "FCS-Alt", /* (9) */
195 "SDP", /* (10) */
196 "Num-Mode", /* (11) */
197 "deprecated(12)", /* used to be a Multi-Link-Procedure*/
198 "Call-Back", /* (13) */
199 "deprecated(14)", /* used to be a Connect-Time */
200 "deprecated(15)", /* used to be a Compund-Frames */
201 "deprecated(16)", /* used to be a Nominal-Data-Encap */
202 "MRRU", /* (17) */
203 "12-Bit seq #", /* (18) */
204 "End-Disc", /* (19) */
205 "Proprietary", /* (20) */
206 "DCE-Id", /* (21) */
207 "MP+", /* (22) */
208 "Link-Disc", /* (23) */
209 "LCP-Auth-Opt", /* (24) */
210 "COBS", /* (25) */
211 "Prefix-elision", /* (26) */
212 "Multilink-header-Form",/* (27) */
213 "I18N", /* (28) */
214 "SDL-over-SONET/SDH", /* (29) */
215 "PPP-Muxing", /* (30) */
216};
217
218/* ECP - to be supported */
219
220/* CCP Config Options */
221
222#define CCPOPT_OUI 0 /* RFC1962 */
223#define CCPOPT_PRED1 1 /* RFC1962 */
224#define CCPOPT_PRED2 2 /* RFC1962 */
225#define CCPOPT_PJUMP 3 /* RFC1962 */
226/* 4-15 unassigned */
227#define CCPOPT_HPPPC 16 /* RFC1962 */
228#define CCPOPT_STACLZS 17 /* RFC1974 */
229#define CCPOPT_MPPC 18 /* RFC2118 */
230#define CCPOPT_GFZA 19 /* RFC1962 */
231#define CCPOPT_V42BIS 20 /* RFC1962 */
232#define CCPOPT_BSDCOMP 21 /* RFC1977 */
233/* 22 unassigned */
234#define CCPOPT_LZSDCP 23 /* RFC1967 */
235#define CCPOPT_MVRCA 24 /* RFC1975 */
236#define CCPOPT_DEC 25 /* RFC1976 */
237#define CCPOPT_DEFLATE 26 /* RFC1979 */
238/* 27-254 unassigned */
239#define CCPOPT_RESV 255 /* RFC1962 */
240
JP Abgrall53f17a92014-02-12 14:02:41 -0800241static const struct tok ccpconfopts_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800242 { CCPOPT_OUI, "OUI" },
243 { CCPOPT_PRED1, "Pred-1" },
244 { CCPOPT_PRED2, "Pred-2" },
245 { CCPOPT_PJUMP, "Puddle" },
246 { CCPOPT_HPPPC, "HP-PPC" },
247 { CCPOPT_STACLZS, "Stac-LZS" },
248 { CCPOPT_MPPC, "MPPC" },
249 { CCPOPT_GFZA, "Gand-FZA" },
250 { CCPOPT_V42BIS, "V.42bis" },
251 { CCPOPT_BSDCOMP, "BSD-Comp" },
252 { CCPOPT_LZSDCP, "LZS-DCP" },
253 { CCPOPT_MVRCA, "MVRCA" },
254 { CCPOPT_DEC, "DEC" },
255 { CCPOPT_DEFLATE, "Deflate" },
256 { CCPOPT_RESV, "Reserved"},
257 {0, NULL}
258};
259
260/* BACP Config Options */
261
262#define BACPOPT_FPEER 1 /* RFC2125 */
263
JP Abgrall53f17a92014-02-12 14:02:41 -0800264static const struct tok bacconfopts_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800265 { BACPOPT_FPEER, "Favored-Peer" },
266 {0, NULL}
267};
268
269
270/* SDCP - to be supported */
271
272/* IPCP Config Options */
273#define IPCPOPT_2ADDR 1 /* RFC1172, RFC1332 (deprecated) */
274#define IPCPOPT_IPCOMP 2 /* RFC1332 */
275#define IPCPOPT_ADDR 3 /* RFC1332 */
276#define IPCPOPT_MOBILE4 4 /* RFC2290 */
277#define IPCPOPT_PRIDNS 129 /* RFC1877 */
278#define IPCPOPT_PRINBNS 130 /* RFC1877 */
279#define IPCPOPT_SECDNS 131 /* RFC1877 */
280#define IPCPOPT_SECNBNS 132 /* RFC1877 */
281
JP Abgrall53f17a92014-02-12 14:02:41 -0800282static const struct tok ipcpopt_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800283 { IPCPOPT_2ADDR, "IP-Addrs" },
284 { IPCPOPT_IPCOMP, "IP-Comp" },
285 { IPCPOPT_ADDR, "IP-Addr" },
286 { IPCPOPT_MOBILE4, "Home-Addr" },
287 { IPCPOPT_PRIDNS, "Pri-DNS" },
288 { IPCPOPT_PRINBNS, "Pri-NBNS" },
289 { IPCPOPT_SECDNS, "Sec-DNS" },
290 { IPCPOPT_SECNBNS, "Sec-NBNS" },
291 { 0, NULL }
292};
293
294#define IPCPOPT_IPCOMP_HDRCOMP 0x61 /* rfc3544 */
295#define IPCPOPT_IPCOMP_MINLEN 14
296
JP Abgrall53f17a92014-02-12 14:02:41 -0800297static const struct tok ipcpopt_compproto_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800298 { PPP_VJC, "VJ-Comp" },
299 { IPCPOPT_IPCOMP_HDRCOMP, "IP Header Compression" },
300 { 0, NULL }
301};
302
JP Abgrall53f17a92014-02-12 14:02:41 -0800303static const struct tok ipcpopt_compproto_subopt_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800304 { 1, "RTP-Compression" },
305 { 2, "Enhanced RTP-Compression" },
306 { 0, NULL }
307};
308
309/* IP6CP Config Options */
310#define IP6CP_IFID 1
311
JP Abgrall53f17a92014-02-12 14:02:41 -0800312static const struct tok ip6cpopt_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800313 { IP6CP_IFID, "Interface-ID" },
314 { 0, NULL }
315};
316
317/* ATCP - to be supported */
318/* OSINLCP - to be supported */
319/* BVCP - to be supported */
320/* BCP - to be supported */
321/* IPXCP - to be supported */
322/* MPLSCP - to be supported */
323
324/* Auth Algorithms */
325
326/* 0-4 Reserved (RFC1994) */
327#define AUTHALG_CHAPMD5 5 /* RFC1994 */
328#define AUTHALG_MSCHAP1 128 /* RFC2433 */
329#define AUTHALG_MSCHAP2 129 /* RFC2795 */
330
JP Abgrall53f17a92014-02-12 14:02:41 -0800331static const struct tok authalg_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800332 { AUTHALG_CHAPMD5, "MD5" },
333 { AUTHALG_MSCHAP1, "MS-CHAPv1" },
334 { AUTHALG_MSCHAP2, "MS-CHAPv2" },
335 { 0, NULL }
336};
337
338/* FCS Alternatives - to be supported */
339
340/* Multilink Endpoint Discriminator (RFC1717) */
341#define MEDCLASS_NULL 0 /* Null Class */
342#define MEDCLASS_LOCAL 1 /* Locally Assigned */
343#define MEDCLASS_IPV4 2 /* Internet Protocol (IPv4) */
344#define MEDCLASS_MAC 3 /* IEEE 802.1 global MAC address */
345#define MEDCLASS_MNB 4 /* PPP Magic Number Block */
346#define MEDCLASS_PSNDN 5 /* Public Switched Network Director Number */
347
348/* PPP LCP Callback */
349#define CALLBACK_AUTH 0 /* Location determined by user auth */
350#define CALLBACK_DSTR 1 /* Dialing string */
351#define CALLBACK_LID 2 /* Location identifier */
352#define CALLBACK_E164 3 /* E.164 number */
353#define CALLBACK_X500 4 /* X.500 distinguished name */
354#define CALLBACK_CBCP 6 /* Location is determined during CBCP nego */
355
JP Abgrall53f17a92014-02-12 14:02:41 -0800356static const struct tok ppp_callback_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800357 { CALLBACK_AUTH, "UserAuth" },
358 { CALLBACK_DSTR, "DialString" },
359 { CALLBACK_LID, "LocalID" },
360 { CALLBACK_E164, "E.164" },
361 { CALLBACK_X500, "X.500" },
362 { CALLBACK_CBCP, "CBCP" },
363 { 0, NULL }
364};
365
366/* CHAP */
367
368#define CHAP_CHAL 1
369#define CHAP_RESP 2
370#define CHAP_SUCC 3
371#define CHAP_FAIL 4
372
JP Abgrall53f17a92014-02-12 14:02:41 -0800373static const struct tok chapcode_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800374 { CHAP_CHAL, "Challenge" },
375 { CHAP_RESP, "Response" },
376 { CHAP_SUCC, "Success" },
377 { CHAP_FAIL, "Fail" },
378 { 0, NULL}
379};
380
381/* PAP */
382
383#define PAP_AREQ 1
384#define PAP_AACK 2
385#define PAP_ANAK 3
386
JP Abgrall53f17a92014-02-12 14:02:41 -0800387static const struct tok papcode_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800388 { PAP_AREQ, "Auth-Req" },
389 { PAP_AACK, "Auth-ACK" },
390 { PAP_ANAK, "Auth-NACK" },
391 { 0, NULL }
392};
393
394/* BAP */
395#define BAP_CALLREQ 1
396#define BAP_CALLRES 2
397#define BAP_CBREQ 3
398#define BAP_CBRES 4
399#define BAP_LDQREQ 5
400#define BAP_LDQRES 6
401#define BAP_CSIND 7
402#define BAP_CSRES 8
403
Elliott Hughes892a68b2015-10-19 14:43:53 -0700404static int print_lcp_config_options(netdissect_options *, const u_char *p, int);
405static int print_ipcp_config_options(netdissect_options *, const u_char *p, int);
406static int print_ip6cp_config_options(netdissect_options *, const u_char *p, int);
407static int print_ccp_config_options(netdissect_options *, const u_char *p, int);
408static int print_bacp_config_options(netdissect_options *, const u_char *p, int);
409static void handle_ppp(netdissect_options *, u_int proto, const u_char *p, int length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800410
411/* generic Control Protocol (e.g. LCP, IPCP, CCP, etc.) handler */
412static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700413handle_ctrl_proto(netdissect_options *ndo,
414 u_int proto, const u_char *pptr, int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800415{
416 const char *typestr;
417 u_int code, len;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700418 int (*pfunc)(netdissect_options *, const u_char *, int);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800419 int x, j;
420 const u_char *tptr;
421
422 tptr=pptr;
423
424 typestr = tok2str(ppptype2str, "unknown ctrl-proto (0x%04x)", proto);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700425 ND_PRINT((ndo, "%s, ", typestr));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800426
427 if (length < 4) /* FIXME weak boundary checking */
428 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700429 ND_TCHECK2(*tptr, 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800430
431 code = *tptr++;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800432
Elliott Hughes892a68b2015-10-19 14:43:53 -0700433 ND_PRINT((ndo, "%s (0x%02x), id %u, length %u",
434 tok2str(cpcodes, "Unknown Opcode",code),
435 code,
436 *tptr++, /* ID */
437 length + 2));
438
439 if (!ndo->ndo_vflag)
440 return;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800441
442 if (length <= 4)
443 return; /* there may be a NULL confreq etc. */
444
Elliott Hughes892a68b2015-10-19 14:43:53 -0700445 ND_TCHECK2(*tptr, 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800446 len = EXTRACT_16BITS(tptr);
447 tptr += 2;
448
Elliott Hughes892a68b2015-10-19 14:43:53 -0700449 ND_PRINT((ndo, "\n\tencoded length %u (=Option(s) length %u)", len, len - 4));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800450
Elliott Hughes892a68b2015-10-19 14:43:53 -0700451 if (ndo->ndo_vflag > 1)
452 print_unknown_data(ndo, pptr - 2, "\n\t", 6);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800453
454
455 switch (code) {
456 case CPCODES_VEXT:
457 if (length < 11)
458 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700459 ND_TCHECK2(*tptr, 4);
460 ND_PRINT((ndo, "\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800461 tptr += 4;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700462 ND_TCHECK2(*tptr, 3);
463 ND_PRINT((ndo, " Vendor: %s (%u)",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800464 tok2str(oui_values,"Unknown",EXTRACT_24BITS(tptr)),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700465 EXTRACT_24BITS(tptr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800466 /* XXX: need to decode Kind and Value(s)? */
467 break;
468 case CPCODES_CONF_REQ:
469 case CPCODES_CONF_ACK:
470 case CPCODES_CONF_NAK:
471 case CPCODES_CONF_REJ:
472 x = len - 4; /* Code(1), Identifier(1) and Length(2) */
473 do {
474 switch (proto) {
475 case PPP_LCP:
476 pfunc = print_lcp_config_options;
477 break;
478 case PPP_IPCP:
479 pfunc = print_ipcp_config_options;
480 break;
481 case PPP_IPV6CP:
482 pfunc = print_ip6cp_config_options;
483 break;
484 case PPP_CCP:
485 pfunc = print_ccp_config_options;
486 break;
487 case PPP_BACP:
488 pfunc = print_bacp_config_options;
489 break;
490 default:
491 /*
492 * No print routine for the options for
493 * this protocol.
494 */
495 pfunc = NULL;
496 break;
497 }
498
499 if (pfunc == NULL) /* catch the above null pointer if unknown CP */
500 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700501
502 if ((j = (*pfunc)(ndo, tptr, len)) == 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800503 break;
504 x -= j;
505 tptr += j;
506 } while (x > 0);
507 break;
508
509 case CPCODES_TERM_REQ:
510 case CPCODES_TERM_ACK:
511 /* XXX: need to decode Data? */
512 break;
513 case CPCODES_CODE_REJ:
514 /* XXX: need to decode Rejected-Packet? */
515 break;
516 case CPCODES_PROT_REJ:
517 if (length < 6)
518 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700519 ND_TCHECK2(*tptr, 2);
520 ND_PRINT((ndo, "\n\t Rejected %s Protocol (0x%04x)",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800521 tok2str(ppptype2str,"unknown", EXTRACT_16BITS(tptr)),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700522 EXTRACT_16BITS(tptr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800523 /* XXX: need to decode Rejected-Information? - hexdump for now */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700524 if (len > 6) {
525 ND_PRINT((ndo, "\n\t Rejected Packet"));
526 print_unknown_data(ndo, tptr + 2, "\n\t ", len - 2);
527 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800528 break;
529 case CPCODES_ECHO_REQ:
530 case CPCODES_ECHO_RPL:
531 case CPCODES_DISC_REQ:
532 if (length < 8)
533 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700534 ND_TCHECK2(*tptr, 4);
535 ND_PRINT((ndo, "\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800536 /* XXX: need to decode Data? - hexdump for now */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700537 if (len > 8) {
538 ND_PRINT((ndo, "\n\t -----trailing data-----"));
539 ND_TCHECK2(tptr[4], len - 8);
540 print_unknown_data(ndo, tptr + 4, "\n\t ", len - 8);
541 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800542 break;
543 case CPCODES_ID:
544 if (length < 8)
545 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700546 ND_TCHECK2(*tptr, 4);
547 ND_PRINT((ndo, "\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800548 /* RFC 1661 says this is intended to be human readable */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700549 if (len > 8) {
550 ND_PRINT((ndo, "\n\t Message\n\t "));
551 if (fn_printn(ndo, tptr + 4, len - 4, ndo->ndo_snapend))
552 goto trunc;
553 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800554 break;
555 case CPCODES_TIME_REM:
556 if (length < 12)
557 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700558 ND_TCHECK2(*tptr, 4);
559 ND_PRINT((ndo, "\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr)));
560 ND_TCHECK2(*(tptr + 4), 4);
561 ND_PRINT((ndo, ", Seconds-Remaining %us", EXTRACT_32BITS(tptr + 4)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800562 /* XXX: need to decode Message? */
563 break;
564 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700565 /* XXX this is dirty but we do not get the
566 * original pointer passed to the begin
567 * the PPP packet */
568 if (ndo->ndo_vflag <= 1)
569 print_unknown_data(ndo, pptr - 2, "\n\t ", length + 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800570 break;
571 }
572 return;
573
574trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700575 ND_PRINT((ndo, "[|%s]", typestr));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800576}
577
578/* LCP config options */
579static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700580print_lcp_config_options(netdissect_options *ndo,
581 const u_char *p, int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800582{
583 int len, opt;
584
585 if (length < 2)
586 return 0;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700587 ND_TCHECK2(*p, 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800588 len = p[1];
589 opt = p[0];
590 if (length < len)
591 return 0;
592 if (len < 2) {
593 if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX))
Elliott Hughes892a68b2015-10-19 14:43:53 -0700594 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
595 lcpconfopts[opt], opt, len));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800596 else
Elliott Hughes892a68b2015-10-19 14:43:53 -0700597 ND_PRINT((ndo, "\n\tunknown LCP option 0x%02x", opt));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800598 return 0;
599 }
600 if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX))
Elliott Hughes892a68b2015-10-19 14:43:53 -0700601 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u", lcpconfopts[opt], opt, len));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800602 else {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700603 ND_PRINT((ndo, "\n\tunknown LCP option 0x%02x", opt));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800604 return len;
605 }
606
607 switch (opt) {
608 case LCPOPT_VEXT:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700609 if (len < 6) {
610 ND_PRINT((ndo, " (length bogus, should be >= 6)"));
611 return len;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800612 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700613 ND_TCHECK2(*(p + 2), 3);
614 ND_PRINT((ndo, ": Vendor: %s (%u)",
615 tok2str(oui_values,"Unknown",EXTRACT_24BITS(p+2)),
616 EXTRACT_24BITS(p + 2)));
617#if 0
618 ND_TCHECK(p[5]);
619 ND_PRINT((ndo, ", kind: 0x%02x", p[5]));
620 ND_PRINT((ndo, ", Value: 0x"));
621 for (i = 0; i < len - 6; i++) {
622 ND_TCHECK(p[6 + i]);
623 ND_PRINT((ndo, "%02x", p[6 + i]));
624 }
625#endif
The Android Open Source Project2949f582009-03-03 19:30:46 -0800626 break;
627 case LCPOPT_MRU:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700628 if (len != 4) {
629 ND_PRINT((ndo, " (length bogus, should be = 4)"));
630 return len;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800631 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700632 ND_TCHECK2(*(p + 2), 2);
633 ND_PRINT((ndo, ": %u", EXTRACT_16BITS(p + 2)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800634 break;
635 case LCPOPT_ACCM:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700636 if (len != 6) {
637 ND_PRINT((ndo, " (length bogus, should be = 6)"));
638 return len;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800639 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700640 ND_TCHECK2(*(p + 2), 4);
641 ND_PRINT((ndo, ": 0x%08x", EXTRACT_32BITS(p + 2)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800642 break;
643 case LCPOPT_AP:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700644 if (len < 4) {
645 ND_PRINT((ndo, " (length bogus, should be >= 4)"));
646 return len;
647 }
648 ND_TCHECK2(*(p + 2), 2);
649 ND_PRINT((ndo, ": %s", tok2str(ppptype2str, "Unknown Auth Proto (0x04x)", EXTRACT_16BITS(p + 2))));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800650
Elliott Hughes892a68b2015-10-19 14:43:53 -0700651 switch (EXTRACT_16BITS(p+2)) {
652 case PPP_CHAP:
653 ND_TCHECK(p[4]);
654 ND_PRINT((ndo, ", %s", tok2str(authalg_values, "Unknown Auth Alg %u", p[4])));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800655 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700656 case PPP_PAP: /* fall through */
657 case PPP_EAP:
658 case PPP_SPAP:
659 case PPP_SPAP_OLD:
The Android Open Source Project2949f582009-03-03 19:30:46 -0800660 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700661 default:
662 print_unknown_data(ndo, p, "\n\t", len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800663 }
664 break;
665 case LCPOPT_QP:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700666 if (len < 4) {
667 ND_PRINT((ndo, " (length bogus, should be >= 4)"));
668 return 0;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800669 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700670 ND_TCHECK2(*(p + 2), 2);
671 if (EXTRACT_16BITS(p+2) == PPP_LQM)
672 ND_PRINT((ndo, ": LQR"));
673 else
674 ND_PRINT((ndo, ": unknown"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800675 break;
676 case LCPOPT_MN:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700677 if (len != 6) {
678 ND_PRINT((ndo, " (length bogus, should be = 6)"));
679 return 0;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800680 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700681 ND_TCHECK2(*(p + 2), 4);
682 ND_PRINT((ndo, ": 0x%08x", EXTRACT_32BITS(p + 2)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800683 break;
684 case LCPOPT_PFC:
685 break;
686 case LCPOPT_ACFC:
687 break;
688 case LCPOPT_LD:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700689 if (len != 4) {
690 ND_PRINT((ndo, " (length bogus, should be = 4)"));
691 return 0;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800692 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700693 ND_TCHECK2(*(p + 2), 2);
694 ND_PRINT((ndo, ": 0x%04x", EXTRACT_16BITS(p + 2)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800695 break;
696 case LCPOPT_CBACK:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700697 if (len < 3) {
698 ND_PRINT((ndo, " (length bogus, should be >= 3)"));
699 return 0;
700 }
701 ND_PRINT((ndo, ": "));
702 ND_TCHECK(p[2]);
703 ND_PRINT((ndo, ": Callback Operation %s (%u)",
704 tok2str(ppp_callback_values, "Unknown", p[2]),
705 p[2]));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800706 break;
707 case LCPOPT_MLMRRU:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700708 if (len != 4) {
709 ND_PRINT((ndo, " (length bogus, should be = 4)"));
710 return 0;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800711 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700712 ND_TCHECK2(*(p + 2), 2);
713 ND_PRINT((ndo, ": %u", EXTRACT_16BITS(p + 2)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800714 break;
715 case LCPOPT_MLED:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700716 if (len < 3) {
717 ND_PRINT((ndo, " (length bogus, should be >= 3)"));
718 return 0;
719 }
720 ND_TCHECK(p[2]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800721 switch (p[2]) { /* class */
722 case MEDCLASS_NULL:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700723 ND_PRINT((ndo, ": Null"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800724 break;
725 case MEDCLASS_LOCAL:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700726 ND_PRINT((ndo, ": Local")); /* XXX */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800727 break;
728 case MEDCLASS_IPV4:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700729 if (len != 7) {
730 ND_PRINT((ndo, " (length bogus, should be = 7)"));
731 return 0;
732 }
733 ND_TCHECK2(*(p + 3), 4);
734 ND_PRINT((ndo, ": IPv4 %s", ipaddr_string(ndo, p + 3)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800735 break;
736 case MEDCLASS_MAC:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700737 if (len != 9) {
738 ND_PRINT((ndo, " (length bogus, should be = 9)"));
739 return 0;
740 }
741 ND_TCHECK2(*(p + 3), 6);
742 ND_PRINT((ndo, ": MAC %s", etheraddr_string(ndo, p + 3)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800743 break;
744 case MEDCLASS_MNB:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700745 ND_PRINT((ndo, ": Magic-Num-Block")); /* XXX */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800746 break;
747 case MEDCLASS_PSNDN:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700748 ND_PRINT((ndo, ": PSNDN")); /* XXX */
749 break;
750 default:
751 ND_PRINT((ndo, ": Unknown class %u", p[2]));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800752 break;
753 }
754 break;
755
756/* XXX: to be supported */
757#if 0
758 case LCPOPT_DEP6:
759 case LCPOPT_FCSALT:
760 case LCPOPT_SDP:
761 case LCPOPT_NUMMODE:
762 case LCPOPT_DEP12:
763 case LCPOPT_DEP14:
764 case LCPOPT_DEP15:
765 case LCPOPT_DEP16:
766 case LCPOPT_MLSSNHF:
767 case LCPOPT_PROP:
768 case LCPOPT_DCEID:
769 case LCPOPT_MPP:
770 case LCPOPT_LCPAOPT:
771 case LCPOPT_COBS:
772 case LCPOPT_PE:
773 case LCPOPT_MLHF:
774 case LCPOPT_I18N:
775 case LCPOPT_SDLOS:
776 case LCPOPT_PPPMUX:
777 break;
778#endif
Elliott Hughes892a68b2015-10-19 14:43:53 -0700779 default:
780 /*
781 * Unknown option; dump it as raw bytes now if we're
782 * not going to do so below.
783 */
784 if (ndo->ndo_vflag < 2)
785 print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
786 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800787 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700788
789 if (ndo->ndo_vflag > 1)
790 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800791
792 return len;
793
794trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700795 ND_PRINT((ndo, "[|lcp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800796 return 0;
797}
798
799/* ML-PPP*/
JP Abgrall53f17a92014-02-12 14:02:41 -0800800static const struct tok ppp_ml_flag_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800801 { 0x80, "begin" },
802 { 0x40, "end" },
803 { 0, NULL }
804};
805
806static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700807handle_mlppp(netdissect_options *ndo,
808 const u_char *p, int length)
809{
810 if (!ndo->ndo_eflag)
811 ND_PRINT((ndo, "MLPPP, "));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800812
Elliott Hughes892a68b2015-10-19 14:43:53 -0700813 ND_PRINT((ndo, "seq 0x%03x, Flags [%s], length %u",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800814 (EXTRACT_16BITS(p))&0x0fff, /* only support 12-Bit sequence space for now */
815 bittok2str(ppp_ml_flag_values, "none", *p & 0xc0),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700816 length));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800817}
818
819/* CHAP */
820static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700821handle_chap(netdissect_options *ndo,
822 const u_char *p, int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800823{
824 u_int code, len;
825 int val_size, name_size, msg_size;
826 const u_char *p0;
827 int i;
828
829 p0 = p;
830 if (length < 1) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700831 ND_PRINT((ndo, "[|chap]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800832 return;
833 } else if (length < 4) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700834 ND_TCHECK(*p);
835 ND_PRINT((ndo, "[|chap 0x%02x]", *p));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800836 return;
837 }
838
Elliott Hughes892a68b2015-10-19 14:43:53 -0700839 ND_TCHECK(*p);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800840 code = *p;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700841 ND_PRINT((ndo, "CHAP, %s (0x%02x)",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800842 tok2str(chapcode_values,"unknown",code),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700843 code));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800844 p++;
845
Elliott Hughes892a68b2015-10-19 14:43:53 -0700846 ND_TCHECK(*p);
847 ND_PRINT((ndo, ", id %u", *p)); /* ID */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800848 p++;
849
Elliott Hughes892a68b2015-10-19 14:43:53 -0700850 ND_TCHECK2(*p, 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800851 len = EXTRACT_16BITS(p);
852 p += 2;
853
854 /*
855 * Note that this is a generic CHAP decoding routine. Since we
856 * don't know which flavor of CHAP (i.e. CHAP-MD5, MS-CHAPv1,
857 * MS-CHAPv2) is used at this point, we can't decode packet
858 * specifically to each algorithms. Instead, we simply decode
859 * the GCD (Gratest Common Denominator) for all algorithms.
860 */
861 switch (code) {
862 case CHAP_CHAL:
863 case CHAP_RESP:
864 if (length - (p - p0) < 1)
865 return;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700866 ND_TCHECK(*p);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800867 val_size = *p; /* value size */
868 p++;
869 if (length - (p - p0) < val_size)
870 return;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700871 ND_PRINT((ndo, ", Value "));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800872 for (i = 0; i < val_size; i++) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700873 ND_TCHECK(*p);
874 ND_PRINT((ndo, "%02x", *p++));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800875 }
876 name_size = len - (p - p0);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700877 ND_PRINT((ndo, ", Name "));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800878 for (i = 0; i < name_size; i++) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700879 ND_TCHECK(*p);
880 safeputchar(ndo, *p++);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800881 }
882 break;
883 case CHAP_SUCC:
884 case CHAP_FAIL:
885 msg_size = len - (p - p0);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700886 ND_PRINT((ndo, ", Msg "));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800887 for (i = 0; i< msg_size; i++) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700888 ND_TCHECK(*p);
889 safeputchar(ndo, *p++);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800890 }
891 break;
892 }
893 return;
894
895trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700896 ND_PRINT((ndo, "[|chap]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800897}
898
899/* PAP (see RFC 1334) */
900static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700901handle_pap(netdissect_options *ndo,
902 const u_char *p, int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800903{
904 u_int code, len;
905 int peerid_len, passwd_len, msg_len;
906 const u_char *p0;
907 int i;
908
909 p0 = p;
910 if (length < 1) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700911 ND_PRINT((ndo, "[|pap]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800912 return;
913 } else if (length < 4) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700914 ND_TCHECK(*p);
915 ND_PRINT((ndo, "[|pap 0x%02x]", *p));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800916 return;
917 }
918
Elliott Hughes892a68b2015-10-19 14:43:53 -0700919 ND_TCHECK(*p);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800920 code = *p;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700921 ND_PRINT((ndo, "PAP, %s (0x%02x)",
922 tok2str(papcode_values, "unknown", code),
923 code));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800924 p++;
925
Elliott Hughes892a68b2015-10-19 14:43:53 -0700926 ND_TCHECK(*p);
927 ND_PRINT((ndo, ", id %u", *p)); /* ID */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800928 p++;
929
Elliott Hughes892a68b2015-10-19 14:43:53 -0700930 ND_TCHECK2(*p, 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800931 len = EXTRACT_16BITS(p);
932 p += 2;
933
934 if ((int)len > length) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700935 ND_PRINT((ndo, ", length %u > packet size", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800936 return;
937 }
938 length = len;
939 if (length < (p - p0)) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700940 ND_PRINT((ndo, ", length %u < PAP header length", length));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800941 return;
942 }
943
944 switch (code) {
945 case PAP_AREQ:
946 if (length - (p - p0) < 1)
947 return;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700948 ND_TCHECK(*p);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800949 peerid_len = *p; /* Peer-ID Length */
950 p++;
951 if (length - (p - p0) < peerid_len)
952 return;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700953 ND_PRINT((ndo, ", Peer "));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800954 for (i = 0; i < peerid_len; i++) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700955 ND_TCHECK(*p);
956 safeputchar(ndo, *p++);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800957 }
958
959 if (length - (p - p0) < 1)
960 return;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700961 ND_TCHECK(*p);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800962 passwd_len = *p; /* Password Length */
963 p++;
964 if (length - (p - p0) < passwd_len)
965 return;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700966 ND_PRINT((ndo, ", Name "));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800967 for (i = 0; i < passwd_len; i++) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700968 ND_TCHECK(*p);
969 safeputchar(ndo, *p++);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800970 }
971 break;
972 case PAP_AACK:
973 case PAP_ANAK:
974 if (length - (p - p0) < 1)
975 return;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700976 ND_TCHECK(*p);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800977 msg_len = *p; /* Msg-Length */
978 p++;
979 if (length - (p - p0) < msg_len)
980 return;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700981 ND_PRINT((ndo, ", Msg "));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800982 for (i = 0; i< msg_len; i++) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700983 ND_TCHECK(*p);
984 safeputchar(ndo, *p++);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800985 }
986 break;
987 }
988 return;
989
990trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700991 ND_PRINT((ndo, "[|pap]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800992}
993
994/* BAP */
995static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700996handle_bap(netdissect_options *ndo _U_,
997 const u_char *p _U_, int length _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800998{
999 /* XXX: to be supported!! */
1000}
1001
1002
1003/* IPCP config options */
1004static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001005print_ipcp_config_options(netdissect_options *ndo,
1006 const u_char *p, int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001007{
1008 int len, opt;
1009 u_int compproto, ipcomp_subopttotallen, ipcomp_subopt, ipcomp_suboptlen;
1010
1011 if (length < 2)
1012 return 0;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001013 ND_TCHECK2(*p, 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001014 len = p[1];
1015 opt = p[0];
1016 if (length < len)
1017 return 0;
1018 if (len < 2) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001019 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001020 tok2str(ipcpopt_values,"unknown",opt),
1021 opt,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001022 len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001023 return 0;
1024 }
1025
Elliott Hughes892a68b2015-10-19 14:43:53 -07001026 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001027 tok2str(ipcpopt_values,"unknown",opt),
1028 opt,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001029 len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001030
1031 switch (opt) {
1032 case IPCPOPT_2ADDR: /* deprecated */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001033 if (len != 10) {
1034 ND_PRINT((ndo, " (length bogus, should be = 10)"));
1035 return len;
1036 }
1037 ND_TCHECK2(*(p + 6), 4);
1038 ND_PRINT((ndo, ": src %s, dst %s",
1039 ipaddr_string(ndo, p + 2),
1040 ipaddr_string(ndo, p + 6)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001041 break;
1042 case IPCPOPT_IPCOMP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001043 if (len < 4) {
1044 ND_PRINT((ndo, " (length bogus, should be >= 4)"));
1045 return 0;
1046 }
1047 ND_TCHECK2(*(p + 2), 2);
1048 compproto = EXTRACT_16BITS(p+2);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001049
Elliott Hughes892a68b2015-10-19 14:43:53 -07001050 ND_PRINT((ndo, ": %s (0x%02x):",
1051 tok2str(ipcpopt_compproto_values, "Unknown", compproto),
1052 compproto));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001053
1054 switch (compproto) {
1055 case PPP_VJC:
1056 /* XXX: VJ-Comp parameters should be decoded */
1057 break;
1058 case IPCPOPT_IPCOMP_HDRCOMP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001059 if (len < IPCPOPT_IPCOMP_MINLEN) {
1060 ND_PRINT((ndo, " (length bogus, should be >= %u)",
1061 IPCPOPT_IPCOMP_MINLEN));
1062 return 0;
1063 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001064
Elliott Hughes892a68b2015-10-19 14:43:53 -07001065 ND_TCHECK2(*(p + 2), IPCPOPT_IPCOMP_MINLEN);
1066 ND_PRINT((ndo, "\n\t TCP Space %u, non-TCP Space %u" \
The Android Open Source Project2949f582009-03-03 19:30:46 -08001067 ", maxPeriod %u, maxTime %u, maxHdr %u",
1068 EXTRACT_16BITS(p+4),
1069 EXTRACT_16BITS(p+6),
1070 EXTRACT_16BITS(p+8),
1071 EXTRACT_16BITS(p+10),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001072 EXTRACT_16BITS(p+12)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001073
1074 /* suboptions present ? */
1075 if (len > IPCPOPT_IPCOMP_MINLEN) {
1076 ipcomp_subopttotallen = len - IPCPOPT_IPCOMP_MINLEN;
1077 p += IPCPOPT_IPCOMP_MINLEN;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001078
1079 ND_PRINT((ndo, "\n\t Suboptions, length %u", ipcomp_subopttotallen));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001080
1081 while (ipcomp_subopttotallen >= 2) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001082 ND_TCHECK2(*p, 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001083 ipcomp_subopt = *p;
1084 ipcomp_suboptlen = *(p+1);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001085
The Android Open Source Project2949f582009-03-03 19:30:46 -08001086 /* sanity check */
1087 if (ipcomp_subopt == 0 ||
1088 ipcomp_suboptlen == 0 )
1089 break;
1090
1091 /* XXX: just display the suboptions for now */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001092 ND_PRINT((ndo, "\n\t\t%s Suboption #%u, length %u",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001093 tok2str(ipcpopt_compproto_subopt_values,
1094 "Unknown",
1095 ipcomp_subopt),
1096 ipcomp_subopt,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001097 ipcomp_suboptlen));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001098
1099 ipcomp_subopttotallen -= ipcomp_suboptlen;
1100 p += ipcomp_suboptlen;
1101 }
1102 }
1103 break;
1104 default:
1105 break;
1106 }
1107 break;
1108
1109 case IPCPOPT_ADDR: /* those options share the same format - fall through */
1110 case IPCPOPT_MOBILE4:
1111 case IPCPOPT_PRIDNS:
1112 case IPCPOPT_PRINBNS:
1113 case IPCPOPT_SECDNS:
1114 case IPCPOPT_SECNBNS:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001115 if (len != 6) {
1116 ND_PRINT((ndo, " (length bogus, should be = 6)"));
1117 return 0;
1118 }
1119 ND_TCHECK2(*(p + 2), 4);
1120 ND_PRINT((ndo, ": %s", ipaddr_string(ndo, p + 2)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001121 break;
1122 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001123 /*
1124 * Unknown option; dump it as raw bytes now if we're
1125 * not going to do so below.
1126 */
1127 if (ndo->ndo_vflag < 2)
1128 print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001129 break;
1130 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001131 if (ndo->ndo_vflag > 1)
1132 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
The Android Open Source Project2949f582009-03-03 19:30:46 -08001133 return len;
1134
The Android Open Source Project2949f582009-03-03 19:30:46 -08001135trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001136 ND_PRINT((ndo, "[|ipcp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001137 return 0;
1138}
1139
1140/* IP6CP config options */
1141static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001142print_ip6cp_config_options(netdissect_options *ndo,
1143 const u_char *p, int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001144{
1145 int len, opt;
1146
1147 if (length < 2)
1148 return 0;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001149 ND_TCHECK2(*p, 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001150 len = p[1];
1151 opt = p[0];
1152 if (length < len)
1153 return 0;
1154 if (len < 2) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001155 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001156 tok2str(ip6cpopt_values,"unknown",opt),
1157 opt,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001158 len));
1159 return 0;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001160 }
1161
Elliott Hughes892a68b2015-10-19 14:43:53 -07001162 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001163 tok2str(ip6cpopt_values,"unknown",opt),
1164 opt,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001165 len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001166
1167 switch (opt) {
1168 case IP6CP_IFID:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001169 if (len != 10) {
1170 ND_PRINT((ndo, " (length bogus, should be = 10)"));
1171 return len;
1172 }
1173 ND_TCHECK2(*(p + 2), 8);
1174 ND_PRINT((ndo, ": %04x:%04x:%04x:%04x",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001175 EXTRACT_16BITS(p + 2),
1176 EXTRACT_16BITS(p + 4),
1177 EXTRACT_16BITS(p + 6),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001178 EXTRACT_16BITS(p + 8)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001179 break;
1180 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001181 /*
1182 * Unknown option; dump it as raw bytes now if we're
1183 * not going to do so below.
1184 */
1185 if (ndo->ndo_vflag < 2)
1186 print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001187 break;
1188 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001189 if (ndo->ndo_vflag > 1)
1190 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
The Android Open Source Project2949f582009-03-03 19:30:46 -08001191
1192 return len;
1193
The Android Open Source Project2949f582009-03-03 19:30:46 -08001194trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001195 ND_PRINT((ndo, "[|ip6cp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001196 return 0;
1197}
1198
1199
1200/* CCP config options */
1201static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001202print_ccp_config_options(netdissect_options *ndo,
1203 const u_char *p, int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001204{
1205 int len, opt;
1206
1207 if (length < 2)
1208 return 0;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001209 ND_TCHECK2(*p, 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001210 len = p[1];
1211 opt = p[0];
1212 if (length < len)
1213 return 0;
1214 if (len < 2) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001215 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1216 tok2str(ccpconfopts_values, "Unknown", opt),
1217 opt,
1218 len));
1219 return 0;
1220 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001221
Elliott Hughes892a68b2015-10-19 14:43:53 -07001222 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u",
1223 tok2str(ccpconfopts_values, "Unknown", opt),
1224 opt,
1225 len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001226
1227 switch (opt) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001228 case CCPOPT_BSDCOMP:
1229 if (len < 3) {
1230 ND_PRINT((ndo, " (length bogus, should be >= 3)"));
1231 return len;
1232 }
1233 ND_TCHECK2(*(p + 2), 1);
1234 ND_PRINT((ndo, ": Version: %u, Dictionary Bits: %u",
1235 p[2] >> 5, p[2] & 0x1f));
1236 break;
1237 case CCPOPT_MVRCA:
1238 if (len < 4) {
1239 ND_PRINT((ndo, " (length bogus, should be >= 4)"));
1240 return len;
1241 }
1242 ND_TCHECK2(*(p + 2), 1);
1243 ND_PRINT((ndo, ": Features: %u, PxP: %s, History: %u, #CTX-ID: %u",
1244 (p[2] & 0xc0) >> 6,
1245 (p[2] & 0x20) ? "Enabled" : "Disabled",
1246 p[2] & 0x1f, p[3]));
1247 break;
1248 case CCPOPT_DEFLATE:
1249 if (len < 4) {
1250 ND_PRINT((ndo, " (length bogus, should be >= 4)"));
1251 return len;
1252 }
1253 ND_TCHECK2(*(p + 2), 1);
1254 ND_PRINT((ndo, ": Window: %uK, Method: %s (0x%x), MBZ: %u, CHK: %u",
1255 (p[2] & 0xf0) >> 4,
1256 ((p[2] & 0x0f) == 8) ? "zlib" : "unkown",
1257 p[2] & 0x0f, (p[3] & 0xfc) >> 2, p[3] & 0x03));
1258 break;
1259
1260/* XXX: to be supported */
1261#if 0
The Android Open Source Project2949f582009-03-03 19:30:46 -08001262 case CCPOPT_OUI:
1263 case CCPOPT_PRED1:
1264 case CCPOPT_PRED2:
1265 case CCPOPT_PJUMP:
1266 case CCPOPT_HPPPC:
1267 case CCPOPT_STACLZS:
1268 case CCPOPT_MPPC:
1269 case CCPOPT_GFZA:
1270 case CCPOPT_V42BIS:
The Android Open Source Project2949f582009-03-03 19:30:46 -08001271 case CCPOPT_LZSDCP:
The Android Open Source Project2949f582009-03-03 19:30:46 -08001272 case CCPOPT_DEC:
The Android Open Source Project2949f582009-03-03 19:30:46 -08001273 case CCPOPT_RESV:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001274 break;
1275#endif
The Android Open Source Project2949f582009-03-03 19:30:46 -08001276 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001277 /*
1278 * Unknown option; dump it as raw bytes now if we're
1279 * not going to do so below.
1280 */
1281 if (ndo->ndo_vflag < 2)
1282 print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001283 break;
1284 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001285 if (ndo->ndo_vflag > 1)
1286 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
The Android Open Source Project2949f582009-03-03 19:30:46 -08001287
1288 return len;
1289
1290trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001291 ND_PRINT((ndo, "[|ccp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001292 return 0;
1293}
1294
1295/* BACP config options */
1296static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001297print_bacp_config_options(netdissect_options *ndo,
1298 const u_char *p, int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001299{
1300 int len, opt;
1301
1302 if (length < 2)
1303 return 0;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001304 ND_TCHECK2(*p, 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001305 len = p[1];
1306 opt = p[0];
1307 if (length < len)
1308 return 0;
1309 if (len < 2) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001310 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1311 tok2str(bacconfopts_values, "Unknown", opt),
1312 opt,
1313 len));
1314 return 0;
1315 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001316
Elliott Hughes892a68b2015-10-19 14:43:53 -07001317 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u",
1318 tok2str(bacconfopts_values, "Unknown", opt),
1319 opt,
1320 len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001321
1322 switch (opt) {
1323 case BACPOPT_FPEER:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001324 if (len != 6) {
1325 ND_PRINT((ndo, " (length bogus, should be = 6)"));
1326 return len;
1327 }
1328 ND_TCHECK2(*(p + 2), 4);
1329 ND_PRINT((ndo, ": Magic-Num 0x%08x", EXTRACT_32BITS(p + 2)));
1330 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001331 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001332 /*
1333 * Unknown option; dump it as raw bytes now if we're
1334 * not going to do so below.
1335 */
1336 if (ndo->ndo_vflag < 2)
1337 print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001338 break;
1339 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001340 if (ndo->ndo_vflag > 1)
1341 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
The Android Open Source Project2949f582009-03-03 19:30:46 -08001342
1343 return len;
1344
1345trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001346 ND_PRINT((ndo, "[|bacp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001347 return 0;
1348}
1349
The Android Open Source Project2949f582009-03-03 19:30:46 -08001350static void
Elliott Hughes892a68b2015-10-19 14:43:53 -07001351ppp_hdlc(netdissect_options *ndo,
1352 const u_char *p, int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001353{
Elliott Hughes892a68b2015-10-19 14:43:53 -07001354 u_char *b, *t, c;
1355 const u_char *s;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001356 int i, proto;
1357 const void *se;
1358
Elliott Hughes892a68b2015-10-19 14:43:53 -07001359 if (length <= 0)
1360 return;
1361
1362 b = (u_char *)malloc(length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001363 if (b == NULL)
1364 return;
1365
1366 /*
1367 * Unescape all the data into a temporary, private, buffer.
1368 * Do this so that we dont overwrite the original packet
1369 * contents.
1370 */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001371 for (s = p, t = b, i = length; i > 0 && ND_TTEST(*s); i--) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001372 c = *s++;
1373 if (c == 0x7d) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001374 if (i <= 1 || !ND_TTEST(*s))
1375 break;
1376 i--;
1377 c = *s++ ^ 0x20;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001378 }
1379 *t++ = c;
1380 }
1381
Elliott Hughes892a68b2015-10-19 14:43:53 -07001382 se = ndo->ndo_snapend;
1383 ndo->ndo_snapend = t;
1384 length = t - b;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001385
1386 /* now lets guess about the payload codepoint format */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001387 if (length < 1)
1388 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001389 proto = *b; /* start with a one-octet codepoint guess */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001390
The Android Open Source Project2949f582009-03-03 19:30:46 -08001391 switch (proto) {
1392 case PPP_IP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001393 ip_print(ndo, b + 1, length - 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001394 goto cleanup;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001395 case PPP_IPV6:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001396 ip6_print(ndo, b + 1, length - 1);
JP Abgrall53f17a92014-02-12 14:02:41 -08001397 goto cleanup;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001398 default: /* no luck - try next guess */
JP Abgrall53f17a92014-02-12 14:02:41 -08001399 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001400 }
1401
Elliott Hughes892a68b2015-10-19 14:43:53 -07001402 if (length < 2)
1403 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001404 proto = EXTRACT_16BITS(b); /* next guess - load two octets */
1405
1406 switch (proto) {
1407 case (PPP_ADDRESS << 8 | PPP_CONTROL): /* looks like a PPP frame */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001408 if (length < 4)
1409 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001410 proto = EXTRACT_16BITS(b+2); /* load the PPP proto-id */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001411 handle_ppp(ndo, proto, b + 4, length - 4);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001412 break;
1413 default: /* last guess - proto must be a PPP proto-id */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001414 handle_ppp(ndo, proto, b + 2, length - 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001415 break;
1416 }
1417
1418cleanup:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001419 ndo->ndo_snapend = se;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001420 free(b);
1421 return;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001422
1423trunc:
1424 ndo->ndo_snapend = se;
1425 free(b);
1426 ND_PRINT((ndo, "[|ppp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001427}
1428
1429
1430/* PPP */
1431static void
Elliott Hughes892a68b2015-10-19 14:43:53 -07001432handle_ppp(netdissect_options *ndo,
1433 u_int proto, const u_char *p, int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001434{
Elliott Hughes892a68b2015-10-19 14:43:53 -07001435 if ((proto & 0xff00) == 0x7e00) { /* is this an escape code ? */
1436 ppp_hdlc(ndo, p - 1, length);
1437 return;
1438 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001439
1440 switch (proto) {
1441 case PPP_LCP: /* fall through */
1442 case PPP_IPCP:
1443 case PPP_OSICP:
1444 case PPP_MPLSCP:
1445 case PPP_IPV6CP:
1446 case PPP_CCP:
1447 case PPP_BACP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001448 handle_ctrl_proto(ndo, proto, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001449 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001450 case PPP_ML:
1451 handle_mlppp(ndo, p, length);
1452 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001453 case PPP_CHAP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001454 handle_chap(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001455 break;
1456 case PPP_PAP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001457 handle_pap(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001458 break;
1459 case PPP_BAP: /* XXX: not yet completed */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001460 handle_bap(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001461 break;
1462 case ETHERTYPE_IP: /*XXX*/
1463 case PPP_VJNC:
1464 case PPP_IP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001465 ip_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001466 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001467 case ETHERTYPE_IPV6: /*XXX*/
1468 case PPP_IPV6:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001469 ip6_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001470 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001471 case ETHERTYPE_IPX: /*XXX*/
1472 case PPP_IPX:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001473 ipx_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001474 break;
1475 case PPP_OSI:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001476 isoclns_print(ndo, p, length, length);
1477 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001478 case PPP_MPLS_UCAST:
1479 case PPP_MPLS_MCAST:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001480 mpls_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001481 break;
1482 case PPP_COMP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001483 ND_PRINT((ndo, "compressed PPP data"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001484 break;
1485 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001486 ND_PRINT((ndo, "%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto)));
1487 print_unknown_data(ndo, p, "\n\t", length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001488 break;
1489 }
1490}
1491
1492/* Standard PPP printer */
1493u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001494ppp_print(netdissect_options *ndo,
1495 register const u_char *p, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001496{
1497 u_int proto,ppp_header;
1498 u_int olen = length; /* _o_riginal length */
1499 u_int hdr_len = 0;
1500
1501 /*
1502 * Here, we assume that p points to the Address and Control
1503 * field (if they present).
1504 */
1505 if (length < 2)
1506 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001507 ND_TCHECK2(*p, 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001508 ppp_header = EXTRACT_16BITS(p);
1509
1510 switch(ppp_header) {
1511 case (PPP_WITHDIRECTION_IN << 8 | PPP_CONTROL):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001512 if (ndo->ndo_eflag) ND_PRINT((ndo, "In "));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001513 p += 2;
1514 length -= 2;
1515 hdr_len += 2;
1516 break;
1517 case (PPP_WITHDIRECTION_OUT << 8 | PPP_CONTROL):
Elliott Hughes892a68b2015-10-19 14:43:53 -07001518 if (ndo->ndo_eflag) ND_PRINT((ndo, "Out "));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001519 p += 2;
1520 length -= 2;
1521 hdr_len += 2;
1522 break;
1523 case (PPP_ADDRESS << 8 | PPP_CONTROL):
1524 p += 2; /* ACFC not used */
1525 length -= 2;
1526 hdr_len += 2;
1527 break;
1528
1529 default:
1530 break;
1531 }
1532
1533 if (length < 2)
1534 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001535 ND_TCHECK(*p);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001536 if (*p % 2) {
1537 proto = *p; /* PFC is used */
1538 p++;
1539 length--;
1540 hdr_len++;
1541 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001542 ND_TCHECK2(*p, 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001543 proto = EXTRACT_16BITS(p);
1544 p += 2;
1545 length -= 2;
1546 hdr_len += 2;
1547 }
1548
Elliott Hughes892a68b2015-10-19 14:43:53 -07001549 if (ndo->ndo_eflag)
1550 ND_PRINT((ndo, "%s (0x%04x), length %u: ",
1551 tok2str(ppptype2str, "unknown", proto),
1552 proto,
1553 olen));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001554
Elliott Hughes892a68b2015-10-19 14:43:53 -07001555 handle_ppp(ndo, proto, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001556 return (hdr_len);
1557trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001558 ND_PRINT((ndo, "[|ppp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001559 return (0);
1560}
1561
1562
1563/* PPP I/F printer */
1564u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001565ppp_if_print(netdissect_options *ndo,
1566 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001567{
1568 register u_int length = h->len;
1569 register u_int caplen = h->caplen;
1570
1571 if (caplen < PPP_HDRLEN) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001572 ND_PRINT((ndo, "[|ppp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001573 return (caplen);
1574 }
1575
1576#if 0
1577 /*
1578 * XXX: seems to assume that there are 2 octets prepended to an
1579 * actual PPP frame. The 1st octet looks like Input/Output flag
1580 * while 2nd octet is unknown, at least to me
1581 * (mshindo@mshindo.net).
1582 *
1583 * That was what the original tcpdump code did.
1584 *
1585 * FreeBSD's "if_ppp.c" *does* set the first octet to 1 for outbound
1586 * packets and 0 for inbound packets - but only if the
1587 * protocol field has the 0x8000 bit set (i.e., it's a network
1588 * control protocol); it does so before running the packet through
1589 * "bpf_filter" to see if it should be discarded, and to see
1590 * if we should update the time we sent the most recent packet...
1591 *
1592 * ...but it puts the original address field back after doing
1593 * so.
1594 *
1595 * NetBSD's "if_ppp.c" doesn't set the first octet in that fashion.
1596 *
1597 * I don't know if any PPP implementation handed up to a BPF
1598 * device packets with the first octet being 1 for outbound and
1599 * 0 for inbound packets, so I (guy@alum.mit.edu) don't know
1600 * whether that ever needs to be checked or not.
1601 *
1602 * Note that NetBSD has a DLT_PPP_SERIAL, which it uses for PPP,
1603 * and its tcpdump appears to assume that the frame always
1604 * begins with an address field and a control field, and that
1605 * the address field might be 0x0f or 0x8f, for Cisco
1606 * point-to-point with HDLC framing as per section 4.3.1 of RFC
1607 * 1547, as well as 0xff, for PPP in HDLC-like framing as per
1608 * RFC 1662.
1609 *
1610 * (Is the Cisco framing in question what DLT_C_HDLC, in
1611 * BSD/OS, is?)
1612 */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001613 if (ndo->ndo_eflag)
1614 ND_PRINT((ndo, "%c %4d %02x ", p[0] ? 'O' : 'I', length, p[1]));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001615#endif
1616
Elliott Hughes892a68b2015-10-19 14:43:53 -07001617 ppp_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001618
1619 return (0);
1620}
1621
1622/*
1623 * PPP I/F printer to use if we know that RFC 1662-style PPP in HDLC-like
1624 * framing, or Cisco PPP with HDLC framing as per section 4.3.1 of RFC 1547,
1625 * is being used (i.e., we don't check for PPP_ADDRESS and PPP_CONTROL,
1626 * discard them *if* those are the first two octets, and parse the remaining
1627 * packet as a PPP packet, as "ppp_print()" does).
1628 *
1629 * This handles, for example, DLT_PPP_SERIAL in NetBSD.
1630 */
1631u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001632ppp_hdlc_if_print(netdissect_options *ndo,
1633 const struct pcap_pkthdr *h, register const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001634{
1635 register u_int length = h->len;
1636 register u_int caplen = h->caplen;
1637 u_int proto;
1638 u_int hdrlen = 0;
1639
1640 if (caplen < 2) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001641 ND_PRINT((ndo, "[|ppp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001642 return (caplen);
1643 }
1644
1645 switch (p[0]) {
1646
1647 case PPP_ADDRESS:
1648 if (caplen < 4) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001649 ND_PRINT((ndo, "[|ppp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001650 return (caplen);
1651 }
1652
Elliott Hughes892a68b2015-10-19 14:43:53 -07001653 if (ndo->ndo_eflag)
1654 ND_PRINT((ndo, "%02x %02x %d ", p[0], p[1], length));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001655 p += 2;
1656 length -= 2;
1657 hdrlen += 2;
1658
1659 proto = EXTRACT_16BITS(p);
1660 p += 2;
1661 length -= 2;
1662 hdrlen += 2;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001663 ND_PRINT((ndo, "%s: ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001664
Elliott Hughes892a68b2015-10-19 14:43:53 -07001665 handle_ppp(ndo, proto, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001666 break;
1667
1668 case CHDLC_UNICAST:
1669 case CHDLC_BCAST:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001670 return (chdlc_if_print(ndo, h, p));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001671
1672 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001673 if (ndo->ndo_eflag)
1674 ND_PRINT((ndo, "%02x %02x %d ", p[0], p[1], length));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001675 p += 2;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001676 hdrlen += 2;
1677
1678 /*
1679 * XXX - NetBSD's "ppp_netbsd_serial_if_print()" treats
1680 * the next two octets as an Ethernet type; does that
1681 * ever happen?
1682 */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001683 ND_PRINT((ndo, "unknown addr %02x; ctrl %02x", p[0], p[1]));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001684 break;
1685 }
1686
1687 return (hdrlen);
1688}
1689
1690#define PPP_BSDI_HDRLEN 24
1691
1692/* BSD/OS specific PPP printer */
1693u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001694ppp_bsdos_if_print(netdissect_options *ndo _U_,
1695 const struct pcap_pkthdr *h _U_, register const u_char *p _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001696{
1697 register int hdrlength;
1698#ifdef __bsdi__
1699 register u_int length = h->len;
1700 register u_int caplen = h->caplen;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001701 uint16_t ptype;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001702 const u_char *q;
1703 int i;
1704
1705 if (caplen < PPP_BSDI_HDRLEN) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001706 ND_PRINT((ndo, "[|ppp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001707 return (caplen)
1708 }
1709
1710 hdrlength = 0;
1711
1712#if 0
1713 if (p[0] == PPP_ADDRESS && p[1] == PPP_CONTROL) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001714 if (ndo->ndo_eflag)
1715 ND_PRINT((ndo, "%02x %02x ", p[0], p[1]));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001716 p += 2;
1717 hdrlength = 2;
1718 }
1719
Elliott Hughes892a68b2015-10-19 14:43:53 -07001720 if (ndo->ndo_eflag)
1721 ND_PRINT((ndo, "%d ", length));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001722 /* Retrieve the protocol type */
1723 if (*p & 01) {
1724 /* Compressed protocol field */
1725 ptype = *p;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001726 if (ndo->ndo_eflag)
1727 ND_PRINT((ndo, "%02x ", ptype));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001728 p++;
1729 hdrlength += 1;
1730 } else {
1731 /* Un-compressed protocol field */
JP Abgrall53f17a92014-02-12 14:02:41 -08001732 ptype = EXTRACT_16BITS(p);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001733 if (ndo->ndo_eflag)
1734 ND_PRINT((ndo, "%04x ", ptype));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001735 p += 2;
1736 hdrlength += 2;
1737 }
1738#else
1739 ptype = 0; /*XXX*/
Elliott Hughes892a68b2015-10-19 14:43:53 -07001740 if (ndo->ndo_eflag)
1741 ND_PRINT((ndo, "%c ", p[SLC_DIR] ? 'O' : 'I'));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001742 if (p[SLC_LLHL]) {
1743 /* link level header */
1744 struct ppp_header *ph;
1745
1746 q = p + SLC_BPFHDRLEN;
1747 ph = (struct ppp_header *)q;
1748 if (ph->phdr_addr == PPP_ADDRESS
1749 && ph->phdr_ctl == PPP_CONTROL) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001750 if (ndo->ndo_eflag)
1751 ND_PRINT((ndo, "%02x %02x ", q[0], q[1]));
JP Abgrall53f17a92014-02-12 14:02:41 -08001752 ptype = EXTRACT_16BITS(&ph->phdr_type);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001753 if (ndo->ndo_eflag && (ptype == PPP_VJC || ptype == PPP_VJNC)) {
1754 ND_PRINT((ndo, "%s ", tok2str(ppptype2str,
1755 "proto-#%d", ptype)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001756 }
1757 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001758 if (ndo->ndo_eflag) {
1759 ND_PRINT((ndo, "LLH=["));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001760 for (i = 0; i < p[SLC_LLHL]; i++)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001761 ND_PRINT((ndo, "%02x", q[i]));
1762 ND_PRINT((ndo, "] "));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001763 }
1764 }
1765 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001766 if (ndo->ndo_eflag)
1767 ND_PRINT((ndo, "%d ", length));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001768 if (p[SLC_CHL]) {
1769 q = p + SLC_BPFHDRLEN + p[SLC_LLHL];
1770
1771 switch (ptype) {
1772 case PPP_VJC:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001773 ptype = vjc_print(ndo, q, ptype);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001774 hdrlength = PPP_BSDI_HDRLEN;
1775 p += hdrlength;
1776 switch (ptype) {
1777 case PPP_IP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001778 ip_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001779 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001780 case PPP_IPV6:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001781 ip6_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001782 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001783 case PPP_MPLS_UCAST:
1784 case PPP_MPLS_MCAST:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001785 mpls_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001786 break;
1787 }
1788 goto printx;
1789 case PPP_VJNC:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001790 ptype = vjc_print(ndo, q, ptype);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001791 hdrlength = PPP_BSDI_HDRLEN;
1792 p += hdrlength;
1793 switch (ptype) {
1794 case PPP_IP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001795 ip_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001796 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001797 case PPP_IPV6:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001798 ip6_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001799 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001800 case PPP_MPLS_UCAST:
1801 case PPP_MPLS_MCAST:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001802 mpls_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001803 break;
1804 }
1805 goto printx;
1806 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001807 if (ndo->ndo_eflag) {
1808 ND_PRINT((ndo, "CH=["));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001809 for (i = 0; i < p[SLC_LLHL]; i++)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001810 ND_PRINT((ndo, "%02x", q[i]));
1811 ND_PRINT((ndo, "] "));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001812 }
1813 break;
1814 }
1815 }
1816
1817 hdrlength = PPP_BSDI_HDRLEN;
1818#endif
1819
1820 length -= hdrlength;
1821 p += hdrlength;
1822
1823 switch (ptype) {
1824 case PPP_IP:
1825 ip_print(p, length);
1826 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001827 case PPP_IPV6:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001828 ip6_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001829 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001830 case PPP_MPLS_UCAST:
1831 case PPP_MPLS_MCAST:
1832 mpls_print(ndo, p, length);
1833 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001834 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001835 ND_PRINT((ndo, "%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", ptype)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001836 }
1837
1838printx:
1839#else /* __bsdi */
1840 hdrlength = 0;
1841#endif /* __bsdi__ */
1842 return (hdrlength);
1843}
1844
1845
1846/*
1847 * Local Variables:
1848 * c-style: whitesmith
1849 * c-basic-offset: 8
1850 * End:
1851 */