print-ppp.c (98527) | print-ppp.c (127675) |
---|---|
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 --- 7 unchanged lines hidden (view full) --- 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 * | 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 --- 7 unchanged lines hidden (view full) --- 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 * $FreeBSD: head/contrib/tcpdump/print-ppp.c 98527 2002-06-21 00:49:02Z fenner $ | 24 * $FreeBSD: head/contrib/tcpdump/print-ppp.c 127675 2004-03-31 14:57:24Z bms $ |
25 */ 26 27/* 28 * TODO: 29 * o resolve XXX as much as possible 30 * o MP support 31 * o BAP support 32 */ 33 34#ifndef lint | 25 */ 26 27/* 28 * TODO: 29 * o resolve XXX as much as possible 30 * o MP support 31 * o BAP support 32 */ 33 34#ifndef lint |
35static const char rcsid[] = 36 "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.64 2001/09/09 02:04:19 guy Exp $ (LBL)"; | 35static const char rcsid[] _U_ = 36 "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.89.2.3 2004/03/24 03:32:43 guy Exp $ (LBL)"; |
37#endif 38 39#ifdef HAVE_CONFIG_H 40#include "config.h" 41#endif 42 | 37#endif 38 39#ifdef HAVE_CONFIG_H 40#include "config.h" 41#endif 42 |
43#include <sys/param.h> 44#include <sys/time.h> | 43#include <tcpdump-stdinc.h> |
45 46#ifdef __bsdi__ 47#include <net/slcompress.h> 48#include <net/if_ppp.h> 49#endif 50 | 44 45#ifdef __bsdi__ 46#include <net/slcompress.h> 47#include <net/if_ppp.h> 48#endif 49 |
51#include <netinet/in.h> 52 53#include <ctype.h> 54#include <netdb.h> | |
55#include <pcap.h> 56#include <stdio.h> 57 58#include "interface.h" 59#include "extract.h" 60#include "addrtoname.h" 61#include "ppp.h" 62#include "chdlc.h" 63#include "ethertype.h" 64 65/* 66 * The following constatns are defined by IANA. Please refer to 67 * http://www.isi.edu/in-notes/iana/assignments/ppp-numbers 68 * for the up-to-date information. 69 */ 70 | 50#include <pcap.h> 51#include <stdio.h> 52 53#include "interface.h" 54#include "extract.h" 55#include "addrtoname.h" 56#include "ppp.h" 57#include "chdlc.h" 58#include "ethertype.h" 59 60/* 61 * The following constatns are defined by IANA. Please refer to 62 * http://www.isi.edu/in-notes/iana/assignments/ppp-numbers 63 * for the up-to-date information. 64 */ 65 |
71/* Control Protocols (LCP/IPCP/CCP etc.) Codes */ | 66/* Protocol Codes defined in ppp.h */ |
72 | 67 |
68struct tok ppptype2str[] = { 69 { PPP_IP, "IP" }, 70 { PPP_OSI, "OSI" }, 71 { PPP_NS, "NS" }, 72 { PPP_DECNET, "DECNET" }, 73 { PPP_APPLE, "APPLE" }, 74 { PPP_IPX, "IPX" }, 75 { PPP_VJC, "VJC" }, 76 { PPP_VJNC, "VJNC" }, 77 { PPP_BRPDU, "BRPDU" }, 78 { PPP_STII, "STII" }, 79 { PPP_VINES, "VINES" }, 80 { PPP_MPLS_UCAST, "MPLS" }, 81 { PPP_MPLS_MCAST, "MPLS" }, 82 83 { PPP_HELLO, "HELLO" }, 84 { PPP_LUXCOM, "LUXCOM" }, 85 { PPP_SNS, "SNS" }, 86 { PPP_IPCP, "IPCP" }, 87 { PPP_OSICP, "OSICP" }, 88 { PPP_NSCP, "NSCP" }, 89 { PPP_DECNETCP, "DECNETCP" }, 90 { PPP_APPLECP, "APPLECP" }, 91 { PPP_IPXCP, "IPXCP" }, 92 { PPP_STIICP, "STIICP" }, 93 { PPP_VINESCP, "VINESCP" }, 94 { PPP_MPLSCP, "MPLSCP" }, 95 96 { PPP_LCP, "LCP" }, 97 { PPP_PAP, "PAP" }, 98 { PPP_LQM, "LQM" }, 99 { PPP_CHAP, "CHAP" }, 100 { PPP_BACP, "BACP" }, 101 { PPP_BAP, "BAP" }, 102 { PPP_MP, "ML" }, 103 { 0, NULL } 104}; 105 106/* Control Protocols (LCP/IPCP/CCP etc.) Codes defined in RFC 1661 */ 107 |
|
73#define CPCODES_VEXT 0 /* Vendor-Specific (RFC2153) */ 74#define CPCODES_CONF_REQ 1 /* Configure-Request */ 75#define CPCODES_CONF_ACK 2 /* Configure-Ack */ 76#define CPCODES_CONF_NAK 3 /* Configure-Nak */ 77#define CPCODES_CONF_REJ 4 /* Configure-Reject */ 78#define CPCODES_TERM_REQ 5 /* Terminate-Request */ 79#define CPCODES_TERM_ACK 6 /* Terminate-Ack */ 80#define CPCODES_CODE_REJ 7 /* Code-Reject */ 81#define CPCODES_PROT_REJ 8 /* Protocol-Reject (LCP only) */ 82#define CPCODES_ECHO_REQ 9 /* Echo-Request (LCP only) */ 83#define CPCODES_ECHO_RPL 10 /* Echo-Reply (LCP only) */ 84#define CPCODES_DISC_REQ 11 /* Discard-Request (LCP only) */ | 108#define CPCODES_VEXT 0 /* Vendor-Specific (RFC2153) */ 109#define CPCODES_CONF_REQ 1 /* Configure-Request */ 110#define CPCODES_CONF_ACK 2 /* Configure-Ack */ 111#define CPCODES_CONF_NAK 3 /* Configure-Nak */ 112#define CPCODES_CONF_REJ 4 /* Configure-Reject */ 113#define CPCODES_TERM_REQ 5 /* Terminate-Request */ 114#define CPCODES_TERM_ACK 6 /* Terminate-Ack */ 115#define CPCODES_CODE_REJ 7 /* Code-Reject */ 116#define CPCODES_PROT_REJ 8 /* Protocol-Reject (LCP only) */ 117#define CPCODES_ECHO_REQ 9 /* Echo-Request (LCP only) */ 118#define CPCODES_ECHO_RPL 10 /* Echo-Reply (LCP only) */ 119#define CPCODES_DISC_REQ 11 /* Discard-Request (LCP only) */ |
85#define CPCODES_ID 12 /* Identification (LCP only) */ 86#define CPCODES_TIME_REM 13 /* Time-Remaining (LCP only) */ 87#define CPCODES_RESET_REQ 14 /* Reset-Request (CCP only) */ | 120#define CPCODES_ID 12 /* Identification (LCP only) RFC1570 */ 121#define CPCODES_TIME_REM 13 /* Time-Remaining (LCP only) RFC1570 */ 122#define CPCODES_RESET_REQ 14 /* Reset-Request (CCP only) RFC1962 */ |
88#define CPCODES_RESET_REP 15 /* Reset-Reply (CCP only) */ 89 | 123#define CPCODES_RESET_REP 15 /* Reset-Reply (CCP only) */ 124 |
90#define CPCODES_MIN CPCODES_VEXT 91#define CPCODES_MAX CPCODES_RESET_REP 92 93static const char *cpcodes[] = { 94 /* 95 * Control Protocol code values (RFC1661) 96 */ 97 "Vend-Ext", /* (0) RFC2153 */ 98 "Conf-Req", /* (1) */ 99 "Conf-Ack", /* (2) */ 100 "Conf-Nak", /* (3) */ 101 "Conf-Rej", /* (4) */ 102 "Term-Req", /* (5) */ 103 "Term-Ack", /* (6) */ 104 "Code-Rej", /* (7) */ 105 "Prot-Rej", /* (8) */ 106 "Echo-Req", /* (9) */ 107 "Echo-Rep", /* (10) */ 108 "Disc-Req", /* (11) */ 109 "Ident", /* (12) RFC1570 */ 110 "Time-Rem", /* (13) RFC1570 */ 111 "Reset-Req", /* (14) RFC1962 */ 112 "Reset-Ack", /* (15) RFC1962 */ | 125struct tok cpcodes[] = { 126 {CPCODES_VEXT, "Vendor-Extension"}, /* RFC2153 */ 127 {CPCODES_CONF_REQ, "Conf-Request"}, 128 {CPCODES_CONF_ACK, "Conf-Ack"}, 129 {CPCODES_CONF_NAK, "Conf-Nack"}, 130 {CPCODES_CONF_REJ, "Conf-Reject"}, 131 {CPCODES_TERM_REQ, "Term-Request"}, 132 {CPCODES_TERM_ACK, "Term-Ack"}, 133 {CPCODES_CODE_REJ, "Code-Reject"}, 134 {CPCODES_PROT_REJ, "Prot-Reject"}, 135 {CPCODES_ECHO_REQ, "Echo-Request"}, 136 {CPCODES_ECHO_RPL, "Echo-Reply"}, 137 {CPCODES_DISC_REQ, "Disc-Req"}, 138 {CPCODES_ID, "Ident"}, /* RFC1570 */ 139 {CPCODES_TIME_REM, "Time-Rem"}, /* RFC1570 */ 140 {CPCODES_RESET_REQ, "Reset-Req"}, /* RFC1962 */ 141 {CPCODES_RESET_REP, "Reset-Ack"}, /* RFC1962 */ 142 {0, NULL} |
113}; 114 115/* LCP Config Options */ 116 117#define LCPOPT_VEXT 0 118#define LCPOPT_MRU 1 119#define LCPOPT_ACCM 2 120#define LCPOPT_AP 3 --- 137 unchanged lines hidden (view full) --- 258#define IPCPOPT_SECDNS 131 /* RFC1877 */ 259#define IPCPOPT_SECNBNS 132 /* RFC1877 */ 260 261/* ATCP - to be supported */ 262/* OSINLCP - to be supported */ 263/* BVCP - to be supported */ 264/* BCP - to be supported */ 265/* IPXCP - to be supported */ | 143}; 144 145/* LCP Config Options */ 146 147#define LCPOPT_VEXT 0 148#define LCPOPT_MRU 1 149#define LCPOPT_ACCM 2 150#define LCPOPT_AP 3 --- 137 unchanged lines hidden (view full) --- 288#define IPCPOPT_SECDNS 131 /* RFC1877 */ 289#define IPCPOPT_SECNBNS 132 /* RFC1877 */ 290 291/* ATCP - to be supported */ 292/* OSINLCP - to be supported */ 293/* BVCP - to be supported */ 294/* BCP - to be supported */ 295/* IPXCP - to be supported */ |
296/* MPLSCP - to be supported */ |
|
266 267/* Auth Algorithms */ 268 269/* 0-4 Reserved (RFC1994) */ 270#define AUTHALG_CHAPMD5 5 /* RFC1994 */ 271#define AUTHALG_MSCHAP1 128 /* RFC2433 */ 272#define AUTHALG_MSCHAP2 129 /* RFC2795 */ 273 --- 52 unchanged lines hidden (view full) --- 326#define BAP_CALLRES 2 327#define BAP_CBREQ 3 328#define BAP_CBRES 4 329#define BAP_LDQREQ 5 330#define BAP_LDQRES 6 331#define BAP_CSIND 7 332#define BAP_CSRES 8 333 | 297 298/* Auth Algorithms */ 299 300/* 0-4 Reserved (RFC1994) */ 301#define AUTHALG_CHAPMD5 5 /* RFC1994 */ 302#define AUTHALG_MSCHAP1 128 /* RFC2433 */ 303#define AUTHALG_MSCHAP2 129 /* RFC2795 */ 304 --- 52 unchanged lines hidden (view full) --- 357#define BAP_CALLRES 2 358#define BAP_CBREQ 3 359#define BAP_CBRES 4 360#define BAP_LDQREQ 5 361#define BAP_LDQRES 6 362#define BAP_CSIND 7 363#define BAP_CSRES 8 364 |
334static const char *ppp_protoname (u_int proto); | |
335static void handle_ctrl_proto (u_int proto,const u_char *p, int length); 336static void handle_chap (const u_char *p, int length); 337static void handle_pap (const u_char *p, int length); 338static void handle_bap (const u_char *p, int length); 339static int print_lcp_config_options (const u_char *p, int); 340static int print_ipcp_config_options (const u_char *p, int); 341static int print_ccp_config_options (const u_char *p, int); 342static int print_bacp_config_options (const u_char *p, int); 343static void handle_ppp (u_int proto, const u_char *p, int length); 344 | 365static void handle_ctrl_proto (u_int proto,const u_char *p, int length); 366static void handle_chap (const u_char *p, int length); 367static void handle_pap (const u_char *p, int length); 368static void handle_bap (const u_char *p, int length); 369static int print_lcp_config_options (const u_char *p, int); 370static int print_ipcp_config_options (const u_char *p, int); 371static int print_ccp_config_options (const u_char *p, int); 372static int print_bacp_config_options (const u_char *p, int); 373static void handle_ppp (u_int proto, const u_char *p, int length); 374 |
345static const char * 346ppp_protoname(u_int proto) 347{ 348 static char buf[20]; 349 350 switch (proto) { 351 case PPP_IP: return "IP"; 352 case PPP_IPV6: return "IPv6"; 353#ifdef PPP_XNS 354 case PPP_XNS: return "XNS"; 355#endif 356 case PPP_IPX: return "IPX"; 357 case PPP_OSI: return "OSI"; 358 case PPP_VJC: return "VJC"; 359 case PPP_VJNC: return "VJNC"; 360 case PPP_COMP: return "COMP"; 361 case PPP_IPCP: return "IPCP"; 362 case PPP_IPV6CP: return "IPv6CP"; 363 case PPP_IPXCP: return "IPXCP"; 364 case PPP_OSICP: return "OSICP"; 365 case PPP_CCP: return "CCP"; 366 case PPP_LCP: return "LCP"; 367 case PPP_PAP: return "PAP"; 368#ifdef PPP_LQR 369 case PPP_LQR: return "LQR"; 370#endif 371 case PPP_CHAP: return "CHAP"; 372 case PPP_BACP: return "BACP"; 373 case PPP_BAP: return "BAP"; 374 default: 375 snprintf(buf, sizeof(buf), "unknown-0x%04x", proto); 376 return buf; 377 } 378} 379 | |
380/* generic Control Protocol (e.g. LCP, IPCP, CCP, etc.) handler */ 381static void | 375/* generic Control Protocol (e.g. LCP, IPCP, CCP, etc.) handler */ 376static void |
382handle_ctrl_proto(u_int proto, const u_char *p, int length) | 377handle_ctrl_proto(u_int proto, const u_char *pptr, int length) |
383{ | 378{ |
379 const char *typestr; |
|
384 u_int code, len; 385 int (*pfunc)(const u_char *, int); 386 int x, j; | 380 u_int code, len; 381 int (*pfunc)(const u_char *, int); 382 int x, j; |
383 const u_char *tptr; |
|
387 | 384 |
388 if (length < 1) { 389 printf("[|%s]", ppp_protoname(proto)); 390 return; 391 } else if (length < 4) { 392 printf("[|%s 0x%02x]", ppp_protoname(proto), *p); 393 return; 394 } | 385 tptr=pptr; |
395 | 386 |
396 code = *p; 397 if ((code >= CPCODES_MIN) && (code <= CPCODES_MAX)) 398 printf("%s", cpcodes[code]); 399 else { 400 printf("0x%02x", code); 401 return; 402 } 403 p++; | 387 typestr = tok2str(ppptype2str, "unknown", proto); 388 printf("%s, ",typestr); |
404 | 389 |
405 printf("(%u)", *p); /* ID */ 406 p++; | 390 if (length < 4) /* FIXME weak boundary checking */ 391 goto trunc; 392 TCHECK2(*tptr, 2); |
407 | 393 |
408 len = EXTRACT_16BITS(p); 409 p += 2; | 394 code = *tptr++; 395 396 printf("%s (0x%02x), id %u", 397 tok2str(cpcodes, "Unknown Opcode",code), 398 code, 399 *tptr++); /* ID */ |
410 | 400 |
401 TCHECK2(*tptr, 2); 402 len = EXTRACT_16BITS(tptr); 403 tptr += 2; 404 |
|
411 if (length <= 4) 412 return; /* there may be a NULL confreq etc. */ 413 414 switch (code) { 415 case CPCODES_VEXT: 416 if (length < 11) 417 break; | 405 if (length <= 4) 406 return; /* there may be a NULL confreq etc. */ 407 408 switch (code) { 409 case CPCODES_VEXT: 410 if (length < 11) 411 break; |
418 printf(", Magic-Num=%08x", EXTRACT_32BITS(p)); 419 p += 4; 420 printf(" OUI=%02x%02x%02x", p[0], p[1], p[2]); | 412 TCHECK2(*tptr, 4); 413 printf(", Magic-Num 0x%08x", EXTRACT_32BITS(tptr)); 414 tptr += 4; 415 TCHECK2(*tptr, 3); 416 printf(" OUI 0x%06x", EXTRACT_24BITS(tptr)); |
421 /* XXX: need to decode Kind and Value(s)? */ 422 break; 423 case CPCODES_CONF_REQ: 424 case CPCODES_CONF_ACK: 425 case CPCODES_CONF_NAK: 426 case CPCODES_CONF_REJ: 427 x = len - 4; /* Code(1), Identifier(1) and Length(2) */ 428 do { --- 14 unchanged lines hidden (view full) --- 443 /* 444 * This should never happen, but we set 445 * "pfunc" to squelch uninitialized 446 * variable warnings from compilers. 447 */ 448 pfunc = NULL; 449 break; 450 } | 417 /* XXX: need to decode Kind and Value(s)? */ 418 break; 419 case CPCODES_CONF_REQ: 420 case CPCODES_CONF_ACK: 421 case CPCODES_CONF_NAK: 422 case CPCODES_CONF_REJ: 423 x = len - 4; /* Code(1), Identifier(1) and Length(2) */ 424 do { --- 14 unchanged lines hidden (view full) --- 439 /* 440 * This should never happen, but we set 441 * "pfunc" to squelch uninitialized 442 * variable warnings from compilers. 443 */ 444 pfunc = NULL; 445 break; 446 } |
451 if ((j = (*pfunc)(p, len)) == 0) | 447 if ((j = (*pfunc)(tptr, len)) == 0) |
452 break; 453 x -= j; | 448 break; 449 x -= j; |
454 p += j; | 450 tptr += j; |
455 } while (x > 0); 456 break; 457 458 case CPCODES_TERM_REQ: 459 case CPCODES_TERM_ACK: 460 /* XXX: need to decode Data? */ 461 break; 462 case CPCODES_CODE_REJ: 463 /* XXX: need to decode Rejected-Packet? */ 464 break; 465 case CPCODES_PROT_REJ: 466 if (length < 6) 467 break; | 451 } while (x > 0); 452 break; 453 454 case CPCODES_TERM_REQ: 455 case CPCODES_TERM_ACK: 456 /* XXX: need to decode Data? */ 457 break; 458 case CPCODES_CODE_REJ: 459 /* XXX: need to decode Rejected-Packet? */ 460 break; 461 case CPCODES_PROT_REJ: 462 if (length < 6) 463 break; |
468 printf(", Rejected-Protocol=%04x", EXTRACT_16BITS(p)); | 464 TCHECK2(*tptr, 2); 465 printf(", Rejected %s Protocol (0x%04x)", 466 tok2str(ppptype2str,"unknown", EXTRACT_16BITS(tptr)), 467 EXTRACT_16BITS(tptr)); |
469 /* XXX: need to decode Rejected-Information? */ 470 break; 471 case CPCODES_ECHO_REQ: 472 case CPCODES_ECHO_RPL: 473 case CPCODES_DISC_REQ: 474 case CPCODES_ID: 475 if (length < 8) 476 break; | 468 /* XXX: need to decode Rejected-Information? */ 469 break; 470 case CPCODES_ECHO_REQ: 471 case CPCODES_ECHO_RPL: 472 case CPCODES_DISC_REQ: 473 case CPCODES_ID: 474 if (length < 8) 475 break; |
477 printf(", Magic-Num=%08x", EXTRACT_32BITS(p)); | 476 TCHECK2(*tptr, 4); 477 printf(", Magic-Num 0x%08x", EXTRACT_32BITS(tptr)); |
478 /* XXX: need to decode Data? */ 479 break; 480 case CPCODES_TIME_REM: 481 if (length < 12) 482 break; | 478 /* XXX: need to decode Data? */ 479 break; 480 case CPCODES_TIME_REM: 481 if (length < 12) 482 break; |
483 printf(", Magic-Num=%08x", EXTRACT_32BITS(p)); 484 printf(" Seconds-Remaining=%u", EXTRACT_32BITS(p + 4)); | 483 TCHECK2(*tptr, 4); 484 printf(", Magic-Num 0x%08x", EXTRACT_32BITS(tptr)); 485 TCHECK2(*(tptr + 4), 4); 486 printf(", Seconds-Remaining %us", EXTRACT_32BITS(tptr + 4)); |
485 /* XXX: need to decode Message? */ 486 break; 487 default: | 487 /* XXX: need to decode Message? */ 488 break; 489 default: |
488 printf(", unknown-Codes-0x%02x", code); | 490 /* XXX this is dirty but we do not get the 491 * original pointer passed to the begin 492 * the PPP packet */ 493 if (vflag <= 1) 494 print_unknown_data(pptr-2,"\n\t",length+2); |
489 break; 490 } | 495 break; 496 } |
497 printf(", length %u", length); 498 499 if (vflag >1) 500 print_unknown_data(pptr-2,"\n\t",length+2); 501 return; 502 503trunc: 504 printf("[|%s]", typestr); |
|
491} 492 493/* LCP config options */ 494static int 495print_lcp_config_options(const u_char *p, int length) 496{ 497 int len, opt; 498 499 if (length < 2) 500 return 0; | 505} 506 507/* LCP config options */ 508static int 509print_lcp_config_options(const u_char *p, int length) 510{ 511 int len, opt; 512 513 if (length < 2) 514 return 0; |
515 TCHECK2(*p, 2); |
|
501 len = p[1]; 502 opt = p[0]; 503 if (length < len) 504 return 0; 505 if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX)) | 516 len = p[1]; 517 opt = p[0]; 518 if (length < len) 519 return 0; 520 if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX)) |
506 printf(", %s", lcpconfopts[opt]); | 521 printf(", %s ", lcpconfopts[opt]); |
507 else { | 522 else { |
508 printf(", unknwhown-%d", opt); | 523 printf(", unknown LCP option 0x%02x", opt); |
509 return len; 510 } 511 512 switch (opt) { 513 case LCPOPT_VEXT: 514 if (len >= 6) { | 524 return len; 525 } 526 527 switch (opt) { 528 case LCPOPT_VEXT: 529 if (len >= 6) { |
515 printf(" OUI=%02x%02x%02x", p[2], p[3], p[4]); | 530 TCHECK2(*(p + 2), 3); 531 printf(" OUI 0x%06x", EXTRACT_24BITS(p+2)); |
516#if 0 | 532#if 0 |
517 printf(" kind=%02x", p[5]); 518 printf(" val=") | 533 TCHECK(p[5]); 534 printf(" kind 0x%02x", p[5]); 535 printf(" val 0x") |
519 for (i = 0; i < len - 6; i++) { | 536 for (i = 0; i < len - 6; i++) { |
537 TCHECK(p[6 + i]); |
|
520 printf("%02x", p[6 + i]); 521 } 522#endif 523 } 524 break; 525 case LCPOPT_MRU: | 538 printf("%02x", p[6 + i]); 539 } 540#endif 541 } 542 break; 543 case LCPOPT_MRU: |
526 if (len == 4) 527 printf("=%u", EXTRACT_16BITS(p + 2)); | 544 if (len == 4) { 545 TCHECK2(*(p + 2), 2); 546 printf(" %u", EXTRACT_16BITS(p + 2)); 547 } |
528 break; 529 case LCPOPT_ACCM: | 548 break; 549 case LCPOPT_ACCM: |
530 if (len == 6) 531 printf("=%08x", EXTRACT_32BITS(p + 2)); | 550 if (len == 6) { 551 TCHECK2(*(p + 2), 4); 552 printf(" %08x", EXTRACT_32BITS(p + 2)); 553 } |
532 break; 533 case LCPOPT_AP: 534 if (len >= 4) { | 554 break; 555 case LCPOPT_AP: 556 if (len >= 4) { |
535 if (p[2] == 0xc0 && p[3] == 0x23) 536 printf(" PAP"); 537 else if (p[2] == 0xc2 && p[3] == 0x23) { 538 printf(" CHAP/"); 539 switch (p[4]) { 540 default: 541 printf("unknown-algorithm-%u", p[4]); 542 break; 543 case AUTHALG_CHAPMD5: 544 printf("MD5"); 545 break; 546 case AUTHALG_MSCHAP1: 547 printf("MSCHAPv1"); 548 break; 549 case AUTHALG_MSCHAP2: 550 printf("MSCHAPv2"); 551 break; 552 } | 557 TCHECK2(*(p + 2), 2); 558 switch (EXTRACT_16BITS(p+2)) { 559 case PPP_PAP: 560 printf(" PAP"); 561 break; 562 case PPP_CHAP: 563 printf(" CHAP"); 564 TCHECK(p[4]); 565 switch (p[4]) { 566 default: 567 printf(", unknown-algorithm-%u", p[4]); 568 break; 569 case AUTHALG_CHAPMD5: 570 printf(", MD5"); 571 break; 572 case AUTHALG_MSCHAP1: 573 printf(", MSCHAPv1"); 574 break; 575 case AUTHALG_MSCHAP2: 576 printf(", MSCHAPv2"); 577 break; |
553 } | 578 } |
554 else if (p[2] == 0xc2 && p[3] == 0x27) 555 printf(" EAP"); 556 else if (p[2] == 0xc0 && p[3] == 0x27) 557 printf(" SPAP"); 558 else if (p[2] == 0xc1 && p[3] == 0x23) 559 printf(" Old-SPAP"); 560 else 561 printf("unknown"); | 579 break; 580 case PPP_EAP: 581 printf(" EAP"); 582 break; 583 case PPP_SPAP: 584 printf(" SPAP"); 585 break; 586 case PPP_SPAP_OLD: 587 printf(" Old-SPAP"); 588 break; 589 default: 590 printf("unknown"); 591 } |
562 } 563 break; 564 case LCPOPT_QP: 565 if (len >= 4) { | 592 } 593 break; 594 case LCPOPT_QP: 595 if (len >= 4) { |
566 if (p[2] == 0xc0 && p[3] == 0x25) | 596 TCHECK2(*(p + 2), 2); 597 if (EXTRACT_16BITS(p+2) == PPP_LQM) |
567 printf(" LQR"); 568 else 569 printf(" unknown"); 570 } 571 break; 572 case LCPOPT_MN: | 598 printf(" LQR"); 599 else 600 printf(" unknown"); 601 } 602 break; 603 case LCPOPT_MN: |
573 if (len == 6) 574 printf("=%08x", EXTRACT_32BITS(p + 2)); | 604 if (len == 6) { 605 TCHECK2(*(p + 2), 4); 606 printf(" 0x%08x", EXTRACT_32BITS(p + 2)); 607 } |
575 break; 576 case LCPOPT_PFC: 577 break; 578 case LCPOPT_ACFC: 579 break; 580 case LCPOPT_LD: | 608 break; 609 case LCPOPT_PFC: 610 break; 611 case LCPOPT_ACFC: 612 break; 613 case LCPOPT_LD: |
581 if (len == 4) 582 printf("=%04x", EXTRACT_16BITS(p + 2)); | 614 if (len == 4) { 615 TCHECK2(*(p + 2), 2); 616 printf(" 0x%04x", EXTRACT_16BITS(p + 2)); 617 } |
583 break; 584 case LCPOPT_CBACK: 585 if (len < 3) 586 break; | 618 break; 619 case LCPOPT_CBACK: 620 if (len < 3) 621 break; |
622 TCHECK(p[2]); |
|
587 switch (p[2]) { /* Operation */ 588 case CALLBACK_AUTH: 589 printf(" UserAuth"); 590 break; 591 case CALLBACK_DSTR: 592 printf(" DialString"); 593 break; 594 case CALLBACK_LID: --- 9 unchanged lines hidden (view full) --- 604 printf(" CBCP"); 605 break; 606 default: 607 printf(" unknown-operation=%u", p[2]); 608 break; 609 } 610 break; 611 case LCPOPT_MLMRRU: | 623 switch (p[2]) { /* Operation */ 624 case CALLBACK_AUTH: 625 printf(" UserAuth"); 626 break; 627 case CALLBACK_DSTR: 628 printf(" DialString"); 629 break; 630 case CALLBACK_LID: --- 9 unchanged lines hidden (view full) --- 640 printf(" CBCP"); 641 break; 642 default: 643 printf(" unknown-operation=%u", p[2]); 644 break; 645 } 646 break; 647 case LCPOPT_MLMRRU: |
612 if (len == 4) 613 printf("=%u", EXTRACT_16BITS(p + 2)); | 648 if (len == 4) { 649 TCHECK2(*(p + 2), 2); 650 printf(" %u", EXTRACT_16BITS(p + 2)); 651 } |
614 break; 615 case LCPOPT_MLED: 616 if (len < 3) 617 break; | 652 break; 653 case LCPOPT_MLED: 654 if (len < 3) 655 break; |
656 TCHECK(p[2]); |
|
618 switch (p[2]) { /* class */ 619 case MEDCLASS_NULL: 620 printf(" Null"); 621 break; 622 case MEDCLASS_LOCAL: 623 printf(" Local"); /* XXX */ 624 break; 625 case MEDCLASS_IPV4: 626 if (len != 7) 627 break; | 657 switch (p[2]) { /* class */ 658 case MEDCLASS_NULL: 659 printf(" Null"); 660 break; 661 case MEDCLASS_LOCAL: 662 printf(" Local"); /* XXX */ 663 break; 664 case MEDCLASS_IPV4: 665 if (len != 7) 666 break; |
628 printf(" IPv4=%s", ipaddr_string(p + 3)); | 667 TCHECK2(*(p + 3), 4); 668 printf(" IPv4 %s", ipaddr_string(p + 3)); |
629 break; 630 case MEDCLASS_MAC: 631 if (len != 9) 632 break; | 669 break; 670 case MEDCLASS_MAC: 671 if (len != 9) 672 break; |
633 printf(" MAC=%02x:%02x:%02x:%02x:%02x:%02x", | 673 TCHECK(p[8]); 674 printf(" MAC %02x:%02x:%02x:%02x:%02x:%02x", |
634 p[3], p[4], p[5], p[6], p[7], p[8]); 635 break; 636 case MEDCLASS_MNB: 637 printf(" Magic-Num-Block"); /* XXX */ 638 break; 639 case MEDCLASS_PSNDN: 640 printf(" PSNDN"); /* XXX */ 641 break; --- 20 unchanged lines hidden (view full) --- 662 case LCPOPT_MLHF: 663 case LCPOPT_I18N: 664 case LCPOPT_SDLOS: 665 case LCPOPT_PPPMUX: 666 break; 667#endif 668 } 669 return len; | 675 p[3], p[4], p[5], p[6], p[7], p[8]); 676 break; 677 case MEDCLASS_MNB: 678 printf(" Magic-Num-Block"); /* XXX */ 679 break; 680 case MEDCLASS_PSNDN: 681 printf(" PSNDN"); /* XXX */ 682 break; --- 20 unchanged lines hidden (view full) --- 703 case LCPOPT_MLHF: 704 case LCPOPT_I18N: 705 case LCPOPT_SDLOS: 706 case LCPOPT_PPPMUX: 707 break; 708#endif 709 } 710 return len; |
711 712trunc: 713 printf("[|lcp]"); 714 return 0; |
|
670} 671 672/* CHAP */ 673static void 674handle_chap(const u_char *p, int length) 675{ 676 u_int code, len; 677 int val_size, name_size, msg_size; 678 const u_char *p0; 679 int i; 680 681 p0 = p; 682 if (length < 1) { 683 printf("[|chap]"); 684 return; 685 } else if (length < 4) { | 715} 716 717/* CHAP */ 718static void 719handle_chap(const u_char *p, int length) 720{ 721 u_int code, len; 722 int val_size, name_size, msg_size; 723 const u_char *p0; 724 int i; 725 726 p0 = p; 727 if (length < 1) { 728 printf("[|chap]"); 729 return; 730 } else if (length < 4) { |
731 TCHECK(*p); |
|
686 printf("[|chap 0x%02x]", *p); 687 return; 688 } 689 | 732 printf("[|chap 0x%02x]", *p); 733 return; 734 } 735 |
736 TCHECK(*p); |
|
690 code = *p; 691 if ((code >= CHAP_CODEMIN) && (code <= CHAP_CODEMAX)) 692 printf("%s", chapcode[code - 1]); 693 else { 694 printf("0x%02x", code); 695 return; 696 } 697 p++; 698 | 737 code = *p; 738 if ((code >= CHAP_CODEMIN) && (code <= CHAP_CODEMAX)) 739 printf("%s", chapcode[code - 1]); 740 else { 741 printf("0x%02x", code); 742 return; 743 } 744 p++; 745 |
746 TCHECK(*p); |
|
699 printf("(%u)", *p); /* ID */ 700 p++; 701 | 747 printf("(%u)", *p); /* ID */ 748 p++; 749 |
750 TCHECK2(*p, 2); |
|
702 len = EXTRACT_16BITS(p); 703 p += 2; 704 705 /* 706 * Note that this is a generic CHAP decoding routine. Since we 707 * don't know which flavor of CHAP (i.e. CHAP-MD5, MS-CHAPv1, 708 * MS-CHAPv2) is used at this point, we can't decode packet 709 * specifically to each algorithms. Instead, we simply decode 710 * the GCD (Gratest Common Denominator) for all algorithms. 711 */ 712 switch (code) { 713 case CHAP_CHAL: 714 case CHAP_RESP: 715 if (length - (p - p0) < 1) 716 return; | 751 len = EXTRACT_16BITS(p); 752 p += 2; 753 754 /* 755 * Note that this is a generic CHAP decoding routine. Since we 756 * don't know which flavor of CHAP (i.e. CHAP-MD5, MS-CHAPv1, 757 * MS-CHAPv2) is used at this point, we can't decode packet 758 * specifically to each algorithms. Instead, we simply decode 759 * the GCD (Gratest Common Denominator) for all algorithms. 760 */ 761 switch (code) { 762 case CHAP_CHAL: 763 case CHAP_RESP: 764 if (length - (p - p0) < 1) 765 return; |
766 TCHECK(*p); |
|
717 val_size = *p; /* value size */ 718 p++; 719 if (length - (p - p0) < val_size) 720 return; | 767 val_size = *p; /* value size */ 768 p++; 769 if (length - (p - p0) < val_size) 770 return; |
721 printf(", Value="); 722 for (i = 0; i < val_size; i++) | 771 printf(", Value "); 772 for (i = 0; i < val_size; i++) { 773 TCHECK(*p); |
723 printf("%02x", *p++); | 774 printf("%02x", *p++); |
775 } |
|
724 name_size = len - (p - p0); | 776 name_size = len - (p - p0); |
725 printf(", Name="); 726 for (i = 0; i < name_size; i++) | 777 printf(", Name "); 778 for (i = 0; i < name_size; i++) { 779 TCHECK(*p); |
727 safeputchar(*p++); | 780 safeputchar(*p++); |
781 } |
|
728 break; 729 case CHAP_SUCC: 730 case CHAP_FAIL: 731 msg_size = len - (p - p0); | 782 break; 783 case CHAP_SUCC: 784 case CHAP_FAIL: 785 msg_size = len - (p - p0); |
732 printf(", Msg="); 733 for (i = 0; i< msg_size; i++) | 786 printf(", Msg "); 787 for (i = 0; i< msg_size; i++) { 788 TCHECK(*p); |
734 safeputchar(*p++); | 789 safeputchar(*p++); |
790 } |
|
735 break; 736 } | 791 break; 792 } |
793 return; 794 795trunc: 796 printf("[|chap]"); |
|
737} 738 739/* PAP (see RFC 1334) */ 740static void 741handle_pap(const u_char *p, int length) 742{ 743 u_int code, len; 744 int peerid_len, passwd_len, msg_len; 745 const u_char *p0; 746 int i; 747 748 p0 = p; 749 if (length < 1) { 750 printf("[|pap]"); 751 return; 752 } else if (length < 4) { | 797} 798 799/* PAP (see RFC 1334) */ 800static void 801handle_pap(const u_char *p, int length) 802{ 803 u_int code, len; 804 int peerid_len, passwd_len, msg_len; 805 const u_char *p0; 806 int i; 807 808 p0 = p; 809 if (length < 1) { 810 printf("[|pap]"); 811 return; 812 } else if (length < 4) { |
813 TCHECK(*p); |
|
753 printf("[|pap 0x%02x]", *p); 754 return; 755 } 756 | 814 printf("[|pap 0x%02x]", *p); 815 return; 816 } 817 |
818 TCHECK(*p); |
|
757 code = *p; 758 if ((code >= PAP_CODEMIN) && (code <= PAP_CODEMAX)) 759 printf("%s", papcode[code - 1]); 760 else { 761 printf("0x%02x", code); 762 return; 763 } 764 p++; 765 | 819 code = *p; 820 if ((code >= PAP_CODEMIN) && (code <= PAP_CODEMAX)) 821 printf("%s", papcode[code - 1]); 822 else { 823 printf("0x%02x", code); 824 return; 825 } 826 p++; 827 |
828 TCHECK(*p); |
|
766 printf("(%u)", *p); /* ID */ 767 p++; 768 | 829 printf("(%u)", *p); /* ID */ 830 p++; 831 |
832 TCHECK2(*p, 2); |
|
769 len = EXTRACT_16BITS(p); 770 p += 2; 771 772 switch (code) { 773 case PAP_AREQ: 774 if (length - (p - p0) < 1) 775 return; | 833 len = EXTRACT_16BITS(p); 834 p += 2; 835 836 switch (code) { 837 case PAP_AREQ: 838 if (length - (p - p0) < 1) 839 return; |
840 TCHECK(*p); |
|
776 peerid_len = *p; /* Peer-ID Length */ 777 p++; 778 if (length - (p - p0) < peerid_len) 779 return; | 841 peerid_len = *p; /* Peer-ID Length */ 842 p++; 843 if (length - (p - p0) < peerid_len) 844 return; |
780 printf(", Peer="); 781 for (i = 0; i < peerid_len; i++) | 845 printf(", Peer "); 846 for (i = 0; i < peerid_len; i++) { 847 TCHECK(*p); |
782 safeputchar(*p++); | 848 safeputchar(*p++); |
849 } |
|
783 784 if (length - (p - p0) < 1) 785 return; | 850 851 if (length - (p - p0) < 1) 852 return; |
853 TCHECK(*p); |
|
786 passwd_len = *p; /* Password Length */ 787 p++; 788 if (length - (p - p0) < passwd_len) 789 return; | 854 passwd_len = *p; /* Password Length */ 855 p++; 856 if (length - (p - p0) < passwd_len) 857 return; |
790 printf(", Name="); 791 for (i = 0; i < passwd_len; i++) | 858 printf(", Name "); 859 for (i = 0; i < passwd_len; i++) { 860 TCHECK(*p); |
792 safeputchar(*p++); | 861 safeputchar(*p++); |
862 } |
|
793 break; 794 case PAP_AACK: 795 case PAP_ANAK: 796 if (length - (p - p0) < 1) 797 return; | 863 break; 864 case PAP_AACK: 865 case PAP_ANAK: 866 if (length - (p - p0) < 1) 867 return; |
868 TCHECK(*p); |
|
798 msg_len = *p; /* Msg-Length */ 799 p++; 800 if (length - (p - p0) < msg_len) 801 return; | 869 msg_len = *p; /* Msg-Length */ 870 p++; 871 if (length - (p - p0) < msg_len) 872 return; |
802 printf(", Msg="); 803 for (i = 0; i< msg_len; i++) | 873 printf(", Msg "); 874 for (i = 0; i< msg_len; i++) { 875 TCHECK(*p); |
804 safeputchar(*p++); | 876 safeputchar(*p++); |
877 } |
|
805 break; 806 } 807 return; | 878 break; 879 } 880 return; |
881 882trunc: 883 printf("[|pap]"); |
|
808} 809 810/* BAP */ 811static void | 884} 885 886/* BAP */ 887static void |
812handle_bap(const u_char *p, int length) | 888handle_bap(const u_char *p _U_, int length _U_) |
813{ 814 /* XXX: to be supported!! */ 815} 816 817 818/* IPCP config options */ 819static int 820print_ipcp_config_options(const u_char *p, int length) 821{ 822 int len, opt; 823 824 if (length < 2) 825 return 0; | 889{ 890 /* XXX: to be supported!! */ 891} 892 893 894/* IPCP config options */ 895static int 896print_ipcp_config_options(const u_char *p, int length) 897{ 898 int len, opt; 899 900 if (length < 2) 901 return 0; |
902 TCHECK2(*p, 2); |
|
826 len = p[1]; 827 opt = p[0]; 828 if (length < len) 829 return 0; 830 switch (opt) { 831 case IPCPOPT_2ADDR: /* deprecated */ 832 if (len != 10) 833 goto invlen; | 903 len = p[1]; 904 opt = p[0]; 905 if (length < len) 906 return 0; 907 switch (opt) { 908 case IPCPOPT_2ADDR: /* deprecated */ 909 if (len != 10) 910 goto invlen; |
834 printf(", IP-Addrs src=%s dst=%s", | 911 TCHECK2(*(p + 6), 4); 912 printf(", IP-Addrs src %s, dst %s", |
835 ipaddr_string(p + 2), 836 ipaddr_string(p + 6)); 837 break; 838 case IPCPOPT_IPCOMP: 839 if (len < 4) 840 goto invlen; 841 printf(", IP-Comp"); | 913 ipaddr_string(p + 2), 914 ipaddr_string(p + 6)); 915 break; 916 case IPCPOPT_IPCOMP: 917 if (len < 4) 918 goto invlen; 919 printf(", IP-Comp"); |
920 TCHECK2(*(p + 2), 2); |
|
842 if (EXTRACT_16BITS(p + 2) == PPP_VJC) { 843 printf(" VJ-Comp"); 844 /* XXX: VJ-Comp parameters should be decoded */ 845 } else 846 printf(" unknown-comp-proto=%04x", EXTRACT_16BITS(p + 2)); 847 break; 848 case IPCPOPT_ADDR: 849 if (len != 6) 850 goto invlen; | 921 if (EXTRACT_16BITS(p + 2) == PPP_VJC) { 922 printf(" VJ-Comp"); 923 /* XXX: VJ-Comp parameters should be decoded */ 924 } else 925 printf(" unknown-comp-proto=%04x", EXTRACT_16BITS(p + 2)); 926 break; 927 case IPCPOPT_ADDR: 928 if (len != 6) 929 goto invlen; |
851 printf(", IP-Addr=%s", ipaddr_string(p + 2)); | 930 TCHECK2(*(p + 2), 4); 931 printf(", IP-Addr %s", ipaddr_string(p + 2)); |
852 break; 853 case IPCPOPT_MOBILE4: 854 if (len != 6) 855 goto invlen; | 932 break; 933 case IPCPOPT_MOBILE4: 934 if (len != 6) 935 goto invlen; |
856 printf(", Home-Addr=%s", ipaddr_string(p + 2)); | 936 TCHECK2(*(p + 2), 4); 937 printf(", Home-Addr %s", ipaddr_string(p + 2)); |
857 break; 858 case IPCPOPT_PRIDNS: 859 if (len != 6) 860 goto invlen; | 938 break; 939 case IPCPOPT_PRIDNS: 940 if (len != 6) 941 goto invlen; |
861 printf(", Pri-DNS=%s", ipaddr_string(p + 2)); | 942 TCHECK2(*(p + 2), 4); 943 printf(", Pri-DNS %s", ipaddr_string(p + 2)); |
862 break; 863 case IPCPOPT_PRINBNS: 864 if (len != 6) 865 goto invlen; | 944 break; 945 case IPCPOPT_PRINBNS: 946 if (len != 6) 947 goto invlen; |
866 printf(", Pri-NBNS=%s", ipaddr_string(p + 2)); | 948 TCHECK2(*(p + 2), 4); 949 printf(", Pri-NBNS %s", ipaddr_string(p + 2)); |
867 break; 868 case IPCPOPT_SECDNS: 869 if (len != 6) 870 goto invlen; | 950 break; 951 case IPCPOPT_SECDNS: 952 if (len != 6) 953 goto invlen; |
871 printf(", Sec-DNS=%s", ipaddr_string(p + 2)); | 954 TCHECK2(*(p + 2), 4); 955 printf(", Sec-DNS %s", ipaddr_string(p + 2)); |
872 break; 873 case IPCPOPT_SECNBNS: 874 if (len != 6) 875 goto invlen; | 956 break; 957 case IPCPOPT_SECNBNS: 958 if (len != 6) 959 goto invlen; |
876 printf(", Sec-NBNS=%s", ipaddr_string(p + 2)); | 960 TCHECK2(*(p + 2), 4); 961 printf(", Sec-NBNS %s", ipaddr_string(p + 2)); |
877 break; 878 default: 879 printf(", unknown-%d", opt); 880 break; 881 } 882 return len; 883 884invlen: 885 printf(", invalid-length-%d", opt); 886 return 0; | 962 break; 963 default: 964 printf(", unknown-%d", opt); 965 break; 966 } 967 return len; 968 969invlen: 970 printf(", invalid-length-%d", opt); 971 return 0; |
972 973trunc: 974 printf("[|ipcp]"); 975 return 0; |
|
887} 888 889/* CCP config options */ 890static int 891print_ccp_config_options(const u_char *p, int length) 892{ 893 int len, opt; 894 895 if (length < 2) 896 return 0; | 976} 977 978/* CCP config options */ 979static int 980print_ccp_config_options(const u_char *p, int length) 981{ 982 int len, opt; 983 984 if (length < 2) 985 return 0; |
986 TCHECK2(*p, 2); |
|
897 len = p[1]; 898 opt = p[0]; 899 if (length < len) 900 return 0; 901 if ((opt >= CCPOPT_MIN) && (opt <= CCPOPT_MAX)) 902 printf(", %s", ccpconfopts[opt]); 903#if 0 /* XXX */ 904 switch (opt) { --- 15 unchanged lines hidden (view full) --- 920 break; 921 922 default: 923 printf(", unknown-%d", opt); 924 break; 925 } 926#endif 927 return len; | 987 len = p[1]; 988 opt = p[0]; 989 if (length < len) 990 return 0; 991 if ((opt >= CCPOPT_MIN) && (opt <= CCPOPT_MAX)) 992 printf(", %s", ccpconfopts[opt]); 993#if 0 /* XXX */ 994 switch (opt) { --- 15 unchanged lines hidden (view full) --- 1010 break; 1011 1012 default: 1013 printf(", unknown-%d", opt); 1014 break; 1015 } 1016#endif 1017 return len; |
1018 1019trunc: 1020 printf("[|ccp]"); 1021 return 0; |
|
928} 929 930/* BACP config options */ 931static int 932print_bacp_config_options(const u_char *p, int length) 933{ 934 int len, opt; 935 936 if (length < 2) 937 return 0; | 1022} 1023 1024/* BACP config options */ 1025static int 1026print_bacp_config_options(const u_char *p, int length) 1027{ 1028 int len, opt; 1029 1030 if (length < 2) 1031 return 0; |
1032 TCHECK2(*p, 2); |
|
938 len = p[1]; 939 opt = p[0]; 940 if (length < len) 941 return 0; 942 if (opt == BACPOPT_FPEER) { | 1033 len = p[1]; 1034 opt = p[0]; 1035 if (length < len) 1036 return 0; 1037 if (opt == BACPOPT_FPEER) { |
1038 TCHECK2(*(p + 2), 4); |
|
943 printf(", Favored-Peer"); | 1039 printf(", Favored-Peer"); |
944 printf(" Magic-Num=%08x", EXTRACT_32BITS(p + 2)); | 1040 printf(", Magic-Num 0x%08x", EXTRACT_32BITS(p + 2)); |
945 } else { 946 printf(", unknown-option-%d", opt); 947 } 948 return len; | 1041 } else { 1042 printf(", unknown-option-%d", opt); 1043 } 1044 return len; |
1045 1046trunc: 1047 printf("[|bacp]"); 1048 return 0; |
|
949} 950 951 952/* PPP */ 953static void 954handle_ppp(u_int proto, const u_char *p, int length) 955{ 956 switch (proto) { 957 case PPP_LCP: 958 case PPP_IPCP: | 1049} 1050 1051 1052/* PPP */ 1053static void 1054handle_ppp(u_int proto, const u_char *p, int length) 1055{ 1056 switch (proto) { 1057 case PPP_LCP: 1058 case PPP_IPCP: |
1059 case PPP_OSICP: 1060 case PPP_MPLSCP: 1061 case PPP_IPV6CP: |
|
959 case PPP_CCP: 960 case PPP_BACP: 961 handle_ctrl_proto(proto, p, length); 962 break; 963 case PPP_CHAP: 964 handle_chap(p, length); 965 break; 966 case PPP_PAP: --- 12 unchanged lines hidden (view full) --- 979 ip6_print(p, length); 980 break; 981#endif 982 case ETHERTYPE_IPX: /*XXX*/ 983 case PPP_IPX: 984 ipx_print(p, length); 985 break; 986 case PPP_OSI: | 1062 case PPP_CCP: 1063 case PPP_BACP: 1064 handle_ctrl_proto(proto, p, length); 1065 break; 1066 case PPP_CHAP: 1067 handle_chap(p, length); 1068 break; 1069 case PPP_PAP: --- 12 unchanged lines hidden (view full) --- 1082 ip6_print(p, length); 1083 break; 1084#endif 1085 case ETHERTYPE_IPX: /*XXX*/ 1086 case PPP_IPX: 1087 ipx_print(p, length); 1088 break; 1089 case PPP_OSI: |
987 isoclns_print(p, length, length, NULL, NULL); | 1090 isoclns_print(p, length, length); |
988 break; | 1091 break; |
989 default: | 1092 case PPP_MPLS_UCAST: 1093 case PPP_MPLS_MCAST: 1094 mpls_print(p, length); |
990 break; | 1095 break; |
1096 default: 1097 printf("unknown PPP protocol (0x%04x)", proto); 1098 print_unknown_data(p,"\n\t",length); 1099 break; |
|
991 } 992} 993 994/* Standard PPP printer */ | 1100 } 1101} 1102 1103/* Standard PPP printer */ |
995void | 1104u_int |
996ppp_print(register const u_char *p, u_int length) 997{ 998 u_int proto; | 1105ppp_print(register const u_char *p, u_int length) 1106{ 1107 u_int proto; |
999 u_int full_length = length; | 1108 u_int olen = length; /* _o_riginal length */ 1109 u_int hdr_len = 0; |
1000 1001 /* 1002 * Here, we assume that p points to the Address and Control 1003 * field (if they present). 1004 */ 1005 if (length < 2) 1006 goto trunc; | 1110 1111 /* 1112 * Here, we assume that p points to the Address and Control 1113 * field (if they present). 1114 */ 1115 if (length < 2) 1116 goto trunc; |
1117 TCHECK2(*p, 2); |
|
1007 if (*p == PPP_ADDRESS && *(p + 1) == PPP_CONTROL) { 1008 p += 2; /* ACFC not used */ 1009 length -= 2; | 1118 if (*p == PPP_ADDRESS && *(p + 1) == PPP_CONTROL) { 1119 p += 2; /* ACFC not used */ 1120 length -= 2; |
1121 hdr_len += 2; |
|
1010 } 1011 1012 if (length < 2) 1013 goto trunc; | 1122 } 1123 1124 if (length < 2) 1125 goto trunc; |
1126 TCHECK(*p); |
|
1014 if (*p % 2) { 1015 proto = *p; /* PFC is used */ 1016 p++; 1017 length--; | 1127 if (*p % 2) { 1128 proto = *p; /* PFC is used */ 1129 p++; 1130 length--; |
1131 hdr_len++; |
|
1018 } else { | 1132 } else { |
1133 TCHECK2(*p, 2); |
|
1019 proto = EXTRACT_16BITS(p); 1020 p += 2; 1021 length -= 2; | 1134 proto = EXTRACT_16BITS(p); 1135 p += 2; 1136 length -= 2; |
1137 hdr_len += 2; |
|
1022 } 1023 | 1138 } 1139 |
1024 if (eflag) 1025 printf("%s %d: ", ppp_protoname(proto), full_length); | 1140 if (eflag) 1141 printf("PPP-%s (0x%04x), length %u: ", 1142 tok2str(ppptype2str, "unknown", proto), 1143 proto, 1144 olen); |
1026 1027 handle_ppp(proto, p, length); | 1145 1146 handle_ppp(proto, p, length); |
1028 return; | 1147 return (hdr_len); |
1029trunc: 1030 printf("[|ppp]"); | 1148trunc: 1149 printf("[|ppp]"); |
1150 return (0); |
|
1031} 1032 1033 1034/* PPP I/F printer */ | 1151} 1152 1153 1154/* PPP I/F printer */ |
1035void 1036ppp_if_print(u_char *user, const struct pcap_pkthdr *h, 1037 register const u_char *p) | 1155u_int 1156ppp_if_print(const struct pcap_pkthdr *h, register const u_char *p) |
1038{ 1039 register u_int length = h->len; 1040 register u_int caplen = h->caplen; 1041 | 1157{ 1158 register u_int length = h->len; 1159 register u_int caplen = h->caplen; 1160 |
1042 ++infodelay; 1043 ts_print(&h->ts); 1044 | |
1045 if (caplen < PPP_HDRLEN) { 1046 printf("[|ppp]"); | 1161 if (caplen < PPP_HDRLEN) { 1162 printf("[|ppp]"); |
1047 goto out; | 1163 return (caplen); |
1048 } 1049 | 1164 } 1165 |
1050 /* 1051 * Some printers want to get back at the link level addresses, 1052 * and/or check that they're not walking off the end of the packet. 1053 * Rather than pass them all the way down, we set these globals. */ 1054 1055 packetp = p; 1056 snapend = p + caplen; 1057 | |
1058#if 0 1059 /* 1060 * XXX: seems to assume that there are 2 octets prepended to an 1061 * actual PPP frame. The 1st octet looks like Input/Output flag 1062 * while 2nd octet is unknown, at least to me 1063 * (mshindo@mshindo.net). 1064 * 1065 * That was what the original tcpdump code did. --- 27 unchanged lines hidden (view full) --- 1093 * BSD/OS, is?) 1094 */ 1095 if (eflag) 1096 printf("%c %4d %02x ", p[0] ? 'O' : 'I', length, p[1]); 1097#endif 1098 1099 ppp_print(p, length); 1100 | 1166#if 0 1167 /* 1168 * XXX: seems to assume that there are 2 octets prepended to an 1169 * actual PPP frame. The 1st octet looks like Input/Output flag 1170 * while 2nd octet is unknown, at least to me 1171 * (mshindo@mshindo.net). 1172 * 1173 * That was what the original tcpdump code did. --- 27 unchanged lines hidden (view full) --- 1201 * BSD/OS, is?) 1202 */ 1203 if (eflag) 1204 printf("%c %4d %02x ", p[0] ? 'O' : 'I', length, p[1]); 1205#endif 1206 1207 ppp_print(p, length); 1208 |
1101 if (xflag) 1102 default_print(p, caplen); 1103out: 1104 putchar('\n'); 1105 --infodelay; 1106 if (infoprint) 1107 info(0); | 1209 return (0); |
1108} 1109 1110/* 1111 * PPP I/F printer to use if we know that RFC 1662-style PPP in HDLC-like 1112 * framing, or Cisco PPP with HDLC framing as per section 4.3.1 of RFC 1547, 1113 * is being used (i.e., we don't check for PPP_ADDRESS and PPP_CONTROL, 1114 * discard them *if* those are the first two octets, and parse the remaining 1115 * packet as a PPP packet, as "ppp_print()" does). 1116 * 1117 * This handles, for example, DLT_PPP_SERIAL in NetBSD. 1118 */ | 1210} 1211 1212/* 1213 * PPP I/F printer to use if we know that RFC 1662-style PPP in HDLC-like 1214 * framing, or Cisco PPP with HDLC framing as per section 4.3.1 of RFC 1547, 1215 * is being used (i.e., we don't check for PPP_ADDRESS and PPP_CONTROL, 1216 * discard them *if* those are the first two octets, and parse the remaining 1217 * packet as a PPP packet, as "ppp_print()" does). 1218 * 1219 * This handles, for example, DLT_PPP_SERIAL in NetBSD. 1220 */ |
1119void 1120ppp_hdlc_if_print(u_char *user, const struct pcap_pkthdr *h, 1121 register const u_char *p) | 1221u_int 1222ppp_hdlc_if_print(const struct pcap_pkthdr *h, register const u_char *p) |
1122{ 1123 register u_int length = h->len; 1124 register u_int caplen = h->caplen; 1125 u_int proto; | 1223{ 1224 register u_int length = h->len; 1225 register u_int caplen = h->caplen; 1226 u_int proto; |
1227 u_int hdrlen = 0; |
|
1126 | 1228 |
1127 ++infodelay; 1128 ts_print(&h->ts); 1129 | |
1130 if (caplen < 2) { 1131 printf("[|ppp]"); | 1229 if (caplen < 2) { 1230 printf("[|ppp]"); |
1132 goto out; | 1231 return (caplen); |
1133 } 1134 | 1232 } 1233 |
1135 /* 1136 * Some printers want to get back at the link level addresses, 1137 * and/or check that they're not walking off the end of the packet. 1138 * Rather than pass them all the way down, we set these globals. 1139 */ 1140 packetp = p; 1141 snapend = p + caplen; 1142 | |
1143 switch (p[0]) { 1144 1145 case PPP_ADDRESS: 1146 if (caplen < 4) { 1147 printf("[|ppp]"); | 1234 switch (p[0]) { 1235 1236 case PPP_ADDRESS: 1237 if (caplen < 4) { 1238 printf("[|ppp]"); |
1148 goto out; | 1239 return (caplen); |
1149 } 1150 1151 if (eflag) 1152 printf("%02x %02x %d ", p[0], p[1], length); 1153 p += 2; 1154 length -= 2; | 1240 } 1241 1242 if (eflag) 1243 printf("%02x %02x %d ", p[0], p[1], length); 1244 p += 2; 1245 length -= 2; |
1246 hdrlen += 2; |
|
1155 1156 proto = EXTRACT_16BITS(p); 1157 p += 2; 1158 length -= 2; | 1247 1248 proto = EXTRACT_16BITS(p); 1249 p += 2; 1250 length -= 2; |
1159 if (eflag) 1160 printf("%s: ", ppp_protoname(proto)); | 1251 hdrlen += 2; 1252 printf("%s: ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto)); |
1161 1162 handle_ppp(proto, p, length); 1163 break; 1164 1165 case CHDLC_UNICAST: 1166 case CHDLC_BCAST: | 1253 1254 handle_ppp(proto, p, length); 1255 break; 1256 1257 case CHDLC_UNICAST: 1258 case CHDLC_BCAST: |
1167 chdlc_print(p, length, caplen); 1168 goto out; | 1259 return (chdlc_if_print(h, p)); |
1169 1170 default: 1171 if (eflag) 1172 printf("%02x %02x %d ", p[0], p[1], length); 1173 p += 2; 1174 length -= 2; | 1260 1261 default: 1262 if (eflag) 1263 printf("%02x %02x %d ", p[0], p[1], length); 1264 p += 2; 1265 length -= 2; |
1266 hdrlen += 2; |
|
1175 1176 /* 1177 * XXX - NetBSD's "ppp_netbsd_serial_if_print()" treats 1178 * the next two octets as an Ethernet type; does that 1179 * ever happen? 1180 */ 1181 printf("unknown addr %02x; ctrl %02x", p[0], p[1]); 1182 break; 1183 } 1184 | 1267 1268 /* 1269 * XXX - NetBSD's "ppp_netbsd_serial_if_print()" treats 1270 * the next two octets as an Ethernet type; does that 1271 * ever happen? 1272 */ 1273 printf("unknown addr %02x; ctrl %02x", p[0], p[1]); 1274 break; 1275 } 1276 |
1185 if (xflag) 1186 default_print(p, caplen); 1187out: 1188 putchar('\n'); 1189 --infodelay; 1190 if (infoprint) 1191 info(0); | 1277 return (hdrlen); |
1192} 1193 | 1278} 1279 |
1194 1195 1196struct tok ppptype2str[] = { 1197 { PPP_IP, "IP" }, 1198 { PPP_OSI, "OSI" }, 1199 { PPP_NS, "NS" }, 1200 { PPP_DECNET, "DECNET" }, 1201 { PPP_APPLE, "APPLE" }, 1202 { PPP_IPX, "IPX" }, 1203 { PPP_VJC, "VJC" }, 1204 { PPP_VJNC, "VJNC" }, 1205 { PPP_BRPDU, "BRPDU" }, 1206 { PPP_STII, "STII" }, 1207 { PPP_VINES, "VINES" }, 1208 1209 { PPP_HELLO, "HELLO" }, 1210 { PPP_LUXCOM, "LUXCOM" }, 1211 { PPP_SNS, "SNS" }, 1212 { PPP_IPCP, "IPCP" }, 1213 { PPP_OSICP, "OSICP" }, 1214 { PPP_NSCP, "NSCP" }, 1215 { PPP_DECNETCP, "DECNETCP" }, 1216 { PPP_APPLECP, "APPLECP" }, 1217 { PPP_IPXCP, "IPXCP" }, 1218 { PPP_STIICP, "STIICP" }, 1219 { PPP_VINESCP, "VINESCP" }, 1220 1221 { PPP_LCP, "LCP" }, 1222 { PPP_PAP, "PAP" }, 1223 { PPP_LQM, "LQM" }, 1224 { PPP_CHAP, "CHAP" }, 1225 { PPP_BACP, "BACP" }, 1226 { PPP_BAP, "BAP" }, 1227 { PPP_MP, "MP" }, 1228 { 0, NULL } 1229}; 1230 | |
1231#define PPP_BSDI_HDRLEN 24 1232 1233/* BSD/OS specific PPP printer */ | 1280#define PPP_BSDI_HDRLEN 24 1281 1282/* BSD/OS specific PPP printer */ |
1234void 1235ppp_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, 1236 register const u_char *p) | 1283u_int 1284ppp_bsdos_if_print(const struct pcap_pkthdr *h _U_, register const u_char *p _U_) |
1237{ | 1285{ |
1286 register int hdrlength; |
|
1238#ifdef __bsdi__ 1239 register u_int length = h->len; 1240 register u_int caplen = h->caplen; | 1287#ifdef __bsdi__ 1288 register u_int length = h->len; 1289 register u_int caplen = h->caplen; |
1241 register int hdrlength; | |
1242 u_int16_t ptype; 1243 const u_char *q; 1244 int i; 1245 | 1290 u_int16_t ptype; 1291 const u_char *q; 1292 int i; 1293 |
1246 ++infodelay; 1247 ts_print(&h->ts); 1248 | |
1249 if (caplen < PPP_BSDI_HDRLEN) { 1250 printf("[|ppp]"); | 1294 if (caplen < PPP_BSDI_HDRLEN) { 1295 printf("[|ppp]"); |
1251 goto out; | 1296 return (caplen) |
1252 } 1253 | 1297 } 1298 |
1254 /* 1255 * Some printers want to get back at the link level addresses, 1256 * and/or check that they're not walking off the end of the packet. 1257 * Rather than pass them all the way down, we set these globals. 1258 */ 1259 packetp = p; 1260 snapend = p + caplen; | |
1261 hdrlength = 0; 1262 1263#if 0 1264 if (p[0] == PPP_ADDRESS && p[1] == PPP_CONTROL) { 1265 if (eflag) 1266 printf("%02x %02x ", p[0], p[1]); 1267 p += 2; 1268 hdrlength = 2; --- 47 unchanged lines hidden (view full) --- 1316 } 1317 if (eflag) 1318 printf("%d ", length); 1319 if (p[SLC_CHL]) { 1320 q = p + SLC_BPFHDRLEN + p[SLC_LLHL]; 1321 1322 switch (ptype) { 1323 case PPP_VJC: | 1299 hdrlength = 0; 1300 1301#if 0 1302 if (p[0] == PPP_ADDRESS && p[1] == PPP_CONTROL) { 1303 if (eflag) 1304 printf("%02x %02x ", p[0], p[1]); 1305 p += 2; 1306 hdrlength = 2; --- 47 unchanged lines hidden (view full) --- 1354 } 1355 if (eflag) 1356 printf("%d ", length); 1357 if (p[SLC_CHL]) { 1358 q = p + SLC_BPFHDRLEN + p[SLC_LLHL]; 1359 1360 switch (ptype) { 1361 case PPP_VJC: |
1324 ptype = vjc_print(q, length - (q - p), ptype); | 1362 ptype = vjc_print(q, ptype); |
1325 hdrlength = PPP_BSDI_HDRLEN; 1326 p += hdrlength; 1327 switch (ptype) { 1328 case PPP_IP: 1329 ip_print(p, length); 1330 break; 1331#ifdef INET6 1332 case PPP_IPV6: 1333 ip6_print(p, length); 1334 break; 1335#endif | 1363 hdrlength = PPP_BSDI_HDRLEN; 1364 p += hdrlength; 1365 switch (ptype) { 1366 case PPP_IP: 1367 ip_print(p, length); 1368 break; 1369#ifdef INET6 1370 case PPP_IPV6: 1371 ip6_print(p, length); 1372 break; 1373#endif |
1374 case PPP_MPLS_UCAST: 1375 case PPP_MPLS_MCAST: 1376 mpls_print(p, length); 1377 break; |
|
1336 } 1337 goto printx; 1338 case PPP_VJNC: | 1378 } 1379 goto printx; 1380 case PPP_VJNC: |
1339 ptype = vjc_print(q, length - (q - p), ptype); | 1381 ptype = vjc_print(q, ptype); |
1340 hdrlength = PPP_BSDI_HDRLEN; 1341 p += hdrlength; 1342 switch (ptype) { 1343 case PPP_IP: 1344 ip_print(p, length); 1345 break; 1346#ifdef INET6 1347 case PPP_IPV6: 1348 ip6_print(p, length); 1349 break; 1350#endif | 1382 hdrlength = PPP_BSDI_HDRLEN; 1383 p += hdrlength; 1384 switch (ptype) { 1385 case PPP_IP: 1386 ip_print(p, length); 1387 break; 1388#ifdef INET6 1389 case PPP_IPV6: 1390 ip6_print(p, length); 1391 break; 1392#endif |
1393 case PPP_MPLS_UCAST: 1394 case PPP_MPLS_MCAST: 1395 mpls_print(p, length); 1396 break; |
|
1351 } 1352 goto printx; 1353 default: 1354 if (eflag) { 1355 printf("CH=["); 1356 for (i = 0; i < p[SLC_LLHL]; i++) 1357 printf("%02x", q[i]); 1358 printf("] "); --- 12 unchanged lines hidden (view full) --- 1371 case PPP_IP: 1372 ip_print(p, length); 1373 break; 1374#ifdef INET6 1375 case PPP_IPV6: 1376 ip6_print(p, length); 1377 break; 1378#endif | 1397 } 1398 goto printx; 1399 default: 1400 if (eflag) { 1401 printf("CH=["); 1402 for (i = 0; i < p[SLC_LLHL]; i++) 1403 printf("%02x", q[i]); 1404 printf("] "); --- 12 unchanged lines hidden (view full) --- 1417 case PPP_IP: 1418 ip_print(p, length); 1419 break; 1420#ifdef INET6 1421 case PPP_IPV6: 1422 ip6_print(p, length); 1423 break; 1424#endif |
1425 case PPP_MPLS_UCAST: 1426 case PPP_MPLS_MCAST: 1427 mpls_print(p, length); 1428 break; |
|
1379 default: | 1429 default: |
1380 printf("%s ", tok2str(ppptype2str, "proto-#%d", ptype)); | 1430 printf("%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", ptype)); |
1381 } 1382 1383printx: | 1431 } 1432 1433printx: |
1384 if (xflag) 1385 default_print((const u_char *)p, caplen - hdrlength); 1386out: 1387 putchar('\n'); 1388 --infodelay; 1389 if (infoprint) 1390 info(0); | 1434#else /* __bsdi */ 1435 hdrlength = 0; |
1391#endif /* __bsdi__ */ | 1436#endif /* __bsdi__ */ |
1437 return (hdrlength); |
|
1392} | 1438} |