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@ascend.co.jp)
25 static const char rcsid
[] =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-l2tp.c,v 1.1 1999-10-30 05:11:18 itojun Exp $";
29 #include <sys/types.h>
30 #include <sys/param.h>
33 #include "interface.h"
35 static char tstr
[] = " [|l2tp]";
45 static u_char
*l2tp_message_type_string
[] = {
46 "RESERVED_0", /* 0 Reserved */
47 "SCCRQ", /* 1 Start-Control-Connection-Request */
48 "SCCRP", /* 2 Start-Control-Connection-Reply */
49 "SCCCN", /* 3 Start-Control-Connection-Connected */
50 "StopCCN", /* 4 Stop-Control-Connection-Notification */
51 "RESERVED_5", /* 5 Reserved */
52 "HELLO", /* 6 Hello */
53 "OCRQ", /* 7 Outgoing-Call-Request */
54 "OCRP", /* 8 Outgoing-Call-Reply */
55 "OCCN", /* 9 Outgoing-Call-Connected */
56 "ICRQ", /* 10 Incoming-Call-Request */
57 "ICRP", /* 11 Incoming-Call-Reply */
58 "ICCN", /* 12 Incoming-Call-Connected */
59 "RESERVED_13", /* 13 Reserved */
60 "CDN", /* 14 Call-Disconnect-Notify */
61 "WEN", /* 15 WAN-Error-Notify */
62 "SLI" /* 16 Set-Link-Info */
63 #define L2TP_MAX_MSGTYPE_INDEX 17
66 static void l2tp_msgtype_print(const u_char
*dat
, u_int length
);
67 static void l2tp_result_code_print(const u_char
*dat
, u_int length
);
68 static void l2tp_proto_ver_print(const u_char
*dat
, u_int length
);
69 static void l2tp_framing_cap_print(const u_char
*dat
, u_int length
);
70 static void l2tp_bearer_cap_print(const u_char
*dat
, u_int length
);
71 static void l2tp_tie_breaker_print(const u_char
*dat
, u_int length
);
72 static void l2tp_firm_ver_print(const u_char
*dat
, u_int length
);
73 static void l2tp_host_name_print(const u_char
*dat
, u_int length
);
74 static void l2tp_vendor_name_print(const u_char
*dat
, u_int length
);
75 static void l2tp_assnd_tun_id_print(const u_char
*dat
, u_int length
);
76 static void l2tp_recv_win_size_print(const u_char
*dat
, u_int length
);
77 static void l2tp_challenge_print(const u_char
*dat
, u_int length
);
78 static void l2tp_q931_cc_print(const u_char
*dat
, u_int length
);
79 static void l2tp_challenge_resp_print(const u_char
*dat
, u_int length
);
80 static void l2tp_assnd_sess_id_print(const u_char
*dat
, u_int length
);
81 static void l2tp_call_ser_num_print(const u_char
*dat
, u_int length
);
82 static void l2tp_minimum_bps_print(const u_char
*dat
, u_int length
);
83 static void l2tp_maximum_bps_print(const u_char
*dat
, u_int length
);
84 static void l2tp_bearer_type_print(const u_char
*dat
, u_int length
);
85 static void l2tp_framing_type_print(const u_char
*dat
, u_int length
);
86 static void l2tp_packet_proc_delay_print(const u_char
*dat
, u_int length
);
87 static void l2tp_called_number_print(const u_char
*dat
, u_int length
);
88 static void l2tp_calling_number_print(const u_char
*dat
, u_int length
);
89 static void l2tp_sub_address_print(const u_char
*dat
, u_int length
);
90 static void l2tp_tx_conn_speed_print(const u_char
*dat
, u_int length
);
91 static void l2tp_phy_channel_id_print(const u_char
*dat
, u_int length
);
92 static void l2tp_ini_recv_lcp_print(const u_char
*dat
, u_int length
);
93 static void l2tp_last_sent_lcp_print(const u_char
*dat
, u_int length
);
94 static void l2tp_last_recv_lcp_print(const u_char
*dat
, u_int length
);
95 static void l2tp_proxy_auth_type_print(const u_char
*dat
, u_int length
);
96 static void l2tp_proxy_auth_name_print(const u_char
*dat
, u_int length
);
97 static void l2tp_proxy_auth_chal_print(const u_char
*dat
, u_int length
);
98 static void l2tp_proxy_auth_id_print(const u_char
*dat
, u_int length
);
99 static void l2tp_proxy_auth_resp_print(const u_char
*dat
, u_int length
);
100 static void l2tp_call_errors_print(const u_char
*dat
, u_int length
);
101 static void l2tp_accm_print(const u_char
*dat
, u_int length
);
102 static void l2tp_random_vector_print(const u_char
*dat
, u_int length
);
103 static void l2tp_private_grp_id_print(const u_char
*dat
, u_int length
);
104 static void l2tp_rx_conn_speed_print(const u_char
*dat
, u_int length
);
105 static void l2tp_seq_required_print(const u_char
*dat
, u_int length
);
106 static void l2tp_avp_print(const u_char
*dat
, u_int length
);
108 static struct l2tp_avp_vec l2tp_avp
[] = {
109 {"MSGTYPE", l2tp_msgtype_print
}, /* 0 Message Type */
110 {"RESULT_CODE", l2tp_result_code_print
}, /* 1 Result Code */
111 {"PROTO_VER", l2tp_proto_ver_print
}, /* 2 Protocol Version */
112 {"FRAMING_CAP", l2tp_framing_cap_print
}, /* 3 Framing Capabilities */
113 {"BEARER_CAP", l2tp_bearer_cap_print
}, /* 4 Bearer Capabilities */
114 {"TIE_BREAKER", l2tp_tie_breaker_print
}, /* 5 Tie Breaker */
115 {"FIRM_VER", l2tp_firm_ver_print
}, /* 6 Firmware Revision */
116 {"HOST_NAME", l2tp_host_name_print
}, /* 7 Host Name */
117 {"VENDOR_NAME", l2tp_vendor_name_print
}, /* 8 Vendor Name */
118 {"ASSND_TUN_ID", l2tp_assnd_tun_id_print
}, /* 9 Assigned Tunnel ID */
119 {"RECV_WIN_SIZE", l2tp_recv_win_size_print
}, /* 10 Receive Window Size */
120 {"CHALLENGE", l2tp_challenge_print
}, /* 11 Challenge */
121 {"Q931_CC", l2tp_q931_cc_print
}, /* 12 Q.931 Cause Code */
122 {"CHALLENGE_RESP", l2tp_challenge_resp_print
},/* 13 Challenge Response */
123 {"ASSND_SESS_ID", l2tp_assnd_sess_id_print
}, /* 14 Assigned Session ID */
124 {"CALL_SER_NUM", l2tp_call_ser_num_print
}, /* 15 Call Serial Number */
125 {"MINIMUM_BPS", l2tp_minimum_bps_print
},/* 16 Minimum BPS */
126 {"MAXIMUM_BPS", l2tp_maximum_bps_print
}, /* 17 Maximum BPS */
127 {"BEARER_TYPE", l2tp_bearer_type_print
},/* 18 Bearer Type */
128 {"FRAMING_TYPE", l2tp_framing_type_print
}, /* 19 Framing Type */
129 {"PACKET_PROC_DELAY", l2tp_packet_proc_delay_print
}, /* 20 Packet Processing Delay (OBSOLETE) */
130 {"CALLED_NUMBER", l2tp_called_number_print
}, /* 21 Called Number */
131 {"CALLING_NUMBER", l2tp_calling_number_print
},/* 22 Calling Number */
132 {"SUB_ADDRESS", l2tp_sub_address_print
},/* 23 Sub-Address */
133 {"TX_CONN_SPEED", l2tp_tx_conn_speed_print
}, /* 24 (Tx) Connect Speed */
134 {"PHY_CHANNEL_ID", l2tp_phy_channel_id_print
},/* 25 Physical Channel ID */
135 {"INI_RECV_LCP", l2tp_ini_recv_lcp_print
}, /* 26 Initial Received LCP CONFREQ */
136 {"LAST_SENT_LCP", l2tp_last_sent_lcp_print
}, /* 27 Last Sent LCP CONFREQ */
137 {"LAST_RECV_LCP", l2tp_last_recv_lcp_print
}, /* 28 Last Received LCP CONFREQ */
138 {"PROXY_AUTH_TYPE", l2tp_proxy_auth_type_print
},/* 29 Proxy Authen Type */
139 {"PROXY_AUTH_NAME", l2tp_proxy_auth_name_print
},/* 30 Proxy Authen Name */
140 {"PROXY_AUTH_CHAL", l2tp_proxy_auth_chal_print
},/* 31 Proxy Authen Challenge */
141 {"PROXY_AUTH_ID", l2tp_proxy_auth_id_print
}, /* 32 Proxy Authen ID */
142 {"PROXY_AUTH_RESP", l2tp_proxy_auth_resp_print
},/* 33 Proxy Authen Response */
143 {"CALL_ERRORS", l2tp_call_errors_print
}, /* 34 Call Errors */
144 {"ACCM", l2tp_accm_print
}, /* 35 ACCM */
145 {"RANDOM_VECTOR", l2tp_random_vector_print
}, /* 36 Random Vector */
146 {"PRIVATE_GRP_ID", l2tp_private_grp_id_print
},/* 37 Private Group ID */
147 {"RX_CONN_SPEED", l2tp_rx_conn_speed_print
}, /* 38 (Rx) Connect Speed */
148 {"SEQ_REQUIRED", l2tp_seq_required_print
}, /* 39 Sequencing Required */
149 #define L2TP_MAX_AVP_INDEX 40
152 static char *l2tp_result_code_StopCCN
[] = {
154 "General request to clear control connection",
155 "General error--Error Code indicates the problem",
156 "Control channel already exists",
157 "Requester is not authorized to establish a control channel",
158 "The protocol version of the requester is not supported",
159 "Requester is being shut down",
160 "Finite State Machine error"
161 #define L2TP_MAX_RESULT_CODE_STOPCC_INDEX 8
164 static char *l2tp_result_code_CDN
[] = {
166 "Call disconnected due to loss of carrier",
167 "Call disconnected for the reason indicated in error code",
168 "Call disconnected for administrative reasons",
169 "Call failed due to lack of appropriate facilities being " \
170 "available (temporary condition)",
171 "Call failed due to lack of appropriate facilities being " \
172 "available (permanent condition)",
173 "Invalid destination",
174 "Call failed due to no carrier detected",
175 "Call failed due to detection of a busy signal",
176 "Call failed due to lack of a dial tone",
177 "Call was not established within time allotted by LAC",
178 "Call was connected but no appropriate framing was detected"
179 #define L2TP_MAX_RESULT_CODE_CDN_INDEX 12
182 static char *l2tp_error_code_general
[] = {
184 "No control connection exists yet for this LAC-LNS pair",
186 "One of the field values was out of range or " \
187 "reserved field was non-zero"
188 "Insufficient resources to handle this operation now",
189 "The Session ID is invalid in this context",
190 "A generic vendor-specific error occurred in the LAC",
192 #define L2TP_MAX_ERROR_CODE_GENERAL_INDEX 8
195 /******************************/
196 /* generic print out routines */
197 /******************************/
199 print_string(const u_char
*dat
, u_int length
)
202 for (i
=0; i
<length
; i
++) {
203 printf("%c", *dat
++);
208 print_octets(const u_char
*dat
, u_int length
)
211 for (i
=0; i
<length
; i
++) {
212 printf("%02x", *dat
++);
217 print_short(const u_short
*dat
)
219 printf("%d", ntohs(*dat
));
223 print_int(const u_int
*dat
)
225 printf("%d", ntohl(*dat
));
228 /**********************************/
229 /* AVP-specific print out routines*/
230 /**********************************/
232 l2tp_msgtype_print(const u_char
*dat
, u_int length
)
234 u_short
*ptr
= (u_short
*)dat
;
236 if (ntohs(*ptr
) < L2TP_MAX_MSGTYPE_INDEX
) {
237 printf("%s", l2tp_message_type_string
[ntohs(*ptr
)]);
242 l2tp_result_code_print(const u_char
*dat
, u_int length
)
244 /* we just print out the result and error code number */
245 u_short
*ptr
= (u_short
*)dat
;
247 if (length
== 2) { /* result code */
248 printf("%d", ntohs(*ptr
));
249 } else if (length
== 4) { /* result & error code */
250 printf("%d/%d", ntohs(*ptr
), ntohs(*(ptr
+1)));
251 } else if (length
> 4) { /* result & error code & msg */
252 printf("%d/%d %s", ntohs(*ptr
), ntohs(*(ptr
+1)));
253 print_string((u_char
*)(ptr
+2), length
- 4);
258 l2tp_proto_ver_print(const u_char
*dat
, u_int length
)
260 printf("%d.%d", *dat
, *(dat
+1));
265 l2tp_framing_cap_print(const u_char
*dat
, u_int length
)
267 u_int
*ptr
= (u_int
*)dat
;
269 if (ntohl(*ptr
) & L2TP_FRAMING_CAP_ASYNC_MASK
) {
272 if (ntohl(*ptr
) & L2TP_FRAMING_CAP_SYNC_MASK
) {
278 l2tp_bearer_cap_print(const u_char
*dat
, u_int length
)
280 u_int
*ptr
= (u_int
*)dat
;
282 if (ntohl(*ptr
) & L2TP_BEARER_CAP_ANALOG_MASK
) {
285 if (ntohl(*ptr
) & L2TP_BEARER_CAP_DIGITAL_MASK
) {
291 l2tp_tie_breaker_print(const u_char
*dat
, u_int length
)
293 printf("%lx", *(u_long
*)dat
); /* XXX */
297 l2tp_firm_ver_print(const u_char
*dat
, u_int length
)
299 print_short((u_short
*)dat
);
303 l2tp_host_name_print(const u_char
*dat
, u_int length
)
305 print_string(dat
, length
);
309 l2tp_vendor_name_print(const u_char
*dat
, u_int length
)
311 print_string(dat
, length
);
315 l2tp_assnd_tun_id_print(const u_char
*dat
, u_int length
)
317 print_short((u_short
*)dat
);
321 l2tp_recv_win_size_print(const u_char
*dat
, u_int length
)
323 print_short((u_short
*)dat
);
327 l2tp_challenge_print(const u_char
*dat
, u_int length
)
329 print_octets(dat
, length
);
333 l2tp_q931_cc_print(const u_char
*dat
, u_int length
)
335 print_short((u_short
*)dat
);
336 printf(",%02x", dat
+2);
339 print_string(dat
+3, length
-3);
344 l2tp_challenge_resp_print(const u_char
*dat
, u_int length
)
346 print_octets(dat
, 16); /* XXX length should be 16? */
350 l2tp_assnd_sess_id_print(const u_char
*dat
, u_int length
)
352 print_short((u_short
*)dat
);
356 l2tp_call_ser_num_print(const u_char
*dat
, u_int length
)
358 print_int((u_int
*)dat
);
362 l2tp_minimum_bps_print(const u_char
*dat
, u_int length
)
364 print_int((u_int
*)dat
);
368 l2tp_maximum_bps_print(const u_char
*dat
, u_int length
)
370 print_int((u_int
*)dat
);
374 l2tp_bearer_type_print(const u_char
*dat
, u_int length
)
376 u_int
*ptr
= (u_int
*)dat
;
378 if (ntohl(*ptr
) & L2TP_BEARER_TYPE_ANALOG_MASK
) {
381 if (ntohl(*ptr
) & L2TP_BEARER_TYPE_DIGITAL_MASK
) {
387 l2tp_framing_type_print(const u_char
*dat
, u_int length
)
389 u_int
*ptr
= (u_int
*)dat
;
391 if (ntohl(*ptr
) & L2TP_FRAMING_TYPE_ASYNC_MASK
) {
394 if (ntohl(*ptr
) & L2TP_FRAMING_TYPE_SYNC_MASK
) {
400 l2tp_packet_proc_delay_print(const u_char
*dat
, u_int length
)
406 l2tp_called_number_print(const u_char
*dat
, u_int length
)
408 print_string(dat
, length
);
412 l2tp_calling_number_print(const u_char
*dat
, u_int length
)
414 print_string(dat
, length
);
418 l2tp_sub_address_print(const u_char
*dat
, u_int length
)
420 print_string(dat
, length
);
424 l2tp_tx_conn_speed_print(const u_char
*dat
, u_int length
)
426 print_int((u_int
*)dat
);
430 l2tp_phy_channel_id_print(const u_char
*dat
, u_int length
)
432 print_int((u_int
*)dat
);
436 l2tp_ini_recv_lcp_print(const u_char
*dat
, u_int length
)
438 print_octets(dat
, length
);
442 l2tp_last_sent_lcp_print(const u_char
*dat
, u_int length
)
444 print_octets(dat
, length
);
448 l2tp_last_recv_lcp_print(const u_char
*dat
, u_int length
)
450 print_octets(dat
, length
);
454 l2tp_proxy_auth_type_print(const u_char
*dat
, u_int length
)
456 u_short
*ptr
= (u_short
*)dat
;
458 switch (ntohs(*ptr
)) {
459 case L2TP_AUTHEN_TYPE_RESERVED
:
462 case L2TP_AUTHEN_TYPE_TEXTUAL
:
465 case L2TP_AUTHEN_TYPE_CHAP
:
468 case L2TP_AUTHEN_TYPE_PAP
:
471 case L2TP_AUTHEN_TYPE_NO_AUTH
:
474 case L2TP_AUTHEN_TYPE_MSCHAP
:
483 l2tp_proxy_auth_name_print(const u_char
*dat
, u_int length
)
485 print_octets(dat
, length
);
489 l2tp_proxy_auth_chal_print(const u_char
*dat
, u_int length
)
491 print_octets(dat
, length
);
495 l2tp_proxy_auth_id_print(const u_char
*dat
, u_int length
)
497 u_short
*ptr
= (u_short
*)dat
;
499 printf("%d", ntohs(*ptr
) & L2TP_PROXY_AUTH_ID_MASK
);
503 l2tp_proxy_auth_resp_print(const u_char
*dat
, u_int length
)
505 print_octets(dat
, length
);
509 l2tp_call_errors_print(const u_char
*dat
, u_int length
)
511 struct l2tp_call_errors
*ptr
= (struct l2tp_call_errors
*)dat
;
513 printf("CRCErr=%d FrameErr=%d HardOver=%d BufOver=%d ",
516 ptr
->hardware_overruns
,
517 ptr
->buffer_overruns
);
518 printf("Timeout=%d AlingErr=%d",
520 ptr
->alignment_errs
);
524 l2tp_accm_print(const u_char
*dat
, u_int length
)
526 struct l2tp_accm
*ptr
= (struct l2tp_accm
*)dat
;
528 printf("send=%x recv=%x", ptr
->send_accm
, ptr
->recv_accm
);
532 l2tp_random_vector_print(const u_char
*dat
, u_int length
)
534 print_octets(dat
, length
);
538 l2tp_private_grp_id_print(const u_char
*dat
, u_int length
)
540 print_string(dat
, length
);
541 /* XXX print_octets is more appropriate?? */
545 l2tp_rx_conn_speed_print(const u_char
*dat
, u_int length
)
547 print_int((u_int
*)dat
);
551 l2tp_seq_required_print(const u_char
*dat
, u_int length
)
557 l2tp_avp_print(const u_char
*dat
, u_int length
)
560 const u_short
*ptr
= (u_short
*)dat
;
564 if (length
> 0 && (snapend
- dat
) >= 2) {
565 /* there must be at least two octets for the length
567 if ((len
= (ntohs(*ptr
) & L2TP_AVP_HDR_LEN_MASK
)) <=
569 if (ntohs(*ptr
) & L2TP_AVP_HDR_FLAG_MANDATORY
) {
572 if (ntohs(*ptr
) & L2TP_AVP_HDR_FLAG_HIDDEN
) {
582 if (ntohs(*ptr
)) { /* IETF == 0 */
583 printf("vendor=%04x", ntohs(*ptr
));
587 if (ntohs(*ptr
) < L2TP_MAX_AVP_INDEX
) {
588 printf("%s", l2tp_avp
[ntohs(*ptr
)].name
);
591 (l2tp_avp
[ntohs(*ptr
)].print
)
592 ((u_char
*)ptr
+2, len
-6);
598 printf(" invalid AVP %s", ntohs(*ptr
));
601 l2tp_avp_print(dat
+ len
, length
- len
);
602 } else if (length
== 0) {
611 l2tp_print(const u_char
*dat
, u_int length
)
613 const u_short
*ptr
= (u_short
*)dat
;
614 u_int cnt
= 0; /* total octets consumed */
616 int flag_t
, flag_l
, flag_s
, flag_o
, flag_p
;
619 flag_t
= flag_l
= flag_s
= flag_o
= flag_p
= FALSE
;
621 if (min(length
, snapend
- dat
) - 6 < 0) {
622 /* flag/ver, tunnel_id, session_id must be present for
623 this packet to be properly decoded */
628 if ((ntohs(*ptr
) & L2TP_VERSION_MASK
) == L2TP_VERSION_L2TP
) {
630 } else if ((ntohs(*ptr
) & L2TP_VERSION_MASK
) == L2TP_VERSION_L2F
) {
632 return; /* nothing to do */
634 printf(" Unknown Version, neither L2F(1) nor L2TP(2)");
635 return; /* nothing we can do */
639 if (ntohs(*ptr
) & L2TP_FLAG_TYPE
) {
643 if (ntohs(*ptr
) & L2TP_FLAG_LENGTH
) {
647 if (ntohs(*ptr
) & L2TP_FLAG_SEQUENCE
) {
651 if (ntohs(*ptr
) & L2TP_FLAG_OFFSET
) {
655 if (ntohs(*ptr
) & L2TP_FLAG_PRIORITY
) {
665 l2tp_len
= ntohs(*ptr
++); /* XXX need to consider
672 printf("(%d/", ntohs(*ptr
++)); /* Tunnel ID */
673 printf("%d)", ntohs(*ptr
++)); /* Session ID */
677 printf("Ns=%d,", ntohs(*ptr
++));
678 printf("Nr=%d", ntohs(*ptr
++));
684 (u_char
*)ptr
+= pad
;
689 if (length
- cnt
== 0) {
692 l2tp_avp_print((u_char
*)ptr
, length
- cnt
);
697 ppp_hdlc_print((u_char
*)ptr
, length
- cnt
);