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