2 * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
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
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.
21 * L2TP support contributed by Motonori Shindo (mshindo@mshindo.net)
28 #include <netdissect-stdinc.h>
30 #include "netdissect.h"
33 #define L2TP_FLAG_TYPE 0x8000 /* Type (0=Data, 1=Control) */
34 #define L2TP_FLAG_LENGTH 0x4000 /* Length */
35 #define L2TP_FLAG_SEQUENCE 0x0800 /* Sequence */
36 #define L2TP_FLAG_OFFSET 0x0200 /* Offset */
37 #define L2TP_FLAG_PRIORITY 0x0100 /* Priority */
39 #define L2TP_VERSION_MASK 0x000f /* Version Mask */
40 #define L2TP_VERSION_L2F 0x0001 /* L2F */
41 #define L2TP_VERSION_L2TP 0x0002 /* L2TP */
43 #define L2TP_AVP_HDR_FLAG_MANDATORY 0x8000 /* Mandatory Flag */
44 #define L2TP_AVP_HDR_FLAG_HIDDEN 0x4000 /* Hidden Flag */
45 #define L2TP_AVP_HDR_LEN_MASK 0x03ff /* Length Mask */
47 #define L2TP_FRAMING_CAP_SYNC_MASK 0x00000001 /* Synchronous */
48 #define L2TP_FRAMING_CAP_ASYNC_MASK 0x00000002 /* Asynchronous */
50 #define L2TP_FRAMING_TYPE_SYNC_MASK 0x00000001 /* Synchronous */
51 #define L2TP_FRAMING_TYPE_ASYNC_MASK 0x00000002 /* Asynchronous */
53 #define L2TP_BEARER_CAP_DIGITAL_MASK 0x00000001 /* Digital */
54 #define L2TP_BEARER_CAP_ANALOG_MASK 0x00000002 /* Analog */
56 #define L2TP_BEARER_TYPE_DIGITAL_MASK 0x00000001 /* Digital */
57 #define L2TP_BEARER_TYPE_ANALOG_MASK 0x00000002 /* Analog */
60 #define L2TP_AUTHEN_TYPE_RESERVED 0x0000 /* Reserved */
61 #define L2TP_AUTHEN_TYPE_TEXTUAL 0x0001 /* Textual username/password exchange */
62 #define L2TP_AUTHEN_TYPE_CHAP 0x0002 /* PPP CHAP */
63 #define L2TP_AUTHEN_TYPE_PAP 0x0003 /* PPP PAP */
64 #define L2TP_AUTHEN_TYPE_NO_AUTH 0x0004 /* No Authentication */
65 #define L2TP_AUTHEN_TYPE_MSCHAPv1 0x0005 /* MSCHAPv1 */
67 #define L2TP_PROXY_AUTH_ID_MASK 0x00ff
69 static const char tstr
[] = " [|l2tp]";
71 #define L2TP_MSGTYPE_SCCRQ 1 /* Start-Control-Connection-Request */
72 #define L2TP_MSGTYPE_SCCRP 2 /* Start-Control-Connection-Reply */
73 #define L2TP_MSGTYPE_SCCCN 3 /* Start-Control-Connection-Connected */
74 #define L2TP_MSGTYPE_STOPCCN 4 /* Stop-Control-Connection-Notification */
75 #define L2TP_MSGTYPE_HELLO 6 /* Hello */
76 #define L2TP_MSGTYPE_OCRQ 7 /* Outgoing-Call-Request */
77 #define L2TP_MSGTYPE_OCRP 8 /* Outgoing-Call-Reply */
78 #define L2TP_MSGTYPE_OCCN 9 /* Outgoing-Call-Connected */
79 #define L2TP_MSGTYPE_ICRQ 10 /* Incoming-Call-Request */
80 #define L2TP_MSGTYPE_ICRP 11 /* Incoming-Call-Reply */
81 #define L2TP_MSGTYPE_ICCN 12 /* Incoming-Call-Connected */
82 #define L2TP_MSGTYPE_CDN 14 /* Call-Disconnect-Notify */
83 #define L2TP_MSGTYPE_WEN 15 /* WAN-Error-Notify */
84 #define L2TP_MSGTYPE_SLI 16 /* Set-Link-Info */
86 static const struct tok l2tp_msgtype2str
[] = {
87 { L2TP_MSGTYPE_SCCRQ
, "SCCRQ" },
88 { L2TP_MSGTYPE_SCCRP
, "SCCRP" },
89 { L2TP_MSGTYPE_SCCCN
, "SCCCN" },
90 { L2TP_MSGTYPE_STOPCCN
, "StopCCN" },
91 { L2TP_MSGTYPE_HELLO
, "HELLO" },
92 { L2TP_MSGTYPE_OCRQ
, "OCRQ" },
93 { L2TP_MSGTYPE_OCRP
, "OCRP" },
94 { L2TP_MSGTYPE_OCCN
, "OCCN" },
95 { L2TP_MSGTYPE_ICRQ
, "ICRQ" },
96 { L2TP_MSGTYPE_ICRP
, "ICRP" },
97 { L2TP_MSGTYPE_ICCN
, "ICCN" },
98 { L2TP_MSGTYPE_CDN
, "CDN" },
99 { L2TP_MSGTYPE_WEN
, "WEN" },
100 { L2TP_MSGTYPE_SLI
, "SLI" },
104 #define L2TP_AVP_MSGTYPE 0 /* Message Type */
105 #define L2TP_AVP_RESULT_CODE 1 /* Result Code */
106 #define L2TP_AVP_PROTO_VER 2 /* Protocol Version */
107 #define L2TP_AVP_FRAMING_CAP 3 /* Framing Capabilities */
108 #define L2TP_AVP_BEARER_CAP 4 /* Bearer Capabilities */
109 #define L2TP_AVP_TIE_BREAKER 5 /* Tie Breaker */
110 #define L2TP_AVP_FIRM_VER 6 /* Firmware Revision */
111 #define L2TP_AVP_HOST_NAME 7 /* Host Name */
112 #define L2TP_AVP_VENDOR_NAME 8 /* Vendor Name */
113 #define L2TP_AVP_ASSND_TUN_ID 9 /* Assigned Tunnel ID */
114 #define L2TP_AVP_RECV_WIN_SIZE 10 /* Receive Window Size */
115 #define L2TP_AVP_CHALLENGE 11 /* Challenge */
116 #define L2TP_AVP_Q931_CC 12 /* Q.931 Cause Code */
117 #define L2TP_AVP_CHALLENGE_RESP 13 /* Challenge Response */
118 #define L2TP_AVP_ASSND_SESS_ID 14 /* Assigned Session ID */
119 #define L2TP_AVP_CALL_SER_NUM 15 /* Call Serial Number */
120 #define L2TP_AVP_MINIMUM_BPS 16 /* Minimum BPS */
121 #define L2TP_AVP_MAXIMUM_BPS 17 /* Maximum BPS */
122 #define L2TP_AVP_BEARER_TYPE 18 /* Bearer Type */
123 #define L2TP_AVP_FRAMING_TYPE 19 /* Framing Type */
124 #define L2TP_AVP_PACKET_PROC_DELAY 20 /* Packet Processing Delay (OBSOLETE) */
125 #define L2TP_AVP_CALLED_NUMBER 21 /* Called Number */
126 #define L2TP_AVP_CALLING_NUMBER 22 /* Calling Number */
127 #define L2TP_AVP_SUB_ADDRESS 23 /* Sub-Address */
128 #define L2TP_AVP_TX_CONN_SPEED 24 /* (Tx) Connect Speed */
129 #define L2TP_AVP_PHY_CHANNEL_ID 25 /* Physical Channel ID */
130 #define L2TP_AVP_INI_RECV_LCP 26 /* Initial Received LCP CONFREQ */
131 #define L2TP_AVP_LAST_SENT_LCP 27 /* Last Sent LCP CONFREQ */
132 #define L2TP_AVP_LAST_RECV_LCP 28 /* Last Received LCP CONFREQ */
133 #define L2TP_AVP_PROXY_AUTH_TYPE 29 /* Proxy Authen Type */
134 #define L2TP_AVP_PROXY_AUTH_NAME 30 /* Proxy Authen Name */
135 #define L2TP_AVP_PROXY_AUTH_CHAL 31 /* Proxy Authen Challenge */
136 #define L2TP_AVP_PROXY_AUTH_ID 32 /* Proxy Authen ID */
137 #define L2TP_AVP_PROXY_AUTH_RESP 33 /* Proxy Authen Response */
138 #define L2TP_AVP_CALL_ERRORS 34 /* Call Errors */
139 #define L2TP_AVP_ACCM 35 /* ACCM */
140 #define L2TP_AVP_RANDOM_VECTOR 36 /* Random Vector */
141 #define L2TP_AVP_PRIVATE_GRP_ID 37 /* Private Group ID */
142 #define L2TP_AVP_RX_CONN_SPEED 38 /* (Rx) Connect Speed */
143 #define L2TP_AVP_SEQ_REQUIRED 39 /* Sequencing Required */
144 #define L2TP_AVP_PPP_DISCON_CC 46 /* PPP Disconnect Cause Code */
146 static const struct tok l2tp_avp2str
[] = {
147 { L2TP_AVP_MSGTYPE
, "MSGTYPE" },
148 { L2TP_AVP_RESULT_CODE
, "RESULT_CODE" },
149 { L2TP_AVP_PROTO_VER
, "PROTO_VER" },
150 { L2TP_AVP_FRAMING_CAP
, "FRAMING_CAP" },
151 { L2TP_AVP_BEARER_CAP
, "BEARER_CAP" },
152 { L2TP_AVP_TIE_BREAKER
, "TIE_BREAKER" },
153 { L2TP_AVP_FIRM_VER
, "FIRM_VER" },
154 { L2TP_AVP_HOST_NAME
, "HOST_NAME" },
155 { L2TP_AVP_VENDOR_NAME
, "VENDOR_NAME" },
156 { L2TP_AVP_ASSND_TUN_ID
, "ASSND_TUN_ID" },
157 { L2TP_AVP_RECV_WIN_SIZE
, "RECV_WIN_SIZE" },
158 { L2TP_AVP_CHALLENGE
, "CHALLENGE" },
159 { L2TP_AVP_Q931_CC
, "Q931_CC", },
160 { L2TP_AVP_CHALLENGE_RESP
, "CHALLENGE_RESP" },
161 { L2TP_AVP_ASSND_SESS_ID
, "ASSND_SESS_ID" },
162 { L2TP_AVP_CALL_SER_NUM
, "CALL_SER_NUM" },
163 { L2TP_AVP_MINIMUM_BPS
, "MINIMUM_BPS" },
164 { L2TP_AVP_MAXIMUM_BPS
, "MAXIMUM_BPS" },
165 { L2TP_AVP_BEARER_TYPE
, "BEARER_TYPE" },
166 { L2TP_AVP_FRAMING_TYPE
, "FRAMING_TYPE" },
167 { L2TP_AVP_PACKET_PROC_DELAY
, "PACKET_PROC_DELAY" },
168 { L2TP_AVP_CALLED_NUMBER
, "CALLED_NUMBER" },
169 { L2TP_AVP_CALLING_NUMBER
, "CALLING_NUMBER" },
170 { L2TP_AVP_SUB_ADDRESS
, "SUB_ADDRESS" },
171 { L2TP_AVP_TX_CONN_SPEED
, "TX_CONN_SPEED" },
172 { L2TP_AVP_PHY_CHANNEL_ID
, "PHY_CHANNEL_ID" },
173 { L2TP_AVP_INI_RECV_LCP
, "INI_RECV_LCP" },
174 { L2TP_AVP_LAST_SENT_LCP
, "LAST_SENT_LCP" },
175 { L2TP_AVP_LAST_RECV_LCP
, "LAST_RECV_LCP" },
176 { L2TP_AVP_PROXY_AUTH_TYPE
, "PROXY_AUTH_TYPE" },
177 { L2TP_AVP_PROXY_AUTH_NAME
, "PROXY_AUTH_NAME" },
178 { L2TP_AVP_PROXY_AUTH_CHAL
, "PROXY_AUTH_CHAL" },
179 { L2TP_AVP_PROXY_AUTH_ID
, "PROXY_AUTH_ID" },
180 { L2TP_AVP_PROXY_AUTH_RESP
, "PROXY_AUTH_RESP" },
181 { L2TP_AVP_CALL_ERRORS
, "CALL_ERRORS" },
182 { L2TP_AVP_ACCM
, "ACCM" },
183 { L2TP_AVP_RANDOM_VECTOR
, "RANDOM_VECTOR" },
184 { L2TP_AVP_PRIVATE_GRP_ID
, "PRIVATE_GRP_ID" },
185 { L2TP_AVP_RX_CONN_SPEED
, "RX_CONN_SPEED" },
186 { L2TP_AVP_SEQ_REQUIRED
, "SEQ_REQUIRED" },
187 { L2TP_AVP_PPP_DISCON_CC
, "PPP_DISCON_CC" },
191 static const struct tok l2tp_authentype2str
[] = {
192 { L2TP_AUTHEN_TYPE_RESERVED
, "Reserved" },
193 { L2TP_AUTHEN_TYPE_TEXTUAL
, "Textual" },
194 { L2TP_AUTHEN_TYPE_CHAP
, "CHAP" },
195 { L2TP_AUTHEN_TYPE_PAP
, "PAP" },
196 { L2TP_AUTHEN_TYPE_NO_AUTH
, "No Auth" },
197 { L2TP_AUTHEN_TYPE_MSCHAPv1
, "MS-CHAPv1" },
201 #define L2TP_PPP_DISCON_CC_DIRECTION_GLOBAL 0
202 #define L2TP_PPP_DISCON_CC_DIRECTION_AT_PEER 1
203 #define L2TP_PPP_DISCON_CC_DIRECTION_AT_LOCAL 2
205 static const struct tok l2tp_cc_direction2str
[] = {
206 { L2TP_PPP_DISCON_CC_DIRECTION_GLOBAL
, "global error" },
207 { L2TP_PPP_DISCON_CC_DIRECTION_AT_PEER
, "at peer" },
208 { L2TP_PPP_DISCON_CC_DIRECTION_AT_LOCAL
,"at local" },
213 static char *l2tp_result_code_StopCCN
[] = {
215 "General request to clear control connection",
216 "General error--Error Code indicates the problem",
217 "Control channel already exists",
218 "Requester is not authorized to establish a control channel",
219 "The protocol version of the requester is not supported",
220 "Requester is being shut down",
221 "Finite State Machine error"
222 #define L2TP_MAX_RESULT_CODE_STOPCC_INDEX 8
227 static char *l2tp_result_code_CDN
[] = {
229 "Call disconnected due to loss of carrier",
230 "Call disconnected for the reason indicated in error code",
231 "Call disconnected for administrative reasons",
232 "Call failed due to lack of appropriate facilities being " \
233 "available (temporary condition)",
234 "Call failed due to lack of appropriate facilities being " \
235 "available (permanent condition)",
236 "Invalid destination",
237 "Call failed due to no carrier detected",
238 "Call failed due to detection of a busy signal",
239 "Call failed due to lack of a dial tone",
240 "Call was not established within time allotted by LAC",
241 "Call was connected but no appropriate framing was detected"
242 #define L2TP_MAX_RESULT_CODE_CDN_INDEX 12
247 static char *l2tp_error_code_general
[] = {
249 "No control connection exists yet for this LAC-LNS pair",
251 "One of the field values was out of range or " \
252 "reserved field was non-zero"
253 "Insufficient resources to handle this operation now",
254 "The Session ID is invalid in this context",
255 "A generic vendor-specific error occurred in the LAC",
257 #define L2TP_MAX_ERROR_CODE_GENERAL_INDEX 8
261 /******************************/
262 /* generic print out routines */
263 /******************************/
265 print_string(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
268 for (i
=0; i
<length
; i
++) {
269 ND_PRINT((ndo
, "%c", *dat
++));
274 print_octets(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
277 for (i
=0; i
<length
; i
++) {
278 ND_PRINT((ndo
, "%02x", *dat
++));
283 print_16bits_val(netdissect_options
*ndo
, const uint16_t *dat
)
285 ND_PRINT((ndo
, "%u", EXTRACT_16BITS(dat
)));
289 print_32bits_val(netdissect_options
*ndo
, const uint32_t *dat
)
291 ND_PRINT((ndo
, "%lu", (u_long
)EXTRACT_32BITS(dat
)));
294 /***********************************/
295 /* AVP-specific print out routines */
296 /***********************************/
298 l2tp_msgtype_print(netdissect_options
*ndo
, const u_char
*dat
)
300 const uint16_t *ptr
= (const uint16_t *)dat
;
302 ND_PRINT((ndo
, "%s", tok2str(l2tp_msgtype2str
, "MSGTYPE-#%u",
303 EXTRACT_16BITS(ptr
))));
307 l2tp_result_code_print(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
309 const uint16_t *ptr
= (const uint16_t *)dat
;
311 ND_PRINT((ndo
, "%u", EXTRACT_16BITS(ptr
))); ptr
++; /* Result Code */
312 if (length
> 2) { /* Error Code (opt) */
313 ND_PRINT((ndo
, "/%u", EXTRACT_16BITS(ptr
))); ptr
++;
315 if (length
> 4) { /* Error Message (opt) */
316 ND_PRINT((ndo
, " "));
317 print_string(ndo
, (const u_char
*)ptr
, length
- 4);
322 l2tp_proto_ver_print(netdissect_options
*ndo
, const uint16_t *dat
)
324 ND_PRINT((ndo
, "%u.%u", (EXTRACT_16BITS(dat
) >> 8),
325 (EXTRACT_16BITS(dat
) & 0xff)));
329 l2tp_framing_cap_print(netdissect_options
*ndo
, const u_char
*dat
)
331 const uint32_t *ptr
= (const uint32_t *)dat
;
333 if (EXTRACT_32BITS(ptr
) & L2TP_FRAMING_CAP_ASYNC_MASK
) {
334 ND_PRINT((ndo
, "A"));
336 if (EXTRACT_32BITS(ptr
) & L2TP_FRAMING_CAP_SYNC_MASK
) {
337 ND_PRINT((ndo
, "S"));
342 l2tp_bearer_cap_print(netdissect_options
*ndo
, const u_char
*dat
)
344 const uint32_t *ptr
= (const uint32_t *)dat
;
346 if (EXTRACT_32BITS(ptr
) & L2TP_BEARER_CAP_ANALOG_MASK
) {
347 ND_PRINT((ndo
, "A"));
349 if (EXTRACT_32BITS(ptr
) & L2TP_BEARER_CAP_DIGITAL_MASK
) {
350 ND_PRINT((ndo
, "D"));
355 l2tp_q931_cc_print(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
357 print_16bits_val(ndo
, (const uint16_t *)dat
);
358 ND_PRINT((ndo
, ", %02x", dat
[2]));
360 ND_PRINT((ndo
, " "));
361 print_string(ndo
, dat
+3, length
-3);
366 l2tp_bearer_type_print(netdissect_options
*ndo
, const u_char
*dat
)
368 const uint32_t *ptr
= (const uint32_t *)dat
;
370 if (EXTRACT_32BITS(ptr
) & L2TP_BEARER_TYPE_ANALOG_MASK
) {
371 ND_PRINT((ndo
, "A"));
373 if (EXTRACT_32BITS(ptr
) & L2TP_BEARER_TYPE_DIGITAL_MASK
) {
374 ND_PRINT((ndo
, "D"));
379 l2tp_framing_type_print(netdissect_options
*ndo
, const u_char
*dat
)
381 const uint32_t *ptr
= (const uint32_t *)dat
;
383 if (EXTRACT_32BITS(ptr
) & L2TP_FRAMING_TYPE_ASYNC_MASK
) {
384 ND_PRINT((ndo
, "A"));
386 if (EXTRACT_32BITS(ptr
) & L2TP_FRAMING_TYPE_SYNC_MASK
) {
387 ND_PRINT((ndo
, "S"));
392 l2tp_packet_proc_delay_print(netdissect_options
*ndo
)
394 ND_PRINT((ndo
, "obsolete"));
398 l2tp_proxy_auth_type_print(netdissect_options
*ndo
, const u_char
*dat
)
400 const uint16_t *ptr
= (const uint16_t *)dat
;
402 ND_PRINT((ndo
, "%s", tok2str(l2tp_authentype2str
,
403 "AuthType-#%u", EXTRACT_16BITS(ptr
))));
407 l2tp_proxy_auth_id_print(netdissect_options
*ndo
, const u_char
*dat
)
409 const uint16_t *ptr
= (const uint16_t *)dat
;
411 ND_PRINT((ndo
, "%u", EXTRACT_16BITS(ptr
) & L2TP_PROXY_AUTH_ID_MASK
));
415 l2tp_call_errors_print(netdissect_options
*ndo
, const u_char
*dat
)
417 const uint16_t *ptr
= (const uint16_t *)dat
;
418 uint16_t val_h
, val_l
;
420 ptr
++; /* skip "Reserved" */
422 val_h
= EXTRACT_16BITS(ptr
); ptr
++;
423 val_l
= EXTRACT_16BITS(ptr
); ptr
++;
424 ND_PRINT((ndo
, "CRCErr=%u ", (val_h
<<16) + val_l
));
426 val_h
= EXTRACT_16BITS(ptr
); ptr
++;
427 val_l
= EXTRACT_16BITS(ptr
); ptr
++;
428 ND_PRINT((ndo
, "FrameErr=%u ", (val_h
<<16) + val_l
));
430 val_h
= EXTRACT_16BITS(ptr
); ptr
++;
431 val_l
= EXTRACT_16BITS(ptr
); ptr
++;
432 ND_PRINT((ndo
, "HardOver=%u ", (val_h
<<16) + val_l
));
434 val_h
= EXTRACT_16BITS(ptr
); ptr
++;
435 val_l
= EXTRACT_16BITS(ptr
); ptr
++;
436 ND_PRINT((ndo
, "BufOver=%u ", (val_h
<<16) + val_l
));
438 val_h
= EXTRACT_16BITS(ptr
); ptr
++;
439 val_l
= EXTRACT_16BITS(ptr
); ptr
++;
440 ND_PRINT((ndo
, "Timeout=%u ", (val_h
<<16) + val_l
));
442 val_h
= EXTRACT_16BITS(ptr
); ptr
++;
443 val_l
= EXTRACT_16BITS(ptr
); ptr
++;
444 ND_PRINT((ndo
, "AlignErr=%u ", (val_h
<<16) + val_l
));
448 l2tp_accm_print(netdissect_options
*ndo
, const u_char
*dat
)
450 const uint16_t *ptr
= (const uint16_t *)dat
;
451 uint16_t val_h
, val_l
;
453 ptr
++; /* skip "Reserved" */
455 val_h
= EXTRACT_16BITS(ptr
); ptr
++;
456 val_l
= EXTRACT_16BITS(ptr
); ptr
++;
457 ND_PRINT((ndo
, "send=%08x ", (val_h
<<16) + val_l
));
459 val_h
= EXTRACT_16BITS(ptr
); ptr
++;
460 val_l
= EXTRACT_16BITS(ptr
); ptr
++;
461 ND_PRINT((ndo
, "recv=%08x ", (val_h
<<16) + val_l
));
465 l2tp_ppp_discon_cc_print(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
467 const uint16_t *ptr
= (const uint16_t *)dat
;
469 ND_PRINT((ndo
, "%04x, ", EXTRACT_16BITS(ptr
))); ptr
++; /* Disconnect Code */
470 ND_PRINT((ndo
, "%04x ", EXTRACT_16BITS(ptr
))); ptr
++; /* Control Protocol Number */
471 ND_PRINT((ndo
, "%s", tok2str(l2tp_cc_direction2str
,
472 "Direction-#%u", *((const u_char
*)ptr
++))));
475 ND_PRINT((ndo
, " "));
476 print_string(ndo
, (const u_char
*)ptr
, length
-5);
481 l2tp_avp_print(netdissect_options
*ndo
, const u_char
*dat
, int length
)
484 const uint16_t *ptr
= (const uint16_t *)dat
;
492 ND_PRINT((ndo
, " "));
494 ND_TCHECK(*ptr
); /* Flags & Length */
495 len
= EXTRACT_16BITS(ptr
) & L2TP_AVP_HDR_LEN_MASK
;
497 /* If it is not long enough to contain the header, we'll give up. */
501 /* If it goes past the end of the remaining length of the packet,
503 if (len
> (u_int
)length
)
506 /* If it goes past the end of the remaining length of the captured
507 data, we'll give up. */
508 ND_TCHECK2(*ptr
, len
);
509 /* After this point, no need to worry about truncation */
511 if (EXTRACT_16BITS(ptr
) & L2TP_AVP_HDR_FLAG_MANDATORY
) {
512 ND_PRINT((ndo
, "*"));
514 if (EXTRACT_16BITS(ptr
) & L2TP_AVP_HDR_FLAG_HIDDEN
) {
516 ND_PRINT((ndo
, "?"));
520 if (EXTRACT_16BITS(ptr
)) {
521 /* Vendor Specific Attribute */
522 ND_PRINT((ndo
, "VENDOR%04x:", EXTRACT_16BITS(ptr
))); ptr
++;
523 ND_PRINT((ndo
, "ATTR%04x", EXTRACT_16BITS(ptr
))); ptr
++;
524 ND_PRINT((ndo
, "("));
525 print_octets(ndo
, (const u_char
*)ptr
, len
-6);
526 ND_PRINT((ndo
, ")"));
528 /* IETF-defined Attributes */
530 attr_type
= EXTRACT_16BITS(ptr
); ptr
++;
531 ND_PRINT((ndo
, "%s", tok2str(l2tp_avp2str
, "AVP-#%u", attr_type
)));
532 ND_PRINT((ndo
, "("));
534 ND_PRINT((ndo
, "???"));
537 case L2TP_AVP_MSGTYPE
:
538 l2tp_msgtype_print(ndo
, (const u_char
*)ptr
);
540 case L2TP_AVP_RESULT_CODE
:
541 l2tp_result_code_print(ndo
, (const u_char
*)ptr
, len
-6);
543 case L2TP_AVP_PROTO_VER
:
544 l2tp_proto_ver_print(ndo
, ptr
);
546 case L2TP_AVP_FRAMING_CAP
:
547 l2tp_framing_cap_print(ndo
, (const u_char
*)ptr
);
549 case L2TP_AVP_BEARER_CAP
:
550 l2tp_bearer_cap_print(ndo
, (const u_char
*)ptr
);
552 case L2TP_AVP_TIE_BREAKER
:
553 print_octets(ndo
, (const u_char
*)ptr
, 8);
555 case L2TP_AVP_FIRM_VER
:
556 case L2TP_AVP_ASSND_TUN_ID
:
557 case L2TP_AVP_RECV_WIN_SIZE
:
558 case L2TP_AVP_ASSND_SESS_ID
:
559 print_16bits_val(ndo
, ptr
);
561 case L2TP_AVP_HOST_NAME
:
562 case L2TP_AVP_VENDOR_NAME
:
563 case L2TP_AVP_CALLING_NUMBER
:
564 case L2TP_AVP_CALLED_NUMBER
:
565 case L2TP_AVP_SUB_ADDRESS
:
566 case L2TP_AVP_PROXY_AUTH_NAME
:
567 case L2TP_AVP_PRIVATE_GRP_ID
:
568 print_string(ndo
, (const u_char
*)ptr
, len
-6);
570 case L2TP_AVP_CHALLENGE
:
571 case L2TP_AVP_INI_RECV_LCP
:
572 case L2TP_AVP_LAST_SENT_LCP
:
573 case L2TP_AVP_LAST_RECV_LCP
:
574 case L2TP_AVP_PROXY_AUTH_CHAL
:
575 case L2TP_AVP_PROXY_AUTH_RESP
:
576 case L2TP_AVP_RANDOM_VECTOR
:
577 print_octets(ndo
, (const u_char
*)ptr
, len
-6);
579 case L2TP_AVP_Q931_CC
:
580 l2tp_q931_cc_print(ndo
, (const u_char
*)ptr
, len
-6);
582 case L2TP_AVP_CHALLENGE_RESP
:
583 print_octets(ndo
, (const u_char
*)ptr
, 16);
585 case L2TP_AVP_CALL_SER_NUM
:
586 case L2TP_AVP_MINIMUM_BPS
:
587 case L2TP_AVP_MAXIMUM_BPS
:
588 case L2TP_AVP_TX_CONN_SPEED
:
589 case L2TP_AVP_PHY_CHANNEL_ID
:
590 case L2TP_AVP_RX_CONN_SPEED
:
591 print_32bits_val(ndo
, (const uint32_t *)ptr
);
593 case L2TP_AVP_BEARER_TYPE
:
594 l2tp_bearer_type_print(ndo
, (const u_char
*)ptr
);
596 case L2TP_AVP_FRAMING_TYPE
:
597 l2tp_framing_type_print(ndo
, (const u_char
*)ptr
);
599 case L2TP_AVP_PACKET_PROC_DELAY
:
600 l2tp_packet_proc_delay_print(ndo
);
602 case L2TP_AVP_PROXY_AUTH_TYPE
:
603 l2tp_proxy_auth_type_print(ndo
, (const u_char
*)ptr
);
605 case L2TP_AVP_PROXY_AUTH_ID
:
606 l2tp_proxy_auth_id_print(ndo
, (const u_char
*)ptr
);
608 case L2TP_AVP_CALL_ERRORS
:
609 l2tp_call_errors_print(ndo
, (const u_char
*)ptr
);
612 l2tp_accm_print(ndo
, (const u_char
*)ptr
);
614 case L2TP_AVP_SEQ_REQUIRED
:
615 break; /* No Attribute Value */
616 case L2TP_AVP_PPP_DISCON_CC
:
617 l2tp_ppp_discon_cc_print(ndo
, (const u_char
*)ptr
, len
-6);
623 ND_PRINT((ndo
, ")"));
626 l2tp_avp_print(ndo
, dat
+len
, length
-len
);
630 ND_PRINT((ndo
, "|..."));
635 l2tp_print(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
637 const u_char
*ptr
= dat
;
638 u_int cnt
= 0; /* total octets consumed */
640 int flag_t
, flag_l
, flag_s
, flag_o
;
643 flag_t
= flag_l
= flag_s
= flag_o
= FALSE
;
645 ND_TCHECK2(*ptr
, 2); /* Flags & Version */
646 if ((EXTRACT_16BITS(ptr
) & L2TP_VERSION_MASK
) == L2TP_VERSION_L2TP
) {
647 ND_PRINT((ndo
, " l2tp:"));
648 } else if ((EXTRACT_16BITS(ptr
) & L2TP_VERSION_MASK
) == L2TP_VERSION_L2F
) {
649 ND_PRINT((ndo
, " l2f:"));
650 return; /* nothing to do */
652 ND_PRINT((ndo
, " Unknown Version, neither L2F(1) nor L2TP(2)"));
653 return; /* nothing we can do */
656 ND_PRINT((ndo
, "["));
657 if (EXTRACT_16BITS(ptr
) & L2TP_FLAG_TYPE
) {
659 ND_PRINT((ndo
, "T"));
661 if (EXTRACT_16BITS(ptr
) & L2TP_FLAG_LENGTH
) {
663 ND_PRINT((ndo
, "L"));
665 if (EXTRACT_16BITS(ptr
) & L2TP_FLAG_SEQUENCE
) {
667 ND_PRINT((ndo
, "S"));
669 if (EXTRACT_16BITS(ptr
) & L2TP_FLAG_OFFSET
) {
671 ND_PRINT((ndo
, "O"));
673 if (EXTRACT_16BITS(ptr
) & L2TP_FLAG_PRIORITY
)
674 ND_PRINT((ndo
, "P"));
675 ND_PRINT((ndo
, "]"));
681 ND_TCHECK2(*ptr
, 2); /* Length */
682 l2tp_len
= EXTRACT_16BITS(ptr
);
689 ND_TCHECK2(*ptr
, 2); /* Tunnel ID */
690 ND_PRINT((ndo
, "(%u/", EXTRACT_16BITS(ptr
)));
693 ND_TCHECK2(*ptr
, 2); /* Session ID */
694 ND_PRINT((ndo
, "%u)", EXTRACT_16BITS(ptr
)));
699 ND_TCHECK2(*ptr
, 2); /* Ns */
700 ND_PRINT((ndo
, "Ns=%u,", EXTRACT_16BITS(ptr
)));
703 ND_TCHECK2(*ptr
, 2); /* Nr */
704 ND_PRINT((ndo
, "Nr=%u", EXTRACT_16BITS(ptr
)));
710 ND_TCHECK2(*ptr
, 2); /* Offset Size */
711 pad
= EXTRACT_16BITS(ptr
);
717 if (length
< l2tp_len
) {
718 ND_PRINT((ndo
, " Length %u larger than packet", l2tp_len
));
724 ND_PRINT((ndo
, " Length %u smaller than header length", length
));
729 ND_PRINT((ndo
, " No length"));
732 if (length
- cnt
== 0) {
733 ND_PRINT((ndo
, " ZLB"));
735 l2tp_avp_print(ndo
, ptr
, length
- cnt
);
738 ND_PRINT((ndo
, " {"));
739 ppp_print(ndo
, ptr
, length
- cnt
);
740 ND_PRINT((ndo
, "}"));
746 ND_PRINT((ndo
, "%s", tstr
));