]> The Tcpdump Group git mirrors - tcpdump/blob - print-l2tp.c
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[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 #include <config.h>
29
30 #include "netdissect-stdinc.h"
31
32 #define ND_LONGJMP_FROM_TCHECK
33 #include "netdissect.h"
34 #include "extract.h"
35
36 #define L2TP_FLAG_TYPE 0x8000 /* Type (0=Data, 1=Control) */
37 #define L2TP_FLAG_LENGTH 0x4000 /* Length */
38 #define L2TP_FLAG_SEQUENCE 0x0800 /* Sequence */
39 #define L2TP_FLAG_OFFSET 0x0200 /* Offset */
40 #define L2TP_FLAG_PRIORITY 0x0100 /* Priority */
41
42 #define L2TP_VERSION_MASK 0x000f /* Version Mask */
43 #define L2TP_VERSION_L2F 0x0001 /* L2F */
44 #define L2TP_VERSION_L2TP 0x0002 /* L2TP */
45
46 #define L2TP_AVP_HDR_FLAG_MANDATORY 0x8000 /* Mandatory Flag */
47 #define L2TP_AVP_HDR_FLAG_HIDDEN 0x4000 /* Hidden Flag */
48 #define L2TP_AVP_HDR_LEN_MASK 0x03ff /* Length Mask */
49
50 #define L2TP_FRAMING_CAP_SYNC_MASK 0x00000001 /* Synchronous */
51 #define L2TP_FRAMING_CAP_ASYNC_MASK 0x00000002 /* Asynchronous */
52
53 #define L2TP_FRAMING_TYPE_SYNC_MASK 0x00000001 /* Synchronous */
54 #define L2TP_FRAMING_TYPE_ASYNC_MASK 0x00000002 /* Asynchronous */
55
56 #define L2TP_BEARER_CAP_DIGITAL_MASK 0x00000001 /* Digital */
57 #define L2TP_BEARER_CAP_ANALOG_MASK 0x00000002 /* Analog */
58
59 #define L2TP_BEARER_TYPE_DIGITAL_MASK 0x00000001 /* Digital */
60 #define L2TP_BEARER_TYPE_ANALOG_MASK 0x00000002 /* Analog */
61
62 /* Authen Type */
63 #define L2TP_AUTHEN_TYPE_RESERVED 0x0000 /* Reserved */
64 #define L2TP_AUTHEN_TYPE_TEXTUAL 0x0001 /* Textual username/password exchange */
65 #define L2TP_AUTHEN_TYPE_CHAP 0x0002 /* PPP CHAP */
66 #define L2TP_AUTHEN_TYPE_PAP 0x0003 /* PPP PAP */
67 #define L2TP_AUTHEN_TYPE_NO_AUTH 0x0004 /* No Authentication */
68 #define L2TP_AUTHEN_TYPE_MSCHAPv1 0x0005 /* MSCHAPv1 */
69
70 #define L2TP_PROXY_AUTH_ID_MASK 0x00ff
71
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
88 static const struct tok l2tp_msgtype2str[] = {
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 - RFC 3145 */
147
148 static const struct tok l2tp_avp2str[] = {
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
193 static const struct tok l2tp_authentype2str[] = {
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
207 static const struct tok l2tp_cc_direction2str[] = {
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
267 print_octets(netdissect_options *ndo, const u_char *dat, u_int length)
268 {
269 u_int i;
270 for (i=0; i<length; i++) {
271 ND_PRINT("%02x", GET_U_1(dat));
272 dat++;
273 }
274 }
275
276 static void
277 print_16bits_val(netdissect_options *ndo, const uint8_t *dat)
278 {
279 ND_PRINT("%u", GET_BE_U_2(dat));
280 }
281
282 static void
283 print_32bits_val(netdissect_options *ndo, const uint8_t *dat)
284 {
285 ND_PRINT("%u", GET_BE_U_4(dat));
286 }
287
288 /***********************************/
289 /* AVP-specific print out routines */
290 /***********************************/
291 static void
292 l2tp_msgtype_print(netdissect_options *ndo, const u_char *dat, u_int length)
293 {
294 if (length < 2) {
295 ND_PRINT("AVP too short");
296 return;
297 }
298 ND_PRINT("%s", tok2str(l2tp_msgtype2str, "MSGTYPE-#%u",
299 GET_BE_U_2(dat)));
300 }
301
302 static void
303 l2tp_result_code_print(netdissect_options *ndo, const u_char *dat, u_int length)
304 {
305 /* Result Code */
306 if (length < 2) {
307 ND_PRINT("AVP too short");
308 return;
309 }
310 ND_PRINT("%u", GET_BE_U_2(dat));
311 dat += 2;
312 length -= 2;
313
314 /* Error Code (opt) */
315 if (length == 0)
316 return;
317 if (length < 2) {
318 ND_PRINT(" AVP too short");
319 return;
320 }
321 ND_PRINT("/%u", GET_BE_U_2(dat));
322 dat += 2;
323 length -= 2;
324
325 /* Error Message (opt) */
326 if (length == 0)
327 return;
328 ND_PRINT(" ");
329 nd_printjn(ndo, dat, length);
330 }
331
332 static void
333 l2tp_proto_ver_print(netdissect_options *ndo, const u_char *dat, u_int length)
334 {
335 if (length < 2) {
336 ND_PRINT("AVP too short");
337 return;
338 }
339 ND_PRINT("%u.%u", (GET_BE_U_2(dat) >> 8),
340 (GET_BE_U_2(dat) & 0xff));
341 }
342
343 static void
344 l2tp_framing_cap_print(netdissect_options *ndo, const u_char *dat, u_int length)
345 {
346 if (length < 4) {
347 ND_PRINT("AVP too short");
348 return;
349 }
350 if (GET_BE_U_4(dat) & L2TP_FRAMING_CAP_ASYNC_MASK) {
351 ND_PRINT("A");
352 }
353 if (GET_BE_U_4(dat) & L2TP_FRAMING_CAP_SYNC_MASK) {
354 ND_PRINT("S");
355 }
356 }
357
358 static void
359 l2tp_bearer_cap_print(netdissect_options *ndo, const u_char *dat, u_int length)
360 {
361 if (length < 4) {
362 ND_PRINT("AVP too short");
363 return;
364 }
365 if (GET_BE_U_4(dat) & L2TP_BEARER_CAP_ANALOG_MASK) {
366 ND_PRINT("A");
367 }
368 if (GET_BE_U_4(dat) & L2TP_BEARER_CAP_DIGITAL_MASK) {
369 ND_PRINT("D");
370 }
371 }
372
373 static void
374 l2tp_q931_cc_print(netdissect_options *ndo, const u_char *dat, u_int length)
375 {
376 if (length < 3) {
377 ND_PRINT("AVP too short");
378 return;
379 }
380 print_16bits_val(ndo, dat);
381 ND_PRINT(", %02x", GET_U_1(dat + 2));
382 dat += 3;
383 length -= 3;
384 if (length != 0) {
385 ND_PRINT(" ");
386 nd_printjn(ndo, dat, length);
387 }
388 }
389
390 static void
391 l2tp_bearer_type_print(netdissect_options *ndo, const u_char *dat, u_int length)
392 {
393 if (length < 4) {
394 ND_PRINT("AVP too short");
395 return;
396 }
397 if (GET_BE_U_4(dat) & L2TP_BEARER_TYPE_ANALOG_MASK) {
398 ND_PRINT("A");
399 }
400 if (GET_BE_U_4(dat) & L2TP_BEARER_TYPE_DIGITAL_MASK) {
401 ND_PRINT("D");
402 }
403 }
404
405 static void
406 l2tp_framing_type_print(netdissect_options *ndo, const u_char *dat, u_int length)
407 {
408 if (length < 4) {
409 ND_PRINT("AVP too short");
410 return;
411 }
412 if (GET_BE_U_4(dat) & L2TP_FRAMING_TYPE_ASYNC_MASK) {
413 ND_PRINT("A");
414 }
415 if (GET_BE_U_4(dat) & L2TP_FRAMING_TYPE_SYNC_MASK) {
416 ND_PRINT("S");
417 }
418 }
419
420 static void
421 l2tp_packet_proc_delay_print(netdissect_options *ndo)
422 {
423 ND_PRINT("obsolete");
424 }
425
426 static void
427 l2tp_proxy_auth_type_print(netdissect_options *ndo, const u_char *dat, u_int length)
428 {
429 if (length < 2) {
430 ND_PRINT("AVP too short");
431 return;
432 }
433 ND_PRINT("%s", tok2str(l2tp_authentype2str,
434 "AuthType-#%u", GET_BE_U_2(dat)));
435 }
436
437 static void
438 l2tp_proxy_auth_id_print(netdissect_options *ndo, const u_char *dat, u_int length)
439 {
440 if (length < 2) {
441 ND_PRINT("AVP too short");
442 return;
443 }
444 ND_PRINT("%u", GET_BE_U_2(dat) & L2TP_PROXY_AUTH_ID_MASK);
445 }
446
447 static void
448 l2tp_call_errors_print(netdissect_options *ndo, const u_char *dat, u_int length)
449 {
450 uint32_t val;
451
452 if (length < 2) {
453 ND_PRINT("AVP too short");
454 return;
455 }
456 dat += 2; /* skip "Reserved" */
457 length -= 2;
458
459 if (length < 4) {
460 ND_PRINT("AVP too short");
461 return;
462 }
463 val = GET_BE_U_4(dat); dat += 4; length -= 4;
464 ND_PRINT("CRCErr=%u ", val);
465
466 if (length < 4) {
467 ND_PRINT("AVP too short");
468 return;
469 }
470 val = GET_BE_U_4(dat); dat += 4; length -= 4;
471 ND_PRINT("FrameErr=%u ", val);
472
473 if (length < 4) {
474 ND_PRINT("AVP too short");
475 return;
476 }
477 val = GET_BE_U_4(dat); dat += 4; length -= 4;
478 ND_PRINT("HardOver=%u ", val);
479
480 if (length < 4) {
481 ND_PRINT("AVP too short");
482 return;
483 }
484 val = GET_BE_U_4(dat); dat += 4; length -= 4;
485 ND_PRINT("BufOver=%u ", val);
486
487 if (length < 4) {
488 ND_PRINT("AVP too short");
489 return;
490 }
491 val = GET_BE_U_4(dat); dat += 4; length -= 4;
492 ND_PRINT("Timeout=%u ", val);
493
494 if (length < 4) {
495 ND_PRINT("AVP too short");
496 return;
497 }
498 val = GET_BE_U_4(dat); dat += 4; length -= 4;
499 ND_PRINT("AlignErr=%u ", val);
500 }
501
502 static void
503 l2tp_accm_print(netdissect_options *ndo, const u_char *dat, u_int length)
504 {
505 uint32_t val;
506
507 if (length < 2) {
508 ND_PRINT("AVP too short");
509 return;
510 }
511 dat += 2; /* skip "Reserved" */
512 length -= 2;
513
514 if (length < 4) {
515 ND_PRINT("AVP too short");
516 return;
517 }
518 val = GET_BE_U_4(dat); dat += 4; length -= 4;
519 ND_PRINT("send=%08x ", val);
520
521 if (length < 4) {
522 ND_PRINT("AVP too short");
523 return;
524 }
525 val = GET_BE_U_4(dat); dat += 4; length -= 4;
526 ND_PRINT("recv=%08x ", val);
527 }
528
529 static void
530 l2tp_ppp_discon_cc_print(netdissect_options *ndo, const u_char *dat, u_int length)
531 {
532 if (length < 5) {
533 ND_PRINT("AVP too short");
534 return;
535 }
536 /* Disconnect Code */
537 ND_PRINT("%04x, ", GET_BE_U_2(dat));
538 dat += 2;
539 length -= 2;
540 /* Control Protocol Number */
541 ND_PRINT("%04x ", GET_BE_U_2(dat));
542 dat += 2;
543 length -= 2;
544 /* Direction */
545 ND_PRINT("%s", tok2str(l2tp_cc_direction2str,
546 "Direction-#%u", GET_U_1(dat)));
547 dat++;
548 length--;
549
550 if (length != 0) {
551 ND_PRINT(" ");
552 nd_printjn(ndo, (const u_char *)dat, length);
553 }
554 }
555
556 static u_int
557 l2tp_avp_print(netdissect_options *ndo, const u_char *dat, u_int length)
558 {
559 u_int len;
560 uint16_t attr_type;
561 int hidden = FALSE;
562
563 ND_PRINT(" ");
564 /* Flags & Length */
565 len = GET_BE_U_2(dat) & L2TP_AVP_HDR_LEN_MASK;
566
567 /* If it is not long enough to contain the header, we'll give up. */
568 ND_ICHECKMSG_U("AVP length", len, <, 6);
569
570 /* If it goes past the end of the remaining length of the packet,
571 we'll give up. */
572 if (len > length) {
573 ND_PRINT(" (len > %u)", length);
574 goto invalid;
575 }
576
577 /* If it goes past the end of the remaining length of the captured
578 data, we'll give up. */
579 ND_TCHECK_LEN(dat, len);
580
581 /*
582 * After this point, we don't need to check whether we go past
583 * the length of the captured data; however, we *do* need to
584 * check whether we go past the end of the AVP.
585 */
586
587 if (GET_BE_U_2(dat) & L2TP_AVP_HDR_FLAG_MANDATORY) {
588 ND_PRINT("*");
589 }
590 if (GET_BE_U_2(dat) & L2TP_AVP_HDR_FLAG_HIDDEN) {
591 hidden = TRUE;
592 ND_PRINT("?");
593 }
594 dat += 2;
595
596 if (GET_BE_U_2(dat)) {
597 /* Vendor Specific Attribute */
598 ND_PRINT("VENDOR%04x:", GET_BE_U_2(dat)); dat += 2;
599 ND_PRINT("ATTR%04x", GET_BE_U_2(dat)); dat += 2;
600 ND_PRINT("(");
601 print_octets(ndo, dat, len-6);
602 ND_PRINT(")");
603 } else {
604 /* IETF-defined Attributes */
605 dat += 2;
606 attr_type = GET_BE_U_2(dat); dat += 2;
607 ND_PRINT("%s", tok2str(l2tp_avp2str, "AVP-#%u", attr_type));
608 ND_PRINT("(");
609 if (hidden) {
610 ND_PRINT("???");
611 } else {
612 switch (attr_type) {
613 case L2TP_AVP_MSGTYPE:
614 l2tp_msgtype_print(ndo, dat, len-6);
615 break;
616 case L2TP_AVP_RESULT_CODE:
617 l2tp_result_code_print(ndo, dat, len-6);
618 break;
619 case L2TP_AVP_PROTO_VER:
620 l2tp_proto_ver_print(ndo, dat, len-6);
621 break;
622 case L2TP_AVP_FRAMING_CAP:
623 l2tp_framing_cap_print(ndo, dat, len-6);
624 break;
625 case L2TP_AVP_BEARER_CAP:
626 l2tp_bearer_cap_print(ndo, dat, len-6);
627 break;
628 case L2TP_AVP_TIE_BREAKER:
629 if (len-6 < 8) {
630 ND_PRINT("AVP too short");
631 break;
632 }
633 print_octets(ndo, dat, 8);
634 break;
635 case L2TP_AVP_FIRM_VER:
636 case L2TP_AVP_ASSND_TUN_ID:
637 case L2TP_AVP_RECV_WIN_SIZE:
638 case L2TP_AVP_ASSND_SESS_ID:
639 if (len-6 < 2) {
640 ND_PRINT("AVP too short");
641 break;
642 }
643 print_16bits_val(ndo, dat);
644 break;
645 case L2TP_AVP_HOST_NAME:
646 case L2TP_AVP_VENDOR_NAME:
647 case L2TP_AVP_CALLING_NUMBER:
648 case L2TP_AVP_CALLED_NUMBER:
649 case L2TP_AVP_SUB_ADDRESS:
650 case L2TP_AVP_PROXY_AUTH_NAME:
651 case L2TP_AVP_PRIVATE_GRP_ID:
652 nd_printjn(ndo, dat, len-6);
653 break;
654 case L2TP_AVP_CHALLENGE:
655 case L2TP_AVP_INI_RECV_LCP:
656 case L2TP_AVP_LAST_SENT_LCP:
657 case L2TP_AVP_LAST_RECV_LCP:
658 case L2TP_AVP_PROXY_AUTH_CHAL:
659 case L2TP_AVP_PROXY_AUTH_RESP:
660 case L2TP_AVP_RANDOM_VECTOR:
661 print_octets(ndo, dat, len-6);
662 break;
663 case L2TP_AVP_Q931_CC:
664 l2tp_q931_cc_print(ndo, dat, len-6);
665 break;
666 case L2TP_AVP_CHALLENGE_RESP:
667 if (len-6 < 16) {
668 ND_PRINT("AVP too short");
669 break;
670 }
671 print_octets(ndo, dat, 16);
672 break;
673 case L2TP_AVP_CALL_SER_NUM:
674 case L2TP_AVP_MINIMUM_BPS:
675 case L2TP_AVP_MAXIMUM_BPS:
676 case L2TP_AVP_TX_CONN_SPEED:
677 case L2TP_AVP_PHY_CHANNEL_ID:
678 case L2TP_AVP_RX_CONN_SPEED:
679 if (len-6 < 4) {
680 ND_PRINT("AVP too short");
681 break;
682 }
683 print_32bits_val(ndo, dat);
684 break;
685 case L2TP_AVP_BEARER_TYPE:
686 l2tp_bearer_type_print(ndo, dat, len-6);
687 break;
688 case L2TP_AVP_FRAMING_TYPE:
689 l2tp_framing_type_print(ndo, dat, len-6);
690 break;
691 case L2TP_AVP_PACKET_PROC_DELAY:
692 l2tp_packet_proc_delay_print(ndo);
693 break;
694 case L2TP_AVP_PROXY_AUTH_TYPE:
695 l2tp_proxy_auth_type_print(ndo, dat, len-6);
696 break;
697 case L2TP_AVP_PROXY_AUTH_ID:
698 l2tp_proxy_auth_id_print(ndo, dat, len-6);
699 break;
700 case L2TP_AVP_CALL_ERRORS:
701 l2tp_call_errors_print(ndo, dat, len-6);
702 break;
703 case L2TP_AVP_ACCM:
704 l2tp_accm_print(ndo, dat, len-6);
705 break;
706 case L2TP_AVP_SEQ_REQUIRED:
707 break; /* No Attribute Value */
708 case L2TP_AVP_PPP_DISCON_CC:
709 l2tp_ppp_discon_cc_print(ndo, dat, len-6);
710 break;
711 default:
712 break;
713 }
714 }
715 ND_PRINT(")");
716 }
717
718 return (len);
719
720 invalid:
721 return (0);
722 }
723
724
725 void
726 l2tp_print(netdissect_options *ndo, const u_char *dat, u_int length)
727 {
728 const u_char *ptr = dat;
729 u_int cnt = 0; /* total octets consumed */
730 uint16_t pad;
731 int flag_t, flag_l, flag_s, flag_o;
732 uint16_t l2tp_len;
733
734 ndo->ndo_protocol = "l2tp";
735 flag_t = flag_l = flag_s = flag_o = FALSE;
736
737 if ((GET_BE_U_2(ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2TP) {
738 ND_PRINT(" l2tp:");
739 } else if ((GET_BE_U_2(ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2F) {
740 ND_PRINT(" l2f:");
741 return; /* nothing to do */
742 } else {
743 ND_PRINT(" Unknown Version, neither L2F(1) nor L2TP(2)");
744 return; /* nothing we can do */
745 }
746
747 ND_PRINT("[");
748 if (GET_BE_U_2(ptr) & L2TP_FLAG_TYPE) {
749 flag_t = TRUE;
750 ND_PRINT("T");
751 }
752 if (GET_BE_U_2(ptr) & L2TP_FLAG_LENGTH) {
753 flag_l = TRUE;
754 ND_PRINT("L");
755 }
756 if (GET_BE_U_2(ptr) & L2TP_FLAG_SEQUENCE) {
757 flag_s = TRUE;
758 ND_PRINT("S");
759 }
760 if (GET_BE_U_2(ptr) & L2TP_FLAG_OFFSET) {
761 flag_o = TRUE;
762 ND_PRINT("O");
763 }
764 if (GET_BE_U_2(ptr) & L2TP_FLAG_PRIORITY)
765 ND_PRINT("P");
766 ND_PRINT("]");
767
768 ptr += 2;
769 cnt += 2;
770
771 if (flag_l) {
772 l2tp_len = GET_BE_U_2(ptr);
773 ptr += 2;
774 cnt += 2;
775 } else {
776 l2tp_len = 0;
777 }
778 /* Tunnel ID */
779 ND_PRINT("(%u/", GET_BE_U_2(ptr));
780 ptr += 2;
781 cnt += 2;
782 /* Session ID */
783 ND_PRINT("%u)", GET_BE_U_2(ptr));
784 ptr += 2;
785 cnt += 2;
786
787 if (flag_s) {
788 ND_PRINT("Ns=%u,", GET_BE_U_2(ptr));
789 ptr += 2;
790 cnt += 2;
791 ND_PRINT("Nr=%u", GET_BE_U_2(ptr));
792 ptr += 2;
793 cnt += 2;
794 }
795
796 if (flag_o) { /* Offset Size */
797 pad = GET_BE_U_2(ptr);
798 /* Offset padding octets in packet buffer? */
799 ND_TCHECK_LEN(ptr + 2, pad);
800 ptr += (2 + pad);
801 cnt += (2 + pad);
802 }
803
804 if (flag_l) {
805 if (length < l2tp_len) {
806 ND_PRINT(" Length %u larger than packet", l2tp_len);
807 goto invalid;
808 }
809 length = l2tp_len;
810 }
811 if (length < cnt) {
812 ND_PRINT(" Length %u smaller than header length", length);
813 goto invalid;
814 }
815 if (flag_t) {
816 if (!flag_l) {
817 ND_PRINT(" No length");
818 goto invalid;
819 }
820 if (length - cnt == 0) {
821 ND_PRINT(" ZLB");
822 } else {
823 /*
824 * Print AVPs.
825 */
826 while (length - cnt != 0) {
827 u_int avp_length;
828
829 avp_length = l2tp_avp_print(ndo, ptr, length - cnt);
830 if (avp_length == 0) {
831 goto invalid;
832 }
833 cnt += avp_length;
834 ptr += avp_length;
835 }
836 }
837 } else {
838 ND_PRINT(" {");
839 ppp_print(ndo, ptr, length - cnt);
840 ND_PRINT("}");
841 }
842 return;
843 invalid:
844 nd_print_invalid(ndo);
845 }