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