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