]> The Tcpdump Group git mirrors - tcpdump/blob - print-ppp.c
b6723f8544783c3801039fc164a41d22e1948aa7
[tcpdump] / print-ppp.c
1 /*
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 /* \summary: Point to Point Protocol (PPP) printer */
26
27 /*
28 * TODO:
29 * o resolve XXX as much as possible
30 * o MP support
31 * o BAP support
32 */
33
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
37
38 #include <netdissect-stdinc.h>
39
40 #ifdef __bsdi__
41 #include <net/slcompress.h>
42 #include <net/if_ppp.h>
43 #endif
44
45 #include <stdlib.h>
46
47 #include "netdissect.h"
48 #include "extract.h"
49 #include "addrtoname.h"
50 #include "ppp.h"
51 #include "chdlc.h"
52 #include "ethertype.h"
53 #include "oui.h"
54
55 /*
56 * The following constatns are defined by IANA. Please refer to
57 * http://www.isi.edu/in-notes/iana/assignments/ppp-numbers
58 * for the up-to-date information.
59 */
60
61 /* Protocol Codes defined in ppp.h */
62
63 static const struct tok ppptype2str[] = {
64 { PPP_IP, "IP" },
65 { PPP_OSI, "OSI" },
66 { PPP_NS, "NS" },
67 { PPP_DECNET, "DECNET" },
68 { PPP_APPLE, "APPLE" },
69 { PPP_IPX, "IPX" },
70 { PPP_VJC, "VJC IP" },
71 { PPP_VJNC, "VJNC IP" },
72 { PPP_BRPDU, "BRPDU" },
73 { PPP_STII, "STII" },
74 { PPP_VINES, "VINES" },
75 { PPP_MPLS_UCAST, "MPLS" },
76 { PPP_MPLS_MCAST, "MPLS" },
77 { PPP_COMP, "Compressed"},
78 { PPP_ML, "MLPPP"},
79 { PPP_IPV6, "IP6"},
80
81 { PPP_HELLO, "HELLO" },
82 { PPP_LUXCOM, "LUXCOM" },
83 { PPP_SNS, "SNS" },
84 { PPP_IPCP, "IPCP" },
85 { PPP_OSICP, "OSICP" },
86 { PPP_NSCP, "NSCP" },
87 { PPP_DECNETCP, "DECNETCP" },
88 { PPP_APPLECP, "APPLECP" },
89 { PPP_IPXCP, "IPXCP" },
90 { PPP_STIICP, "STIICP" },
91 { PPP_VINESCP, "VINESCP" },
92 { PPP_IPV6CP, "IP6CP" },
93 { PPP_MPLSCP, "MPLSCP" },
94
95 { PPP_LCP, "LCP" },
96 { PPP_PAP, "PAP" },
97 { PPP_LQM, "LQM" },
98 { PPP_CHAP, "CHAP" },
99 { PPP_EAP, "EAP" },
100 { PPP_SPAP, "SPAP" },
101 { PPP_SPAP_OLD, "Old-SPAP" },
102 { PPP_BACP, "BACP" },
103 { PPP_BAP, "BAP" },
104 { PPP_MPCP, "MLPPP-CP" },
105 { PPP_CCP, "CCP" },
106 { 0, NULL }
107 };
108
109 /* Control Protocols (LCP/IPCP/CCP etc.) Codes defined in RFC 1661 */
110
111 #define CPCODES_VEXT 0 /* Vendor-Specific (RFC2153) */
112 #define CPCODES_CONF_REQ 1 /* Configure-Request */
113 #define CPCODES_CONF_ACK 2 /* Configure-Ack */
114 #define CPCODES_CONF_NAK 3 /* Configure-Nak */
115 #define CPCODES_CONF_REJ 4 /* Configure-Reject */
116 #define CPCODES_TERM_REQ 5 /* Terminate-Request */
117 #define CPCODES_TERM_ACK 6 /* Terminate-Ack */
118 #define CPCODES_CODE_REJ 7 /* Code-Reject */
119 #define CPCODES_PROT_REJ 8 /* Protocol-Reject (LCP only) */
120 #define CPCODES_ECHO_REQ 9 /* Echo-Request (LCP only) */
121 #define CPCODES_ECHO_RPL 10 /* Echo-Reply (LCP only) */
122 #define CPCODES_DISC_REQ 11 /* Discard-Request (LCP only) */
123 #define CPCODES_ID 12 /* Identification (LCP only) RFC1570 */
124 #define CPCODES_TIME_REM 13 /* Time-Remaining (LCP only) RFC1570 */
125 #define CPCODES_RESET_REQ 14 /* Reset-Request (CCP only) RFC1962 */
126 #define CPCODES_RESET_REP 15 /* Reset-Reply (CCP only) */
127
128 static const struct tok cpcodes[] = {
129 {CPCODES_VEXT, "Vendor-Extension"}, /* RFC2153 */
130 {CPCODES_CONF_REQ, "Conf-Request"},
131 {CPCODES_CONF_ACK, "Conf-Ack"},
132 {CPCODES_CONF_NAK, "Conf-Nack"},
133 {CPCODES_CONF_REJ, "Conf-Reject"},
134 {CPCODES_TERM_REQ, "Term-Request"},
135 {CPCODES_TERM_ACK, "Term-Ack"},
136 {CPCODES_CODE_REJ, "Code-Reject"},
137 {CPCODES_PROT_REJ, "Prot-Reject"},
138 {CPCODES_ECHO_REQ, "Echo-Request"},
139 {CPCODES_ECHO_RPL, "Echo-Reply"},
140 {CPCODES_DISC_REQ, "Disc-Req"},
141 {CPCODES_ID, "Ident"}, /* RFC1570 */
142 {CPCODES_TIME_REM, "Time-Rem"}, /* RFC1570 */
143 {CPCODES_RESET_REQ, "Reset-Req"}, /* RFC1962 */
144 {CPCODES_RESET_REP, "Reset-Ack"}, /* RFC1962 */
145 {0, NULL}
146 };
147
148 /* LCP Config Options */
149
150 #define LCPOPT_VEXT 0
151 #define LCPOPT_MRU 1
152 #define LCPOPT_ACCM 2
153 #define LCPOPT_AP 3
154 #define LCPOPT_QP 4
155 #define LCPOPT_MN 5
156 #define LCPOPT_DEP6 6
157 #define LCPOPT_PFC 7
158 #define LCPOPT_ACFC 8
159 #define LCPOPT_FCSALT 9
160 #define LCPOPT_SDP 10
161 #define LCPOPT_NUMMODE 11
162 #define LCPOPT_DEP12 12
163 #define LCPOPT_CBACK 13
164 #define LCPOPT_DEP14 14
165 #define LCPOPT_DEP15 15
166 #define LCPOPT_DEP16 16
167 #define LCPOPT_MLMRRU 17
168 #define LCPOPT_MLSSNHF 18
169 #define LCPOPT_MLED 19
170 #define LCPOPT_PROP 20
171 #define LCPOPT_DCEID 21
172 #define LCPOPT_MPP 22
173 #define LCPOPT_LD 23
174 #define LCPOPT_LCPAOPT 24
175 #define LCPOPT_COBS 25
176 #define LCPOPT_PE 26
177 #define LCPOPT_MLHF 27
178 #define LCPOPT_I18N 28
179 #define LCPOPT_SDLOS 29
180 #define LCPOPT_PPPMUX 30
181
182 #define LCPOPT_MIN LCPOPT_VEXT
183 #define LCPOPT_MAX LCPOPT_PPPMUX
184
185 static const char *lcpconfopts[] = {
186 "Vend-Ext", /* (0) */
187 "MRU", /* (1) */
188 "ACCM", /* (2) */
189 "Auth-Prot", /* (3) */
190 "Qual-Prot", /* (4) */
191 "Magic-Num", /* (5) */
192 "deprecated(6)", /* used to be a Quality Protocol */
193 "PFC", /* (7) */
194 "ACFC", /* (8) */
195 "FCS-Alt", /* (9) */
196 "SDP", /* (10) */
197 "Num-Mode", /* (11) */
198 "deprecated(12)", /* used to be a Multi-Link-Procedure*/
199 "Call-Back", /* (13) */
200 "deprecated(14)", /* used to be a Connect-Time */
201 "deprecated(15)", /* used to be a Compund-Frames */
202 "deprecated(16)", /* used to be a Nominal-Data-Encap */
203 "MRRU", /* (17) */
204 "12-Bit seq #", /* (18) */
205 "End-Disc", /* (19) */
206 "Proprietary", /* (20) */
207 "DCE-Id", /* (21) */
208 "MP+", /* (22) */
209 "Link-Disc", /* (23) */
210 "LCP-Auth-Opt", /* (24) */
211 "COBS", /* (25) */
212 "Prefix-elision", /* (26) */
213 "Multilink-header-Form",/* (27) */
214 "I18N", /* (28) */
215 "SDL-over-SONET/SDH", /* (29) */
216 "PPP-Muxing", /* (30) */
217 };
218
219 /* ECP - to be supported */
220
221 /* CCP Config Options */
222
223 #define CCPOPT_OUI 0 /* RFC1962 */
224 #define CCPOPT_PRED1 1 /* RFC1962 */
225 #define CCPOPT_PRED2 2 /* RFC1962 */
226 #define CCPOPT_PJUMP 3 /* RFC1962 */
227 /* 4-15 unassigned */
228 #define CCPOPT_HPPPC 16 /* RFC1962 */
229 #define CCPOPT_STACLZS 17 /* RFC1974 */
230 #define CCPOPT_MPPC 18 /* RFC2118 */
231 #define CCPOPT_GFZA 19 /* RFC1962 */
232 #define CCPOPT_V42BIS 20 /* RFC1962 */
233 #define CCPOPT_BSDCOMP 21 /* RFC1977 */
234 /* 22 unassigned */
235 #define CCPOPT_LZSDCP 23 /* RFC1967 */
236 #define CCPOPT_MVRCA 24 /* RFC1975 */
237 #define CCPOPT_DEC 25 /* RFC1976 */
238 #define CCPOPT_DEFLATE 26 /* RFC1979 */
239 /* 27-254 unassigned */
240 #define CCPOPT_RESV 255 /* RFC1962 */
241
242 static const struct tok ccpconfopts_values[] = {
243 { CCPOPT_OUI, "OUI" },
244 { CCPOPT_PRED1, "Pred-1" },
245 { CCPOPT_PRED2, "Pred-2" },
246 { CCPOPT_PJUMP, "Puddle" },
247 { CCPOPT_HPPPC, "HP-PPC" },
248 { CCPOPT_STACLZS, "Stac-LZS" },
249 { CCPOPT_MPPC, "MPPC" },
250 { CCPOPT_GFZA, "Gand-FZA" },
251 { CCPOPT_V42BIS, "V.42bis" },
252 { CCPOPT_BSDCOMP, "BSD-Comp" },
253 { CCPOPT_LZSDCP, "LZS-DCP" },
254 { CCPOPT_MVRCA, "MVRCA" },
255 { CCPOPT_DEC, "DEC" },
256 { CCPOPT_DEFLATE, "Deflate" },
257 { CCPOPT_RESV, "Reserved"},
258 {0, NULL}
259 };
260
261 /* BACP Config Options */
262
263 #define BACPOPT_FPEER 1 /* RFC2125 */
264
265 static const struct tok bacconfopts_values[] = {
266 { BACPOPT_FPEER, "Favored-Peer" },
267 {0, NULL}
268 };
269
270
271 /* SDCP - to be supported */
272
273 /* IPCP Config Options */
274 #define IPCPOPT_2ADDR 1 /* RFC1172, RFC1332 (deprecated) */
275 #define IPCPOPT_IPCOMP 2 /* RFC1332 */
276 #define IPCPOPT_ADDR 3 /* RFC1332 */
277 #define IPCPOPT_MOBILE4 4 /* RFC2290 */
278 #define IPCPOPT_PRIDNS 129 /* RFC1877 */
279 #define IPCPOPT_PRINBNS 130 /* RFC1877 */
280 #define IPCPOPT_SECDNS 131 /* RFC1877 */
281 #define IPCPOPT_SECNBNS 132 /* RFC1877 */
282
283 static const struct tok ipcpopt_values[] = {
284 { IPCPOPT_2ADDR, "IP-Addrs" },
285 { IPCPOPT_IPCOMP, "IP-Comp" },
286 { IPCPOPT_ADDR, "IP-Addr" },
287 { IPCPOPT_MOBILE4, "Home-Addr" },
288 { IPCPOPT_PRIDNS, "Pri-DNS" },
289 { IPCPOPT_PRINBNS, "Pri-NBNS" },
290 { IPCPOPT_SECDNS, "Sec-DNS" },
291 { IPCPOPT_SECNBNS, "Sec-NBNS" },
292 { 0, NULL }
293 };
294
295 #define IPCPOPT_IPCOMP_HDRCOMP 0x61 /* rfc3544 */
296 #define IPCPOPT_IPCOMP_MINLEN 14
297
298 static const struct tok ipcpopt_compproto_values[] = {
299 { PPP_VJC, "VJ-Comp" },
300 { IPCPOPT_IPCOMP_HDRCOMP, "IP Header Compression" },
301 { 0, NULL }
302 };
303
304 static const struct tok ipcpopt_compproto_subopt_values[] = {
305 { 1, "RTP-Compression" },
306 { 2, "Enhanced RTP-Compression" },
307 { 0, NULL }
308 };
309
310 /* IP6CP Config Options */
311 #define IP6CP_IFID 1
312
313 static const struct tok ip6cpopt_values[] = {
314 { IP6CP_IFID, "Interface-ID" },
315 { 0, NULL }
316 };
317
318 /* ATCP - to be supported */
319 /* OSINLCP - to be supported */
320 /* BVCP - to be supported */
321 /* BCP - to be supported */
322 /* IPXCP - to be supported */
323 /* MPLSCP - to be supported */
324
325 /* Auth Algorithms */
326
327 /* 0-4 Reserved (RFC1994) */
328 #define AUTHALG_CHAPMD5 5 /* RFC1994 */
329 #define AUTHALG_MSCHAP1 128 /* RFC2433 */
330 #define AUTHALG_MSCHAP2 129 /* RFC2795 */
331
332 static const struct tok authalg_values[] = {
333 { AUTHALG_CHAPMD5, "MD5" },
334 { AUTHALG_MSCHAP1, "MS-CHAPv1" },
335 { AUTHALG_MSCHAP2, "MS-CHAPv2" },
336 { 0, NULL }
337 };
338
339 /* FCS Alternatives - to be supported */
340
341 /* Multilink Endpoint Discriminator (RFC1717) */
342 #define MEDCLASS_NULL 0 /* Null Class */
343 #define MEDCLASS_LOCAL 1 /* Locally Assigned */
344 #define MEDCLASS_IPV4 2 /* Internet Protocol (IPv4) */
345 #define MEDCLASS_MAC 3 /* IEEE 802.1 global MAC address */
346 #define MEDCLASS_MNB 4 /* PPP Magic Number Block */
347 #define MEDCLASS_PSNDN 5 /* Public Switched Network Director Number */
348
349 /* PPP LCP Callback */
350 #define CALLBACK_AUTH 0 /* Location determined by user auth */
351 #define CALLBACK_DSTR 1 /* Dialing string */
352 #define CALLBACK_LID 2 /* Location identifier */
353 #define CALLBACK_E164 3 /* E.164 number */
354 #define CALLBACK_X500 4 /* X.500 distinguished name */
355 #define CALLBACK_CBCP 6 /* Location is determined during CBCP nego */
356
357 static const struct tok ppp_callback_values[] = {
358 { CALLBACK_AUTH, "UserAuth" },
359 { CALLBACK_DSTR, "DialString" },
360 { CALLBACK_LID, "LocalID" },
361 { CALLBACK_E164, "E.164" },
362 { CALLBACK_X500, "X.500" },
363 { CALLBACK_CBCP, "CBCP" },
364 { 0, NULL }
365 };
366
367 /* CHAP */
368
369 #define CHAP_CHAL 1
370 #define CHAP_RESP 2
371 #define CHAP_SUCC 3
372 #define CHAP_FAIL 4
373
374 static const struct tok chapcode_values[] = {
375 { CHAP_CHAL, "Challenge" },
376 { CHAP_RESP, "Response" },
377 { CHAP_SUCC, "Success" },
378 { CHAP_FAIL, "Fail" },
379 { 0, NULL}
380 };
381
382 /* PAP */
383
384 #define PAP_AREQ 1
385 #define PAP_AACK 2
386 #define PAP_ANAK 3
387
388 static const struct tok papcode_values[] = {
389 { PAP_AREQ, "Auth-Req" },
390 { PAP_AACK, "Auth-ACK" },
391 { PAP_ANAK, "Auth-NACK" },
392 { 0, NULL }
393 };
394
395 /* BAP */
396 #define BAP_CALLREQ 1
397 #define BAP_CALLRES 2
398 #define BAP_CBREQ 3
399 #define BAP_CBRES 4
400 #define BAP_LDQREQ 5
401 #define BAP_LDQRES 6
402 #define BAP_CSIND 7
403 #define BAP_CSRES 8
404
405 static int print_lcp_config_options(netdissect_options *, const u_char *p, int);
406 static int print_ipcp_config_options(netdissect_options *, const u_char *p, int);
407 static int print_ip6cp_config_options(netdissect_options *, const u_char *p, int);
408 static int print_ccp_config_options(netdissect_options *, const u_char *p, int);
409 static int print_bacp_config_options(netdissect_options *, const u_char *p, int);
410 static void handle_ppp(netdissect_options *, u_int proto, const u_char *p, int length);
411
412 /* generic Control Protocol (e.g. LCP, IPCP, CCP, etc.) handler */
413 static void
414 handle_ctrl_proto(netdissect_options *ndo,
415 u_int proto, const u_char *pptr, int length)
416 {
417 const char *typestr;
418 u_int code, len;
419 int (*pfunc)(netdissect_options *, const u_char *, int);
420 int x, j;
421 const u_char *tptr;
422
423 tptr=pptr;
424
425 typestr = tok2str(ppptype2str, "unknown ctrl-proto (0x%04x)", proto);
426 ND_PRINT((ndo, "%s, ", typestr));
427
428 if (length < 4) /* FIXME weak boundary checking */
429 goto trunc;
430 ND_TCHECK2(*tptr, 2);
431
432 code = *tptr++;
433
434 ND_PRINT((ndo, "%s (0x%02x), id %u, length %u",
435 tok2str(cpcodes, "Unknown Opcode",code),
436 code,
437 EXTRACT_8BITS(tptr), /* ID */
438 length + 2));
439 tptr++;
440
441 if (!ndo->ndo_vflag)
442 return;
443
444 if (length <= 4)
445 return; /* there may be a NULL confreq etc. */
446
447 ND_TCHECK2(*tptr, 2);
448 len = EXTRACT_BE_16BITS(tptr);
449 tptr += 2;
450
451 ND_PRINT((ndo, "\n\tencoded length %u (=Option(s) length %u)", len, len - 4));
452
453 if (ndo->ndo_vflag > 1)
454 print_unknown_data(ndo, pptr - 2, "\n\t", 6);
455
456
457 switch (code) {
458 case CPCODES_VEXT:
459 if (length < 11)
460 break;
461 ND_TCHECK2(*tptr, 4);
462 ND_PRINT((ndo, "\n\t Magic-Num 0x%08x", EXTRACT_BE_32BITS(tptr)));
463 tptr += 4;
464 ND_TCHECK2(*tptr, 3);
465 ND_PRINT((ndo, " Vendor: %s (%u)",
466 tok2str(oui_values,"Unknown",EXTRACT_BE_24BITS(tptr)),
467 EXTRACT_BE_24BITS(tptr)));
468 /* XXX: need to decode Kind and Value(s)? */
469 break;
470 case CPCODES_CONF_REQ:
471 case CPCODES_CONF_ACK:
472 case CPCODES_CONF_NAK:
473 case CPCODES_CONF_REJ:
474 x = len - 4; /* Code(1), Identifier(1) and Length(2) */
475 do {
476 switch (proto) {
477 case PPP_LCP:
478 pfunc = print_lcp_config_options;
479 break;
480 case PPP_IPCP:
481 pfunc = print_ipcp_config_options;
482 break;
483 case PPP_IPV6CP:
484 pfunc = print_ip6cp_config_options;
485 break;
486 case PPP_CCP:
487 pfunc = print_ccp_config_options;
488 break;
489 case PPP_BACP:
490 pfunc = print_bacp_config_options;
491 break;
492 default:
493 /*
494 * No print routine for the options for
495 * this protocol.
496 */
497 pfunc = NULL;
498 break;
499 }
500
501 if (pfunc == NULL) /* catch the above null pointer if unknown CP */
502 break;
503
504 if ((j = (*pfunc)(ndo, tptr, len)) == 0)
505 break;
506 x -= j;
507 tptr += j;
508 } while (x > 0);
509 break;
510
511 case CPCODES_TERM_REQ:
512 case CPCODES_TERM_ACK:
513 /* XXX: need to decode Data? */
514 break;
515 case CPCODES_CODE_REJ:
516 /* XXX: need to decode Rejected-Packet? */
517 break;
518 case CPCODES_PROT_REJ:
519 if (length < 6)
520 break;
521 ND_TCHECK2(*tptr, 2);
522 ND_PRINT((ndo, "\n\t Rejected %s Protocol (0x%04x)",
523 tok2str(ppptype2str,"unknown", EXTRACT_BE_16BITS(tptr)),
524 EXTRACT_BE_16BITS(tptr)));
525 /* XXX: need to decode Rejected-Information? - hexdump for now */
526 if (len > 6) {
527 ND_PRINT((ndo, "\n\t Rejected Packet"));
528 print_unknown_data(ndo, tptr + 2, "\n\t ", len - 2);
529 }
530 break;
531 case CPCODES_ECHO_REQ:
532 case CPCODES_ECHO_RPL:
533 case CPCODES_DISC_REQ:
534 if (length < 8)
535 break;
536 ND_TCHECK2(*tptr, 4);
537 ND_PRINT((ndo, "\n\t Magic-Num 0x%08x", EXTRACT_BE_32BITS(tptr)));
538 /* XXX: need to decode Data? - hexdump for now */
539 if (len > 8) {
540 ND_PRINT((ndo, "\n\t -----trailing data-----"));
541 ND_TCHECK2(tptr[4], len - 8);
542 print_unknown_data(ndo, tptr + 4, "\n\t ", len - 8);
543 }
544 break;
545 case CPCODES_ID:
546 if (length < 8)
547 break;
548 ND_TCHECK2(*tptr, 4);
549 ND_PRINT((ndo, "\n\t Magic-Num 0x%08x", EXTRACT_BE_32BITS(tptr)));
550 /* RFC 1661 says this is intended to be human readable */
551 if (len > 8) {
552 ND_PRINT((ndo, "\n\t Message\n\t "));
553 if (fn_printn(ndo, tptr + 4, len - 4, ndo->ndo_snapend))
554 goto trunc;
555 }
556 break;
557 case CPCODES_TIME_REM:
558 if (length < 12)
559 break;
560 ND_TCHECK2(*tptr, 4);
561 ND_PRINT((ndo, "\n\t Magic-Num 0x%08x", EXTRACT_BE_32BITS(tptr)));
562 ND_TCHECK2(*(tptr + 4), 4);
563 ND_PRINT((ndo, ", Seconds-Remaining %us", EXTRACT_BE_32BITS(tptr + 4)));
564 /* XXX: need to decode Message? */
565 break;
566 default:
567 /* XXX this is dirty but we do not get the
568 * original pointer passed to the begin
569 * the PPP packet */
570 if (ndo->ndo_vflag <= 1)
571 print_unknown_data(ndo, pptr - 2, "\n\t ", length + 2);
572 break;
573 }
574 return;
575
576 trunc:
577 ND_PRINT((ndo, "[|%s]", typestr));
578 }
579
580 /* LCP config options */
581 static int
582 print_lcp_config_options(netdissect_options *ndo,
583 const u_char *p, int length)
584 {
585 int len, opt;
586
587 if (length < 2)
588 return 0;
589 ND_TCHECK2(*p, 2);
590 len = p[1];
591 opt = p[0];
592 if (length < len)
593 return 0;
594 if (len < 2) {
595 if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX))
596 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
597 lcpconfopts[opt], opt, len));
598 else
599 ND_PRINT((ndo, "\n\tunknown LCP option 0x%02x", opt));
600 return 0;
601 }
602 if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX))
603 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u", lcpconfopts[opt], opt, len));
604 else {
605 ND_PRINT((ndo, "\n\tunknown LCP option 0x%02x", opt));
606 return len;
607 }
608
609 switch (opt) {
610 case LCPOPT_VEXT:
611 if (len < 6) {
612 ND_PRINT((ndo, " (length bogus, should be >= 6)"));
613 return len;
614 }
615 ND_TCHECK_24BITS(p + 2);
616 ND_PRINT((ndo, ": Vendor: %s (%u)",
617 tok2str(oui_values,"Unknown",EXTRACT_BE_24BITS(p + 2)),
618 EXTRACT_BE_24BITS(p + 2)));
619 #if 0
620 ND_TCHECK(p[5]);
621 ND_PRINT((ndo, ", kind: 0x%02x", p[5]));
622 ND_PRINT((ndo, ", Value: 0x"));
623 for (i = 0; i < len - 6; i++) {
624 ND_TCHECK(p[6 + i]);
625 ND_PRINT((ndo, "%02x", p[6 + i]));
626 }
627 #endif
628 break;
629 case LCPOPT_MRU:
630 if (len != 4) {
631 ND_PRINT((ndo, " (length bogus, should be = 4)"));
632 return len;
633 }
634 ND_TCHECK_16BITS(p + 2);
635 ND_PRINT((ndo, ": %u", EXTRACT_BE_16BITS(p + 2)));
636 break;
637 case LCPOPT_ACCM:
638 if (len != 6) {
639 ND_PRINT((ndo, " (length bogus, should be = 6)"));
640 return len;
641 }
642 ND_TCHECK_32BITS(p + 2);
643 ND_PRINT((ndo, ": 0x%08x", EXTRACT_BE_32BITS(p + 2)));
644 break;
645 case LCPOPT_AP:
646 if (len < 4) {
647 ND_PRINT((ndo, " (length bogus, should be >= 4)"));
648 return len;
649 }
650 ND_TCHECK_16BITS(p + 2);
651 ND_PRINT((ndo, ": %s", tok2str(ppptype2str, "Unknown Auth Proto (0x04x)", EXTRACT_BE_16BITS(p + 2))));
652
653 switch (EXTRACT_BE_16BITS(p + 2)) {
654 case PPP_CHAP:
655 ND_TCHECK(p[4]);
656 ND_PRINT((ndo, ", %s", tok2str(authalg_values, "Unknown Auth Alg %u", p[4])));
657 break;
658 case PPP_PAP: /* fall through */
659 case PPP_EAP:
660 case PPP_SPAP:
661 case PPP_SPAP_OLD:
662 break;
663 default:
664 print_unknown_data(ndo, p, "\n\t", len);
665 }
666 break;
667 case LCPOPT_QP:
668 if (len < 4) {
669 ND_PRINT((ndo, " (length bogus, should be >= 4)"));
670 return 0;
671 }
672 ND_TCHECK_16BITS(p+2);
673 if (EXTRACT_BE_16BITS(p + 2) == PPP_LQM)
674 ND_PRINT((ndo, ": LQR"));
675 else
676 ND_PRINT((ndo, ": unknown"));
677 break;
678 case LCPOPT_MN:
679 if (len != 6) {
680 ND_PRINT((ndo, " (length bogus, should be = 6)"));
681 return 0;
682 }
683 ND_TCHECK_32BITS(p + 2);
684 ND_PRINT((ndo, ": 0x%08x", EXTRACT_BE_32BITS(p + 2)));
685 break;
686 case LCPOPT_PFC:
687 break;
688 case LCPOPT_ACFC:
689 break;
690 case LCPOPT_LD:
691 if (len != 4) {
692 ND_PRINT((ndo, " (length bogus, should be = 4)"));
693 return 0;
694 }
695 ND_TCHECK_16BITS(p + 2);
696 ND_PRINT((ndo, ": 0x%04x", EXTRACT_BE_16BITS(p + 2)));
697 break;
698 case LCPOPT_CBACK:
699 if (len < 3) {
700 ND_PRINT((ndo, " (length bogus, should be >= 3)"));
701 return 0;
702 }
703 ND_PRINT((ndo, ": "));
704 ND_TCHECK(p[2]);
705 ND_PRINT((ndo, ": Callback Operation %s (%u)",
706 tok2str(ppp_callback_values, "Unknown", p[2]),
707 p[2]));
708 break;
709 case LCPOPT_MLMRRU:
710 if (len != 4) {
711 ND_PRINT((ndo, " (length bogus, should be = 4)"));
712 return 0;
713 }
714 ND_TCHECK_16BITS(p + 2);
715 ND_PRINT((ndo, ": %u", EXTRACT_BE_16BITS(p + 2)));
716 break;
717 case LCPOPT_MLED:
718 if (len < 3) {
719 ND_PRINT((ndo, " (length bogus, should be >= 3)"));
720 return 0;
721 }
722 ND_TCHECK(p[2]);
723 switch (p[2]) { /* class */
724 case MEDCLASS_NULL:
725 ND_PRINT((ndo, ": Null"));
726 break;
727 case MEDCLASS_LOCAL:
728 ND_PRINT((ndo, ": Local")); /* XXX */
729 break;
730 case MEDCLASS_IPV4:
731 if (len != 7) {
732 ND_PRINT((ndo, " (length bogus, should be = 7)"));
733 return 0;
734 }
735 ND_TCHECK2(*(p + 3), 4);
736 ND_PRINT((ndo, ": IPv4 %s", ipaddr_string(ndo, p + 3)));
737 break;
738 case MEDCLASS_MAC:
739 if (len != 9) {
740 ND_PRINT((ndo, " (length bogus, should be = 9)"));
741 return 0;
742 }
743 ND_TCHECK2(*(p + 3), 6);
744 ND_PRINT((ndo, ": MAC %s", etheraddr_string(ndo, p + 3)));
745 break;
746 case MEDCLASS_MNB:
747 ND_PRINT((ndo, ": Magic-Num-Block")); /* XXX */
748 break;
749 case MEDCLASS_PSNDN:
750 ND_PRINT((ndo, ": PSNDN")); /* XXX */
751 break;
752 default:
753 ND_PRINT((ndo, ": Unknown class %u", p[2]));
754 break;
755 }
756 break;
757
758 /* XXX: to be supported */
759 #if 0
760 case LCPOPT_DEP6:
761 case LCPOPT_FCSALT:
762 case LCPOPT_SDP:
763 case LCPOPT_NUMMODE:
764 case LCPOPT_DEP12:
765 case LCPOPT_DEP14:
766 case LCPOPT_DEP15:
767 case LCPOPT_DEP16:
768 case LCPOPT_MLSSNHF:
769 case LCPOPT_PROP:
770 case LCPOPT_DCEID:
771 case LCPOPT_MPP:
772 case LCPOPT_LCPAOPT:
773 case LCPOPT_COBS:
774 case LCPOPT_PE:
775 case LCPOPT_MLHF:
776 case LCPOPT_I18N:
777 case LCPOPT_SDLOS:
778 case LCPOPT_PPPMUX:
779 break;
780 #endif
781 default:
782 /*
783 * Unknown option; dump it as raw bytes now if we're
784 * not going to do so below.
785 */
786 if (ndo->ndo_vflag < 2)
787 print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
788 break;
789 }
790
791 if (ndo->ndo_vflag > 1)
792 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
793
794 return len;
795
796 trunc:
797 ND_PRINT((ndo, "[|lcp]"));
798 return 0;
799 }
800
801 /* ML-PPP*/
802 static const struct tok ppp_ml_flag_values[] = {
803 { 0x80, "begin" },
804 { 0x40, "end" },
805 { 0, NULL }
806 };
807
808 static void
809 handle_mlppp(netdissect_options *ndo,
810 const u_char *p, int length)
811 {
812 if (!ndo->ndo_eflag)
813 ND_PRINT((ndo, "MLPPP, "));
814
815 if (length < 2) {
816 ND_PRINT((ndo, "[|mlppp]"));
817 return;
818 }
819 if (!ND_TTEST_16BITS(p)) {
820 ND_PRINT((ndo, "[|mlppp]"));
821 return;
822 }
823
824 ND_PRINT((ndo, "seq 0x%03x, Flags [%s], length %u",
825 (EXTRACT_BE_16BITS(p))&0x0fff, /* only support 12-Bit sequence space for now */
826 bittok2str(ppp_ml_flag_values, "none", EXTRACT_8BITS(p) & 0xc0),
827 length));
828 }
829
830 /* CHAP */
831 static void
832 handle_chap(netdissect_options *ndo,
833 const u_char *p, int length)
834 {
835 u_int code, len;
836 int val_size, name_size, msg_size;
837 const u_char *p0;
838 int i;
839
840 p0 = p;
841 if (length < 1) {
842 ND_PRINT((ndo, "[|chap]"));
843 return;
844 } else if (length < 4) {
845 ND_TCHECK(*p);
846 ND_PRINT((ndo, "[|chap 0x%02x]", *p));
847 return;
848 }
849
850 ND_TCHECK(*p);
851 code = *p;
852 ND_PRINT((ndo, "CHAP, %s (0x%02x)",
853 tok2str(chapcode_values,"unknown",code),
854 code));
855 p++;
856
857 ND_TCHECK(*p);
858 ND_PRINT((ndo, ", id %u", *p)); /* ID */
859 p++;
860
861 ND_TCHECK2(*p, 2);
862 len = EXTRACT_BE_16BITS(p);
863 p += 2;
864
865 /*
866 * Note that this is a generic CHAP decoding routine. Since we
867 * don't know which flavor of CHAP (i.e. CHAP-MD5, MS-CHAPv1,
868 * MS-CHAPv2) is used at this point, we can't decode packet
869 * specifically to each algorithms. Instead, we simply decode
870 * the GCD (Gratest Common Denominator) for all algorithms.
871 */
872 switch (code) {
873 case CHAP_CHAL:
874 case CHAP_RESP:
875 if (length - (p - p0) < 1)
876 return;
877 ND_TCHECK(*p);
878 val_size = *p; /* value size */
879 p++;
880 if (length - (p - p0) < val_size)
881 return;
882 ND_PRINT((ndo, ", Value "));
883 for (i = 0; i < val_size; i++) {
884 ND_TCHECK(*p);
885 ND_PRINT((ndo, "%02x", *p++));
886 }
887 name_size = len - (p - p0);
888 ND_PRINT((ndo, ", Name "));
889 for (i = 0; i < name_size; i++) {
890 ND_TCHECK(*p);
891 safeputchar(ndo, *p++);
892 }
893 break;
894 case CHAP_SUCC:
895 case CHAP_FAIL:
896 msg_size = len - (p - p0);
897 ND_PRINT((ndo, ", Msg "));
898 for (i = 0; i< msg_size; i++) {
899 ND_TCHECK(*p);
900 safeputchar(ndo, *p++);
901 }
902 break;
903 }
904 return;
905
906 trunc:
907 ND_PRINT((ndo, "[|chap]"));
908 }
909
910 /* PAP (see RFC 1334) */
911 static void
912 handle_pap(netdissect_options *ndo,
913 const u_char *p, int length)
914 {
915 u_int code, len;
916 int peerid_len, passwd_len, msg_len;
917 const u_char *p0;
918 int i;
919
920 p0 = p;
921 if (length < 1) {
922 ND_PRINT((ndo, "[|pap]"));
923 return;
924 } else if (length < 4) {
925 ND_TCHECK(*p);
926 ND_PRINT((ndo, "[|pap 0x%02x]", *p));
927 return;
928 }
929
930 ND_TCHECK(*p);
931 code = *p;
932 ND_PRINT((ndo, "PAP, %s (0x%02x)",
933 tok2str(papcode_values, "unknown", code),
934 code));
935 p++;
936
937 ND_TCHECK(*p);
938 ND_PRINT((ndo, ", id %u", *p)); /* ID */
939 p++;
940
941 ND_TCHECK2(*p, 2);
942 len = EXTRACT_BE_16BITS(p);
943 p += 2;
944
945 if ((int)len > length) {
946 ND_PRINT((ndo, ", length %u > packet size", len));
947 return;
948 }
949 length = len;
950 if (length < (p - p0)) {
951 ND_PRINT((ndo, ", length %u < PAP header length", length));
952 return;
953 }
954
955 switch (code) {
956 case PAP_AREQ:
957 /* A valid Authenticate-Request is 6 or more octets long. */
958 if (len < 6)
959 goto trunc;
960 if (length - (p - p0) < 1)
961 return;
962 ND_TCHECK(*p);
963 peerid_len = *p; /* Peer-ID Length */
964 p++;
965 if (length - (p - p0) < peerid_len)
966 return;
967 ND_PRINT((ndo, ", Peer "));
968 for (i = 0; i < peerid_len; i++) {
969 ND_TCHECK(*p);
970 safeputchar(ndo, *p++);
971 }
972
973 if (length - (p - p0) < 1)
974 return;
975 ND_TCHECK(*p);
976 passwd_len = *p; /* Password Length */
977 p++;
978 if (length - (p - p0) < passwd_len)
979 return;
980 ND_PRINT((ndo, ", Name "));
981 for (i = 0; i < passwd_len; i++) {
982 ND_TCHECK(*p);
983 safeputchar(ndo, *p++);
984 }
985 break;
986 case PAP_AACK:
987 case PAP_ANAK:
988 /* Although some implementations ignore truncation at
989 * this point and at least one generates a truncated
990 * packet, RFC 1334 section 2.2.2 clearly states that
991 * both AACK and ANAK are at least 5 bytes long.
992 */
993 if (len < 5)
994 goto trunc;
995 if (length - (p - p0) < 1)
996 return;
997 ND_TCHECK(*p);
998 msg_len = *p; /* Msg-Length */
999 p++;
1000 if (length - (p - p0) < msg_len)
1001 return;
1002 ND_PRINT((ndo, ", Msg "));
1003 for (i = 0; i< msg_len; i++) {
1004 ND_TCHECK(*p);
1005 safeputchar(ndo, *p++);
1006 }
1007 break;
1008 }
1009 return;
1010
1011 trunc:
1012 ND_PRINT((ndo, "[|pap]"));
1013 }
1014
1015 /* BAP */
1016 static void
1017 handle_bap(netdissect_options *ndo _U_,
1018 const u_char *p _U_, int length _U_)
1019 {
1020 /* XXX: to be supported!! */
1021 }
1022
1023
1024 /* IPCP config options */
1025 static int
1026 print_ipcp_config_options(netdissect_options *ndo,
1027 const u_char *p, int length)
1028 {
1029 int len, opt;
1030 u_int compproto, ipcomp_subopttotallen, ipcomp_subopt, ipcomp_suboptlen;
1031
1032 if (length < 2)
1033 return 0;
1034 ND_TCHECK2(*p, 2);
1035 len = p[1];
1036 opt = p[0];
1037 if (length < len)
1038 return 0;
1039 if (len < 2) {
1040 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1041 tok2str(ipcpopt_values,"unknown",opt),
1042 opt,
1043 len));
1044 return 0;
1045 }
1046
1047 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u",
1048 tok2str(ipcpopt_values,"unknown",opt),
1049 opt,
1050 len));
1051
1052 switch (opt) {
1053 case IPCPOPT_2ADDR: /* deprecated */
1054 if (len != 10) {
1055 ND_PRINT((ndo, " (length bogus, should be = 10)"));
1056 return len;
1057 }
1058 ND_TCHECK2(*(p + 6), 4);
1059 ND_PRINT((ndo, ": src %s, dst %s",
1060 ipaddr_string(ndo, p + 2),
1061 ipaddr_string(ndo, p + 6)));
1062 break;
1063 case IPCPOPT_IPCOMP:
1064 if (len < 4) {
1065 ND_PRINT((ndo, " (length bogus, should be >= 4)"));
1066 return 0;
1067 }
1068 ND_TCHECK_16BITS(p+2);
1069 compproto = EXTRACT_BE_16BITS(p + 2);
1070
1071 ND_PRINT((ndo, ": %s (0x%02x):",
1072 tok2str(ipcpopt_compproto_values, "Unknown", compproto),
1073 compproto));
1074
1075 switch (compproto) {
1076 case PPP_VJC:
1077 /* XXX: VJ-Comp parameters should be decoded */
1078 break;
1079 case IPCPOPT_IPCOMP_HDRCOMP:
1080 if (len < IPCPOPT_IPCOMP_MINLEN) {
1081 ND_PRINT((ndo, " (length bogus, should be >= %u)",
1082 IPCPOPT_IPCOMP_MINLEN));
1083 return 0;
1084 }
1085
1086 ND_TCHECK2(*(p + 2), IPCPOPT_IPCOMP_MINLEN);
1087 ND_PRINT((ndo, "\n\t TCP Space %u, non-TCP Space %u" \
1088 ", maxPeriod %u, maxTime %u, maxHdr %u",
1089 EXTRACT_BE_16BITS(p + 4),
1090 EXTRACT_BE_16BITS(p + 6),
1091 EXTRACT_BE_16BITS(p + 8),
1092 EXTRACT_BE_16BITS(p + 10),
1093 EXTRACT_BE_16BITS(p + 12)));
1094
1095 /* suboptions present ? */
1096 if (len > IPCPOPT_IPCOMP_MINLEN) {
1097 ipcomp_subopttotallen = len - IPCPOPT_IPCOMP_MINLEN;
1098 p += IPCPOPT_IPCOMP_MINLEN;
1099
1100 ND_PRINT((ndo, "\n\t Suboptions, length %u", ipcomp_subopttotallen));
1101
1102 while (ipcomp_subopttotallen >= 2) {
1103 ND_TCHECK2(*p, 2);
1104 ipcomp_subopt = *p;
1105 ipcomp_suboptlen = *(p+1);
1106
1107 /* sanity check */
1108 if (ipcomp_subopt == 0 ||
1109 ipcomp_suboptlen == 0 )
1110 break;
1111
1112 /* XXX: just display the suboptions for now */
1113 ND_PRINT((ndo, "\n\t\t%s Suboption #%u, length %u",
1114 tok2str(ipcpopt_compproto_subopt_values,
1115 "Unknown",
1116 ipcomp_subopt),
1117 ipcomp_subopt,
1118 ipcomp_suboptlen));
1119
1120 ipcomp_subopttotallen -= ipcomp_suboptlen;
1121 p += ipcomp_suboptlen;
1122 }
1123 }
1124 break;
1125 default:
1126 break;
1127 }
1128 break;
1129
1130 case IPCPOPT_ADDR: /* those options share the same format - fall through */
1131 case IPCPOPT_MOBILE4:
1132 case IPCPOPT_PRIDNS:
1133 case IPCPOPT_PRINBNS:
1134 case IPCPOPT_SECDNS:
1135 case IPCPOPT_SECNBNS:
1136 if (len != 6) {
1137 ND_PRINT((ndo, " (length bogus, should be = 6)"));
1138 return 0;
1139 }
1140 ND_TCHECK2(*(p + 2), 4);
1141 ND_PRINT((ndo, ": %s", ipaddr_string(ndo, p + 2)));
1142 break;
1143 default:
1144 /*
1145 * Unknown option; dump it as raw bytes now if we're
1146 * not going to do so below.
1147 */
1148 if (ndo->ndo_vflag < 2)
1149 print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
1150 break;
1151 }
1152 if (ndo->ndo_vflag > 1)
1153 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
1154 return len;
1155
1156 trunc:
1157 ND_PRINT((ndo, "[|ipcp]"));
1158 return 0;
1159 }
1160
1161 /* IP6CP config options */
1162 static int
1163 print_ip6cp_config_options(netdissect_options *ndo,
1164 const u_char *p, int length)
1165 {
1166 int len, opt;
1167
1168 if (length < 2)
1169 return 0;
1170 ND_TCHECK2(*p, 2);
1171 len = p[1];
1172 opt = p[0];
1173 if (length < len)
1174 return 0;
1175 if (len < 2) {
1176 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1177 tok2str(ip6cpopt_values,"unknown",opt),
1178 opt,
1179 len));
1180 return 0;
1181 }
1182
1183 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u",
1184 tok2str(ip6cpopt_values,"unknown",opt),
1185 opt,
1186 len));
1187
1188 switch (opt) {
1189 case IP6CP_IFID:
1190 if (len != 10) {
1191 ND_PRINT((ndo, " (length bogus, should be = 10)"));
1192 return len;
1193 }
1194 ND_TCHECK2(*(p + 2), 8);
1195 ND_PRINT((ndo, ": %04x:%04x:%04x:%04x",
1196 EXTRACT_BE_16BITS(p + 2),
1197 EXTRACT_BE_16BITS(p + 4),
1198 EXTRACT_BE_16BITS(p + 6),
1199 EXTRACT_BE_16BITS(p + 8)));
1200 break;
1201 default:
1202 /*
1203 * Unknown option; dump it as raw bytes now if we're
1204 * not going to do so below.
1205 */
1206 if (ndo->ndo_vflag < 2)
1207 print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
1208 break;
1209 }
1210 if (ndo->ndo_vflag > 1)
1211 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
1212
1213 return len;
1214
1215 trunc:
1216 ND_PRINT((ndo, "[|ip6cp]"));
1217 return 0;
1218 }
1219
1220
1221 /* CCP config options */
1222 static int
1223 print_ccp_config_options(netdissect_options *ndo,
1224 const u_char *p, int length)
1225 {
1226 int len, opt;
1227
1228 if (length < 2)
1229 return 0;
1230 ND_TCHECK2(*p, 2);
1231 len = p[1];
1232 opt = p[0];
1233 if (length < len)
1234 return 0;
1235 if (len < 2) {
1236 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1237 tok2str(ccpconfopts_values, "Unknown", opt),
1238 opt,
1239 len));
1240 return 0;
1241 }
1242
1243 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u",
1244 tok2str(ccpconfopts_values, "Unknown", opt),
1245 opt,
1246 len));
1247
1248 switch (opt) {
1249 case CCPOPT_BSDCOMP:
1250 if (len < 3) {
1251 ND_PRINT((ndo, " (length bogus, should be >= 3)"));
1252 return len;
1253 }
1254 ND_TCHECK(p[2]);
1255 ND_PRINT((ndo, ": Version: %u, Dictionary Bits: %u",
1256 p[2] >> 5, p[2] & 0x1f));
1257 break;
1258 case CCPOPT_MVRCA:
1259 if (len < 4) {
1260 ND_PRINT((ndo, " (length bogus, should be >= 4)"));
1261 return len;
1262 }
1263 ND_TCHECK(p[3]);
1264 ND_PRINT((ndo, ": Features: %u, PxP: %s, History: %u, #CTX-ID: %u",
1265 (p[2] & 0xc0) >> 6,
1266 (p[2] & 0x20) ? "Enabled" : "Disabled",
1267 p[2] & 0x1f, p[3]));
1268 break;
1269 case CCPOPT_DEFLATE:
1270 if (len < 4) {
1271 ND_PRINT((ndo, " (length bogus, should be >= 4)"));
1272 return len;
1273 }
1274 ND_TCHECK(p[3]);
1275 ND_PRINT((ndo, ": Window: %uK, Method: %s (0x%x), MBZ: %u, CHK: %u",
1276 (p[2] & 0xf0) >> 4,
1277 ((p[2] & 0x0f) == 8) ? "zlib" : "unknown",
1278 p[2] & 0x0f, (p[3] & 0xfc) >> 2, p[3] & 0x03));
1279 break;
1280
1281 /* XXX: to be supported */
1282 #if 0
1283 case CCPOPT_OUI:
1284 case CCPOPT_PRED1:
1285 case CCPOPT_PRED2:
1286 case CCPOPT_PJUMP:
1287 case CCPOPT_HPPPC:
1288 case CCPOPT_STACLZS:
1289 case CCPOPT_MPPC:
1290 case CCPOPT_GFZA:
1291 case CCPOPT_V42BIS:
1292 case CCPOPT_LZSDCP:
1293 case CCPOPT_DEC:
1294 case CCPOPT_RESV:
1295 break;
1296 #endif
1297 default:
1298 /*
1299 * Unknown option; dump it as raw bytes now if we're
1300 * not going to do so below.
1301 */
1302 if (ndo->ndo_vflag < 2)
1303 print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
1304 break;
1305 }
1306 if (ndo->ndo_vflag > 1)
1307 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
1308
1309 return len;
1310
1311 trunc:
1312 ND_PRINT((ndo, "[|ccp]"));
1313 return 0;
1314 }
1315
1316 /* BACP config options */
1317 static int
1318 print_bacp_config_options(netdissect_options *ndo,
1319 const u_char *p, int length)
1320 {
1321 int len, opt;
1322
1323 if (length < 2)
1324 return 0;
1325 ND_TCHECK2(*p, 2);
1326 len = p[1];
1327 opt = p[0];
1328 if (length < len)
1329 return 0;
1330 if (len < 2) {
1331 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1332 tok2str(bacconfopts_values, "Unknown", opt),
1333 opt,
1334 len));
1335 return 0;
1336 }
1337
1338 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u",
1339 tok2str(bacconfopts_values, "Unknown", opt),
1340 opt,
1341 len));
1342
1343 switch (opt) {
1344 case BACPOPT_FPEER:
1345 if (len != 6) {
1346 ND_PRINT((ndo, " (length bogus, should be = 6)"));
1347 return len;
1348 }
1349 ND_TCHECK_32BITS(p + 2);
1350 ND_PRINT((ndo, ": Magic-Num 0x%08x", EXTRACT_BE_32BITS(p + 2)));
1351 break;
1352 default:
1353 /*
1354 * Unknown option; dump it as raw bytes now if we're
1355 * not going to do so below.
1356 */
1357 if (ndo->ndo_vflag < 2)
1358 print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
1359 break;
1360 }
1361 if (ndo->ndo_vflag > 1)
1362 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
1363
1364 return len;
1365
1366 trunc:
1367 ND_PRINT((ndo, "[|bacp]"));
1368 return 0;
1369 }
1370
1371 static void
1372 ppp_hdlc(netdissect_options *ndo,
1373 const u_char *p, int length)
1374 {
1375 u_char *b, *t, c;
1376 const u_char *s;
1377 int i, proto;
1378 const void *se;
1379
1380 if (length <= 0)
1381 return;
1382
1383 b = (u_char *)malloc(length);
1384 if (b == NULL)
1385 return;
1386
1387 /*
1388 * Unescape all the data into a temporary, private, buffer.
1389 * Do this so that we dont overwrite the original packet
1390 * contents.
1391 */
1392 for (s = p, t = b, i = length; i > 0 && ND_TTEST(*s); i--) {
1393 c = *s++;
1394 if (c == 0x7d) {
1395 if (i <= 1 || !ND_TTEST(*s))
1396 break;
1397 i--;
1398 c = EXTRACT_8BITS(s) ^ 0x20;
1399 s++;
1400 }
1401 *t++ = c;
1402 }
1403
1404 se = ndo->ndo_snapend;
1405 ndo->ndo_snapend = t;
1406 length = t - b;
1407
1408 /* now lets guess about the payload codepoint format */
1409 if (length < 1)
1410 goto trunc;
1411 proto = *b; /* start with a one-octet codepoint guess */
1412
1413 switch (proto) {
1414 case PPP_IP:
1415 ip_print(ndo, b + 1, length - 1);
1416 goto cleanup;
1417 case PPP_IPV6:
1418 ip6_print(ndo, b + 1, length - 1);
1419 goto cleanup;
1420 default: /* no luck - try next guess */
1421 break;
1422 }
1423
1424 if (length < 2)
1425 goto trunc;
1426 proto = EXTRACT_BE_16BITS(b); /* next guess - load two octets */
1427
1428 switch (proto) {
1429 case (PPP_ADDRESS << 8 | PPP_CONTROL): /* looks like a PPP frame */
1430 if (length < 4)
1431 goto trunc;
1432 proto = EXTRACT_BE_16BITS(b + 2); /* load the PPP proto-id */
1433 handle_ppp(ndo, proto, b + 4, length - 4);
1434 break;
1435 default: /* last guess - proto must be a PPP proto-id */
1436 handle_ppp(ndo, proto, b + 2, length - 2);
1437 break;
1438 }
1439
1440 cleanup:
1441 ndo->ndo_snapend = se;
1442 free(b);
1443 return;
1444
1445 trunc:
1446 ndo->ndo_snapend = se;
1447 free(b);
1448 ND_PRINT((ndo, "[|ppp]"));
1449 }
1450
1451
1452 /* PPP */
1453 static void
1454 handle_ppp(netdissect_options *ndo,
1455 u_int proto, const u_char *p, int length)
1456 {
1457 if ((proto & 0xff00) == 0x7e00) { /* is this an escape code ? */
1458 ppp_hdlc(ndo, p - 1, length);
1459 return;
1460 }
1461
1462 switch (proto) {
1463 case PPP_LCP: /* fall through */
1464 case PPP_IPCP:
1465 case PPP_OSICP:
1466 case PPP_MPLSCP:
1467 case PPP_IPV6CP:
1468 case PPP_CCP:
1469 case PPP_BACP:
1470 handle_ctrl_proto(ndo, proto, p, length);
1471 break;
1472 case PPP_ML:
1473 handle_mlppp(ndo, p, length);
1474 break;
1475 case PPP_CHAP:
1476 handle_chap(ndo, p, length);
1477 break;
1478 case PPP_PAP:
1479 handle_pap(ndo, p, length);
1480 break;
1481 case PPP_BAP: /* XXX: not yet completed */
1482 handle_bap(ndo, p, length);
1483 break;
1484 case ETHERTYPE_IP: /*XXX*/
1485 case PPP_VJNC:
1486 case PPP_IP:
1487 ip_print(ndo, p, length);
1488 break;
1489 case ETHERTYPE_IPV6: /*XXX*/
1490 case PPP_IPV6:
1491 ip6_print(ndo, p, length);
1492 break;
1493 case ETHERTYPE_IPX: /*XXX*/
1494 case PPP_IPX:
1495 ipx_print(ndo, p, length);
1496 break;
1497 case PPP_OSI:
1498 isoclns_print(ndo, p, length);
1499 break;
1500 case PPP_MPLS_UCAST:
1501 case PPP_MPLS_MCAST:
1502 mpls_print(ndo, p, length);
1503 break;
1504 case PPP_COMP:
1505 ND_PRINT((ndo, "compressed PPP data"));
1506 break;
1507 default:
1508 ND_PRINT((ndo, "%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto)));
1509 print_unknown_data(ndo, p, "\n\t", length);
1510 break;
1511 }
1512 }
1513
1514 /* Standard PPP printer */
1515 u_int
1516 ppp_print(netdissect_options *ndo,
1517 register const u_char *p, u_int length)
1518 {
1519 u_int proto,ppp_header;
1520 u_int olen = length; /* _o_riginal length */
1521 u_int hdr_len = 0;
1522
1523 /*
1524 * Here, we assume that p points to the Address and Control
1525 * field (if they present).
1526 */
1527 if (length < 2)
1528 goto trunc;
1529 ND_TCHECK2(*p, 2);
1530 ppp_header = EXTRACT_BE_16BITS(p);
1531
1532 switch(ppp_header) {
1533 case (PPP_WITHDIRECTION_IN << 8 | PPP_CONTROL):
1534 if (ndo->ndo_eflag) ND_PRINT((ndo, "In "));
1535 p += 2;
1536 length -= 2;
1537 hdr_len += 2;
1538 break;
1539 case (PPP_WITHDIRECTION_OUT << 8 | PPP_CONTROL):
1540 if (ndo->ndo_eflag) ND_PRINT((ndo, "Out "));
1541 p += 2;
1542 length -= 2;
1543 hdr_len += 2;
1544 break;
1545 case (PPP_ADDRESS << 8 | PPP_CONTROL):
1546 p += 2; /* ACFC not used */
1547 length -= 2;
1548 hdr_len += 2;
1549 break;
1550
1551 default:
1552 break;
1553 }
1554
1555 if (length < 2)
1556 goto trunc;
1557 ND_TCHECK(*p);
1558 if (*p % 2) {
1559 proto = *p; /* PFC is used */
1560 p++;
1561 length--;
1562 hdr_len++;
1563 } else {
1564 ND_TCHECK2(*p, 2);
1565 proto = EXTRACT_BE_16BITS(p);
1566 p += 2;
1567 length -= 2;
1568 hdr_len += 2;
1569 }
1570
1571 if (ndo->ndo_eflag)
1572 ND_PRINT((ndo, "%s (0x%04x), length %u: ",
1573 tok2str(ppptype2str, "unknown", proto),
1574 proto,
1575 olen));
1576
1577 handle_ppp(ndo, proto, p, length);
1578 return (hdr_len);
1579 trunc:
1580 ND_PRINT((ndo, "[|ppp]"));
1581 return (0);
1582 }
1583
1584
1585 /* PPP I/F printer */
1586 u_int
1587 ppp_if_print(netdissect_options *ndo,
1588 const struct pcap_pkthdr *h, register const u_char *p)
1589 {
1590 register u_int length = h->len;
1591 register u_int caplen = h->caplen;
1592
1593 if (caplen < PPP_HDRLEN) {
1594 ND_PRINT((ndo, "[|ppp]"));
1595 return (caplen);
1596 }
1597
1598 #if 0
1599 /*
1600 * XXX: seems to assume that there are 2 octets prepended to an
1601 * actual PPP frame. The 1st octet looks like Input/Output flag
1602 * while 2nd octet is unknown, at least to me
1603 * (mshindo@mshindo.net).
1604 *
1605 * That was what the original tcpdump code did.
1606 *
1607 * FreeBSD's "if_ppp.c" *does* set the first octet to 1 for outbound
1608 * packets and 0 for inbound packets - but only if the
1609 * protocol field has the 0x8000 bit set (i.e., it's a network
1610 * control protocol); it does so before running the packet through
1611 * "bpf_filter" to see if it should be discarded, and to see
1612 * if we should update the time we sent the most recent packet...
1613 *
1614 * ...but it puts the original address field back after doing
1615 * so.
1616 *
1617 * NetBSD's "if_ppp.c" doesn't set the first octet in that fashion.
1618 *
1619 * I don't know if any PPP implementation handed up to a BPF
1620 * device packets with the first octet being 1 for outbound and
1621 * 0 for inbound packets, so I (guy@alum.mit.edu) don't know
1622 * whether that ever needs to be checked or not.
1623 *
1624 * Note that NetBSD has a DLT_PPP_SERIAL, which it uses for PPP,
1625 * and its tcpdump appears to assume that the frame always
1626 * begins with an address field and a control field, and that
1627 * the address field might be 0x0f or 0x8f, for Cisco
1628 * point-to-point with HDLC framing as per section 4.3.1 of RFC
1629 * 1547, as well as 0xff, for PPP in HDLC-like framing as per
1630 * RFC 1662.
1631 *
1632 * (Is the Cisco framing in question what DLT_C_HDLC, in
1633 * BSD/OS, is?)
1634 */
1635 if (ndo->ndo_eflag)
1636 ND_PRINT((ndo, "%c %4d %02x ", p[0] ? 'O' : 'I', length, p[1]));
1637 #endif
1638
1639 ppp_print(ndo, p, length);
1640
1641 return (0);
1642 }
1643
1644 /*
1645 * PPP I/F printer to use if we know that RFC 1662-style PPP in HDLC-like
1646 * framing, or Cisco PPP with HDLC framing as per section 4.3.1 of RFC 1547,
1647 * is being used (i.e., we don't check for PPP_ADDRESS and PPP_CONTROL,
1648 * discard them *if* those are the first two octets, and parse the remaining
1649 * packet as a PPP packet, as "ppp_print()" does).
1650 *
1651 * This handles, for example, DLT_PPP_SERIAL in NetBSD.
1652 */
1653 u_int
1654 ppp_hdlc_if_print(netdissect_options *ndo,
1655 const struct pcap_pkthdr *h, register const u_char *p)
1656 {
1657 register u_int length = h->len;
1658 register u_int caplen = h->caplen;
1659 u_int proto;
1660 u_int hdrlen = 0;
1661
1662 if (caplen < 2) {
1663 ND_PRINT((ndo, "[|ppp]"));
1664 return (caplen);
1665 }
1666
1667 switch (p[0]) {
1668
1669 case PPP_ADDRESS:
1670 if (caplen < 4) {
1671 ND_PRINT((ndo, "[|ppp]"));
1672 return (caplen);
1673 }
1674
1675 if (ndo->ndo_eflag)
1676 ND_PRINT((ndo, "%02x %02x %d ", p[0], p[1], length));
1677 p += 2;
1678 length -= 2;
1679 hdrlen += 2;
1680
1681 proto = EXTRACT_BE_16BITS(p);
1682 p += 2;
1683 length -= 2;
1684 hdrlen += 2;
1685 ND_PRINT((ndo, "%s: ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto)));
1686
1687 handle_ppp(ndo, proto, p, length);
1688 break;
1689
1690 case CHDLC_UNICAST:
1691 case CHDLC_BCAST:
1692 return (chdlc_if_print(ndo, h, p));
1693
1694 default:
1695 if (caplen < 4) {
1696 ND_PRINT((ndo, "[|ppp]"));
1697 return (caplen);
1698 }
1699
1700 if (ndo->ndo_eflag)
1701 ND_PRINT((ndo, "%02x %02x %d ", p[0], p[1], length));
1702 p += 2;
1703 hdrlen += 2;
1704
1705 /*
1706 * XXX - NetBSD's "ppp_netbsd_serial_if_print()" treats
1707 * the next two octets as an Ethernet type; does that
1708 * ever happen?
1709 */
1710 ND_PRINT((ndo, "unknown addr %02x; ctrl %02x", p[0], p[1]));
1711 break;
1712 }
1713
1714 return (hdrlen);
1715 }
1716
1717 #define PPP_BSDI_HDRLEN 24
1718
1719 /* BSD/OS specific PPP printer */
1720 u_int
1721 ppp_bsdos_if_print(netdissect_options *ndo _U_,
1722 const struct pcap_pkthdr *h _U_, register const u_char *p _U_)
1723 {
1724 register int hdrlength;
1725 #ifdef __bsdi__
1726 register u_int length = h->len;
1727 register u_int caplen = h->caplen;
1728 uint16_t ptype;
1729 const u_char *q;
1730 int i;
1731
1732 if (caplen < PPP_BSDI_HDRLEN) {
1733 ND_PRINT((ndo, "[|ppp]"));
1734 return (caplen)
1735 }
1736
1737 hdrlength = 0;
1738
1739 #if 0
1740 if (p[0] == PPP_ADDRESS && p[1] == PPP_CONTROL) {
1741 if (ndo->ndo_eflag)
1742 ND_PRINT((ndo, "%02x %02x ", p[0], p[1]));
1743 p += 2;
1744 hdrlength = 2;
1745 }
1746
1747 if (ndo->ndo_eflag)
1748 ND_PRINT((ndo, "%d ", length));
1749 /* Retrieve the protocol type */
1750 if (*p & 01) {
1751 /* Compressed protocol field */
1752 ptype = *p;
1753 if (ndo->ndo_eflag)
1754 ND_PRINT((ndo, "%02x ", ptype));
1755 p++;
1756 hdrlength += 1;
1757 } else {
1758 /* Un-compressed protocol field */
1759 ptype = EXTRACT_16BITS(p);
1760 if (ndo->ndo_eflag)
1761 ND_PRINT((ndo, "%04x ", ptype));
1762 p += 2;
1763 hdrlength += 2;
1764 }
1765 #else
1766 ptype = 0; /*XXX*/
1767 if (ndo->ndo_eflag)
1768 ND_PRINT((ndo, "%c ", p[SLC_DIR] ? 'O' : 'I'));
1769 if (p[SLC_LLHL]) {
1770 /* link level header */
1771 struct ppp_header *ph;
1772
1773 q = p + SLC_BPFHDRLEN;
1774 ph = (struct ppp_header *)q;
1775 if (ph->phdr_addr == PPP_ADDRESS
1776 && ph->phdr_ctl == PPP_CONTROL) {
1777 if (ndo->ndo_eflag)
1778 ND_PRINT((ndo, "%02x %02x ", q[0], q[1]));
1779 ptype = EXTRACT_16BITS(&ph->phdr_type);
1780 if (ndo->ndo_eflag && (ptype == PPP_VJC || ptype == PPP_VJNC)) {
1781 ND_PRINT((ndo, "%s ", tok2str(ppptype2str,
1782 "proto-#%d", ptype)));
1783 }
1784 } else {
1785 if (ndo->ndo_eflag) {
1786 ND_PRINT((ndo, "LLH=["));
1787 for (i = 0; i < p[SLC_LLHL]; i++)
1788 ND_PRINT((ndo, "%02x", q[i]));
1789 ND_PRINT((ndo, "] "));
1790 }
1791 }
1792 }
1793 if (ndo->ndo_eflag)
1794 ND_PRINT((ndo, "%d ", length));
1795 if (p[SLC_CHL]) {
1796 q = p + SLC_BPFHDRLEN + p[SLC_LLHL];
1797
1798 switch (ptype) {
1799 case PPP_VJC:
1800 ptype = vjc_print(ndo, q, ptype);
1801 hdrlength = PPP_BSDI_HDRLEN;
1802 p += hdrlength;
1803 switch (ptype) {
1804 case PPP_IP:
1805 ip_print(ndo, p, length);
1806 break;
1807 case PPP_IPV6:
1808 ip6_print(ndo, p, length);
1809 break;
1810 case PPP_MPLS_UCAST:
1811 case PPP_MPLS_MCAST:
1812 mpls_print(ndo, p, length);
1813 break;
1814 }
1815 goto printx;
1816 case PPP_VJNC:
1817 ptype = vjc_print(ndo, q, ptype);
1818 hdrlength = PPP_BSDI_HDRLEN;
1819 p += hdrlength;
1820 switch (ptype) {
1821 case PPP_IP:
1822 ip_print(ndo, p, length);
1823 break;
1824 case PPP_IPV6:
1825 ip6_print(ndo, p, length);
1826 break;
1827 case PPP_MPLS_UCAST:
1828 case PPP_MPLS_MCAST:
1829 mpls_print(ndo, p, length);
1830 break;
1831 }
1832 goto printx;
1833 default:
1834 if (ndo->ndo_eflag) {
1835 ND_PRINT((ndo, "CH=["));
1836 for (i = 0; i < p[SLC_LLHL]; i++)
1837 ND_PRINT((ndo, "%02x", q[i]));
1838 ND_PRINT((ndo, "] "));
1839 }
1840 break;
1841 }
1842 }
1843
1844 hdrlength = PPP_BSDI_HDRLEN;
1845 #endif
1846
1847 length -= hdrlength;
1848 p += hdrlength;
1849
1850 switch (ptype) {
1851 case PPP_IP:
1852 ip_print(p, length);
1853 break;
1854 case PPP_IPV6:
1855 ip6_print(ndo, p, length);
1856 break;
1857 case PPP_MPLS_UCAST:
1858 case PPP_MPLS_MCAST:
1859 mpls_print(ndo, p, length);
1860 break;
1861 default:
1862 ND_PRINT((ndo, "%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", ptype)));
1863 }
1864
1865 printx:
1866 #else /* __bsdi */
1867 hdrlength = 0;
1868 #endif /* __bsdi__ */
1869 return (hdrlength);
1870 }
1871
1872
1873 /*
1874 * Local Variables:
1875 * c-style: whitesmith
1876 * c-basic-offset: 8
1877 * End:
1878 */