1 /* $OpenBSD: print-l2tp.c,v 1.4 2009/07/12 18:11:03 jsg Exp $ */ 2 3 /* 4 * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that: (1) source code distributions 9 * retain the above copyright notice and this paragraph in its entirety, (2) 10 * distributions including binary code include the above copyright notice and 11 * this paragraph in its entirety in the documentation or other materials 12 * provided with the distribution, and (3) all advertising materials mentioning 13 * features or use of this software display the following acknowledgement: 14 * ``This product includes software developed by the University of California, 15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 16 * the University nor the names of its contributors may be used to endorse 17 * or promote products derived from this software without specific prior 18 * written permission. 19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 22 * 23 * L2TP support contributed by Motonori Shindo (mshindo@ascend.co.jp) 24 */ 25 26 #ifndef lint 27 static const char rcsid[] = 28 "@(#) $Id: print-l2tp.c,v 1.4 2009/07/12 18:11:03 jsg Exp $"; 29 #endif 30 31 #include <sys/types.h> 32 #include <sys/param.h> 33 #include <stdio.h> 34 35 #include "l2tp.h" 36 #include "interface.h" 37 38 static char tstr[] = " [|l2tp]"; 39 40 #ifndef TRUE 41 #define TRUE 1 42 #endif 43 44 #ifndef FALSE 45 #define FALSE 0 46 #endif 47 48 static u_char *l2tp_message_type_string[] = { 49 "RESERVED_0", /* 0 Reserved */ 50 "SCCRQ", /* 1 Start-Control-Connection-Request */ 51 "SCCRP", /* 2 Start-Control-Connection-Reply */ 52 "SCCCN", /* 3 Start-Control-Connection-Connected */ 53 "StopCCN", /* 4 Stop-Control-Connection-Notification */ 54 "RESERVED_5", /* 5 Reserved */ 55 "HELLO", /* 6 Hello */ 56 "OCRQ", /* 7 Outgoing-Call-Request */ 57 "OCRP", /* 8 Outgoing-Call-Reply */ 58 "OCCN", /* 9 Outgoing-Call-Connected */ 59 "ICRQ", /* 10 Incoming-Call-Request */ 60 "ICRP", /* 11 Incoming-Call-Reply */ 61 "ICCN", /* 12 Incoming-Call-Connected */ 62 "RESERVED_13", /* 13 Reserved */ 63 "CDN", /* 14 Call-Disconnect-Notify */ 64 "WEN", /* 15 WAN-Error-Notify */ 65 "SLI" /* 16 Set-Link-Info */ 66 #define L2TP_MAX_MSGTYPE_INDEX 17 67 }; 68 69 static void l2tp_msgtype_print(const u_char *dat, u_int length); 70 static void l2tp_result_code_print(const u_char *dat, u_int length); 71 static void l2tp_proto_ver_print(const u_char *dat, u_int length); 72 static void l2tp_framing_cap_print(const u_char *dat, u_int length); 73 static void l2tp_bearer_cap_print(const u_char *dat, u_int length); 74 static void l2tp_tie_breaker_print(const u_char *dat, u_int length); 75 static void l2tp_firm_ver_print(const u_char *dat, u_int length); 76 static void l2tp_host_name_print(const u_char *dat, u_int length); 77 static void l2tp_vendor_name_print(const u_char *dat, u_int length); 78 static void l2tp_assnd_tun_id_print(const u_char *dat, u_int length); 79 static void l2tp_recv_win_size_print(const u_char *dat, u_int length); 80 static void l2tp_challenge_print(const u_char *dat, u_int length); 81 static void l2tp_q931_cc_print(const u_char *dat, u_int length); 82 static void l2tp_challenge_resp_print(const u_char *dat, u_int length); 83 static void l2tp_assnd_sess_id_print(const u_char *dat, u_int length); 84 static void l2tp_call_ser_num_print(const u_char *dat, u_int length); 85 static void l2tp_minimum_bps_print(const u_char *dat, u_int length); 86 static void l2tp_maximum_bps_print(const u_char *dat, u_int length); 87 static void l2tp_bearer_type_print(const u_char *dat, u_int length); 88 static void l2tp_framing_type_print(const u_char *dat, u_int length); 89 static void l2tp_packet_proc_delay_print(const u_char *dat, u_int length); 90 static void l2tp_called_number_print(const u_char *dat, u_int length); 91 static void l2tp_calling_number_print(const u_char *dat, u_int length); 92 static void l2tp_sub_address_print(const u_char *dat, u_int length); 93 static void l2tp_tx_conn_speed_print(const u_char *dat, u_int length); 94 static void l2tp_phy_channel_id_print(const u_char *dat, u_int length); 95 static void l2tp_ini_recv_lcp_print(const u_char *dat, u_int length); 96 static void l2tp_last_sent_lcp_print(const u_char *dat, u_int length); 97 static void l2tp_last_recv_lcp_print(const u_char *dat, u_int length); 98 static void l2tp_proxy_auth_type_print(const u_char *dat, u_int length); 99 static void l2tp_proxy_auth_name_print(const u_char *dat, u_int length); 100 static void l2tp_proxy_auth_chal_print(const u_char *dat, u_int length); 101 static void l2tp_proxy_auth_id_print(const u_char *dat, u_int length); 102 static void l2tp_proxy_auth_resp_print(const u_char *dat, u_int length); 103 static void l2tp_call_errors_print(const u_char *dat, u_int length); 104 static void l2tp_accm_print(const u_char *dat, u_int length); 105 static void l2tp_random_vector_print(const u_char *dat, u_int length); 106 static void l2tp_private_grp_id_print(const u_char *dat, u_int length); 107 static void l2tp_rx_conn_speed_print(const u_char *dat, u_int length); 108 static void l2tp_seq_required_print(const u_char *dat, u_int length); 109 static void l2tp_avp_print(const u_char *dat, u_int length); 110 111 static struct l2tp_avp_vec l2tp_avp[] = { 112 {"MSGTYPE", l2tp_msgtype_print}, /* 0 Message Type */ 113 {"RESULT_CODE", l2tp_result_code_print}, /* 1 Result Code */ 114 {"PROTO_VER", l2tp_proto_ver_print}, /* 2 Protocol Version */ 115 {"FRAMING_CAP", l2tp_framing_cap_print}, /* 3 Framing Capabilities */ 116 {"BEARER_CAP", l2tp_bearer_cap_print}, /* 4 Bearer Capabilities */ 117 {"TIE_BREAKER", l2tp_tie_breaker_print}, /* 5 Tie Breaker */ 118 {"FIRM_VER", l2tp_firm_ver_print}, /* 6 Firmware Revision */ 119 {"HOST_NAME", l2tp_host_name_print}, /* 7 Host Name */ 120 {"VENDOR_NAME", l2tp_vendor_name_print}, /* 8 Vendor Name */ 121 {"ASSND_TUN_ID", l2tp_assnd_tun_id_print}, /* 9 Assigned Tunnel ID */ 122 {"RECV_WIN_SIZE", l2tp_recv_win_size_print}, /* 10 Receive Window Size */ 123 {"CHALLENGE", l2tp_challenge_print}, /* 11 Challenge */ 124 {"Q931_CC", l2tp_q931_cc_print}, /* 12 Q.931 Cause Code */ 125 {"CHALLENGE_RESP", l2tp_challenge_resp_print},/* 13 Challenge Response */ 126 {"ASSND_SESS_ID", l2tp_assnd_sess_id_print}, /* 14 Assigned Session ID */ 127 {"CALL_SER_NUM", l2tp_call_ser_num_print}, /* 15 Call Serial Number */ 128 {"MINIMUM_BPS", l2tp_minimum_bps_print},/* 16 Minimum BPS */ 129 {"MAXIMUM_BPS", l2tp_maximum_bps_print}, /* 17 Maximum BPS */ 130 {"BEARER_TYPE", l2tp_bearer_type_print},/* 18 Bearer Type */ 131 {"FRAMING_TYPE", l2tp_framing_type_print}, /* 19 Framing Type */ 132 {"PACKET_PROC_DELAY", l2tp_packet_proc_delay_print}, /* 20 Packet Processing Delay (OBSOLETE) */ 133 {"CALLED_NUMBER", l2tp_called_number_print}, /* 21 Called Number */ 134 {"CALLING_NUMBER", l2tp_calling_number_print},/* 22 Calling Number */ 135 {"SUB_ADDRESS", l2tp_sub_address_print},/* 23 Sub-Address */ 136 {"TX_CONN_SPEED", l2tp_tx_conn_speed_print}, /* 24 (Tx) Connect Speed */ 137 {"PHY_CHANNEL_ID", l2tp_phy_channel_id_print},/* 25 Physical Channel ID */ 138 {"INI_RECV_LCP", l2tp_ini_recv_lcp_print}, /* 26 Initial Received LCP CONFREQ */ 139 {"LAST_SENT_LCP", l2tp_last_sent_lcp_print}, /* 27 Last Sent LCP CONFREQ */ 140 {"LAST_RECV_LCP", l2tp_last_recv_lcp_print}, /* 28 Last Received LCP CONFREQ */ 141 {"PROXY_AUTH_TYPE", l2tp_proxy_auth_type_print},/* 29 Proxy Authen Type */ 142 {"PROXY_AUTH_NAME", l2tp_proxy_auth_name_print},/* 30 Proxy Authen Name */ 143 {"PROXY_AUTH_CHAL", l2tp_proxy_auth_chal_print},/* 31 Proxy Authen Challenge */ 144 {"PROXY_AUTH_ID", l2tp_proxy_auth_id_print}, /* 32 Proxy Authen ID */ 145 {"PROXY_AUTH_RESP", l2tp_proxy_auth_resp_print},/* 33 Proxy Authen Response */ 146 {"CALL_ERRORS", l2tp_call_errors_print}, /* 34 Call Errors */ 147 {"ACCM", l2tp_accm_print}, /* 35 ACCM */ 148 {"RANDOM_VECTOR", l2tp_random_vector_print}, /* 36 Random Vector */ 149 {"PRIVATE_GRP_ID", l2tp_private_grp_id_print},/* 37 Private Group ID */ 150 {"RX_CONN_SPEED", l2tp_rx_conn_speed_print}, /* 38 (Rx) Connect Speed */ 151 {"SEQ_REQUIRED", l2tp_seq_required_print}, /* 39 Sequencing Required */ 152 #define L2TP_MAX_AVP_INDEX 40 153 }; 154 155 #if 0 156 static char *l2tp_result_code_StopCCN[] = { 157 "Reserved", 158 "General request to clear control connection", 159 "General error--Error Code indicates the problem", 160 "Control channel already exists", 161 "Requester is not authorized to establish a control channel", 162 "The protocol version of the requester is not supported", 163 "Requester is being shut down", 164 "Finite State Machine error" 165 #define L2TP_MAX_RESULT_CODE_STOPCC_INDEX 8 166 }; 167 #endif 168 169 #if 0 170 static char *l2tp_result_code_CDN[] = { 171 "Reserved", 172 "Call disconnected due to loss of carrier", 173 "Call disconnected for the reason indicated in error code", 174 "Call disconnected for administrative reasons", 175 "Call failed due to lack of appropriate facilities being " \ 176 "available (temporary condition)", 177 "Call failed due to lack of appropriate facilities being " \ 178 "available (permanent condition)", 179 "Invalid destination", 180 "Call failed due to no carrier detected", 181 "Call failed due to detection of a busy signal", 182 "Call failed due to lack of a dial tone", 183 "Call was not established within time allotted by LAC", 184 "Call was connected but no appropriate framing was detected" 185 #define L2TP_MAX_RESULT_CODE_CDN_INDEX 12 186 }; 187 #endif 188 189 #if 0 190 static char *l2tp_error_code_general[] = { 191 "No general error", 192 "No control connection exists yet for this LAC-LNS pair", 193 "Length is wrong", 194 "One of the field values was out of range or " \ 195 "reserved field was non-zero" 196 "Insufficient resources to handle this operation now", 197 "The Session ID is invalid in this context", 198 "A generic vendor-specific error occurred in the LAC", 199 "Try another" 200 #define L2TP_MAX_ERROR_CODE_GENERAL_INDEX 8 201 }; 202 #endif 203 204 /******************************/ 205 /* generic print out routines */ 206 /******************************/ 207 static void 208 print_string(const u_char *dat, u_int length) 209 { 210 int i; 211 for (i=0; i<length; i++) { 212 printf("%c", *dat++); 213 } 214 } 215 216 static void 217 print_octets(const u_char *dat, u_int length) 218 { 219 int i; 220 for (i=0; i<length; i++) { 221 printf("%02x", *dat++); 222 } 223 } 224 225 static void 226 print_short(const u_short *dat) 227 { 228 printf("%u", ntohs(*dat)); 229 } 230 231 static void 232 print_int(const u_int *dat) 233 { 234 printf("%lu", (u_long)ntohl(*dat)); 235 } 236 237 /**********************************/ 238 /* AVP-specific print out routines*/ 239 /**********************************/ 240 static void 241 l2tp_msgtype_print(const u_char *dat, u_int length) 242 { 243 u_short *ptr = (u_short *)dat; 244 245 if (ntohs(*ptr) < L2TP_MAX_MSGTYPE_INDEX) { 246 printf("%s", l2tp_message_type_string[ntohs(*ptr)]); 247 } 248 } 249 250 static void 251 l2tp_result_code_print(const u_char *dat, u_int length) 252 { 253 /* we just print out the result and error code number */ 254 u_short *ptr = (u_short *)dat; 255 256 if (length == 2) { /* result code */ 257 printf("%d", ntohs(*ptr)); 258 } else if (length == 4) { /* result & error code */ 259 printf("%d/%d", ntohs(*ptr), ntohs(*(ptr+1))); 260 } else if (length > 4) { /* result & error code & msg */ 261 printf("%u/%u ", ntohs(*ptr), ntohs(*(ptr+1))); 262 print_string((u_char *)(ptr+2), length - 4); 263 } 264 } 265 266 static void 267 l2tp_proto_ver_print(const u_char *dat, u_int length) 268 { 269 printf("%d.%d", *dat, *(dat+1)); 270 } 271 272 273 static void 274 l2tp_framing_cap_print(const u_char *dat, u_int length) 275 { 276 u_int *ptr = (u_int *)dat; 277 278 if (ntohl(*ptr) & L2TP_FRAMING_CAP_ASYNC_MASK) { 279 printf("A"); 280 } 281 if (ntohl(*ptr) & L2TP_FRAMING_CAP_SYNC_MASK) { 282 printf("S"); 283 } 284 } 285 286 static void 287 l2tp_bearer_cap_print(const u_char *dat, u_int length) 288 { 289 u_int *ptr = (u_int *)dat; 290 291 if (ntohl(*ptr) & L2TP_BEARER_CAP_ANALOG_MASK) { 292 printf("A"); 293 } 294 if (ntohl(*ptr) & L2TP_BEARER_CAP_DIGITAL_MASK) { 295 printf("D"); 296 } 297 } 298 299 static void 300 l2tp_tie_breaker_print(const u_char *dat, u_int length) 301 { 302 printf("%lx", *(u_long *)dat); /* XXX */ 303 } 304 305 static void 306 l2tp_firm_ver_print(const u_char *dat, u_int length) 307 { 308 print_short((u_short *)dat); 309 } 310 311 static void 312 l2tp_host_name_print(const u_char *dat, u_int length) 313 { 314 print_string(dat, length); 315 } 316 317 static void 318 l2tp_vendor_name_print(const u_char *dat, u_int length) 319 { 320 print_string(dat, length); 321 } 322 323 static void 324 l2tp_assnd_tun_id_print(const u_char *dat, u_int length) 325 { 326 print_short((u_short *)dat); 327 } 328 329 static void 330 l2tp_recv_win_size_print(const u_char *dat, u_int length) 331 { 332 print_short((u_short *)dat); 333 } 334 335 static void 336 l2tp_challenge_print(const u_char *dat, u_int length) 337 { 338 print_octets(dat, length); 339 } 340 341 static void 342 l2tp_q931_cc_print(const u_char *dat, u_int length) 343 { 344 print_short((u_short *)dat); 345 print_short((u_short *)(dat + 2)); 346 if (length > 3) { 347 printf(" "); 348 print_string(dat+3, length-3); 349 } 350 } 351 352 static void 353 l2tp_challenge_resp_print(const u_char *dat, u_int length) 354 { 355 print_octets(dat, 16); /* XXX length should be 16? */ 356 } 357 358 static void 359 l2tp_assnd_sess_id_print(const u_char *dat, u_int length) 360 { 361 print_short((u_short *)dat); 362 } 363 364 static void 365 l2tp_call_ser_num_print(const u_char *dat, u_int length) 366 { 367 print_int((u_int *)dat); 368 } 369 370 static void 371 l2tp_minimum_bps_print(const u_char *dat, u_int length) 372 { 373 print_int((u_int *)dat); 374 } 375 376 static void 377 l2tp_maximum_bps_print(const u_char *dat, u_int length) 378 { 379 print_int((u_int *)dat); 380 } 381 382 static void 383 l2tp_bearer_type_print(const u_char *dat, u_int length) 384 { 385 u_int *ptr = (u_int *)dat; 386 387 if (ntohl(*ptr) & L2TP_BEARER_TYPE_ANALOG_MASK) { 388 printf("A"); 389 } 390 if (ntohl(*ptr) & L2TP_BEARER_TYPE_DIGITAL_MASK) { 391 printf("D"); 392 } 393 } 394 395 static void 396 l2tp_framing_type_print(const u_char *dat, u_int length) 397 { 398 u_int *ptr = (u_int *)dat; 399 400 if (ntohl(*ptr) & L2TP_FRAMING_TYPE_ASYNC_MASK) { 401 printf("A"); 402 } 403 if (ntohl(*ptr) & L2TP_FRAMING_TYPE_SYNC_MASK) { 404 printf("S"); 405 } 406 } 407 408 static void 409 l2tp_packet_proc_delay_print(const u_char *dat, u_int length) 410 { 411 printf("obsolete"); 412 } 413 414 static void 415 l2tp_called_number_print(const u_char *dat, u_int length) 416 { 417 print_string(dat, length); 418 } 419 420 static void 421 l2tp_calling_number_print(const u_char *dat, u_int length) 422 { 423 print_string(dat, length); 424 } 425 426 static void 427 l2tp_sub_address_print(const u_char *dat, u_int length) 428 { 429 print_string(dat, length); 430 } 431 432 static void 433 l2tp_tx_conn_speed_print(const u_char *dat, u_int length) 434 { 435 print_int((u_int *)dat); 436 } 437 438 static void 439 l2tp_phy_channel_id_print(const u_char *dat, u_int length) 440 { 441 print_int((u_int *)dat); 442 } 443 444 static void 445 l2tp_ini_recv_lcp_print(const u_char *dat, u_int length) 446 { 447 print_octets(dat, length); 448 } 449 450 static void 451 l2tp_last_sent_lcp_print(const u_char *dat, u_int length) 452 { 453 print_octets(dat, length); 454 } 455 456 static void 457 l2tp_last_recv_lcp_print(const u_char *dat, u_int length) 458 { 459 print_octets(dat, length); 460 } 461 462 static void 463 l2tp_proxy_auth_type_print(const u_char *dat, u_int length) 464 { 465 u_short *ptr = (u_short *)dat; 466 467 switch (ntohs(*ptr)) { 468 case L2TP_AUTHEN_TYPE_RESERVED: 469 printf("Reserved"); 470 break; 471 case L2TP_AUTHEN_TYPE_TEXTUAL: 472 printf("Textual"); 473 break; 474 case L2TP_AUTHEN_TYPE_CHAP: 475 printf("CHAP"); 476 break; 477 case L2TP_AUTHEN_TYPE_PAP: 478 printf("PAP"); 479 break; 480 case L2TP_AUTHEN_TYPE_NO_AUTH: 481 printf("No Auth"); 482 break; 483 case L2TP_AUTHEN_TYPE_MSCHAP: 484 printf("MS-CHAP"); 485 break; 486 default: 487 printf("unknown"); 488 } 489 } 490 491 static void 492 l2tp_proxy_auth_name_print(const u_char *dat, u_int length) 493 { 494 print_octets(dat, length); 495 } 496 497 static void 498 l2tp_proxy_auth_chal_print(const u_char *dat, u_int length) 499 { 500 print_octets(dat, length); 501 } 502 503 static void 504 l2tp_proxy_auth_id_print(const u_char *dat, u_int length) 505 { 506 u_short *ptr = (u_short *)dat; 507 508 printf("%d", ntohs(*ptr) & L2TP_PROXY_AUTH_ID_MASK); 509 } 510 511 static void 512 l2tp_proxy_auth_resp_print(const u_char *dat, u_int length) 513 { 514 print_octets(dat, length); 515 } 516 517 static void 518 l2tp_call_errors_print(const u_char *dat, u_int length) 519 { 520 struct l2tp_call_errors *ptr = (struct l2tp_call_errors *)dat; 521 522 printf("CRCErr=%d FrameErr=%d HardOver=%d BufOver=%d ", 523 ptr->crc_errs, 524 ptr->framing_errs, 525 ptr->hardware_overruns, 526 ptr->buffer_overruns); 527 printf("Timeout=%d AlingErr=%d", 528 ptr->timeout_errs, 529 ptr->alignment_errs); 530 } 531 532 static void 533 l2tp_accm_print(const u_char *dat, u_int length) 534 { 535 struct l2tp_accm *ptr = (struct l2tp_accm *)dat; 536 537 printf("send=%x recv=%x", ptr->send_accm, ptr->recv_accm); 538 } 539 540 static void 541 l2tp_random_vector_print(const u_char *dat, u_int length) 542 { 543 print_octets(dat, length); 544 } 545 546 static void 547 l2tp_private_grp_id_print(const u_char *dat, u_int length) 548 { 549 print_string(dat, length); 550 /* XXX print_octets is more appropriate?? */ 551 } 552 553 static void 554 l2tp_rx_conn_speed_print(const u_char *dat, u_int length) 555 { 556 print_int((u_int *)dat); 557 } 558 559 static void 560 l2tp_seq_required_print(const u_char *dat, u_int length) 561 { 562 return; 563 } 564 565 static void 566 l2tp_avp_print(const u_char *dat, u_int length) 567 { 568 u_int len; 569 const u_short *ptr = (u_short *)dat; 570 int hidden = FALSE; 571 572 printf(" "); 573 if (length > 0 && (snapend - dat) >= 2) { 574 /* there must be at least two octets for the length 575 to be decoded */ 576 if ((len = (ntohs(*ptr) & L2TP_AVP_HDR_LEN_MASK)) <= 577 (snapend - dat)) { 578 if (ntohs(*ptr) & L2TP_AVP_HDR_FLAG_MANDATORY) { 579 printf("*"); 580 } 581 if (ntohs(*ptr) & L2TP_AVP_HDR_FLAG_HIDDEN) { 582 hidden = TRUE; 583 printf("?"); 584 } 585 } else { 586 printf("|..."); 587 return; 588 } 589 ptr++; 590 591 if (ntohs(*ptr)) { /* IETF == 0 */ 592 printf("vendor=%04x", ntohs(*ptr)); 593 } 594 ptr++; 595 596 if (ntohs(*ptr) < L2TP_MAX_AVP_INDEX) { 597 printf("%s", l2tp_avp[ntohs(*ptr)].name); 598 printf("("); 599 if (!hidden && len >= 6) { 600 (l2tp_avp[ntohs(*ptr)].print) 601 ((u_char *)ptr+2, len-6); 602 } else { 603 printf("???"); 604 } 605 printf(")"); 606 } else { 607 printf(" invalid AVP %u", ntohs(*ptr)); 608 } 609 610 if (length >= len && len > 0) 611 l2tp_avp_print(dat + len, length - len); 612 } else if (length == 0) { 613 return; 614 } else { 615 printf("|..."); 616 } 617 } 618 619 620 void 621 l2tp_print(const u_char *dat, u_int length) 622 { 623 const u_short *ptr = (u_short *)dat; 624 u_int cnt = 0; /* total octets consumed */ 625 u_short pad; 626 int flag_t, flag_l, flag_s, flag_o, flag_p; 627 u_short l2tp_len; 628 629 flag_t = flag_l = flag_s = flag_o = flag_p = FALSE; 630 631 if (length < 6 || snapend - dat < 6) { 632 /* flag/ver, tunnel_id, session_id must be present for 633 this packet to be properly decoded */ 634 printf("%s", tstr); 635 return; 636 } 637 638 if ((ntohs(*ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2TP) { 639 printf(" l2tp:"); 640 } else if ((ntohs(*ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2F) { 641 printf(" l2f:"); 642 return; /* nothing to do */ 643 } else { 644 printf(" Unknown Version, neither L2F(1) nor L2TP(2)"); 645 return; /* nothing we can do */ 646 } 647 648 printf("["); 649 if (ntohs(*ptr) & L2TP_FLAG_TYPE) { 650 flag_t = TRUE; 651 printf("T"); 652 } 653 if (ntohs(*ptr) & L2TP_FLAG_LENGTH) { 654 flag_l = TRUE; 655 printf("L"); 656 } 657 if (ntohs(*ptr) & L2TP_FLAG_SEQUENCE) { 658 flag_s = TRUE; 659 printf("S"); 660 } 661 if (ntohs(*ptr) & L2TP_FLAG_OFFSET) { 662 flag_o = TRUE; 663 printf("O"); 664 } 665 if (ntohs(*ptr) & L2TP_FLAG_PRIORITY) { 666 flag_p = TRUE; 667 printf("P"); 668 } 669 printf("]"); 670 671 ptr++; 672 cnt += 2; 673 674 if (flag_l) { 675 l2tp_len = ntohs(*ptr++); /* XXX need to consider 676 truncation ?? */ 677 cnt += 2; 678 } else { 679 l2tp_len = 0; 680 } 681 682 printf("(%d/", ntohs(*ptr++)); /* Tunnel ID */ 683 printf("%d)", ntohs(*ptr++)); /* Session ID */ 684 cnt += 4; 685 686 if (flag_s) { 687 printf("Ns=%d,", ntohs(*ptr++)); 688 printf("Nr=%d", ntohs(*ptr++)); 689 cnt += 4; 690 } 691 692 if (flag_o) { 693 pad = ntohs(*ptr++); 694 ptr = (u_char *)ptr + pad; 695 cnt += (2 + pad); 696 } 697 698 if (flag_t) { 699 if (length - cnt == 0) { 700 printf(" ZLB"); 701 } else { 702 if (length >= cnt) 703 l2tp_avp_print((u_char *)ptr, length - cnt); 704 } 705 } else { 706 #if 0 707 printf(" {"); 708 ppp_hdlc_print((u_char *)ptr, length - cnt); 709 printf("}"); 710 #else 711 printf("[hdlc|]"); 712 #endif 713 } 714 } 715