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