]> The Tcpdump Group git mirrors - tcpdump/blob - print-ppp.c
c16801fba31f6d02a877d6465a602e5385c1f4cd
[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 *tptr++, /* ID */
438 length + 2));
439
440 if (!ndo->ndo_vflag)
441 return;
442
443 if (length <= 4)
444 return; /* there may be a NULL confreq etc. */
445
446 ND_TCHECK2(*tptr, 2);
447 len = EXTRACT_16BITS(tptr);
448 tptr += 2;
449
450 ND_PRINT((ndo, "\n\tencoded length %u (=Option(s) length %u)", len, len - 4));
451
452 if (ndo->ndo_vflag > 1)
453 print_unknown_data(ndo, pptr - 2, "\n\t", 6);
454
455
456 switch (code) {
457 case CPCODES_VEXT:
458 if (length < 11)
459 break;
460 ND_TCHECK2(*tptr, 4);
461 ND_PRINT((ndo, "\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr)));
462 tptr += 4;
463 ND_TCHECK2(*tptr, 3);
464 ND_PRINT((ndo, " Vendor: %s (%u)",
465 tok2str(oui_values,"Unknown",EXTRACT_24BITS(tptr)),
466 EXTRACT_24BITS(tptr)));
467 /* XXX: need to decode Kind and Value(s)? */
468 break;
469 case CPCODES_CONF_REQ:
470 case CPCODES_CONF_ACK:
471 case CPCODES_CONF_NAK:
472 case CPCODES_CONF_REJ:
473 x = len - 4; /* Code(1), Identifier(1) and Length(2) */
474 do {
475 switch (proto) {
476 case PPP_LCP:
477 pfunc = print_lcp_config_options;
478 break;
479 case PPP_IPCP:
480 pfunc = print_ipcp_config_options;
481 break;
482 case PPP_IPV6CP:
483 pfunc = print_ip6cp_config_options;
484 break;
485 case PPP_CCP:
486 pfunc = print_ccp_config_options;
487 break;
488 case PPP_BACP:
489 pfunc = print_bacp_config_options;
490 break;
491 default:
492 /*
493 * No print routine for the options for
494 * this protocol.
495 */
496 pfunc = NULL;
497 break;
498 }
499
500 if (pfunc == NULL) /* catch the above null pointer if unknown CP */
501 break;
502
503 if ((j = (*pfunc)(ndo, tptr, len)) == 0)
504 break;
505 x -= j;
506 tptr += j;
507 } while (x > 0);
508 break;
509
510 case CPCODES_TERM_REQ:
511 case CPCODES_TERM_ACK:
512 /* XXX: need to decode Data? */
513 break;
514 case CPCODES_CODE_REJ:
515 /* XXX: need to decode Rejected-Packet? */
516 break;
517 case CPCODES_PROT_REJ:
518 if (length < 6)
519 break;
520 ND_TCHECK2(*tptr, 2);
521 ND_PRINT((ndo, "\n\t Rejected %s Protocol (0x%04x)",
522 tok2str(ppptype2str,"unknown", EXTRACT_16BITS(tptr)),
523 EXTRACT_16BITS(tptr)));
524 /* XXX: need to decode Rejected-Information? - hexdump for now */
525 if (len > 6) {
526 ND_PRINT((ndo, "\n\t Rejected Packet"));
527 print_unknown_data(ndo, tptr + 2, "\n\t ", len - 2);
528 }
529 break;
530 case CPCODES_ECHO_REQ:
531 case CPCODES_ECHO_RPL:
532 case CPCODES_DISC_REQ:
533 if (length < 8)
534 break;
535 ND_TCHECK2(*tptr, 4);
536 ND_PRINT((ndo, "\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr)));
537 /* XXX: need to decode Data? - hexdump for now */
538 if (len > 8) {
539 ND_PRINT((ndo, "\n\t -----trailing data-----"));
540 ND_TCHECK2(tptr[4], len - 8);
541 print_unknown_data(ndo, tptr + 4, "\n\t ", len - 8);
542 }
543 break;
544 case CPCODES_ID:
545 if (length < 8)
546 break;
547 ND_TCHECK2(*tptr, 4);
548 ND_PRINT((ndo, "\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr)));
549 /* RFC 1661 says this is intended to be human readable */
550 if (len > 8) {
551 ND_PRINT((ndo, "\n\t Message\n\t "));
552 if (fn_printn(ndo, tptr + 4, len - 4, ndo->ndo_snapend))
553 goto trunc;
554 }
555 break;
556 case CPCODES_TIME_REM:
557 if (length < 12)
558 break;
559 ND_TCHECK2(*tptr, 4);
560 ND_PRINT((ndo, "\n\t Magic-Num 0x%08x", EXTRACT_32BITS(tptr)));
561 ND_TCHECK2(*(tptr + 4), 4);
562 ND_PRINT((ndo, ", Seconds-Remaining %us", EXTRACT_32BITS(tptr + 4)));
563 /* XXX: need to decode Message? */
564 break;
565 default:
566 /* XXX this is dirty but we do not get the
567 * original pointer passed to the begin
568 * the PPP packet */
569 if (ndo->ndo_vflag <= 1)
570 print_unknown_data(ndo, pptr - 2, "\n\t ", length + 2);
571 break;
572 }
573 return;
574
575 trunc:
576 ND_PRINT((ndo, "[|%s]", typestr));
577 }
578
579 /* LCP config options */
580 static int
581 print_lcp_config_options(netdissect_options *ndo,
582 const u_char *p, int length)
583 {
584 int len, opt;
585
586 if (length < 2)
587 return 0;
588 ND_TCHECK2(*p, 2);
589 len = p[1];
590 opt = p[0];
591 if (length < len)
592 return 0;
593 if (len < 2) {
594 if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX))
595 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
596 lcpconfopts[opt], opt, len));
597 else
598 ND_PRINT((ndo, "\n\tunknown LCP option 0x%02x", opt));
599 return 0;
600 }
601 if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX))
602 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u", lcpconfopts[opt], opt, len));
603 else {
604 ND_PRINT((ndo, "\n\tunknown LCP option 0x%02x", opt));
605 return len;
606 }
607
608 switch (opt) {
609 case LCPOPT_VEXT:
610 if (len < 6) {
611 ND_PRINT((ndo, " (length bogus, should be >= 6)"));
612 return len;
613 }
614 ND_TCHECK2(*(p + 2), 3);
615 ND_PRINT((ndo, ": Vendor: %s (%u)",
616 tok2str(oui_values,"Unknown",EXTRACT_24BITS(p+2)),
617 EXTRACT_24BITS(p + 2)));
618 #if 0
619 ND_TCHECK(p[5]);
620 ND_PRINT((ndo, ", kind: 0x%02x", p[5]));
621 ND_PRINT((ndo, ", Value: 0x"));
622 for (i = 0; i < len - 6; i++) {
623 ND_TCHECK(p[6 + i]);
624 ND_PRINT((ndo, "%02x", p[6 + i]));
625 }
626 #endif
627 break;
628 case LCPOPT_MRU:
629 if (len != 4) {
630 ND_PRINT((ndo, " (length bogus, should be = 4)"));
631 return len;
632 }
633 ND_TCHECK2(*(p + 2), 2);
634 ND_PRINT((ndo, ": %u", EXTRACT_16BITS(p + 2)));
635 break;
636 case LCPOPT_ACCM:
637 if (len != 6) {
638 ND_PRINT((ndo, " (length bogus, should be = 6)"));
639 return len;
640 }
641 ND_TCHECK2(*(p + 2), 4);
642 ND_PRINT((ndo, ": 0x%08x", EXTRACT_32BITS(p + 2)));
643 break;
644 case LCPOPT_AP:
645 if (len < 4) {
646 ND_PRINT((ndo, " (length bogus, should be >= 4)"));
647 return len;
648 }
649 ND_TCHECK2(*(p + 2), 2);
650 ND_PRINT((ndo, ": %s", tok2str(ppptype2str, "Unknown Auth Proto (0x04x)", EXTRACT_16BITS(p + 2))));
651
652 switch (EXTRACT_16BITS(p+2)) {
653 case PPP_CHAP:
654 ND_TCHECK(p[4]);
655 ND_PRINT((ndo, ", %s", tok2str(authalg_values, "Unknown Auth Alg %u", p[4])));
656 break;
657 case PPP_PAP: /* fall through */
658 case PPP_EAP:
659 case PPP_SPAP:
660 case PPP_SPAP_OLD:
661 break;
662 default:
663 print_unknown_data(ndo, p, "\n\t", len);
664 }
665 break;
666 case LCPOPT_QP:
667 if (len < 4) {
668 ND_PRINT((ndo, " (length bogus, should be >= 4)"));
669 return 0;
670 }
671 ND_TCHECK2(*(p + 2), 2);
672 if (EXTRACT_16BITS(p+2) == PPP_LQM)
673 ND_PRINT((ndo, ": LQR"));
674 else
675 ND_PRINT((ndo, ": unknown"));
676 break;
677 case LCPOPT_MN:
678 if (len != 6) {
679 ND_PRINT((ndo, " (length bogus, should be = 6)"));
680 return 0;
681 }
682 ND_TCHECK2(*(p + 2), 4);
683 ND_PRINT((ndo, ": 0x%08x", EXTRACT_32BITS(p + 2)));
684 break;
685 case LCPOPT_PFC:
686 break;
687 case LCPOPT_ACFC:
688 break;
689 case LCPOPT_LD:
690 if (len != 4) {
691 ND_PRINT((ndo, " (length bogus, should be = 4)"));
692 return 0;
693 }
694 ND_TCHECK2(*(p + 2), 2);
695 ND_PRINT((ndo, ": 0x%04x", EXTRACT_16BITS(p + 2)));
696 break;
697 case LCPOPT_CBACK:
698 if (len < 3) {
699 ND_PRINT((ndo, " (length bogus, should be >= 3)"));
700 return 0;
701 }
702 ND_PRINT((ndo, ": "));
703 ND_TCHECK(p[2]);
704 ND_PRINT((ndo, ": Callback Operation %s (%u)",
705 tok2str(ppp_callback_values, "Unknown", p[2]),
706 p[2]));
707 break;
708 case LCPOPT_MLMRRU:
709 if (len != 4) {
710 ND_PRINT((ndo, " (length bogus, should be = 4)"));
711 return 0;
712 }
713 ND_TCHECK2(*(p + 2), 2);
714 ND_PRINT((ndo, ": %u", EXTRACT_16BITS(p + 2)));
715 break;
716 case LCPOPT_MLED:
717 if (len < 3) {
718 ND_PRINT((ndo, " (length bogus, should be >= 3)"));
719 return 0;
720 }
721 ND_TCHECK(p[2]);
722 switch (p[2]) { /* class */
723 case MEDCLASS_NULL:
724 ND_PRINT((ndo, ": Null"));
725 break;
726 case MEDCLASS_LOCAL:
727 ND_PRINT((ndo, ": Local")); /* XXX */
728 break;
729 case MEDCLASS_IPV4:
730 if (len != 7) {
731 ND_PRINT((ndo, " (length bogus, should be = 7)"));
732 return 0;
733 }
734 ND_TCHECK2(*(p + 3), 4);
735 ND_PRINT((ndo, ": IPv4 %s", ipaddr_string(ndo, p + 3)));
736 break;
737 case MEDCLASS_MAC:
738 if (len != 9) {
739 ND_PRINT((ndo, " (length bogus, should be = 9)"));
740 return 0;
741 }
742 ND_TCHECK2(*(p + 3), 6);
743 ND_PRINT((ndo, ": MAC %s", etheraddr_string(ndo, p + 3)));
744 break;
745 case MEDCLASS_MNB:
746 ND_PRINT((ndo, ": Magic-Num-Block")); /* XXX */
747 break;
748 case MEDCLASS_PSNDN:
749 ND_PRINT((ndo, ": PSNDN")); /* XXX */
750 break;
751 default:
752 ND_PRINT((ndo, ": Unknown class %u", p[2]));
753 break;
754 }
755 break;
756
757 /* XXX: to be supported */
758 #if 0
759 case LCPOPT_DEP6:
760 case LCPOPT_FCSALT:
761 case LCPOPT_SDP:
762 case LCPOPT_NUMMODE:
763 case LCPOPT_DEP12:
764 case LCPOPT_DEP14:
765 case LCPOPT_DEP15:
766 case LCPOPT_DEP16:
767 case LCPOPT_MLSSNHF:
768 case LCPOPT_PROP:
769 case LCPOPT_DCEID:
770 case LCPOPT_MPP:
771 case LCPOPT_LCPAOPT:
772 case LCPOPT_COBS:
773 case LCPOPT_PE:
774 case LCPOPT_MLHF:
775 case LCPOPT_I18N:
776 case LCPOPT_SDLOS:
777 case LCPOPT_PPPMUX:
778 break;
779 #endif
780 default:
781 /*
782 * Unknown option; dump it as raw bytes now if we're
783 * not going to do so below.
784 */
785 if (ndo->ndo_vflag < 2)
786 print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
787 break;
788 }
789
790 if (ndo->ndo_vflag > 1)
791 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
792
793 return len;
794
795 trunc:
796 ND_PRINT((ndo, "[|lcp]"));
797 return 0;
798 }
799
800 /* ML-PPP*/
801 static const struct tok ppp_ml_flag_values[] = {
802 { 0x80, "begin" },
803 { 0x40, "end" },
804 { 0, NULL }
805 };
806
807 static void
808 handle_mlppp(netdissect_options *ndo,
809 const u_char *p, int length)
810 {
811 if (!ndo->ndo_eflag)
812 ND_PRINT((ndo, "MLPPP, "));
813
814 ND_PRINT((ndo, "seq 0x%03x, Flags [%s], length %u",
815 (EXTRACT_16BITS(p))&0x0fff, /* only support 12-Bit sequence space for now */
816 bittok2str(ppp_ml_flag_values, "none", *p & 0xc0),
817 length));
818 }
819
820 /* CHAP */
821 static void
822 handle_chap(netdissect_options *ndo,
823 const u_char *p, int length)
824 {
825 u_int code, len;
826 int val_size, name_size, msg_size;
827 const u_char *p0;
828 int i;
829
830 p0 = p;
831 if (length < 1) {
832 ND_PRINT((ndo, "[|chap]"));
833 return;
834 } else if (length < 4) {
835 ND_TCHECK(*p);
836 ND_PRINT((ndo, "[|chap 0x%02x]", *p));
837 return;
838 }
839
840 ND_TCHECK(*p);
841 code = *p;
842 ND_PRINT((ndo, "CHAP, %s (0x%02x)",
843 tok2str(chapcode_values,"unknown",code),
844 code));
845 p++;
846
847 ND_TCHECK(*p);
848 ND_PRINT((ndo, ", id %u", *p)); /* ID */
849 p++;
850
851 ND_TCHECK2(*p, 2);
852 len = EXTRACT_16BITS(p);
853 p += 2;
854
855 /*
856 * Note that this is a generic CHAP decoding routine. Since we
857 * don't know which flavor of CHAP (i.e. CHAP-MD5, MS-CHAPv1,
858 * MS-CHAPv2) is used at this point, we can't decode packet
859 * specifically to each algorithms. Instead, we simply decode
860 * the GCD (Gratest Common Denominator) for all algorithms.
861 */
862 switch (code) {
863 case CHAP_CHAL:
864 case CHAP_RESP:
865 if (length - (p - p0) < 1)
866 return;
867 ND_TCHECK(*p);
868 val_size = *p; /* value size */
869 p++;
870 if (length - (p - p0) < val_size)
871 return;
872 ND_PRINT((ndo, ", Value "));
873 for (i = 0; i < val_size; i++) {
874 ND_TCHECK(*p);
875 ND_PRINT((ndo, "%02x", *p++));
876 }
877 name_size = len - (p - p0);
878 ND_PRINT((ndo, ", Name "));
879 for (i = 0; i < name_size; i++) {
880 ND_TCHECK(*p);
881 safeputchar(ndo, *p++);
882 }
883 break;
884 case CHAP_SUCC:
885 case CHAP_FAIL:
886 msg_size = len - (p - p0);
887 ND_PRINT((ndo, ", Msg "));
888 for (i = 0; i< msg_size; i++) {
889 ND_TCHECK(*p);
890 safeputchar(ndo, *p++);
891 }
892 break;
893 }
894 return;
895
896 trunc:
897 ND_PRINT((ndo, "[|chap]"));
898 }
899
900 /* PAP (see RFC 1334) */
901 static void
902 handle_pap(netdissect_options *ndo,
903 const u_char *p, int length)
904 {
905 u_int code, len;
906 int peerid_len, passwd_len, msg_len;
907 const u_char *p0;
908 int i;
909
910 p0 = p;
911 if (length < 1) {
912 ND_PRINT((ndo, "[|pap]"));
913 return;
914 } else if (length < 4) {
915 ND_TCHECK(*p);
916 ND_PRINT((ndo, "[|pap 0x%02x]", *p));
917 return;
918 }
919
920 ND_TCHECK(*p);
921 code = *p;
922 ND_PRINT((ndo, "PAP, %s (0x%02x)",
923 tok2str(papcode_values, "unknown", code),
924 code));
925 p++;
926
927 ND_TCHECK(*p);
928 ND_PRINT((ndo, ", id %u", *p)); /* ID */
929 p++;
930
931 ND_TCHECK2(*p, 2);
932 len = EXTRACT_16BITS(p);
933 p += 2;
934
935 if ((int)len > length) {
936 ND_PRINT((ndo, ", length %u > packet size", len));
937 return;
938 }
939 length = len;
940 if (length < (p - p0)) {
941 ND_PRINT((ndo, ", length %u < PAP header length", length));
942 return;
943 }
944
945 switch (code) {
946 case PAP_AREQ:
947 if (length - (p - p0) < 1)
948 return;
949 ND_TCHECK(*p);
950 peerid_len = *p; /* Peer-ID Length */
951 p++;
952 if (length - (p - p0) < peerid_len)
953 return;
954 ND_PRINT((ndo, ", Peer "));
955 for (i = 0; i < peerid_len; i++) {
956 ND_TCHECK(*p);
957 safeputchar(ndo, *p++);
958 }
959
960 if (length - (p - p0) < 1)
961 return;
962 ND_TCHECK(*p);
963 passwd_len = *p; /* Password Length */
964 p++;
965 if (length - (p - p0) < passwd_len)
966 return;
967 ND_PRINT((ndo, ", Name "));
968 for (i = 0; i < passwd_len; i++) {
969 ND_TCHECK(*p);
970 safeputchar(ndo, *p++);
971 }
972 break;
973 case PAP_AACK:
974 case PAP_ANAK:
975 if (length - (p - p0) < 1)
976 return;
977 ND_TCHECK(*p);
978 msg_len = *p; /* Msg-Length */
979 p++;
980 if (length - (p - p0) < msg_len)
981 return;
982 ND_PRINT((ndo, ", Msg "));
983 for (i = 0; i< msg_len; i++) {
984 ND_TCHECK(*p);
985 safeputchar(ndo, *p++);
986 }
987 break;
988 }
989 return;
990
991 trunc:
992 ND_PRINT((ndo, "[|pap]"));
993 }
994
995 /* BAP */
996 static void
997 handle_bap(netdissect_options *ndo _U_,
998 const u_char *p _U_, int length _U_)
999 {
1000 /* XXX: to be supported!! */
1001 }
1002
1003
1004 /* IPCP config options */
1005 static int
1006 print_ipcp_config_options(netdissect_options *ndo,
1007 const u_char *p, int length)
1008 {
1009 int len, opt;
1010 u_int compproto, ipcomp_subopttotallen, ipcomp_subopt, ipcomp_suboptlen;
1011
1012 if (length < 2)
1013 return 0;
1014 ND_TCHECK2(*p, 2);
1015 len = p[1];
1016 opt = p[0];
1017 if (length < len)
1018 return 0;
1019 if (len < 2) {
1020 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1021 tok2str(ipcpopt_values,"unknown",opt),
1022 opt,
1023 len));
1024 return 0;
1025 }
1026
1027 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u",
1028 tok2str(ipcpopt_values,"unknown",opt),
1029 opt,
1030 len));
1031
1032 switch (opt) {
1033 case IPCPOPT_2ADDR: /* deprecated */
1034 if (len != 10) {
1035 ND_PRINT((ndo, " (length bogus, should be = 10)"));
1036 return len;
1037 }
1038 ND_TCHECK2(*(p + 6), 4);
1039 ND_PRINT((ndo, ": src %s, dst %s",
1040 ipaddr_string(ndo, p + 2),
1041 ipaddr_string(ndo, p + 6)));
1042 break;
1043 case IPCPOPT_IPCOMP:
1044 if (len < 4) {
1045 ND_PRINT((ndo, " (length bogus, should be >= 4)"));
1046 return 0;
1047 }
1048 ND_TCHECK2(*(p + 2), 2);
1049 compproto = EXTRACT_16BITS(p+2);
1050
1051 ND_PRINT((ndo, ": %s (0x%02x):",
1052 tok2str(ipcpopt_compproto_values, "Unknown", compproto),
1053 compproto));
1054
1055 switch (compproto) {
1056 case PPP_VJC:
1057 /* XXX: VJ-Comp parameters should be decoded */
1058 break;
1059 case IPCPOPT_IPCOMP_HDRCOMP:
1060 if (len < IPCPOPT_IPCOMP_MINLEN) {
1061 ND_PRINT((ndo, " (length bogus, should be >= %u)",
1062 IPCPOPT_IPCOMP_MINLEN));
1063 return 0;
1064 }
1065
1066 ND_TCHECK2(*(p + 2), IPCPOPT_IPCOMP_MINLEN);
1067 ND_PRINT((ndo, "\n\t TCP Space %u, non-TCP Space %u" \
1068 ", maxPeriod %u, maxTime %u, maxHdr %u",
1069 EXTRACT_16BITS(p+4),
1070 EXTRACT_16BITS(p+6),
1071 EXTRACT_16BITS(p+8),
1072 EXTRACT_16BITS(p+10),
1073 EXTRACT_16BITS(p+12)));
1074
1075 /* suboptions present ? */
1076 if (len > IPCPOPT_IPCOMP_MINLEN) {
1077 ipcomp_subopttotallen = len - IPCPOPT_IPCOMP_MINLEN;
1078 p += IPCPOPT_IPCOMP_MINLEN;
1079
1080 ND_PRINT((ndo, "\n\t Suboptions, length %u", ipcomp_subopttotallen));
1081
1082 while (ipcomp_subopttotallen >= 2) {
1083 ND_TCHECK2(*p, 2);
1084 ipcomp_subopt = *p;
1085 ipcomp_suboptlen = *(p+1);
1086
1087 /* sanity check */
1088 if (ipcomp_subopt == 0 ||
1089 ipcomp_suboptlen == 0 )
1090 break;
1091
1092 /* XXX: just display the suboptions for now */
1093 ND_PRINT((ndo, "\n\t\t%s Suboption #%u, length %u",
1094 tok2str(ipcpopt_compproto_subopt_values,
1095 "Unknown",
1096 ipcomp_subopt),
1097 ipcomp_subopt,
1098 ipcomp_suboptlen));
1099
1100 ipcomp_subopttotallen -= ipcomp_suboptlen;
1101 p += ipcomp_suboptlen;
1102 }
1103 }
1104 break;
1105 default:
1106 break;
1107 }
1108 break;
1109
1110 case IPCPOPT_ADDR: /* those options share the same format - fall through */
1111 case IPCPOPT_MOBILE4:
1112 case IPCPOPT_PRIDNS:
1113 case IPCPOPT_PRINBNS:
1114 case IPCPOPT_SECDNS:
1115 case IPCPOPT_SECNBNS:
1116 if (len != 6) {
1117 ND_PRINT((ndo, " (length bogus, should be = 6)"));
1118 return 0;
1119 }
1120 ND_TCHECK2(*(p + 2), 4);
1121 ND_PRINT((ndo, ": %s", ipaddr_string(ndo, p + 2)));
1122 break;
1123 default:
1124 /*
1125 * Unknown option; dump it as raw bytes now if we're
1126 * not going to do so below.
1127 */
1128 if (ndo->ndo_vflag < 2)
1129 print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
1130 break;
1131 }
1132 if (ndo->ndo_vflag > 1)
1133 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
1134 return len;
1135
1136 trunc:
1137 ND_PRINT((ndo, "[|ipcp]"));
1138 return 0;
1139 }
1140
1141 /* IP6CP config options */
1142 static int
1143 print_ip6cp_config_options(netdissect_options *ndo,
1144 const u_char *p, int length)
1145 {
1146 int len, opt;
1147
1148 if (length < 2)
1149 return 0;
1150 ND_TCHECK2(*p, 2);
1151 len = p[1];
1152 opt = p[0];
1153 if (length < len)
1154 return 0;
1155 if (len < 2) {
1156 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1157 tok2str(ip6cpopt_values,"unknown",opt),
1158 opt,
1159 len));
1160 return 0;
1161 }
1162
1163 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u",
1164 tok2str(ip6cpopt_values,"unknown",opt),
1165 opt,
1166 len));
1167
1168 switch (opt) {
1169 case IP6CP_IFID:
1170 if (len != 10) {
1171 ND_PRINT((ndo, " (length bogus, should be = 10)"));
1172 return len;
1173 }
1174 ND_TCHECK2(*(p + 2), 8);
1175 ND_PRINT((ndo, ": %04x:%04x:%04x:%04x",
1176 EXTRACT_16BITS(p + 2),
1177 EXTRACT_16BITS(p + 4),
1178 EXTRACT_16BITS(p + 6),
1179 EXTRACT_16BITS(p + 8)));
1180 break;
1181 default:
1182 /*
1183 * Unknown option; dump it as raw bytes now if we're
1184 * not going to do so below.
1185 */
1186 if (ndo->ndo_vflag < 2)
1187 print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
1188 break;
1189 }
1190 if (ndo->ndo_vflag > 1)
1191 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
1192
1193 return len;
1194
1195 trunc:
1196 ND_PRINT((ndo, "[|ip6cp]"));
1197 return 0;
1198 }
1199
1200
1201 /* CCP config options */
1202 static int
1203 print_ccp_config_options(netdissect_options *ndo,
1204 const u_char *p, int length)
1205 {
1206 int len, opt;
1207
1208 if (length < 2)
1209 return 0;
1210 ND_TCHECK2(*p, 2);
1211 len = p[1];
1212 opt = p[0];
1213 if (length < len)
1214 return 0;
1215 if (len < 2) {
1216 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1217 tok2str(ccpconfopts_values, "Unknown", opt),
1218 opt,
1219 len));
1220 return 0;
1221 }
1222
1223 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u",
1224 tok2str(ccpconfopts_values, "Unknown", opt),
1225 opt,
1226 len));
1227
1228 switch (opt) {
1229 case CCPOPT_BSDCOMP:
1230 if (len < 3) {
1231 ND_PRINT((ndo, " (length bogus, should be >= 3)"));
1232 return len;
1233 }
1234 ND_TCHECK2(*(p + 2), 1);
1235 ND_PRINT((ndo, ": Version: %u, Dictionary Bits: %u",
1236 p[2] >> 5, p[2] & 0x1f));
1237 break;
1238 case CCPOPT_MVRCA:
1239 if (len < 4) {
1240 ND_PRINT((ndo, " (length bogus, should be >= 4)"));
1241 return len;
1242 }
1243 ND_TCHECK2(*(p + 2), 1);
1244 ND_PRINT((ndo, ": Features: %u, PxP: %s, History: %u, #CTX-ID: %u",
1245 (p[2] & 0xc0) >> 6,
1246 (p[2] & 0x20) ? "Enabled" : "Disabled",
1247 p[2] & 0x1f, p[3]));
1248 break;
1249 case CCPOPT_DEFLATE:
1250 if (len < 4) {
1251 ND_PRINT((ndo, " (length bogus, should be >= 4)"));
1252 return len;
1253 }
1254 ND_TCHECK2(*(p + 2), 1);
1255 ND_PRINT((ndo, ": Window: %uK, Method: %s (0x%x), MBZ: %u, CHK: %u",
1256 (p[2] & 0xf0) >> 4,
1257 ((p[2] & 0x0f) == 8) ? "zlib" : "unkown",
1258 p[2] & 0x0f, (p[3] & 0xfc) >> 2, p[3] & 0x03));
1259 break;
1260
1261 /* XXX: to be supported */
1262 #if 0
1263 case CCPOPT_OUI:
1264 case CCPOPT_PRED1:
1265 case CCPOPT_PRED2:
1266 case CCPOPT_PJUMP:
1267 case CCPOPT_HPPPC:
1268 case CCPOPT_STACLZS:
1269 case CCPOPT_MPPC:
1270 case CCPOPT_GFZA:
1271 case CCPOPT_V42BIS:
1272 case CCPOPT_LZSDCP:
1273 case CCPOPT_DEC:
1274 case CCPOPT_RESV:
1275 break;
1276 #endif
1277 default:
1278 /*
1279 * Unknown option; dump it as raw bytes now if we're
1280 * not going to do so below.
1281 */
1282 if (ndo->ndo_vflag < 2)
1283 print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
1284 break;
1285 }
1286 if (ndo->ndo_vflag > 1)
1287 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
1288
1289 return len;
1290
1291 trunc:
1292 ND_PRINT((ndo, "[|ccp]"));
1293 return 0;
1294 }
1295
1296 /* BACP config options */
1297 static int
1298 print_bacp_config_options(netdissect_options *ndo,
1299 const u_char *p, int length)
1300 {
1301 int len, opt;
1302
1303 if (length < 2)
1304 return 0;
1305 ND_TCHECK2(*p, 2);
1306 len = p[1];
1307 opt = p[0];
1308 if (length < len)
1309 return 0;
1310 if (len < 2) {
1311 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)",
1312 tok2str(bacconfopts_values, "Unknown", opt),
1313 opt,
1314 len));
1315 return 0;
1316 }
1317
1318 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u",
1319 tok2str(bacconfopts_values, "Unknown", opt),
1320 opt,
1321 len));
1322
1323 switch (opt) {
1324 case BACPOPT_FPEER:
1325 if (len != 6) {
1326 ND_PRINT((ndo, " (length bogus, should be = 6)"));
1327 return len;
1328 }
1329 ND_TCHECK2(*(p + 2), 4);
1330 ND_PRINT((ndo, ": Magic-Num 0x%08x", EXTRACT_32BITS(p + 2)));
1331 break;
1332 default:
1333 /*
1334 * Unknown option; dump it as raw bytes now if we're
1335 * not going to do so below.
1336 */
1337 if (ndo->ndo_vflag < 2)
1338 print_unknown_data(ndo, &p[2], "\n\t ", len - 2);
1339 break;
1340 }
1341 if (ndo->ndo_vflag > 1)
1342 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */
1343
1344 return len;
1345
1346 trunc:
1347 ND_PRINT((ndo, "[|bacp]"));
1348 return 0;
1349 }
1350
1351 static void
1352 ppp_hdlc(netdissect_options *ndo,
1353 const u_char *p, int length)
1354 {
1355 u_char *b, *t, c;
1356 const u_char *s;
1357 int i, proto;
1358 const void *se;
1359
1360 if (length <= 0)
1361 return;
1362
1363 b = (u_char *)malloc(length);
1364 if (b == NULL)
1365 return;
1366
1367 /*
1368 * Unescape all the data into a temporary, private, buffer.
1369 * Do this so that we dont overwrite the original packet
1370 * contents.
1371 */
1372 for (s = p, t = b, i = length; i > 0 && ND_TTEST(*s); i--) {
1373 c = *s++;
1374 if (c == 0x7d) {
1375 if (i <= 1 || !ND_TTEST(*s))
1376 break;
1377 i--;
1378 c = *s++ ^ 0x20;
1379 }
1380 *t++ = c;
1381 }
1382
1383 se = ndo->ndo_snapend;
1384 ndo->ndo_snapend = t;
1385 length = t - b;
1386
1387 /* now lets guess about the payload codepoint format */
1388 if (length < 1)
1389 goto trunc;
1390 proto = *b; /* start with a one-octet codepoint guess */
1391
1392 switch (proto) {
1393 case PPP_IP:
1394 ip_print(ndo, b + 1, length - 1);
1395 goto cleanup;
1396 case PPP_IPV6:
1397 ip6_print(ndo, b + 1, length - 1);
1398 goto cleanup;
1399 default: /* no luck - try next guess */
1400 break;
1401 }
1402
1403 if (length < 2)
1404 goto trunc;
1405 proto = EXTRACT_16BITS(b); /* next guess - load two octets */
1406
1407 switch (proto) {
1408 case (PPP_ADDRESS << 8 | PPP_CONTROL): /* looks like a PPP frame */
1409 if (length < 4)
1410 goto trunc;
1411 proto = EXTRACT_16BITS(b+2); /* load the PPP proto-id */
1412 handle_ppp(ndo, proto, b + 4, length - 4);
1413 break;
1414 default: /* last guess - proto must be a PPP proto-id */
1415 handle_ppp(ndo, proto, b + 2, length - 2);
1416 break;
1417 }
1418
1419 cleanup:
1420 ndo->ndo_snapend = se;
1421 free(b);
1422 return;
1423
1424 trunc:
1425 ndo->ndo_snapend = se;
1426 free(b);
1427 ND_PRINT((ndo, "[|ppp]"));
1428 }
1429
1430
1431 /* PPP */
1432 static void
1433 handle_ppp(netdissect_options *ndo,
1434 u_int proto, const u_char *p, int length)
1435 {
1436 if ((proto & 0xff00) == 0x7e00) { /* is this an escape code ? */
1437 ppp_hdlc(ndo, p - 1, length);
1438 return;
1439 }
1440
1441 switch (proto) {
1442 case PPP_LCP: /* fall through */
1443 case PPP_IPCP:
1444 case PPP_OSICP:
1445 case PPP_MPLSCP:
1446 case PPP_IPV6CP:
1447 case PPP_CCP:
1448 case PPP_BACP:
1449 handle_ctrl_proto(ndo, proto, p, length);
1450 break;
1451 case PPP_ML:
1452 handle_mlppp(ndo, p, length);
1453 break;
1454 case PPP_CHAP:
1455 handle_chap(ndo, p, length);
1456 break;
1457 case PPP_PAP:
1458 handle_pap(ndo, p, length);
1459 break;
1460 case PPP_BAP: /* XXX: not yet completed */
1461 handle_bap(ndo, p, length);
1462 break;
1463 case ETHERTYPE_IP: /*XXX*/
1464 case PPP_VJNC:
1465 case PPP_IP:
1466 ip_print(ndo, p, length);
1467 break;
1468 case ETHERTYPE_IPV6: /*XXX*/
1469 case PPP_IPV6:
1470 ip6_print(ndo, p, length);
1471 break;
1472 case ETHERTYPE_IPX: /*XXX*/
1473 case PPP_IPX:
1474 ipx_print(ndo, p, length);
1475 break;
1476 case PPP_OSI:
1477 isoclns_print(ndo, p, length, length);
1478 break;
1479 case PPP_MPLS_UCAST:
1480 case PPP_MPLS_MCAST:
1481 mpls_print(ndo, p, length);
1482 break;
1483 case PPP_COMP:
1484 ND_PRINT((ndo, "compressed PPP data"));
1485 break;
1486 default:
1487 ND_PRINT((ndo, "%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto)));
1488 print_unknown_data(ndo, p, "\n\t", length);
1489 break;
1490 }
1491 }
1492
1493 /* Standard PPP printer */
1494 u_int
1495 ppp_print(netdissect_options *ndo,
1496 register const u_char *p, u_int length)
1497 {
1498 u_int proto,ppp_header;
1499 u_int olen = length; /* _o_riginal length */
1500 u_int hdr_len = 0;
1501
1502 /*
1503 * Here, we assume that p points to the Address and Control
1504 * field (if they present).
1505 */
1506 if (length < 2)
1507 goto trunc;
1508 ND_TCHECK2(*p, 2);
1509 ppp_header = EXTRACT_16BITS(p);
1510
1511 switch(ppp_header) {
1512 case (PPP_WITHDIRECTION_IN << 8 | PPP_CONTROL):
1513 if (ndo->ndo_eflag) ND_PRINT((ndo, "In "));
1514 p += 2;
1515 length -= 2;
1516 hdr_len += 2;
1517 break;
1518 case (PPP_WITHDIRECTION_OUT << 8 | PPP_CONTROL):
1519 if (ndo->ndo_eflag) ND_PRINT((ndo, "Out "));
1520 p += 2;
1521 length -= 2;
1522 hdr_len += 2;
1523 break;
1524 case (PPP_ADDRESS << 8 | PPP_CONTROL):
1525 p += 2; /* ACFC not used */
1526 length -= 2;
1527 hdr_len += 2;
1528 break;
1529
1530 default:
1531 break;
1532 }
1533
1534 if (length < 2)
1535 goto trunc;
1536 ND_TCHECK(*p);
1537 if (*p % 2) {
1538 proto = *p; /* PFC is used */
1539 p++;
1540 length--;
1541 hdr_len++;
1542 } else {
1543 ND_TCHECK2(*p, 2);
1544 proto = EXTRACT_16BITS(p);
1545 p += 2;
1546 length -= 2;
1547 hdr_len += 2;
1548 }
1549
1550 if (ndo->ndo_eflag)
1551 ND_PRINT((ndo, "%s (0x%04x), length %u: ",
1552 tok2str(ppptype2str, "unknown", proto),
1553 proto,
1554 olen));
1555
1556 handle_ppp(ndo, proto, p, length);
1557 return (hdr_len);
1558 trunc:
1559 ND_PRINT((ndo, "[|ppp]"));
1560 return (0);
1561 }
1562
1563
1564 /* PPP I/F printer */
1565 u_int
1566 ppp_if_print(netdissect_options *ndo,
1567 const struct pcap_pkthdr *h, register const u_char *p)
1568 {
1569 register u_int length = h->len;
1570 register u_int caplen = h->caplen;
1571
1572 if (caplen < PPP_HDRLEN) {
1573 ND_PRINT((ndo, "[|ppp]"));
1574 return (caplen);
1575 }
1576
1577 #if 0
1578 /*
1579 * XXX: seems to assume that there are 2 octets prepended to an
1580 * actual PPP frame. The 1st octet looks like Input/Output flag
1581 * while 2nd octet is unknown, at least to me
1582 * (mshindo@mshindo.net).
1583 *
1584 * That was what the original tcpdump code did.
1585 *
1586 * FreeBSD's "if_ppp.c" *does* set the first octet to 1 for outbound
1587 * packets and 0 for inbound packets - but only if the
1588 * protocol field has the 0x8000 bit set (i.e., it's a network
1589 * control protocol); it does so before running the packet through
1590 * "bpf_filter" to see if it should be discarded, and to see
1591 * if we should update the time we sent the most recent packet...
1592 *
1593 * ...but it puts the original address field back after doing
1594 * so.
1595 *
1596 * NetBSD's "if_ppp.c" doesn't set the first octet in that fashion.
1597 *
1598 * I don't know if any PPP implementation handed up to a BPF
1599 * device packets with the first octet being 1 for outbound and
1600 * 0 for inbound packets, so I (guy@alum.mit.edu) don't know
1601 * whether that ever needs to be checked or not.
1602 *
1603 * Note that NetBSD has a DLT_PPP_SERIAL, which it uses for PPP,
1604 * and its tcpdump appears to assume that the frame always
1605 * begins with an address field and a control field, and that
1606 * the address field might be 0x0f or 0x8f, for Cisco
1607 * point-to-point with HDLC framing as per section 4.3.1 of RFC
1608 * 1547, as well as 0xff, for PPP in HDLC-like framing as per
1609 * RFC 1662.
1610 *
1611 * (Is the Cisco framing in question what DLT_C_HDLC, in
1612 * BSD/OS, is?)
1613 */
1614 if (ndo->ndo_eflag)
1615 ND_PRINT((ndo, "%c %4d %02x ", p[0] ? 'O' : 'I', length, p[1]));
1616 #endif
1617
1618 ppp_print(ndo, p, length);
1619
1620 return (0);
1621 }
1622
1623 /*
1624 * PPP I/F printer to use if we know that RFC 1662-style PPP in HDLC-like
1625 * framing, or Cisco PPP with HDLC framing as per section 4.3.1 of RFC 1547,
1626 * is being used (i.e., we don't check for PPP_ADDRESS and PPP_CONTROL,
1627 * discard them *if* those are the first two octets, and parse the remaining
1628 * packet as a PPP packet, as "ppp_print()" does).
1629 *
1630 * This handles, for example, DLT_PPP_SERIAL in NetBSD.
1631 */
1632 u_int
1633 ppp_hdlc_if_print(netdissect_options *ndo,
1634 const struct pcap_pkthdr *h, register const u_char *p)
1635 {
1636 register u_int length = h->len;
1637 register u_int caplen = h->caplen;
1638 u_int proto;
1639 u_int hdrlen = 0;
1640
1641 if (caplen < 2) {
1642 ND_PRINT((ndo, "[|ppp]"));
1643 return (caplen);
1644 }
1645
1646 switch (p[0]) {
1647
1648 case PPP_ADDRESS:
1649 if (caplen < 4) {
1650 ND_PRINT((ndo, "[|ppp]"));
1651 return (caplen);
1652 }
1653
1654 if (ndo->ndo_eflag)
1655 ND_PRINT((ndo, "%02x %02x %d ", p[0], p[1], length));
1656 p += 2;
1657 length -= 2;
1658 hdrlen += 2;
1659
1660 proto = EXTRACT_16BITS(p);
1661 p += 2;
1662 length -= 2;
1663 hdrlen += 2;
1664 ND_PRINT((ndo, "%s: ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto)));
1665
1666 handle_ppp(ndo, proto, p, length);
1667 break;
1668
1669 case CHDLC_UNICAST:
1670 case CHDLC_BCAST:
1671 return (chdlc_if_print(ndo, h, p));
1672
1673 default:
1674 if (ndo->ndo_eflag)
1675 ND_PRINT((ndo, "%02x %02x %d ", p[0], p[1], length));
1676 p += 2;
1677 hdrlen += 2;
1678
1679 /*
1680 * XXX - NetBSD's "ppp_netbsd_serial_if_print()" treats
1681 * the next two octets as an Ethernet type; does that
1682 * ever happen?
1683 */
1684 ND_PRINT((ndo, "unknown addr %02x; ctrl %02x", p[0], p[1]));
1685 break;
1686 }
1687
1688 return (hdrlen);
1689 }
1690
1691 #define PPP_BSDI_HDRLEN 24
1692
1693 /* BSD/OS specific PPP printer */
1694 u_int
1695 ppp_bsdos_if_print(netdissect_options *ndo _U_,
1696 const struct pcap_pkthdr *h _U_, register const u_char *p _U_)
1697 {
1698 register int hdrlength;
1699 #ifdef __bsdi__
1700 register u_int length = h->len;
1701 register u_int caplen = h->caplen;
1702 uint16_t ptype;
1703 const u_char *q;
1704 int i;
1705
1706 if (caplen < PPP_BSDI_HDRLEN) {
1707 ND_PRINT((ndo, "[|ppp]"));
1708 return (caplen)
1709 }
1710
1711 hdrlength = 0;
1712
1713 #if 0
1714 if (p[0] == PPP_ADDRESS && p[1] == PPP_CONTROL) {
1715 if (ndo->ndo_eflag)
1716 ND_PRINT((ndo, "%02x %02x ", p[0], p[1]));
1717 p += 2;
1718 hdrlength = 2;
1719 }
1720
1721 if (ndo->ndo_eflag)
1722 ND_PRINT((ndo, "%d ", length));
1723 /* Retrieve the protocol type */
1724 if (*p & 01) {
1725 /* Compressed protocol field */
1726 ptype = *p;
1727 if (ndo->ndo_eflag)
1728 ND_PRINT((ndo, "%02x ", ptype));
1729 p++;
1730 hdrlength += 1;
1731 } else {
1732 /* Un-compressed protocol field */
1733 ptype = EXTRACT_16BITS(p);
1734 if (ndo->ndo_eflag)
1735 ND_PRINT((ndo, "%04x ", ptype));
1736 p += 2;
1737 hdrlength += 2;
1738 }
1739 #else
1740 ptype = 0; /*XXX*/
1741 if (ndo->ndo_eflag)
1742 ND_PRINT((ndo, "%c ", p[SLC_DIR] ? 'O' : 'I'));
1743 if (p[SLC_LLHL]) {
1744 /* link level header */
1745 struct ppp_header *ph;
1746
1747 q = p + SLC_BPFHDRLEN;
1748 ph = (struct ppp_header *)q;
1749 if (ph->phdr_addr == PPP_ADDRESS
1750 && ph->phdr_ctl == PPP_CONTROL) {
1751 if (ndo->ndo_eflag)
1752 ND_PRINT((ndo, "%02x %02x ", q[0], q[1]));
1753 ptype = EXTRACT_16BITS(&ph->phdr_type);
1754 if (ndo->ndo_eflag && (ptype == PPP_VJC || ptype == PPP_VJNC)) {
1755 ND_PRINT((ndo, "%s ", tok2str(ppptype2str,
1756 "proto-#%d", ptype)));
1757 }
1758 } else {
1759 if (ndo->ndo_eflag) {
1760 ND_PRINT((ndo, "LLH=["));
1761 for (i = 0; i < p[SLC_LLHL]; i++)
1762 ND_PRINT((ndo, "%02x", q[i]));
1763 ND_PRINT((ndo, "] "));
1764 }
1765 }
1766 }
1767 if (ndo->ndo_eflag)
1768 ND_PRINT((ndo, "%d ", length));
1769 if (p[SLC_CHL]) {
1770 q = p + SLC_BPFHDRLEN + p[SLC_LLHL];
1771
1772 switch (ptype) {
1773 case PPP_VJC:
1774 ptype = vjc_print(ndo, q, ptype);
1775 hdrlength = PPP_BSDI_HDRLEN;
1776 p += hdrlength;
1777 switch (ptype) {
1778 case PPP_IP:
1779 ip_print(ndo, p, length);
1780 break;
1781 case PPP_IPV6:
1782 ip6_print(ndo, p, length);
1783 break;
1784 case PPP_MPLS_UCAST:
1785 case PPP_MPLS_MCAST:
1786 mpls_print(ndo, p, length);
1787 break;
1788 }
1789 goto printx;
1790 case PPP_VJNC:
1791 ptype = vjc_print(ndo, q, ptype);
1792 hdrlength = PPP_BSDI_HDRLEN;
1793 p += hdrlength;
1794 switch (ptype) {
1795 case PPP_IP:
1796 ip_print(ndo, p, length);
1797 break;
1798 case PPP_IPV6:
1799 ip6_print(ndo, p, length);
1800 break;
1801 case PPP_MPLS_UCAST:
1802 case PPP_MPLS_MCAST:
1803 mpls_print(ndo, p, length);
1804 break;
1805 }
1806 goto printx;
1807 default:
1808 if (ndo->ndo_eflag) {
1809 ND_PRINT((ndo, "CH=["));
1810 for (i = 0; i < p[SLC_LLHL]; i++)
1811 ND_PRINT((ndo, "%02x", q[i]));
1812 ND_PRINT((ndo, "] "));
1813 }
1814 break;
1815 }
1816 }
1817
1818 hdrlength = PPP_BSDI_HDRLEN;
1819 #endif
1820
1821 length -= hdrlength;
1822 p += hdrlength;
1823
1824 switch (ptype) {
1825 case PPP_IP:
1826 ip_print(p, length);
1827 break;
1828 case PPP_IPV6:
1829 ip6_print(ndo, p, length);
1830 break;
1831 case PPP_MPLS_UCAST:
1832 case PPP_MPLS_MCAST:
1833 mpls_print(ndo, p, length);
1834 break;
1835 default:
1836 ND_PRINT((ndo, "%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", ptype)));
1837 }
1838
1839 printx:
1840 #else /* __bsdi */
1841 hdrlength = 0;
1842 #endif /* __bsdi__ */
1843 return (hdrlength);
1844 }
1845
1846
1847 /*
1848 * Local Variables:
1849 * c-style: whitesmith
1850 * c-basic-offset: 8
1851 * End:
1852 */