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.3 1999-11-17 04:14:50 assar Exp $";
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <netinet/in.h>
32 #include <arpa/inet.h>
35 #include "interface.h"
37 static char tstr
[] = " [|l2tp]";
47 static char *l2tp_message_type_string
[] = {
48 "RESERVED_0", /* 0 Reserved */
49 "SCCRQ", /* 1 Start-Control-Connection-Request */
50 "SCCRP", /* 2 Start-Control-Connection-Reply */
51 "SCCCN", /* 3 Start-Control-Connection-Connected */
52 "StopCCN", /* 4 Stop-Control-Connection-Notification */
53 "RESERVED_5", /* 5 Reserved */
54 "HELLO", /* 6 Hello */
55 "OCRQ", /* 7 Outgoing-Call-Request */
56 "OCRP", /* 8 Outgoing-Call-Reply */
57 "OCCN", /* 9 Outgoing-Call-Connected */
58 "ICRQ", /* 10 Incoming-Call-Request */
59 "ICRP", /* 11 Incoming-Call-Reply */
60 "ICCN", /* 12 Incoming-Call-Connected */
61 "RESERVED_13", /* 13 Reserved */
62 "CDN", /* 14 Call-Disconnect-Notify */
63 "WEN", /* 15 WAN-Error-Notify */
64 "SLI" /* 16 Set-Link-Info */
65 #define L2TP_MAX_MSGTYPE_INDEX 17
68 static void l2tp_msgtype_print(const u_char
*dat
, u_int length
);
69 static void l2tp_result_code_print(const u_char
*dat
, u_int length
);
70 static void l2tp_proto_ver_print(const u_char
*dat
, u_int length
);
71 static void l2tp_framing_cap_print(const u_char
*dat
, u_int length
);
72 static void l2tp_bearer_cap_print(const u_char
*dat
, u_int length
);
73 static void l2tp_tie_breaker_print(const u_char
*dat
, u_int length
);
74 static void l2tp_firm_ver_print(const u_char
*dat
, u_int length
);
75 static void l2tp_host_name_print(const u_char
*dat
, u_int length
);
76 static void l2tp_vendor_name_print(const u_char
*dat
, u_int length
);
77 static void l2tp_assnd_tun_id_print(const u_char
*dat
, u_int length
);
78 static void l2tp_recv_win_size_print(const u_char
*dat
, u_int length
);
79 static void l2tp_challenge_print(const u_char
*dat
, u_int length
);
80 static void l2tp_q931_cc_print(const u_char
*dat
, u_int length
);
81 static void l2tp_challenge_resp_print(const u_char
*dat
, u_int length
);
82 static void l2tp_assnd_sess_id_print(const u_char
*dat
, u_int length
);
83 static void l2tp_call_ser_num_print(const u_char
*dat
, u_int length
);
84 static void l2tp_minimum_bps_print(const u_char
*dat
, u_int length
);
85 static void l2tp_maximum_bps_print(const u_char
*dat
, u_int length
);
86 static void l2tp_bearer_type_print(const u_char
*dat
, u_int length
);
87 static void l2tp_framing_type_print(const u_char
*dat
, u_int length
);
88 static void l2tp_packet_proc_delay_print(const u_char
*dat
, u_int length
);
89 static void l2tp_called_number_print(const u_char
*dat
, u_int length
);
90 static void l2tp_calling_number_print(const u_char
*dat
, u_int length
);
91 static void l2tp_sub_address_print(const u_char
*dat
, u_int length
);
92 static void l2tp_tx_conn_speed_print(const u_char
*dat
, u_int length
);
93 static void l2tp_phy_channel_id_print(const u_char
*dat
, u_int length
);
94 static void l2tp_ini_recv_lcp_print(const u_char
*dat
, u_int length
);
95 static void l2tp_last_sent_lcp_print(const u_char
*dat
, u_int length
);
96 static void l2tp_last_recv_lcp_print(const u_char
*dat
, u_int length
);
97 static void l2tp_proxy_auth_type_print(const u_char
*dat
, u_int length
);
98 static void l2tp_proxy_auth_name_print(const u_char
*dat
, u_int length
);
99 static void l2tp_proxy_auth_chal_print(const u_char
*dat
, u_int length
);
100 static void l2tp_proxy_auth_id_print(const u_char
*dat
, u_int length
);
101 static void l2tp_proxy_auth_resp_print(const u_char
*dat
, u_int length
);
102 static void l2tp_call_errors_print(const u_char
*dat
, u_int length
);
103 static void l2tp_accm_print(const u_char
*dat
, u_int length
);
104 static void l2tp_random_vector_print(const u_char
*dat
, u_int length
);
105 static void l2tp_private_grp_id_print(const u_char
*dat
, u_int length
);
106 static void l2tp_rx_conn_speed_print(const u_char
*dat
, u_int length
);
107 static void l2tp_seq_required_print(const u_char
*dat
, u_int length
);
108 static void l2tp_avp_print(const u_char
*dat
, u_int length
);
110 static struct l2tp_avp_vec l2tp_avp
[] = {
111 {"MSGTYPE", l2tp_msgtype_print
}, /* 0 Message Type */
112 {"RESULT_CODE", l2tp_result_code_print
}, /* 1 Result Code */
113 {"PROTO_VER", l2tp_proto_ver_print
}, /* 2 Protocol Version */
114 {"FRAMING_CAP", l2tp_framing_cap_print
}, /* 3 Framing Capabilities */
115 {"BEARER_CAP", l2tp_bearer_cap_print
}, /* 4 Bearer Capabilities */
116 {"TIE_BREAKER", l2tp_tie_breaker_print
}, /* 5 Tie Breaker */
117 {"FIRM_VER", l2tp_firm_ver_print
}, /* 6 Firmware Revision */
118 {"HOST_NAME", l2tp_host_name_print
}, /* 7 Host Name */
119 {"VENDOR_NAME", l2tp_vendor_name_print
}, /* 8 Vendor Name */
120 {"ASSND_TUN_ID", l2tp_assnd_tun_id_print
}, /* 9 Assigned Tunnel ID */
121 {"RECV_WIN_SIZE", l2tp_recv_win_size_print
}, /* 10 Receive Window Size */
122 {"CHALLENGE", l2tp_challenge_print
}, /* 11 Challenge */
123 {"Q931_CC", l2tp_q931_cc_print
}, /* 12 Q.931 Cause Code */
124 {"CHALLENGE_RESP", l2tp_challenge_resp_print
},/* 13 Challenge Response */
125 {"ASSND_SESS_ID", l2tp_assnd_sess_id_print
}, /* 14 Assigned Session ID */
126 {"CALL_SER_NUM", l2tp_call_ser_num_print
}, /* 15 Call Serial Number */
127 {"MINIMUM_BPS", l2tp_minimum_bps_print
},/* 16 Minimum BPS */
128 {"MAXIMUM_BPS", l2tp_maximum_bps_print
}, /* 17 Maximum BPS */
129 {"BEARER_TYPE", l2tp_bearer_type_print
},/* 18 Bearer Type */
130 {"FRAMING_TYPE", l2tp_framing_type_print
}, /* 19 Framing Type */
131 {"PACKET_PROC_DELAY", l2tp_packet_proc_delay_print
}, /* 20 Packet Processing Delay (OBSOLETE) */
132 {"CALLED_NUMBER", l2tp_called_number_print
}, /* 21 Called Number */
133 {"CALLING_NUMBER", l2tp_calling_number_print
},/* 22 Calling Number */
134 {"SUB_ADDRESS", l2tp_sub_address_print
},/* 23 Sub-Address */
135 {"TX_CONN_SPEED", l2tp_tx_conn_speed_print
}, /* 24 (Tx) Connect Speed */
136 {"PHY_CHANNEL_ID", l2tp_phy_channel_id_print
},/* 25 Physical Channel ID */
137 {"INI_RECV_LCP", l2tp_ini_recv_lcp_print
}, /* 26 Initial Received LCP CONFREQ */
138 {"LAST_SENT_LCP", l2tp_last_sent_lcp_print
}, /* 27 Last Sent LCP CONFREQ */
139 {"LAST_RECV_LCP", l2tp_last_recv_lcp_print
}, /* 28 Last Received LCP CONFREQ */
140 {"PROXY_AUTH_TYPE", l2tp_proxy_auth_type_print
},/* 29 Proxy Authen Type */
141 {"PROXY_AUTH_NAME", l2tp_proxy_auth_name_print
},/* 30 Proxy Authen Name */
142 {"PROXY_AUTH_CHAL", l2tp_proxy_auth_chal_print
},/* 31 Proxy Authen Challenge */
143 {"PROXY_AUTH_ID", l2tp_proxy_auth_id_print
}, /* 32 Proxy Authen ID */
144 {"PROXY_AUTH_RESP", l2tp_proxy_auth_resp_print
},/* 33 Proxy Authen Response */
145 {"CALL_ERRORS", l2tp_call_errors_print
}, /* 34 Call Errors */
146 {"ACCM", l2tp_accm_print
}, /* 35 ACCM */
147 {"RANDOM_VECTOR", l2tp_random_vector_print
}, /* 36 Random Vector */
148 {"PRIVATE_GRP_ID", l2tp_private_grp_id_print
},/* 37 Private Group ID */
149 {"RX_CONN_SPEED", l2tp_rx_conn_speed_print
}, /* 38 (Rx) Connect Speed */
150 {"SEQ_REQUIRED", l2tp_seq_required_print
}, /* 39 Sequencing Required */
151 #define L2TP_MAX_AVP_INDEX 40
154 static char *l2tp_result_code_StopCCN
[] = {
156 "General request to clear control connection",
157 "General error--Error Code indicates the problem",
158 "Control channel already exists",
159 "Requester is not authorized to establish a control channel",
160 "The protocol version of the requester is not supported",
161 "Requester is being shut down",
162 "Finite State Machine error"
163 #define L2TP_MAX_RESULT_CODE_STOPCC_INDEX 8
166 static char *l2tp_result_code_CDN
[] = {
168 "Call disconnected due to loss of carrier",
169 "Call disconnected for the reason indicated in error code",
170 "Call disconnected for administrative reasons",
171 "Call failed due to lack of appropriate facilities being " \
172 "available (temporary condition)",
173 "Call failed due to lack of appropriate facilities being " \
174 "available (permanent condition)",
175 "Invalid destination",
176 "Call failed due to no carrier detected",
177 "Call failed due to detection of a busy signal",
178 "Call failed due to lack of a dial tone",
179 "Call was not established within time allotted by LAC",
180 "Call was connected but no appropriate framing was detected"
181 #define L2TP_MAX_RESULT_CODE_CDN_INDEX 12
184 static char *l2tp_error_code_general
[] = {
186 "No control connection exists yet for this LAC-LNS pair",
188 "One of the field values was out of range or " \
189 "reserved field was non-zero"
190 "Insufficient resources to handle this operation now",
191 "The Session ID is invalid in this context",
192 "A generic vendor-specific error occurred in the LAC",
194 #define L2TP_MAX_ERROR_CODE_GENERAL_INDEX 8
197 /******************************/
198 /* generic print out routines */
199 /******************************/
201 print_string(const u_char
*dat
, u_int length
)
204 for (i
=0; i
<length
; i
++) {
205 printf("%c", *dat
++);
210 print_octets(const u_char
*dat
, u_int length
)
213 for (i
=0; i
<length
; i
++) {
214 printf("%02x", *dat
++);
219 print_short(const u_short
*dat
)
221 printf("%d", ntohs(*dat
));
225 print_int(const u_int
*dat
)
227 printf("%d", ntohl(*dat
));
230 /**********************************/
231 /* AVP-specific print out routines*/
232 /**********************************/
234 l2tp_msgtype_print(const u_char
*dat
, u_int length
)
236 u_short
*ptr
= (u_short
*)dat
;
238 if (ntohs(*ptr
) < L2TP_MAX_MSGTYPE_INDEX
) {
239 printf("%s", l2tp_message_type_string
[ntohs(*ptr
)]);
244 l2tp_result_code_print(const u_char
*dat
, u_int length
)
246 /* we just print out the result and error code number */
247 u_short
*ptr
= (u_short
*)dat
;
249 if (length
== 2) { /* result code */
250 printf("%d", ntohs(*ptr
));
251 } else if (length
== 4) { /* result & error code */
252 printf("%d/%d", ntohs(*ptr
), ntohs(*(ptr
+1)));
253 } else if (length
> 4) { /* result & error code & msg */
254 printf("%d/%d %s", ntohs(*ptr
), ntohs(*(ptr
+1)));
255 print_string((u_char
*)(ptr
+2), length
- 4);
260 l2tp_proto_ver_print(const u_char
*dat
, u_int length
)
262 printf("%d.%d", *dat
, *(dat
+1));
267 l2tp_framing_cap_print(const u_char
*dat
, u_int length
)
269 u_int
*ptr
= (u_int
*)dat
;
271 if (ntohl(*ptr
) & L2TP_FRAMING_CAP_ASYNC_MASK
) {
274 if (ntohl(*ptr
) & L2TP_FRAMING_CAP_SYNC_MASK
) {
280 l2tp_bearer_cap_print(const u_char
*dat
, u_int length
)
282 u_int
*ptr
= (u_int
*)dat
;
284 if (ntohl(*ptr
) & L2TP_BEARER_CAP_ANALOG_MASK
) {
287 if (ntohl(*ptr
) & L2TP_BEARER_CAP_DIGITAL_MASK
) {
293 l2tp_tie_breaker_print(const u_char
*dat
, u_int length
)
295 printf("%lx", *(u_long
*)dat
); /* XXX */
299 l2tp_firm_ver_print(const u_char
*dat
, u_int length
)
301 print_short((u_short
*)dat
);
305 l2tp_host_name_print(const u_char
*dat
, u_int length
)
307 print_string(dat
, length
);
311 l2tp_vendor_name_print(const u_char
*dat
, u_int length
)
313 print_string(dat
, length
);
317 l2tp_assnd_tun_id_print(const u_char
*dat
, u_int length
)
319 print_short((u_short
*)dat
);
323 l2tp_recv_win_size_print(const u_char
*dat
, u_int length
)
325 print_short((u_short
*)dat
);
329 l2tp_challenge_print(const u_char
*dat
, u_int length
)
331 print_octets(dat
, length
);
335 l2tp_q931_cc_print(const u_char
*dat
, u_int length
)
337 print_short((u_short
*)dat
);
338 printf(",%02x", dat
+2);
341 print_string(dat
+3, length
-3);
346 l2tp_challenge_resp_print(const u_char
*dat
, u_int length
)
348 print_octets(dat
, 16); /* XXX length should be 16? */
352 l2tp_assnd_sess_id_print(const u_char
*dat
, u_int length
)
354 print_short((u_short
*)dat
);
358 l2tp_call_ser_num_print(const u_char
*dat
, u_int length
)
360 print_int((u_int
*)dat
);
364 l2tp_minimum_bps_print(const u_char
*dat
, u_int length
)
366 print_int((u_int
*)dat
);
370 l2tp_maximum_bps_print(const u_char
*dat
, u_int length
)
372 print_int((u_int
*)dat
);
376 l2tp_bearer_type_print(const u_char
*dat
, u_int length
)
378 u_int
*ptr
= (u_int
*)dat
;
380 if (ntohl(*ptr
) & L2TP_BEARER_TYPE_ANALOG_MASK
) {
383 if (ntohl(*ptr
) & L2TP_BEARER_TYPE_DIGITAL_MASK
) {
389 l2tp_framing_type_print(const u_char
*dat
, u_int length
)
391 u_int
*ptr
= (u_int
*)dat
;
393 if (ntohl(*ptr
) & L2TP_FRAMING_TYPE_ASYNC_MASK
) {
396 if (ntohl(*ptr
) & L2TP_FRAMING_TYPE_SYNC_MASK
) {
402 l2tp_packet_proc_delay_print(const u_char
*dat
, u_int length
)
408 l2tp_called_number_print(const u_char
*dat
, u_int length
)
410 print_string(dat
, length
);
414 l2tp_calling_number_print(const u_char
*dat
, u_int length
)
416 print_string(dat
, length
);
420 l2tp_sub_address_print(const u_char
*dat
, u_int length
)
422 print_string(dat
, length
);
426 l2tp_tx_conn_speed_print(const u_char
*dat
, u_int length
)
428 print_int((u_int
*)dat
);
432 l2tp_phy_channel_id_print(const u_char
*dat
, u_int length
)
434 print_int((u_int
*)dat
);
438 l2tp_ini_recv_lcp_print(const u_char
*dat
, u_int length
)
440 print_octets(dat
, length
);
444 l2tp_last_sent_lcp_print(const u_char
*dat
, u_int length
)
446 print_octets(dat
, length
);
450 l2tp_last_recv_lcp_print(const u_char
*dat
, u_int length
)
452 print_octets(dat
, length
);
456 l2tp_proxy_auth_type_print(const u_char
*dat
, u_int length
)
458 u_short
*ptr
= (u_short
*)dat
;
460 switch (ntohs(*ptr
)) {
461 case L2TP_AUTHEN_TYPE_RESERVED
:
464 case L2TP_AUTHEN_TYPE_TEXTUAL
:
467 case L2TP_AUTHEN_TYPE_CHAP
:
470 case L2TP_AUTHEN_TYPE_PAP
:
473 case L2TP_AUTHEN_TYPE_NO_AUTH
:
476 case L2TP_AUTHEN_TYPE_MSCHAP
:
485 l2tp_proxy_auth_name_print(const u_char
*dat
, u_int length
)
487 print_octets(dat
, length
);
491 l2tp_proxy_auth_chal_print(const u_char
*dat
, u_int length
)
493 print_octets(dat
, length
);
497 l2tp_proxy_auth_id_print(const u_char
*dat
, u_int length
)
499 u_short
*ptr
= (u_short
*)dat
;
501 printf("%d", ntohs(*ptr
) & L2TP_PROXY_AUTH_ID_MASK
);
505 l2tp_proxy_auth_resp_print(const u_char
*dat
, u_int length
)
507 print_octets(dat
, length
);
511 l2tp_call_errors_print(const u_char
*dat
, u_int length
)
513 struct l2tp_call_errors
*ptr
= (struct l2tp_call_errors
*)dat
;
515 printf("CRCErr=%d FrameErr=%d HardOver=%d BufOver=%d ",
518 ptr
->hardware_overruns
,
519 ptr
->buffer_overruns
);
520 printf("Timeout=%d AlingErr=%d",
522 ptr
->alignment_errs
);
526 l2tp_accm_print(const u_char
*dat
, u_int length
)
528 struct l2tp_accm
*ptr
= (struct l2tp_accm
*)dat
;
530 printf("send=%x recv=%x", ptr
->send_accm
, ptr
->recv_accm
);
534 l2tp_random_vector_print(const u_char
*dat
, u_int length
)
536 print_octets(dat
, length
);
540 l2tp_private_grp_id_print(const u_char
*dat
, u_int length
)
542 print_string(dat
, length
);
543 /* XXX print_octets is more appropriate?? */
547 l2tp_rx_conn_speed_print(const u_char
*dat
, u_int length
)
549 print_int((u_int
*)dat
);
553 l2tp_seq_required_print(const u_char
*dat
, u_int length
)
559 l2tp_avp_print(const u_char
*dat
, u_int length
)
562 const u_short
*ptr
= (u_short
*)dat
;
566 if (length
> 0 && (snapend
- dat
) >= 2) {
567 /* there must be at least two octets for the length
569 if ((len
= (ntohs(*ptr
) & L2TP_AVP_HDR_LEN_MASK
)) <=
571 if (ntohs(*ptr
) & L2TP_AVP_HDR_FLAG_MANDATORY
) {
574 if (ntohs(*ptr
) & L2TP_AVP_HDR_FLAG_HIDDEN
) {
584 if (ntohs(*ptr
)) { /* IETF == 0 */
585 printf("vendor=%04x", ntohs(*ptr
));
589 if (ntohs(*ptr
) < L2TP_MAX_AVP_INDEX
) {
590 printf("%s", l2tp_avp
[ntohs(*ptr
)].name
);
593 (l2tp_avp
[ntohs(*ptr
)].print
)
594 ((u_char
*)ptr
+2, len
-6);
600 printf(" invalid AVP %s", ntohs(*ptr
));
603 l2tp_avp_print(dat
+ len
, length
- len
);
604 } else if (length
== 0) {
613 l2tp_print(const u_char
*dat
, u_int length
)
615 const u_short
*ptr
= (u_short
*)dat
;
616 u_int cnt
= 0; /* total octets consumed */
618 int flag_t
, flag_l
, flag_s
, flag_o
, flag_p
;
621 flag_t
= flag_l
= flag_s
= flag_o
= flag_p
= FALSE
;
623 if (min(length
, snapend
- dat
) - 6 < 0) {
624 /* flag/ver, tunnel_id, session_id must be present for
625 this packet to be properly decoded */
630 if ((ntohs(*ptr
) & L2TP_VERSION_MASK
) == L2TP_VERSION_L2TP
) {
632 } else if ((ntohs(*ptr
) & L2TP_VERSION_MASK
) == L2TP_VERSION_L2F
) {
634 return; /* nothing to do */
636 printf(" Unknown Version, neither L2F(1) nor L2TP(2)");
637 return; /* nothing we can do */
641 if (ntohs(*ptr
) & L2TP_FLAG_TYPE
) {
645 if (ntohs(*ptr
) & L2TP_FLAG_LENGTH
) {
649 if (ntohs(*ptr
) & L2TP_FLAG_SEQUENCE
) {
653 if (ntohs(*ptr
) & L2TP_FLAG_OFFSET
) {
657 if (ntohs(*ptr
) & L2TP_FLAG_PRIORITY
) {
667 l2tp_len
= ntohs(*ptr
++); /* XXX need to consider
674 printf("(%d/", ntohs(*ptr
++)); /* Tunnel ID */
675 printf("%d)", ntohs(*ptr
++)); /* Session ID */
679 printf("Ns=%d,", ntohs(*ptr
++));
680 printf("Nr=%d", ntohs(*ptr
++));
686 ptr
+= pad
/ sizeof(*ptr
);
691 if (length
- cnt
== 0) {
694 l2tp_avp_print((u_char
*)ptr
, length
- cnt
);
699 ppp_hdlc_print((u_char
*)ptr
, length
- cnt
);