The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 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 | * L2TP support contributed by Motonori Shindo (mshindo@mshindo.net) |
| 22 | */ |
| 23 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 24 | /* \summary: Layer Two Tunneling Protocol (L2TP) printer */ |
| 25 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 26 | #ifdef HAVE_CONFIG_H |
| 27 | #include "config.h" |
| 28 | #endif |
| 29 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 30 | #include <netdissect-stdinc.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 31 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 32 | #include "netdissect.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 33 | #include "extract.h" |
| 34 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 35 | #define L2TP_FLAG_TYPE 0x8000 /* Type (0=Data, 1=Control) */ |
| 36 | #define L2TP_FLAG_LENGTH 0x4000 /* Length */ |
| 37 | #define L2TP_FLAG_SEQUENCE 0x0800 /* Sequence */ |
| 38 | #define L2TP_FLAG_OFFSET 0x0200 /* Offset */ |
| 39 | #define L2TP_FLAG_PRIORITY 0x0100 /* Priority */ |
| 40 | |
| 41 | #define L2TP_VERSION_MASK 0x000f /* Version Mask */ |
| 42 | #define L2TP_VERSION_L2F 0x0001 /* L2F */ |
| 43 | #define L2TP_VERSION_L2TP 0x0002 /* L2TP */ |
| 44 | |
| 45 | #define L2TP_AVP_HDR_FLAG_MANDATORY 0x8000 /* Mandatory Flag */ |
| 46 | #define L2TP_AVP_HDR_FLAG_HIDDEN 0x4000 /* Hidden Flag */ |
| 47 | #define L2TP_AVP_HDR_LEN_MASK 0x03ff /* Length Mask */ |
| 48 | |
| 49 | #define L2TP_FRAMING_CAP_SYNC_MASK 0x00000001 /* Synchronous */ |
| 50 | #define L2TP_FRAMING_CAP_ASYNC_MASK 0x00000002 /* Asynchronous */ |
| 51 | |
| 52 | #define L2TP_FRAMING_TYPE_SYNC_MASK 0x00000001 /* Synchronous */ |
| 53 | #define L2TP_FRAMING_TYPE_ASYNC_MASK 0x00000002 /* Asynchronous */ |
| 54 | |
| 55 | #define L2TP_BEARER_CAP_DIGITAL_MASK 0x00000001 /* Digital */ |
| 56 | #define L2TP_BEARER_CAP_ANALOG_MASK 0x00000002 /* Analog */ |
| 57 | |
| 58 | #define L2TP_BEARER_TYPE_DIGITAL_MASK 0x00000001 /* Digital */ |
| 59 | #define L2TP_BEARER_TYPE_ANALOG_MASK 0x00000002 /* Analog */ |
| 60 | |
| 61 | /* Authen Type */ |
| 62 | #define L2TP_AUTHEN_TYPE_RESERVED 0x0000 /* Reserved */ |
| 63 | #define L2TP_AUTHEN_TYPE_TEXTUAL 0x0001 /* Textual username/password exchange */ |
| 64 | #define L2TP_AUTHEN_TYPE_CHAP 0x0002 /* PPP CHAP */ |
| 65 | #define L2TP_AUTHEN_TYPE_PAP 0x0003 /* PPP PAP */ |
| 66 | #define L2TP_AUTHEN_TYPE_NO_AUTH 0x0004 /* No Authentication */ |
| 67 | #define L2TP_AUTHEN_TYPE_MSCHAPv1 0x0005 /* MSCHAPv1 */ |
| 68 | |
| 69 | #define L2TP_PROXY_AUTH_ID_MASK 0x00ff |
| 70 | |
| 71 | static const char tstr[] = " [|l2tp]"; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 72 | |
| 73 | #define L2TP_MSGTYPE_SCCRQ 1 /* Start-Control-Connection-Request */ |
| 74 | #define L2TP_MSGTYPE_SCCRP 2 /* Start-Control-Connection-Reply */ |
| 75 | #define L2TP_MSGTYPE_SCCCN 3 /* Start-Control-Connection-Connected */ |
| 76 | #define L2TP_MSGTYPE_STOPCCN 4 /* Stop-Control-Connection-Notification */ |
| 77 | #define L2TP_MSGTYPE_HELLO 6 /* Hello */ |
| 78 | #define L2TP_MSGTYPE_OCRQ 7 /* Outgoing-Call-Request */ |
| 79 | #define L2TP_MSGTYPE_OCRP 8 /* Outgoing-Call-Reply */ |
| 80 | #define L2TP_MSGTYPE_OCCN 9 /* Outgoing-Call-Connected */ |
| 81 | #define L2TP_MSGTYPE_ICRQ 10 /* Incoming-Call-Request */ |
| 82 | #define L2TP_MSGTYPE_ICRP 11 /* Incoming-Call-Reply */ |
| 83 | #define L2TP_MSGTYPE_ICCN 12 /* Incoming-Call-Connected */ |
| 84 | #define L2TP_MSGTYPE_CDN 14 /* Call-Disconnect-Notify */ |
| 85 | #define L2TP_MSGTYPE_WEN 15 /* WAN-Error-Notify */ |
| 86 | #define L2TP_MSGTYPE_SLI 16 /* Set-Link-Info */ |
| 87 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 88 | static const struct tok l2tp_msgtype2str[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 89 | { L2TP_MSGTYPE_SCCRQ, "SCCRQ" }, |
| 90 | { L2TP_MSGTYPE_SCCRP, "SCCRP" }, |
| 91 | { L2TP_MSGTYPE_SCCCN, "SCCCN" }, |
| 92 | { L2TP_MSGTYPE_STOPCCN, "StopCCN" }, |
| 93 | { L2TP_MSGTYPE_HELLO, "HELLO" }, |
| 94 | { L2TP_MSGTYPE_OCRQ, "OCRQ" }, |
| 95 | { L2TP_MSGTYPE_OCRP, "OCRP" }, |
| 96 | { L2TP_MSGTYPE_OCCN, "OCCN" }, |
| 97 | { L2TP_MSGTYPE_ICRQ, "ICRQ" }, |
| 98 | { L2TP_MSGTYPE_ICRP, "ICRP" }, |
| 99 | { L2TP_MSGTYPE_ICCN, "ICCN" }, |
| 100 | { L2TP_MSGTYPE_CDN, "CDN" }, |
| 101 | { L2TP_MSGTYPE_WEN, "WEN" }, |
| 102 | { L2TP_MSGTYPE_SLI, "SLI" }, |
| 103 | { 0, NULL } |
| 104 | }; |
| 105 | |
| 106 | #define L2TP_AVP_MSGTYPE 0 /* Message Type */ |
| 107 | #define L2TP_AVP_RESULT_CODE 1 /* Result Code */ |
| 108 | #define L2TP_AVP_PROTO_VER 2 /* Protocol Version */ |
| 109 | #define L2TP_AVP_FRAMING_CAP 3 /* Framing Capabilities */ |
| 110 | #define L2TP_AVP_BEARER_CAP 4 /* Bearer Capabilities */ |
| 111 | #define L2TP_AVP_TIE_BREAKER 5 /* Tie Breaker */ |
| 112 | #define L2TP_AVP_FIRM_VER 6 /* Firmware Revision */ |
| 113 | #define L2TP_AVP_HOST_NAME 7 /* Host Name */ |
| 114 | #define L2TP_AVP_VENDOR_NAME 8 /* Vendor Name */ |
| 115 | #define L2TP_AVP_ASSND_TUN_ID 9 /* Assigned Tunnel ID */ |
| 116 | #define L2TP_AVP_RECV_WIN_SIZE 10 /* Receive Window Size */ |
| 117 | #define L2TP_AVP_CHALLENGE 11 /* Challenge */ |
| 118 | #define L2TP_AVP_Q931_CC 12 /* Q.931 Cause Code */ |
| 119 | #define L2TP_AVP_CHALLENGE_RESP 13 /* Challenge Response */ |
| 120 | #define L2TP_AVP_ASSND_SESS_ID 14 /* Assigned Session ID */ |
| 121 | #define L2TP_AVP_CALL_SER_NUM 15 /* Call Serial Number */ |
| 122 | #define L2TP_AVP_MINIMUM_BPS 16 /* Minimum BPS */ |
| 123 | #define L2TP_AVP_MAXIMUM_BPS 17 /* Maximum BPS */ |
| 124 | #define L2TP_AVP_BEARER_TYPE 18 /* Bearer Type */ |
| 125 | #define L2TP_AVP_FRAMING_TYPE 19 /* Framing Type */ |
| 126 | #define L2TP_AVP_PACKET_PROC_DELAY 20 /* Packet Processing Delay (OBSOLETE) */ |
| 127 | #define L2TP_AVP_CALLED_NUMBER 21 /* Called Number */ |
| 128 | #define L2TP_AVP_CALLING_NUMBER 22 /* Calling Number */ |
| 129 | #define L2TP_AVP_SUB_ADDRESS 23 /* Sub-Address */ |
| 130 | #define L2TP_AVP_TX_CONN_SPEED 24 /* (Tx) Connect Speed */ |
| 131 | #define L2TP_AVP_PHY_CHANNEL_ID 25 /* Physical Channel ID */ |
| 132 | #define L2TP_AVP_INI_RECV_LCP 26 /* Initial Received LCP CONFREQ */ |
| 133 | #define L2TP_AVP_LAST_SENT_LCP 27 /* Last Sent LCP CONFREQ */ |
| 134 | #define L2TP_AVP_LAST_RECV_LCP 28 /* Last Received LCP CONFREQ */ |
| 135 | #define L2TP_AVP_PROXY_AUTH_TYPE 29 /* Proxy Authen Type */ |
| 136 | #define L2TP_AVP_PROXY_AUTH_NAME 30 /* Proxy Authen Name */ |
| 137 | #define L2TP_AVP_PROXY_AUTH_CHAL 31 /* Proxy Authen Challenge */ |
| 138 | #define L2TP_AVP_PROXY_AUTH_ID 32 /* Proxy Authen ID */ |
| 139 | #define L2TP_AVP_PROXY_AUTH_RESP 33 /* Proxy Authen Response */ |
| 140 | #define L2TP_AVP_CALL_ERRORS 34 /* Call Errors */ |
| 141 | #define L2TP_AVP_ACCM 35 /* ACCM */ |
| 142 | #define L2TP_AVP_RANDOM_VECTOR 36 /* Random Vector */ |
| 143 | #define L2TP_AVP_PRIVATE_GRP_ID 37 /* Private Group ID */ |
| 144 | #define L2TP_AVP_RX_CONN_SPEED 38 /* (Rx) Connect Speed */ |
| 145 | #define L2TP_AVP_SEQ_REQUIRED 39 /* Sequencing Required */ |
| 146 | #define L2TP_AVP_PPP_DISCON_CC 46 /* PPP Disconnect Cause Code */ |
| 147 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 148 | static const struct tok l2tp_avp2str[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 149 | { L2TP_AVP_MSGTYPE, "MSGTYPE" }, |
| 150 | { L2TP_AVP_RESULT_CODE, "RESULT_CODE" }, |
| 151 | { L2TP_AVP_PROTO_VER, "PROTO_VER" }, |
| 152 | { L2TP_AVP_FRAMING_CAP, "FRAMING_CAP" }, |
| 153 | { L2TP_AVP_BEARER_CAP, "BEARER_CAP" }, |
| 154 | { L2TP_AVP_TIE_BREAKER, "TIE_BREAKER" }, |
| 155 | { L2TP_AVP_FIRM_VER, "FIRM_VER" }, |
| 156 | { L2TP_AVP_HOST_NAME, "HOST_NAME" }, |
| 157 | { L2TP_AVP_VENDOR_NAME, "VENDOR_NAME" }, |
| 158 | { L2TP_AVP_ASSND_TUN_ID, "ASSND_TUN_ID" }, |
| 159 | { L2TP_AVP_RECV_WIN_SIZE, "RECV_WIN_SIZE" }, |
| 160 | { L2TP_AVP_CHALLENGE, "CHALLENGE" }, |
| 161 | { L2TP_AVP_Q931_CC, "Q931_CC", }, |
| 162 | { L2TP_AVP_CHALLENGE_RESP, "CHALLENGE_RESP" }, |
| 163 | { L2TP_AVP_ASSND_SESS_ID, "ASSND_SESS_ID" }, |
| 164 | { L2TP_AVP_CALL_SER_NUM, "CALL_SER_NUM" }, |
| 165 | { L2TP_AVP_MINIMUM_BPS, "MINIMUM_BPS" }, |
| 166 | { L2TP_AVP_MAXIMUM_BPS, "MAXIMUM_BPS" }, |
| 167 | { L2TP_AVP_BEARER_TYPE, "BEARER_TYPE" }, |
| 168 | { L2TP_AVP_FRAMING_TYPE, "FRAMING_TYPE" }, |
| 169 | { L2TP_AVP_PACKET_PROC_DELAY, "PACKET_PROC_DELAY" }, |
| 170 | { L2TP_AVP_CALLED_NUMBER, "CALLED_NUMBER" }, |
| 171 | { L2TP_AVP_CALLING_NUMBER, "CALLING_NUMBER" }, |
| 172 | { L2TP_AVP_SUB_ADDRESS, "SUB_ADDRESS" }, |
| 173 | { L2TP_AVP_TX_CONN_SPEED, "TX_CONN_SPEED" }, |
| 174 | { L2TP_AVP_PHY_CHANNEL_ID, "PHY_CHANNEL_ID" }, |
| 175 | { L2TP_AVP_INI_RECV_LCP, "INI_RECV_LCP" }, |
| 176 | { L2TP_AVP_LAST_SENT_LCP, "LAST_SENT_LCP" }, |
| 177 | { L2TP_AVP_LAST_RECV_LCP, "LAST_RECV_LCP" }, |
| 178 | { L2TP_AVP_PROXY_AUTH_TYPE, "PROXY_AUTH_TYPE" }, |
| 179 | { L2TP_AVP_PROXY_AUTH_NAME, "PROXY_AUTH_NAME" }, |
| 180 | { L2TP_AVP_PROXY_AUTH_CHAL, "PROXY_AUTH_CHAL" }, |
| 181 | { L2TP_AVP_PROXY_AUTH_ID, "PROXY_AUTH_ID" }, |
| 182 | { L2TP_AVP_PROXY_AUTH_RESP, "PROXY_AUTH_RESP" }, |
| 183 | { L2TP_AVP_CALL_ERRORS, "CALL_ERRORS" }, |
| 184 | { L2TP_AVP_ACCM, "ACCM" }, |
| 185 | { L2TP_AVP_RANDOM_VECTOR, "RANDOM_VECTOR" }, |
| 186 | { L2TP_AVP_PRIVATE_GRP_ID, "PRIVATE_GRP_ID" }, |
| 187 | { L2TP_AVP_RX_CONN_SPEED, "RX_CONN_SPEED" }, |
| 188 | { L2TP_AVP_SEQ_REQUIRED, "SEQ_REQUIRED" }, |
| 189 | { L2TP_AVP_PPP_DISCON_CC, "PPP_DISCON_CC" }, |
| 190 | { 0, NULL } |
| 191 | }; |
| 192 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 193 | static const struct tok l2tp_authentype2str[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 194 | { L2TP_AUTHEN_TYPE_RESERVED, "Reserved" }, |
| 195 | { L2TP_AUTHEN_TYPE_TEXTUAL, "Textual" }, |
| 196 | { L2TP_AUTHEN_TYPE_CHAP, "CHAP" }, |
| 197 | { L2TP_AUTHEN_TYPE_PAP, "PAP" }, |
| 198 | { L2TP_AUTHEN_TYPE_NO_AUTH, "No Auth" }, |
| 199 | { L2TP_AUTHEN_TYPE_MSCHAPv1, "MS-CHAPv1" }, |
| 200 | { 0, NULL } |
| 201 | }; |
| 202 | |
| 203 | #define L2TP_PPP_DISCON_CC_DIRECTION_GLOBAL 0 |
| 204 | #define L2TP_PPP_DISCON_CC_DIRECTION_AT_PEER 1 |
| 205 | #define L2TP_PPP_DISCON_CC_DIRECTION_AT_LOCAL 2 |
| 206 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 207 | static const struct tok l2tp_cc_direction2str[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 208 | { L2TP_PPP_DISCON_CC_DIRECTION_GLOBAL, "global error" }, |
| 209 | { L2TP_PPP_DISCON_CC_DIRECTION_AT_PEER, "at peer" }, |
| 210 | { L2TP_PPP_DISCON_CC_DIRECTION_AT_LOCAL,"at local" }, |
| 211 | { 0, NULL } |
| 212 | }; |
| 213 | |
| 214 | #if 0 |
| 215 | static char *l2tp_result_code_StopCCN[] = { |
| 216 | "Reserved", |
| 217 | "General request to clear control connection", |
| 218 | "General error--Error Code indicates the problem", |
| 219 | "Control channel already exists", |
| 220 | "Requester is not authorized to establish a control channel", |
| 221 | "The protocol version of the requester is not supported", |
| 222 | "Requester is being shut down", |
| 223 | "Finite State Machine error" |
| 224 | #define L2TP_MAX_RESULT_CODE_STOPCC_INDEX 8 |
| 225 | }; |
| 226 | #endif |
| 227 | |
| 228 | #if 0 |
| 229 | static char *l2tp_result_code_CDN[] = { |
| 230 | "Reserved", |
| 231 | "Call disconnected due to loss of carrier", |
| 232 | "Call disconnected for the reason indicated in error code", |
| 233 | "Call disconnected for administrative reasons", |
| 234 | "Call failed due to lack of appropriate facilities being " \ |
| 235 | "available (temporary condition)", |
| 236 | "Call failed due to lack of appropriate facilities being " \ |
| 237 | "available (permanent condition)", |
| 238 | "Invalid destination", |
| 239 | "Call failed due to no carrier detected", |
| 240 | "Call failed due to detection of a busy signal", |
| 241 | "Call failed due to lack of a dial tone", |
| 242 | "Call was not established within time allotted by LAC", |
| 243 | "Call was connected but no appropriate framing was detected" |
| 244 | #define L2TP_MAX_RESULT_CODE_CDN_INDEX 12 |
| 245 | }; |
| 246 | #endif |
| 247 | |
| 248 | #if 0 |
| 249 | static char *l2tp_error_code_general[] = { |
| 250 | "No general error", |
| 251 | "No control connection exists yet for this LAC-LNS pair", |
| 252 | "Length is wrong", |
| 253 | "One of the field values was out of range or " \ |
| 254 | "reserved field was non-zero" |
| 255 | "Insufficient resources to handle this operation now", |
| 256 | "The Session ID is invalid in this context", |
| 257 | "A generic vendor-specific error occurred in the LAC", |
| 258 | "Try another" |
| 259 | #define L2TP_MAX_ERROR_CODE_GENERAL_INDEX 8 |
| 260 | }; |
| 261 | #endif |
| 262 | |
| 263 | /******************************/ |
| 264 | /* generic print out routines */ |
| 265 | /******************************/ |
| 266 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 267 | print_string(netdissect_options *ndo, const u_char *dat, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 268 | { |
| 269 | u_int i; |
| 270 | for (i=0; i<length; i++) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 271 | ND_PRINT((ndo, "%c", *dat++)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | |
| 275 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 276 | print_octets(netdissect_options *ndo, const u_char *dat, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 277 | { |
| 278 | u_int i; |
| 279 | for (i=0; i<length; i++) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 280 | ND_PRINT((ndo, "%02x", *dat++)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
| 284 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 285 | print_16bits_val(netdissect_options *ndo, const uint16_t *dat) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 286 | { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 287 | ND_PRINT((ndo, "%u", EXTRACT_16BITS(dat))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 291 | print_32bits_val(netdissect_options *ndo, const uint32_t *dat) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 292 | { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 293 | ND_PRINT((ndo, "%lu", (u_long)EXTRACT_32BITS(dat))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | /***********************************/ |
| 297 | /* AVP-specific print out routines */ |
| 298 | /***********************************/ |
| 299 | static void |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 300 | l2tp_msgtype_print(netdissect_options *ndo, const u_char *dat, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 301 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 302 | const uint16_t *ptr = (const uint16_t *)dat; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 303 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 304 | if (length < 2) { |
| 305 | ND_PRINT((ndo, "AVP too short")); |
| 306 | return; |
| 307 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 308 | ND_PRINT((ndo, "%s", tok2str(l2tp_msgtype2str, "MSGTYPE-#%u", |
| 309 | EXTRACT_16BITS(ptr)))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 313 | l2tp_result_code_print(netdissect_options *ndo, const u_char *dat, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 314 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 315 | const uint16_t *ptr = (const uint16_t *)dat; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 316 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 317 | /* Result Code */ |
| 318 | if (length < 2) { |
| 319 | ND_PRINT((ndo, "AVP too short")); |
| 320 | return; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 321 | } |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 322 | ND_PRINT((ndo, "%u", EXTRACT_16BITS(ptr))); |
| 323 | ptr++; |
| 324 | length -= 2; |
| 325 | |
| 326 | /* Error Code (opt) */ |
| 327 | if (length == 0) |
| 328 | return; |
| 329 | if (length < 2) { |
| 330 | ND_PRINT((ndo, " AVP too short")); |
| 331 | return; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 332 | } |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 333 | ND_PRINT((ndo, "/%u", EXTRACT_16BITS(ptr))); |
| 334 | ptr++; |
| 335 | length -= 2; |
| 336 | |
| 337 | /* Error Message (opt) */ |
| 338 | if (length == 0) |
| 339 | return; |
| 340 | ND_PRINT((ndo, " ")); |
| 341 | print_string(ndo, (const u_char *)ptr, length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | static void |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 345 | l2tp_proto_ver_print(netdissect_options *ndo, const uint16_t *dat, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 346 | { |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 347 | if (length < 2) { |
| 348 | ND_PRINT((ndo, "AVP too short")); |
| 349 | return; |
| 350 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 351 | ND_PRINT((ndo, "%u.%u", (EXTRACT_16BITS(dat) >> 8), |
| 352 | (EXTRACT_16BITS(dat) & 0xff))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | static void |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 356 | l2tp_framing_cap_print(netdissect_options *ndo, const u_char *dat, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 357 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 358 | const uint32_t *ptr = (const uint32_t *)dat; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 359 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 360 | if (length < 4) { |
| 361 | ND_PRINT((ndo, "AVP too short")); |
| 362 | return; |
| 363 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 364 | if (EXTRACT_32BITS(ptr) & L2TP_FRAMING_CAP_ASYNC_MASK) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 365 | ND_PRINT((ndo, "A")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 366 | } |
| 367 | if (EXTRACT_32BITS(ptr) & L2TP_FRAMING_CAP_SYNC_MASK) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 368 | ND_PRINT((ndo, "S")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | |
| 372 | static void |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 373 | l2tp_bearer_cap_print(netdissect_options *ndo, const u_char *dat, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 374 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 375 | const uint32_t *ptr = (const uint32_t *)dat; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 376 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 377 | if (length < 4) { |
| 378 | ND_PRINT((ndo, "AVP too short")); |
| 379 | return; |
| 380 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 381 | if (EXTRACT_32BITS(ptr) & L2TP_BEARER_CAP_ANALOG_MASK) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 382 | ND_PRINT((ndo, "A")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 383 | } |
| 384 | if (EXTRACT_32BITS(ptr) & L2TP_BEARER_CAP_DIGITAL_MASK) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 385 | ND_PRINT((ndo, "D")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
| 389 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 390 | l2tp_q931_cc_print(netdissect_options *ndo, const u_char *dat, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 391 | { |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 392 | if (length < 3) { |
| 393 | ND_PRINT((ndo, "AVP too short")); |
| 394 | return; |
| 395 | } |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 396 | print_16bits_val(ndo, (const uint16_t *)dat); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 397 | ND_PRINT((ndo, ", %02x", dat[2])); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 398 | dat += 3; |
| 399 | length -= 3; |
| 400 | if (length != 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 401 | ND_PRINT((ndo, " ")); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 402 | print_string(ndo, dat, length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | |
| 406 | static void |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 407 | l2tp_bearer_type_print(netdissect_options *ndo, const u_char *dat, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 408 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 409 | const uint32_t *ptr = (const uint32_t *)dat; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 410 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 411 | if (length < 4) { |
| 412 | ND_PRINT((ndo, "AVP too short")); |
| 413 | return; |
| 414 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 415 | if (EXTRACT_32BITS(ptr) & L2TP_BEARER_TYPE_ANALOG_MASK) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 416 | ND_PRINT((ndo, "A")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 417 | } |
| 418 | if (EXTRACT_32BITS(ptr) & L2TP_BEARER_TYPE_DIGITAL_MASK) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 419 | ND_PRINT((ndo, "D")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | |
| 423 | static void |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 424 | l2tp_framing_type_print(netdissect_options *ndo, const u_char *dat, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 425 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 426 | const uint32_t *ptr = (const uint32_t *)dat; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 427 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 428 | if (length < 4) { |
| 429 | ND_PRINT((ndo, "AVP too short")); |
| 430 | return; |
| 431 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 432 | if (EXTRACT_32BITS(ptr) & L2TP_FRAMING_TYPE_ASYNC_MASK) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 433 | ND_PRINT((ndo, "A")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 434 | } |
| 435 | if (EXTRACT_32BITS(ptr) & L2TP_FRAMING_TYPE_SYNC_MASK) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 436 | ND_PRINT((ndo, "S")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | |
| 440 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 441 | l2tp_packet_proc_delay_print(netdissect_options *ndo) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 442 | { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 443 | ND_PRINT((ndo, "obsolete")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | static void |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 447 | l2tp_proxy_auth_type_print(netdissect_options *ndo, const u_char *dat, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 448 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 449 | const uint16_t *ptr = (const uint16_t *)dat; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 450 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 451 | if (length < 2) { |
| 452 | ND_PRINT((ndo, "AVP too short")); |
| 453 | return; |
| 454 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 455 | ND_PRINT((ndo, "%s", tok2str(l2tp_authentype2str, |
| 456 | "AuthType-#%u", EXTRACT_16BITS(ptr)))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | static void |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 460 | l2tp_proxy_auth_id_print(netdissect_options *ndo, const u_char *dat, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 461 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 462 | const uint16_t *ptr = (const uint16_t *)dat; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 463 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 464 | if (length < 2) { |
| 465 | ND_PRINT((ndo, "AVP too short")); |
| 466 | return; |
| 467 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 468 | ND_PRINT((ndo, "%u", EXTRACT_16BITS(ptr) & L2TP_PROXY_AUTH_ID_MASK)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | static void |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 472 | l2tp_call_errors_print(netdissect_options *ndo, const u_char *dat, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 473 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 474 | const uint16_t *ptr = (const uint16_t *)dat; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 475 | uint16_t val_h, val_l; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 476 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 477 | if (length < 2) { |
| 478 | ND_PRINT((ndo, "AVP too short")); |
| 479 | return; |
| 480 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 481 | ptr++; /* skip "Reserved" */ |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 482 | length -= 2; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 483 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 484 | if (length < 4) { |
| 485 | ND_PRINT((ndo, "AVP too short")); |
| 486 | return; |
| 487 | } |
| 488 | val_h = EXTRACT_16BITS(ptr); ptr++; length -= 2; |
| 489 | val_l = EXTRACT_16BITS(ptr); ptr++; length -= 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 490 | ND_PRINT((ndo, "CRCErr=%u ", (val_h<<16) + val_l)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 491 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 492 | if (length < 4) { |
| 493 | ND_PRINT((ndo, "AVP too short")); |
| 494 | return; |
| 495 | } |
| 496 | val_h = EXTRACT_16BITS(ptr); ptr++; length -= 2; |
| 497 | val_l = EXTRACT_16BITS(ptr); ptr++; length -= 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 498 | ND_PRINT((ndo, "FrameErr=%u ", (val_h<<16) + val_l)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 499 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 500 | if (length < 4) { |
| 501 | ND_PRINT((ndo, "AVP too short")); |
| 502 | return; |
| 503 | } |
| 504 | val_h = EXTRACT_16BITS(ptr); ptr++; length -= 2; |
| 505 | val_l = EXTRACT_16BITS(ptr); ptr++; length -= 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 506 | ND_PRINT((ndo, "HardOver=%u ", (val_h<<16) + val_l)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 507 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 508 | if (length < 4) { |
| 509 | ND_PRINT((ndo, "AVP too short")); |
| 510 | return; |
| 511 | } |
| 512 | val_h = EXTRACT_16BITS(ptr); ptr++; length -= 2; |
| 513 | val_l = EXTRACT_16BITS(ptr); ptr++; length -= 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 514 | ND_PRINT((ndo, "BufOver=%u ", (val_h<<16) + val_l)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 515 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 516 | if (length < 4) { |
| 517 | ND_PRINT((ndo, "AVP too short")); |
| 518 | return; |
| 519 | } |
| 520 | val_h = EXTRACT_16BITS(ptr); ptr++; length -= 2; |
| 521 | val_l = EXTRACT_16BITS(ptr); ptr++; length -= 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 522 | ND_PRINT((ndo, "Timeout=%u ", (val_h<<16) + val_l)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 523 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 524 | if (length < 4) { |
| 525 | ND_PRINT((ndo, "AVP too short")); |
| 526 | return; |
| 527 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 528 | val_h = EXTRACT_16BITS(ptr); ptr++; |
| 529 | val_l = EXTRACT_16BITS(ptr); ptr++; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 530 | ND_PRINT((ndo, "AlignErr=%u ", (val_h<<16) + val_l)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | static void |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 534 | l2tp_accm_print(netdissect_options *ndo, const u_char *dat, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 535 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 536 | const uint16_t *ptr = (const uint16_t *)dat; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 537 | uint16_t val_h, val_l; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 538 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 539 | if (length < 2) { |
| 540 | ND_PRINT((ndo, "AVP too short")); |
| 541 | return; |
| 542 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 543 | ptr++; /* skip "Reserved" */ |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 544 | length -= 2; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 545 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 546 | if (length < 4) { |
| 547 | ND_PRINT((ndo, "AVP too short")); |
| 548 | return; |
| 549 | } |
| 550 | val_h = EXTRACT_16BITS(ptr); ptr++; length -= 2; |
| 551 | val_l = EXTRACT_16BITS(ptr); ptr++; length -= 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 552 | ND_PRINT((ndo, "send=%08x ", (val_h<<16) + val_l)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 553 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 554 | if (length < 4) { |
| 555 | ND_PRINT((ndo, "AVP too short")); |
| 556 | return; |
| 557 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 558 | val_h = EXTRACT_16BITS(ptr); ptr++; |
| 559 | val_l = EXTRACT_16BITS(ptr); ptr++; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 560 | ND_PRINT((ndo, "recv=%08x ", (val_h<<16) + val_l)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 564 | l2tp_ppp_discon_cc_print(netdissect_options *ndo, const u_char *dat, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 565 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 566 | const uint16_t *ptr = (const uint16_t *)dat; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 567 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 568 | if (length < 5) { |
| 569 | ND_PRINT((ndo, "AVP too short")); |
| 570 | return; |
| 571 | } |
| 572 | /* Disconnect Code */ |
| 573 | ND_PRINT((ndo, "%04x, ", EXTRACT_16BITS(dat))); |
| 574 | dat += 2; |
| 575 | length -= 2; |
| 576 | /* Control Protocol Number */ |
| 577 | ND_PRINT((ndo, "%04x ", EXTRACT_16BITS(dat))); |
| 578 | dat += 2; |
| 579 | length -= 2; |
| 580 | /* Direction */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 581 | ND_PRINT((ndo, "%s", tok2str(l2tp_cc_direction2str, |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 582 | "Direction-#%u", EXTRACT_8BITS(ptr)))); |
| 583 | ptr++; |
| 584 | length--; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 585 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 586 | if (length != 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 587 | ND_PRINT((ndo, " ")); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 588 | print_string(ndo, (const u_char *)ptr, length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | |
| 592 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 593 | l2tp_avp_print(netdissect_options *ndo, const u_char *dat, int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 594 | { |
| 595 | u_int len; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 596 | const uint16_t *ptr = (const uint16_t *)dat; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 597 | uint16_t attr_type; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 598 | int hidden = FALSE; |
| 599 | |
| 600 | if (length <= 0) { |
| 601 | return; |
| 602 | } |
| 603 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 604 | ND_PRINT((ndo, " ")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 605 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 606 | ND_TCHECK(*ptr); /* Flags & Length */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 607 | len = EXTRACT_16BITS(ptr) & L2TP_AVP_HDR_LEN_MASK; |
| 608 | |
| 609 | /* If it is not long enough to contain the header, we'll give up. */ |
| 610 | if (len < 6) |
| 611 | goto trunc; |
| 612 | |
| 613 | /* If it goes past the end of the remaining length of the packet, |
| 614 | we'll give up. */ |
| 615 | if (len > (u_int)length) |
| 616 | goto trunc; |
| 617 | |
| 618 | /* If it goes past the end of the remaining length of the captured |
| 619 | data, we'll give up. */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 620 | ND_TCHECK2(*ptr, len); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 621 | |
| 622 | /* |
| 623 | * After this point, we don't need to check whether we go past |
| 624 | * the length of the captured data; however, we *do* need to |
| 625 | * check whether we go past the end of the AVP. |
| 626 | */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 627 | |
| 628 | if (EXTRACT_16BITS(ptr) & L2TP_AVP_HDR_FLAG_MANDATORY) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 629 | ND_PRINT((ndo, "*")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 630 | } |
| 631 | if (EXTRACT_16BITS(ptr) & L2TP_AVP_HDR_FLAG_HIDDEN) { |
| 632 | hidden = TRUE; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 633 | ND_PRINT((ndo, "?")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 634 | } |
| 635 | ptr++; |
| 636 | |
| 637 | if (EXTRACT_16BITS(ptr)) { |
| 638 | /* Vendor Specific Attribute */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 639 | ND_PRINT((ndo, "VENDOR%04x:", EXTRACT_16BITS(ptr))); ptr++; |
| 640 | ND_PRINT((ndo, "ATTR%04x", EXTRACT_16BITS(ptr))); ptr++; |
| 641 | ND_PRINT((ndo, "(")); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 642 | print_octets(ndo, (const u_char *)ptr, len-6); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 643 | ND_PRINT((ndo, ")")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 644 | } else { |
| 645 | /* IETF-defined Attributes */ |
| 646 | ptr++; |
| 647 | attr_type = EXTRACT_16BITS(ptr); ptr++; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 648 | ND_PRINT((ndo, "%s", tok2str(l2tp_avp2str, "AVP-#%u", attr_type))); |
| 649 | ND_PRINT((ndo, "(")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 650 | if (hidden) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 651 | ND_PRINT((ndo, "???")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 652 | } else { |
| 653 | switch (attr_type) { |
| 654 | case L2TP_AVP_MSGTYPE: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 655 | l2tp_msgtype_print(ndo, (const u_char *)ptr, len-6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 656 | break; |
| 657 | case L2TP_AVP_RESULT_CODE: |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 658 | l2tp_result_code_print(ndo, (const u_char *)ptr, len-6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 659 | break; |
| 660 | case L2TP_AVP_PROTO_VER: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 661 | l2tp_proto_ver_print(ndo, ptr, len-6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 662 | break; |
| 663 | case L2TP_AVP_FRAMING_CAP: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 664 | l2tp_framing_cap_print(ndo, (const u_char *)ptr, len-6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 665 | break; |
| 666 | case L2TP_AVP_BEARER_CAP: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 667 | l2tp_bearer_cap_print(ndo, (const u_char *)ptr, len-6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 668 | break; |
| 669 | case L2TP_AVP_TIE_BREAKER: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 670 | if (len-6 < 8) { |
| 671 | ND_PRINT((ndo, "AVP too short")); |
| 672 | break; |
| 673 | } |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 674 | print_octets(ndo, (const u_char *)ptr, 8); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 675 | break; |
| 676 | case L2TP_AVP_FIRM_VER: |
| 677 | case L2TP_AVP_ASSND_TUN_ID: |
| 678 | case L2TP_AVP_RECV_WIN_SIZE: |
| 679 | case L2TP_AVP_ASSND_SESS_ID: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 680 | if (len-6 < 2) { |
| 681 | ND_PRINT((ndo, "AVP too short")); |
| 682 | break; |
| 683 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 684 | print_16bits_val(ndo, ptr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 685 | break; |
| 686 | case L2TP_AVP_HOST_NAME: |
| 687 | case L2TP_AVP_VENDOR_NAME: |
| 688 | case L2TP_AVP_CALLING_NUMBER: |
| 689 | case L2TP_AVP_CALLED_NUMBER: |
| 690 | case L2TP_AVP_SUB_ADDRESS: |
| 691 | case L2TP_AVP_PROXY_AUTH_NAME: |
| 692 | case L2TP_AVP_PRIVATE_GRP_ID: |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 693 | print_string(ndo, (const u_char *)ptr, len-6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 694 | break; |
| 695 | case L2TP_AVP_CHALLENGE: |
| 696 | case L2TP_AVP_INI_RECV_LCP: |
| 697 | case L2TP_AVP_LAST_SENT_LCP: |
| 698 | case L2TP_AVP_LAST_RECV_LCP: |
| 699 | case L2TP_AVP_PROXY_AUTH_CHAL: |
| 700 | case L2TP_AVP_PROXY_AUTH_RESP: |
| 701 | case L2TP_AVP_RANDOM_VECTOR: |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 702 | print_octets(ndo, (const u_char *)ptr, len-6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 703 | break; |
| 704 | case L2TP_AVP_Q931_CC: |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 705 | l2tp_q931_cc_print(ndo, (const u_char *)ptr, len-6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 706 | break; |
| 707 | case L2TP_AVP_CHALLENGE_RESP: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 708 | if (len-6 < 16) { |
| 709 | ND_PRINT((ndo, "AVP too short")); |
| 710 | break; |
| 711 | } |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 712 | print_octets(ndo, (const u_char *)ptr, 16); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 713 | break; |
| 714 | case L2TP_AVP_CALL_SER_NUM: |
| 715 | case L2TP_AVP_MINIMUM_BPS: |
| 716 | case L2TP_AVP_MAXIMUM_BPS: |
| 717 | case L2TP_AVP_TX_CONN_SPEED: |
| 718 | case L2TP_AVP_PHY_CHANNEL_ID: |
| 719 | case L2TP_AVP_RX_CONN_SPEED: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 720 | if (len-6 < 4) { |
| 721 | ND_PRINT((ndo, "AVP too short")); |
| 722 | break; |
| 723 | } |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 724 | print_32bits_val(ndo, (const uint32_t *)ptr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 725 | break; |
| 726 | case L2TP_AVP_BEARER_TYPE: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 727 | l2tp_bearer_type_print(ndo, (const u_char *)ptr, len-6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 728 | break; |
| 729 | case L2TP_AVP_FRAMING_TYPE: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 730 | l2tp_framing_type_print(ndo, (const u_char *)ptr, len-6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 731 | break; |
| 732 | case L2TP_AVP_PACKET_PROC_DELAY: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 733 | l2tp_packet_proc_delay_print(ndo); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 734 | break; |
| 735 | case L2TP_AVP_PROXY_AUTH_TYPE: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 736 | l2tp_proxy_auth_type_print(ndo, (const u_char *)ptr, len-6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 737 | break; |
| 738 | case L2TP_AVP_PROXY_AUTH_ID: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 739 | l2tp_proxy_auth_id_print(ndo, (const u_char *)ptr, len-6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 740 | break; |
| 741 | case L2TP_AVP_CALL_ERRORS: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 742 | l2tp_call_errors_print(ndo, (const u_char *)ptr, len-6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 743 | break; |
| 744 | case L2TP_AVP_ACCM: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 745 | l2tp_accm_print(ndo, (const u_char *)ptr, len-6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 746 | break; |
| 747 | case L2TP_AVP_SEQ_REQUIRED: |
| 748 | break; /* No Attribute Value */ |
| 749 | case L2TP_AVP_PPP_DISCON_CC: |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 750 | l2tp_ppp_discon_cc_print(ndo, (const u_char *)ptr, len-6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 751 | break; |
| 752 | default: |
| 753 | break; |
| 754 | } |
| 755 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 756 | ND_PRINT((ndo, ")")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 757 | } |
| 758 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 759 | l2tp_avp_print(ndo, dat+len, length-len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 760 | return; |
| 761 | |
| 762 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 763 | ND_PRINT((ndo, "|...")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | |
| 767 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 768 | l2tp_print(netdissect_options *ndo, const u_char *dat, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 769 | { |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 770 | const u_char *ptr = dat; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 771 | u_int cnt = 0; /* total octets consumed */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 772 | uint16_t pad; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 773 | int flag_t, flag_l, flag_s, flag_o; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 774 | uint16_t l2tp_len; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 775 | |
| 776 | flag_t = flag_l = flag_s = flag_o = FALSE; |
| 777 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 778 | ND_TCHECK2(*ptr, 2); /* Flags & Version */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 779 | if ((EXTRACT_16BITS(ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2TP) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 780 | ND_PRINT((ndo, " l2tp:")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 781 | } else if ((EXTRACT_16BITS(ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2F) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 782 | ND_PRINT((ndo, " l2f:")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 783 | return; /* nothing to do */ |
| 784 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 785 | ND_PRINT((ndo, " Unknown Version, neither L2F(1) nor L2TP(2)")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 786 | return; /* nothing we can do */ |
| 787 | } |
| 788 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 789 | ND_PRINT((ndo, "[")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 790 | if (EXTRACT_16BITS(ptr) & L2TP_FLAG_TYPE) { |
| 791 | flag_t = TRUE; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 792 | ND_PRINT((ndo, "T")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 793 | } |
| 794 | if (EXTRACT_16BITS(ptr) & L2TP_FLAG_LENGTH) { |
| 795 | flag_l = TRUE; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 796 | ND_PRINT((ndo, "L")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 797 | } |
| 798 | if (EXTRACT_16BITS(ptr) & L2TP_FLAG_SEQUENCE) { |
| 799 | flag_s = TRUE; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 800 | ND_PRINT((ndo, "S")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 801 | } |
| 802 | if (EXTRACT_16BITS(ptr) & L2TP_FLAG_OFFSET) { |
| 803 | flag_o = TRUE; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 804 | ND_PRINT((ndo, "O")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 805 | } |
| 806 | if (EXTRACT_16BITS(ptr) & L2TP_FLAG_PRIORITY) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 807 | ND_PRINT((ndo, "P")); |
| 808 | ND_PRINT((ndo, "]")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 809 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 810 | ptr += 2; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 811 | cnt += 2; |
| 812 | |
| 813 | if (flag_l) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 814 | ND_TCHECK2(*ptr, 2); /* Length */ |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 815 | l2tp_len = EXTRACT_16BITS(ptr); |
| 816 | ptr += 2; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 817 | cnt += 2; |
| 818 | } else { |
| 819 | l2tp_len = 0; |
| 820 | } |
| 821 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 822 | ND_TCHECK2(*ptr, 2); /* Tunnel ID */ |
| 823 | ND_PRINT((ndo, "(%u/", EXTRACT_16BITS(ptr))); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 824 | ptr += 2; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 825 | cnt += 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 826 | ND_TCHECK2(*ptr, 2); /* Session ID */ |
| 827 | ND_PRINT((ndo, "%u)", EXTRACT_16BITS(ptr))); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 828 | ptr += 2; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 829 | cnt += 2; |
| 830 | |
| 831 | if (flag_s) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 832 | ND_TCHECK2(*ptr, 2); /* Ns */ |
| 833 | ND_PRINT((ndo, "Ns=%u,", EXTRACT_16BITS(ptr))); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 834 | ptr += 2; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 835 | cnt += 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 836 | ND_TCHECK2(*ptr, 2); /* Nr */ |
| 837 | ND_PRINT((ndo, "Nr=%u", EXTRACT_16BITS(ptr))); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 838 | ptr += 2; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 839 | cnt += 2; |
| 840 | } |
| 841 | |
| 842 | if (flag_o) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 843 | ND_TCHECK2(*ptr, 2); /* Offset Size */ |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 844 | pad = EXTRACT_16BITS(ptr); |
| 845 | ptr += (2 + pad); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 846 | cnt += (2 + pad); |
| 847 | } |
| 848 | |
| 849 | if (flag_l) { |
| 850 | if (length < l2tp_len) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 851 | ND_PRINT((ndo, " Length %u larger than packet", l2tp_len)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 852 | return; |
| 853 | } |
| 854 | length = l2tp_len; |
| 855 | } |
| 856 | if (length < cnt) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 857 | ND_PRINT((ndo, " Length %u smaller than header length", length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 858 | return; |
| 859 | } |
| 860 | if (flag_t) { |
| 861 | if (!flag_l) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 862 | ND_PRINT((ndo, " No length")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 863 | return; |
| 864 | } |
| 865 | if (length - cnt == 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 866 | ND_PRINT((ndo, " ZLB")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 867 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 868 | l2tp_avp_print(ndo, ptr, length - cnt); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 869 | } |
| 870 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 871 | ND_PRINT((ndo, " {")); |
| 872 | ppp_print(ndo, ptr, length - cnt); |
| 873 | ND_PRINT((ndo, "}")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | return; |
| 877 | |
| 878 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 879 | ND_PRINT((ndo, "%s", tstr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 880 | } |