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