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.9 2017/09/08 14:01:13 christos 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_TCHECK_24BITS(p + 2); 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_TCHECK_16BITS(p + 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_TCHECK_32BITS(p + 2); 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_TCHECK_16BITS(p + 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_TCHECK_16BITS(p+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_TCHECK_32BITS(p + 2); 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_TCHECK_16BITS(p + 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_TCHECK_16BITS(p + 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 if (length < 2) { 820 ND_PRINT((ndo, "[|mlppp]")); 821 return; 822 } 823 if (!ND_TTEST_16BITS(p)) { 824 ND_PRINT((ndo, "[|mlppp]")); 825 return; 826 } 827 828 ND_PRINT((ndo, "seq 0x%03x, Flags [%s], length %u", 829 (EXTRACT_16BITS(p))&0x0fff, /* only support 12-Bit sequence space for now */ 830 bittok2str(ppp_ml_flag_values, "none", *p & 0xc0), 831 length)); 832 } 833 834 /* CHAP */ 835 static void 836 handle_chap(netdissect_options *ndo, 837 const u_char *p, int length) 838 { 839 u_int code, len; 840 int val_size, name_size, msg_size; 841 const u_char *p0; 842 int i; 843 844 p0 = p; 845 if (length < 1) { 846 ND_PRINT((ndo, "[|chap]")); 847 return; 848 } else if (length < 4) { 849 ND_TCHECK(*p); 850 ND_PRINT((ndo, "[|chap 0x%02x]", *p)); 851 return; 852 } 853 854 ND_TCHECK(*p); 855 code = *p; 856 ND_PRINT((ndo, "CHAP, %s (0x%02x)", 857 tok2str(chapcode_values,"unknown",code), 858 code)); 859 p++; 860 861 ND_TCHECK(*p); 862 ND_PRINT((ndo, ", id %u", *p)); /* ID */ 863 p++; 864 865 ND_TCHECK2(*p, 2); 866 len = EXTRACT_16BITS(p); 867 p += 2; 868 869 /* 870 * Note that this is a generic CHAP decoding routine. Since we 871 * don't know which flavor of CHAP (i.e. CHAP-MD5, MS-CHAPv1, 872 * MS-CHAPv2) is used at this point, we can't decode packet 873 * specifically to each algorithms. Instead, we simply decode 874 * the GCD (Gratest Common Denominator) for all algorithms. 875 */ 876 switch (code) { 877 case CHAP_CHAL: 878 case CHAP_RESP: 879 if (length - (p - p0) < 1) 880 return; 881 ND_TCHECK(*p); 882 val_size = *p; /* value size */ 883 p++; 884 if (length - (p - p0) < val_size) 885 return; 886 ND_PRINT((ndo, ", Value ")); 887 for (i = 0; i < val_size; i++) { 888 ND_TCHECK(*p); 889 ND_PRINT((ndo, "%02x", *p++)); 890 } 891 name_size = len - (p - p0); 892 ND_PRINT((ndo, ", Name ")); 893 for (i = 0; i < name_size; i++) { 894 ND_TCHECK(*p); 895 safeputchar(ndo, *p++); 896 } 897 break; 898 case CHAP_SUCC: 899 case CHAP_FAIL: 900 msg_size = len - (p - p0); 901 ND_PRINT((ndo, ", Msg ")); 902 for (i = 0; i< msg_size; i++) { 903 ND_TCHECK(*p); 904 safeputchar(ndo, *p++); 905 } 906 break; 907 } 908 return; 909 910 trunc: 911 ND_PRINT((ndo, "[|chap]")); 912 } 913 914 /* PAP (see RFC 1334) */ 915 static void 916 handle_pap(netdissect_options *ndo, 917 const u_char *p, int length) 918 { 919 u_int code, len; 920 int peerid_len, passwd_len, msg_len; 921 const u_char *p0; 922 int i; 923 924 p0 = p; 925 if (length < 1) { 926 ND_PRINT((ndo, "[|pap]")); 927 return; 928 } else if (length < 4) { 929 ND_TCHECK(*p); 930 ND_PRINT((ndo, "[|pap 0x%02x]", *p)); 931 return; 932 } 933 934 ND_TCHECK(*p); 935 code = *p; 936 ND_PRINT((ndo, "PAP, %s (0x%02x)", 937 tok2str(papcode_values, "unknown", code), 938 code)); 939 p++; 940 941 ND_TCHECK(*p); 942 ND_PRINT((ndo, ", id %u", *p)); /* ID */ 943 p++; 944 945 ND_TCHECK2(*p, 2); 946 len = EXTRACT_16BITS(p); 947 p += 2; 948 949 if ((int)len > length) { 950 ND_PRINT((ndo, ", length %u > packet size", len)); 951 return; 952 } 953 length = len; 954 if (length < (p - p0)) { 955 ND_PRINT((ndo, ", length %u < PAP header length", length)); 956 return; 957 } 958 959 switch (code) { 960 case PAP_AREQ: 961 /* A valid Authenticate-Request is 6 or more octets long. */ 962 if (len < 6) 963 goto trunc; 964 if (length - (p - p0) < 1) 965 return; 966 ND_TCHECK(*p); 967 peerid_len = *p; /* Peer-ID Length */ 968 p++; 969 if (length - (p - p0) < peerid_len) 970 return; 971 ND_PRINT((ndo, ", Peer ")); 972 for (i = 0; i < peerid_len; i++) { 973 ND_TCHECK(*p); 974 safeputchar(ndo, *p++); 975 } 976 977 if (length - (p - p0) < 1) 978 return; 979 ND_TCHECK(*p); 980 passwd_len = *p; /* Password Length */ 981 p++; 982 if (length - (p - p0) < passwd_len) 983 return; 984 ND_PRINT((ndo, ", Name ")); 985 for (i = 0; i < passwd_len; i++) { 986 ND_TCHECK(*p); 987 safeputchar(ndo, *p++); 988 } 989 break; 990 case PAP_AACK: 991 case PAP_ANAK: 992 /* Although some implementations ignore truncation at 993 * this point and at least one generates a truncated 994 * packet, RFC 1334 section 2.2.2 clearly states that 995 * both AACK and ANAK are at least 5 bytes long. 996 */ 997 if (len < 5) 998 goto trunc; 999 if (length - (p - p0) < 1) 1000 return; 1001 ND_TCHECK(*p); 1002 msg_len = *p; /* Msg-Length */ 1003 p++; 1004 if (length - (p - p0) < msg_len) 1005 return; 1006 ND_PRINT((ndo, ", Msg ")); 1007 for (i = 0; i< msg_len; i++) { 1008 ND_TCHECK(*p); 1009 safeputchar(ndo, *p++); 1010 } 1011 break; 1012 } 1013 return; 1014 1015 trunc: 1016 ND_PRINT((ndo, "[|pap]")); 1017 } 1018 1019 /* BAP */ 1020 static void 1021 handle_bap(netdissect_options *ndo _U_, 1022 const u_char *p _U_, int length _U_) 1023 { 1024 /* XXX: to be supported!! */ 1025 } 1026 1027 1028 /* IPCP config options */ 1029 static int 1030 print_ipcp_config_options(netdissect_options *ndo, 1031 const u_char *p, int length) 1032 { 1033 int len, opt; 1034 u_int compproto, ipcomp_subopttotallen, ipcomp_subopt, ipcomp_suboptlen; 1035 1036 if (length < 2) 1037 return 0; 1038 ND_TCHECK2(*p, 2); 1039 len = p[1]; 1040 opt = p[0]; 1041 if (length < len) 1042 return 0; 1043 if (len < 2) { 1044 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)", 1045 tok2str(ipcpopt_values,"unknown",opt), 1046 opt, 1047 len)); 1048 return 0; 1049 } 1050 1051 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u", 1052 tok2str(ipcpopt_values,"unknown",opt), 1053 opt, 1054 len)); 1055 1056 switch (opt) { 1057 case IPCPOPT_2ADDR: /* deprecated */ 1058 if (len != 10) { 1059 ND_PRINT((ndo, " (length bogus, should be = 10)")); 1060 return len; 1061 } 1062 ND_TCHECK2(*(p + 6), 4); 1063 ND_PRINT((ndo, ": src %s, dst %s", 1064 ipaddr_string(ndo, p + 2), 1065 ipaddr_string(ndo, p + 6))); 1066 break; 1067 case IPCPOPT_IPCOMP: 1068 if (len < 4) { 1069 ND_PRINT((ndo, " (length bogus, should be >= 4)")); 1070 return 0; 1071 } 1072 ND_TCHECK_16BITS(p+2); 1073 compproto = EXTRACT_16BITS(p+2); 1074 1075 ND_PRINT((ndo, ": %s (0x%02x):", 1076 tok2str(ipcpopt_compproto_values, "Unknown", compproto), 1077 compproto)); 1078 1079 switch (compproto) { 1080 case PPP_VJC: 1081 /* XXX: VJ-Comp parameters should be decoded */ 1082 break; 1083 case IPCPOPT_IPCOMP_HDRCOMP: 1084 if (len < IPCPOPT_IPCOMP_MINLEN) { 1085 ND_PRINT((ndo, " (length bogus, should be >= %u)", 1086 IPCPOPT_IPCOMP_MINLEN)); 1087 return 0; 1088 } 1089 1090 ND_TCHECK2(*(p + 2), IPCPOPT_IPCOMP_MINLEN); 1091 ND_PRINT((ndo, "\n\t TCP Space %u, non-TCP Space %u" \ 1092 ", maxPeriod %u, maxTime %u, maxHdr %u", 1093 EXTRACT_16BITS(p+4), 1094 EXTRACT_16BITS(p+6), 1095 EXTRACT_16BITS(p+8), 1096 EXTRACT_16BITS(p+10), 1097 EXTRACT_16BITS(p+12))); 1098 1099 /* suboptions present ? */ 1100 if (len > IPCPOPT_IPCOMP_MINLEN) { 1101 ipcomp_subopttotallen = len - IPCPOPT_IPCOMP_MINLEN; 1102 p += IPCPOPT_IPCOMP_MINLEN; 1103 1104 ND_PRINT((ndo, "\n\t Suboptions, length %u", ipcomp_subopttotallen)); 1105 1106 while (ipcomp_subopttotallen >= 2) { 1107 ND_TCHECK2(*p, 2); 1108 ipcomp_subopt = *p; 1109 ipcomp_suboptlen = *(p+1); 1110 1111 /* sanity check */ 1112 if (ipcomp_subopt == 0 || 1113 ipcomp_suboptlen == 0 ) 1114 break; 1115 1116 /* XXX: just display the suboptions for now */ 1117 ND_PRINT((ndo, "\n\t\t%s Suboption #%u, length %u", 1118 tok2str(ipcpopt_compproto_subopt_values, 1119 "Unknown", 1120 ipcomp_subopt), 1121 ipcomp_subopt, 1122 ipcomp_suboptlen)); 1123 1124 ipcomp_subopttotallen -= ipcomp_suboptlen; 1125 p += ipcomp_suboptlen; 1126 } 1127 } 1128 break; 1129 default: 1130 break; 1131 } 1132 break; 1133 1134 case IPCPOPT_ADDR: /* those options share the same format - fall through */ 1135 case IPCPOPT_MOBILE4: 1136 case IPCPOPT_PRIDNS: 1137 case IPCPOPT_PRINBNS: 1138 case IPCPOPT_SECDNS: 1139 case IPCPOPT_SECNBNS: 1140 if (len != 6) { 1141 ND_PRINT((ndo, " (length bogus, should be = 6)")); 1142 return 0; 1143 } 1144 ND_TCHECK2(*(p + 2), 4); 1145 ND_PRINT((ndo, ": %s", ipaddr_string(ndo, p + 2))); 1146 break; 1147 default: 1148 /* 1149 * Unknown option; dump it as raw bytes now if we're 1150 * not going to do so below. 1151 */ 1152 if (ndo->ndo_vflag < 2) 1153 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); 1154 break; 1155 } 1156 if (ndo->ndo_vflag > 1) 1157 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */ 1158 return len; 1159 1160 trunc: 1161 ND_PRINT((ndo, "[|ipcp]")); 1162 return 0; 1163 } 1164 1165 /* IP6CP config options */ 1166 static int 1167 print_ip6cp_config_options(netdissect_options *ndo, 1168 const u_char *p, int length) 1169 { 1170 int len, opt; 1171 1172 if (length < 2) 1173 return 0; 1174 ND_TCHECK2(*p, 2); 1175 len = p[1]; 1176 opt = p[0]; 1177 if (length < len) 1178 return 0; 1179 if (len < 2) { 1180 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)", 1181 tok2str(ip6cpopt_values,"unknown",opt), 1182 opt, 1183 len)); 1184 return 0; 1185 } 1186 1187 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u", 1188 tok2str(ip6cpopt_values,"unknown",opt), 1189 opt, 1190 len)); 1191 1192 switch (opt) { 1193 case IP6CP_IFID: 1194 if (len != 10) { 1195 ND_PRINT((ndo, " (length bogus, should be = 10)")); 1196 return len; 1197 } 1198 ND_TCHECK2(*(p + 2), 8); 1199 ND_PRINT((ndo, ": %04x:%04x:%04x:%04x", 1200 EXTRACT_16BITS(p + 2), 1201 EXTRACT_16BITS(p + 4), 1202 EXTRACT_16BITS(p + 6), 1203 EXTRACT_16BITS(p + 8))); 1204 break; 1205 default: 1206 /* 1207 * Unknown option; dump it as raw bytes now if we're 1208 * not going to do so below. 1209 */ 1210 if (ndo->ndo_vflag < 2) 1211 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); 1212 break; 1213 } 1214 if (ndo->ndo_vflag > 1) 1215 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */ 1216 1217 return len; 1218 1219 trunc: 1220 ND_PRINT((ndo, "[|ip6cp]")); 1221 return 0; 1222 } 1223 1224 1225 /* CCP config options */ 1226 static int 1227 print_ccp_config_options(netdissect_options *ndo, 1228 const u_char *p, int length) 1229 { 1230 int len, opt; 1231 1232 if (length < 2) 1233 return 0; 1234 ND_TCHECK2(*p, 2); 1235 len = p[1]; 1236 opt = p[0]; 1237 if (length < len) 1238 return 0; 1239 if (len < 2) { 1240 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)", 1241 tok2str(ccpconfopts_values, "Unknown", opt), 1242 opt, 1243 len)); 1244 return 0; 1245 } 1246 1247 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u", 1248 tok2str(ccpconfopts_values, "Unknown", opt), 1249 opt, 1250 len)); 1251 1252 switch (opt) { 1253 case CCPOPT_BSDCOMP: 1254 if (len < 3) { 1255 ND_PRINT((ndo, " (length bogus, should be >= 3)")); 1256 return len; 1257 } 1258 ND_TCHECK(p[2]); 1259 ND_PRINT((ndo, ": Version: %u, Dictionary Bits: %u", 1260 p[2] >> 5, p[2] & 0x1f)); 1261 break; 1262 case CCPOPT_MVRCA: 1263 if (len < 4) { 1264 ND_PRINT((ndo, " (length bogus, should be >= 4)")); 1265 return len; 1266 } 1267 ND_TCHECK(p[3]); 1268 ND_PRINT((ndo, ": Features: %u, PxP: %s, History: %u, #CTX-ID: %u", 1269 (p[2] & 0xc0) >> 6, 1270 (p[2] & 0x20) ? "Enabled" : "Disabled", 1271 p[2] & 0x1f, p[3])); 1272 break; 1273 case CCPOPT_DEFLATE: 1274 if (len < 4) { 1275 ND_PRINT((ndo, " (length bogus, should be >= 4)")); 1276 return len; 1277 } 1278 ND_TCHECK(p[3]); 1279 ND_PRINT((ndo, ": Window: %uK, Method: %s (0x%x), MBZ: %u, CHK: %u", 1280 (p[2] & 0xf0) >> 4, 1281 ((p[2] & 0x0f) == 8) ? "zlib" : "unknown", 1282 p[2] & 0x0f, (p[3] & 0xfc) >> 2, p[3] & 0x03)); 1283 break; 1284 1285 /* XXX: to be supported */ 1286 #if 0 1287 case CCPOPT_OUI: 1288 case CCPOPT_PRED1: 1289 case CCPOPT_PRED2: 1290 case CCPOPT_PJUMP: 1291 case CCPOPT_HPPPC: 1292 case CCPOPT_STACLZS: 1293 case CCPOPT_MPPC: 1294 case CCPOPT_GFZA: 1295 case CCPOPT_V42BIS: 1296 case CCPOPT_LZSDCP: 1297 case CCPOPT_DEC: 1298 case CCPOPT_RESV: 1299 break; 1300 #endif 1301 default: 1302 /* 1303 * Unknown option; dump it as raw bytes now if we're 1304 * not going to do so below. 1305 */ 1306 if (ndo->ndo_vflag < 2) 1307 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); 1308 break; 1309 } 1310 if (ndo->ndo_vflag > 1) 1311 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */ 1312 1313 return len; 1314 1315 trunc: 1316 ND_PRINT((ndo, "[|ccp]")); 1317 return 0; 1318 } 1319 1320 /* BACP config options */ 1321 static int 1322 print_bacp_config_options(netdissect_options *ndo, 1323 const u_char *p, int length) 1324 { 1325 int len, opt; 1326 1327 if (length < 2) 1328 return 0; 1329 ND_TCHECK2(*p, 2); 1330 len = p[1]; 1331 opt = p[0]; 1332 if (length < len) 1333 return 0; 1334 if (len < 2) { 1335 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u (length bogus, should be >= 2)", 1336 tok2str(bacconfopts_values, "Unknown", opt), 1337 opt, 1338 len)); 1339 return 0; 1340 } 1341 1342 ND_PRINT((ndo, "\n\t %s Option (0x%02x), length %u", 1343 tok2str(bacconfopts_values, "Unknown", opt), 1344 opt, 1345 len)); 1346 1347 switch (opt) { 1348 case BACPOPT_FPEER: 1349 if (len != 6) { 1350 ND_PRINT((ndo, " (length bogus, should be = 6)")); 1351 return len; 1352 } 1353 ND_TCHECK_32BITS(p + 2); 1354 ND_PRINT((ndo, ": Magic-Num 0x%08x", EXTRACT_32BITS(p + 2))); 1355 break; 1356 default: 1357 /* 1358 * Unknown option; dump it as raw bytes now if we're 1359 * not going to do so below. 1360 */ 1361 if (ndo->ndo_vflag < 2) 1362 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); 1363 break; 1364 } 1365 if (ndo->ndo_vflag > 1) 1366 print_unknown_data(ndo, &p[2], "\n\t ", len - 2); /* exclude TLV header */ 1367 1368 return len; 1369 1370 trunc: 1371 ND_PRINT((ndo, "[|bacp]")); 1372 return 0; 1373 } 1374 1375 static void 1376 ppp_hdlc(netdissect_options *ndo, 1377 const u_char *p, int length) 1378 { 1379 u_char *b, *t, c; 1380 const u_char *s; 1381 int i, proto; 1382 const void *se; 1383 1384 if (length <= 0) 1385 return; 1386 1387 b = (u_char *)malloc(length); 1388 if (b == NULL) 1389 return; 1390 1391 /* 1392 * Unescape all the data into a temporary, private, buffer. 1393 * Do this so that we dont overwrite the original packet 1394 * contents. 1395 */ 1396 for (s = p, t = b, i = length; i > 0 && ND_TTEST(*s); i--) { 1397 c = *s++; 1398 if (c == 0x7d) { 1399 if (i <= 1 || !ND_TTEST(*s)) 1400 break; 1401 i--; 1402 c = *s++ ^ 0x20; 1403 } 1404 *t++ = c; 1405 } 1406 1407 se = ndo->ndo_snapend; 1408 ndo->ndo_snapend = t; 1409 length = t - b; 1410 1411 /* now lets guess about the payload codepoint format */ 1412 if (length < 1) 1413 goto trunc; 1414 proto = *b; /* start with a one-octet codepoint guess */ 1415 1416 switch (proto) { 1417 case PPP_IP: 1418 ip_print(ndo, b + 1, length - 1); 1419 goto cleanup; 1420 case PPP_IPV6: 1421 ip6_print(ndo, b + 1, length - 1); 1422 goto cleanup; 1423 default: /* no luck - try next guess */ 1424 break; 1425 } 1426 1427 if (length < 2) 1428 goto trunc; 1429 proto = EXTRACT_16BITS(b); /* next guess - load two octets */ 1430 1431 switch (proto) { 1432 case (PPP_ADDRESS << 8 | PPP_CONTROL): /* looks like a PPP frame */ 1433 if (length < 4) 1434 goto trunc; 1435 proto = EXTRACT_16BITS(b+2); /* load the PPP proto-id */ 1436 handle_ppp(ndo, proto, b + 4, length - 4); 1437 break; 1438 default: /* last guess - proto must be a PPP proto-id */ 1439 handle_ppp(ndo, proto, b + 2, length - 2); 1440 break; 1441 } 1442 1443 cleanup: 1444 ndo->ndo_snapend = se; 1445 free(b); 1446 return; 1447 1448 trunc: 1449 ndo->ndo_snapend = se; 1450 free(b); 1451 ND_PRINT((ndo, "[|ppp]")); 1452 } 1453 1454 1455 /* PPP */ 1456 static void 1457 handle_ppp(netdissect_options *ndo, 1458 u_int proto, const u_char *p, int length) 1459 { 1460 if ((proto & 0xff00) == 0x7e00) { /* is this an escape code ? */ 1461 ppp_hdlc(ndo, p - 1, length); 1462 return; 1463 } 1464 1465 switch (proto) { 1466 case PPP_LCP: /* fall through */ 1467 case PPP_IPCP: 1468 case PPP_OSICP: 1469 case PPP_MPLSCP: 1470 case PPP_IPV6CP: 1471 case PPP_CCP: 1472 case PPP_BACP: 1473 handle_ctrl_proto(ndo, proto, p, length); 1474 break; 1475 case PPP_ML: 1476 handle_mlppp(ndo, p, length); 1477 break; 1478 case PPP_CHAP: 1479 handle_chap(ndo, p, length); 1480 break; 1481 case PPP_PAP: 1482 handle_pap(ndo, p, length); 1483 break; 1484 case PPP_BAP: /* XXX: not yet completed */ 1485 handle_bap(ndo, p, length); 1486 break; 1487 case ETHERTYPE_IP: /*XXX*/ 1488 case PPP_VJNC: 1489 case PPP_IP: 1490 ip_print(ndo, p, length); 1491 break; 1492 case ETHERTYPE_IPV6: /*XXX*/ 1493 case PPP_IPV6: 1494 ip6_print(ndo, p, length); 1495 break; 1496 case ETHERTYPE_IPX: /*XXX*/ 1497 case PPP_IPX: 1498 ipx_print(ndo, p, length); 1499 break; 1500 case PPP_OSI: 1501 isoclns_print(ndo, p, length); 1502 break; 1503 case PPP_MPLS_UCAST: 1504 case PPP_MPLS_MCAST: 1505 mpls_print(ndo, p, length); 1506 break; 1507 case PPP_COMP: 1508 ND_PRINT((ndo, "compressed PPP data")); 1509 break; 1510 default: 1511 ND_PRINT((ndo, "%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto))); 1512 print_unknown_data(ndo, p, "\n\t", length); 1513 break; 1514 } 1515 } 1516 1517 /* Standard PPP printer */ 1518 u_int 1519 ppp_print(netdissect_options *ndo, 1520 register const u_char *p, u_int length) 1521 { 1522 u_int proto,ppp_header; 1523 u_int olen = length; /* _o_riginal length */ 1524 u_int hdr_len = 0; 1525 1526 /* 1527 * Here, we assume that p points to the Address and Control 1528 * field (if they present). 1529 */ 1530 if (length < 2) 1531 goto trunc; 1532 ND_TCHECK2(*p, 2); 1533 ppp_header = EXTRACT_16BITS(p); 1534 1535 switch(ppp_header) { 1536 case (PPP_WITHDIRECTION_IN << 8 | PPP_CONTROL): 1537 if (ndo->ndo_eflag) ND_PRINT((ndo, "In ")); 1538 p += 2; 1539 length -= 2; 1540 hdr_len += 2; 1541 break; 1542 case (PPP_WITHDIRECTION_OUT << 8 | PPP_CONTROL): 1543 if (ndo->ndo_eflag) ND_PRINT((ndo, "Out ")); 1544 p += 2; 1545 length -= 2; 1546 hdr_len += 2; 1547 break; 1548 case (PPP_ADDRESS << 8 | PPP_CONTROL): 1549 p += 2; /* ACFC not used */ 1550 length -= 2; 1551 hdr_len += 2; 1552 break; 1553 1554 default: 1555 break; 1556 } 1557 1558 if (length < 2) 1559 goto trunc; 1560 ND_TCHECK(*p); 1561 if (*p % 2) { 1562 proto = *p; /* PFC is used */ 1563 p++; 1564 length--; 1565 hdr_len++; 1566 } else { 1567 ND_TCHECK2(*p, 2); 1568 proto = EXTRACT_16BITS(p); 1569 p += 2; 1570 length -= 2; 1571 hdr_len += 2; 1572 } 1573 1574 if (ndo->ndo_eflag) 1575 ND_PRINT((ndo, "%s (0x%04x), length %u: ", 1576 tok2str(ppptype2str, "unknown", proto), 1577 proto, 1578 olen)); 1579 1580 handle_ppp(ndo, proto, p, length); 1581 return (hdr_len); 1582 trunc: 1583 ND_PRINT((ndo, "[|ppp]")); 1584 return (0); 1585 } 1586 1587 1588 /* PPP I/F printer */ 1589 u_int 1590 ppp_if_print(netdissect_options *ndo, 1591 const struct pcap_pkthdr *h, register const u_char *p) 1592 { 1593 register u_int length = h->len; 1594 register u_int caplen = h->caplen; 1595 1596 if (caplen < PPP_HDRLEN) { 1597 ND_PRINT((ndo, "[|ppp]")); 1598 return (caplen); 1599 } 1600 1601 #if 0 1602 /* 1603 * XXX: seems to assume that there are 2 octets prepended to an 1604 * actual PPP frame. The 1st octet looks like Input/Output flag 1605 * while 2nd octet is unknown, at least to me 1606 * (mshindo@mshindo.net). 1607 * 1608 * That was what the original tcpdump code did. 1609 * 1610 * FreeBSD's "if_ppp.c" *does* set the first octet to 1 for outbound 1611 * packets and 0 for inbound packets - but only if the 1612 * protocol field has the 0x8000 bit set (i.e., it's a network 1613 * control protocol); it does so before running the packet through 1614 * "bpf_filter" to see if it should be discarded, and to see 1615 * if we should update the time we sent the most recent packet... 1616 * 1617 * ...but it puts the original address field back after doing 1618 * so. 1619 * 1620 * NetBSD's "if_ppp.c" doesn't set the first octet in that fashion. 1621 * 1622 * I don't know if any PPP implementation handed up to a BPF 1623 * device packets with the first octet being 1 for outbound and 1624 * 0 for inbound packets, so I (guy@alum.mit.edu) don't know 1625 * whether that ever needs to be checked or not. 1626 * 1627 * Note that NetBSD has a DLT_PPP_SERIAL, which it uses for PPP, 1628 * and its tcpdump appears to assume that the frame always 1629 * begins with an address field and a control field, and that 1630 * the address field might be 0x0f or 0x8f, for Cisco 1631 * point-to-point with HDLC framing as per section 4.3.1 of RFC 1632 * 1547, as well as 0xff, for PPP in HDLC-like framing as per 1633 * RFC 1662. 1634 * 1635 * (Is the Cisco framing in question what DLT_C_HDLC, in 1636 * BSD/OS, is?) 1637 */ 1638 if (ndo->ndo_eflag) 1639 ND_PRINT((ndo, "%c %4d %02x ", p[0] ? 'O' : 'I', length, p[1])); 1640 #endif 1641 1642 ppp_print(ndo, p, length); 1643 1644 return (0); 1645 } 1646 1647 /* 1648 * PPP I/F printer to use if we know that RFC 1662-style PPP in HDLC-like 1649 * framing, or Cisco PPP with HDLC framing as per section 4.3.1 of RFC 1547, 1650 * is being used (i.e., we don't check for PPP_ADDRESS and PPP_CONTROL, 1651 * discard them *if* those are the first two octets, and parse the remaining 1652 * packet as a PPP packet, as "ppp_print()" does). 1653 * 1654 * This handles, for example, DLT_PPP_SERIAL in NetBSD. 1655 */ 1656 u_int 1657 ppp_hdlc_if_print(netdissect_options *ndo, 1658 const struct pcap_pkthdr *h, register const u_char *p) 1659 { 1660 register u_int length = h->len; 1661 register u_int caplen = h->caplen; 1662 u_int proto; 1663 u_int hdrlen = 0; 1664 1665 if (caplen < 2) { 1666 ND_PRINT((ndo, "[|ppp]")); 1667 return (caplen); 1668 } 1669 1670 switch (p[0]) { 1671 1672 case PPP_ADDRESS: 1673 if (caplen < 4) { 1674 ND_PRINT((ndo, "[|ppp]")); 1675 return (caplen); 1676 } 1677 1678 if (ndo->ndo_eflag) 1679 ND_PRINT((ndo, "%02x %02x %d ", p[0], p[1], length)); 1680 p += 2; 1681 length -= 2; 1682 hdrlen += 2; 1683 1684 proto = EXTRACT_16BITS(p); 1685 p += 2; 1686 length -= 2; 1687 hdrlen += 2; 1688 ND_PRINT((ndo, "%s: ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto))); 1689 1690 handle_ppp(ndo, proto, p, length); 1691 break; 1692 1693 case CHDLC_UNICAST: 1694 case CHDLC_BCAST: 1695 return (chdlc_if_print(ndo, h, p)); 1696 1697 default: 1698 if (caplen < 4) { 1699 ND_PRINT((ndo, "[|ppp]")); 1700 return (caplen); 1701 } 1702 1703 if (ndo->ndo_eflag) 1704 ND_PRINT((ndo, "%02x %02x %d ", p[0], p[1], length)); 1705 p += 2; 1706 hdrlen += 2; 1707 1708 /* 1709 * XXX - NetBSD's "ppp_netbsd_serial_if_print()" treats 1710 * the next two octets as an Ethernet type; does that 1711 * ever happen? 1712 */ 1713 ND_PRINT((ndo, "unknown addr %02x; ctrl %02x", p[0], p[1])); 1714 break; 1715 } 1716 1717 return (hdrlen); 1718 } 1719 1720 #define PPP_BSDI_HDRLEN 24 1721 1722 /* BSD/OS specific PPP printer */ 1723 u_int 1724 ppp_bsdos_if_print(netdissect_options *ndo _U_, 1725 const struct pcap_pkthdr *h _U_, register const u_char *p _U_) 1726 { 1727 register int hdrlength; 1728 #ifdef __bsdi__ 1729 register u_int length = h->len; 1730 register u_int caplen = h->caplen; 1731 uint16_t ptype; 1732 const u_char *q; 1733 int i; 1734 1735 if (caplen < PPP_BSDI_HDRLEN) { 1736 ND_PRINT((ndo, "[|ppp]")); 1737 return (caplen) 1738 } 1739 1740 hdrlength = 0; 1741 1742 #if 0 1743 if (p[0] == PPP_ADDRESS && p[1] == PPP_CONTROL) { 1744 if (ndo->ndo_eflag) 1745 ND_PRINT((ndo, "%02x %02x ", p[0], p[1])); 1746 p += 2; 1747 hdrlength = 2; 1748 } 1749 1750 if (ndo->ndo_eflag) 1751 ND_PRINT((ndo, "%d ", length)); 1752 /* Retrieve the protocol type */ 1753 if (*p & 01) { 1754 /* Compressed protocol field */ 1755 ptype = *p; 1756 if (ndo->ndo_eflag) 1757 ND_PRINT((ndo, "%02x ", ptype)); 1758 p++; 1759 hdrlength += 1; 1760 } else { 1761 /* Un-compressed protocol field */ 1762 ptype = EXTRACT_16BITS(p); 1763 if (ndo->ndo_eflag) 1764 ND_PRINT((ndo, "%04x ", ptype)); 1765 p += 2; 1766 hdrlength += 2; 1767 } 1768 #else 1769 ptype = 0; /*XXX*/ 1770 if (ndo->ndo_eflag) 1771 ND_PRINT((ndo, "%c ", p[SLC_DIR] ? 'O' : 'I')); 1772 if (p[SLC_LLHL]) { 1773 /* link level header */ 1774 struct ppp_header *ph; 1775 1776 q = p + SLC_BPFHDRLEN; 1777 ph = (struct ppp_header *)q; 1778 if (ph->phdr_addr == PPP_ADDRESS 1779 && ph->phdr_ctl == PPP_CONTROL) { 1780 if (ndo->ndo_eflag) 1781 ND_PRINT((ndo, "%02x %02x ", q[0], q[1])); 1782 ptype = EXTRACT_16BITS(&ph->phdr_type); 1783 if (ndo->ndo_eflag && (ptype == PPP_VJC || ptype == PPP_VJNC)) { 1784 ND_PRINT((ndo, "%s ", tok2str(ppptype2str, 1785 "proto-#%d", ptype))); 1786 } 1787 } else { 1788 if (ndo->ndo_eflag) { 1789 ND_PRINT((ndo, "LLH=[")); 1790 for (i = 0; i < p[SLC_LLHL]; i++) 1791 ND_PRINT((ndo, "%02x", q[i])); 1792 ND_PRINT((ndo, "] ")); 1793 } 1794 } 1795 } 1796 if (ndo->ndo_eflag) 1797 ND_PRINT((ndo, "%d ", length)); 1798 if (p[SLC_CHL]) { 1799 q = p + SLC_BPFHDRLEN + p[SLC_LLHL]; 1800 1801 switch (ptype) { 1802 case PPP_VJC: 1803 ptype = vjc_print(ndo, q, ptype); 1804 hdrlength = PPP_BSDI_HDRLEN; 1805 p += hdrlength; 1806 switch (ptype) { 1807 case PPP_IP: 1808 ip_print(ndo, p, length); 1809 break; 1810 case PPP_IPV6: 1811 ip6_print(ndo, p, length); 1812 break; 1813 case PPP_MPLS_UCAST: 1814 case PPP_MPLS_MCAST: 1815 mpls_print(ndo, p, length); 1816 break; 1817 } 1818 goto printx; 1819 case PPP_VJNC: 1820 ptype = vjc_print(ndo, q, ptype); 1821 hdrlength = PPP_BSDI_HDRLEN; 1822 p += hdrlength; 1823 switch (ptype) { 1824 case PPP_IP: 1825 ip_print(ndo, p, length); 1826 break; 1827 case PPP_IPV6: 1828 ip6_print(ndo, p, length); 1829 break; 1830 case PPP_MPLS_UCAST: 1831 case PPP_MPLS_MCAST: 1832 mpls_print(ndo, p, length); 1833 break; 1834 } 1835 goto printx; 1836 default: 1837 if (ndo->ndo_eflag) { 1838 ND_PRINT((ndo, "CH=[")); 1839 for (i = 0; i < p[SLC_LLHL]; i++) 1840 ND_PRINT((ndo, "%02x", q[i])); 1841 ND_PRINT((ndo, "] ")); 1842 } 1843 break; 1844 } 1845 } 1846 1847 hdrlength = PPP_BSDI_HDRLEN; 1848 #endif 1849 1850 length -= hdrlength; 1851 p += hdrlength; 1852 1853 switch (ptype) { 1854 case PPP_IP: 1855 ip_print(p, length); 1856 break; 1857 case PPP_IPV6: 1858 ip6_print(ndo, p, length); 1859 break; 1860 case PPP_MPLS_UCAST: 1861 case PPP_MPLS_MCAST: 1862 mpls_print(ndo, p, length); 1863 break; 1864 default: 1865 ND_PRINT((ndo, "%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", ptype))); 1866 } 1867 1868 printx: 1869 #else /* __bsdi */ 1870 hdrlength = 0; 1871 #endif /* __bsdi__ */ 1872 return (hdrlength); 1873 } 1874 1875 1876 /* 1877 * Local Variables: 1878 * c-style: whitesmith 1879 * c-basic-offset: 8 1880 * End: 1881 */ 1882