]> The Tcpdump Group git mirrors - tcpdump/blob - print-l2tp.c
Bring in KAME IPv6 tcpdump. replaces esp/ah/isakmp decoder.
[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@ascend.co.jp)
22 */
23
24 #ifndef lint
25 static const char rcsid[] =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-l2tp.c,v 1.1 1999-10-30 05:11:18 itojun Exp $";
27 #endif
28
29 #include <sys/types.h>
30 #include <sys/param.h>
31
32 #include "l2tp.h"
33 #include "interface.h"
34
35 static char tstr[] = " [|l2tp]";
36
37 #ifndef TRUE
38 #define TRUE 1
39 #endif
40
41 #ifndef FALSE
42 #define FALSE 0
43 #endif
44
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
64 };
65
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);
107
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
150 };
151
152 static char *l2tp_result_code_StopCCN[] = {
153 "Reserved",
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
162 };
163
164 static char *l2tp_result_code_CDN[] = {
165 "Reserved",
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
180 };
181
182 static char *l2tp_error_code_general[] = {
183 "No general error",
184 "No control connection exists yet for this LAC-LNS pair",
185 "Length is wrong",
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",
191 "Try another"
192 #define L2TP_MAX_ERROR_CODE_GENERAL_INDEX 8
193 };
194
195 /******************************/
196 /* generic print out routines */
197 /******************************/
198 static void
199 print_string(const u_char *dat, u_int length)
200 {
201 int i;
202 for (i=0; i<length; i++) {
203 printf("%c", *dat++);
204 }
205 }
206
207 static void
208 print_octets(const u_char *dat, u_int length)
209 {
210 int i;
211 for (i=0; i<length; i++) {
212 printf("%02x", *dat++);
213 }
214 }
215
216 static void
217 print_short(const u_short *dat)
218 {
219 printf("%d", ntohs(*dat));
220 }
221
222 static void
223 print_int(const u_int *dat)
224 {
225 printf("%d", ntohl(*dat));
226 }
227
228 /**********************************/
229 /* AVP-specific print out routines*/
230 /**********************************/
231 static void
232 l2tp_msgtype_print(const u_char *dat, u_int length)
233 {
234 u_short *ptr = (u_short *)dat;
235
236 if (ntohs(*ptr) < L2TP_MAX_MSGTYPE_INDEX) {
237 printf("%s", l2tp_message_type_string[ntohs(*ptr)]);
238 }
239 }
240
241 static void
242 l2tp_result_code_print(const u_char *dat, u_int length)
243 {
244 /* we just print out the result and error code number */
245 u_short *ptr = (u_short *)dat;
246
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);
254 }
255 }
256
257 static void
258 l2tp_proto_ver_print(const u_char *dat, u_int length)
259 {
260 printf("%d.%d", *dat, *(dat+1));
261 }
262
263
264 static void
265 l2tp_framing_cap_print(const u_char *dat, u_int length)
266 {
267 u_int *ptr = (u_int *)dat;
268
269 if (ntohl(*ptr) & L2TP_FRAMING_CAP_ASYNC_MASK) {
270 printf("A");
271 }
272 if (ntohl(*ptr) & L2TP_FRAMING_CAP_SYNC_MASK) {
273 printf("S");
274 }
275 }
276
277 static void
278 l2tp_bearer_cap_print(const u_char *dat, u_int length)
279 {
280 u_int *ptr = (u_int *)dat;
281
282 if (ntohl(*ptr) & L2TP_BEARER_CAP_ANALOG_MASK) {
283 printf("A");
284 }
285 if (ntohl(*ptr) & L2TP_BEARER_CAP_DIGITAL_MASK) {
286 printf("D");
287 }
288 }
289
290 static void
291 l2tp_tie_breaker_print(const u_char *dat, u_int length)
292 {
293 printf("%lx", *(u_long *)dat); /* XXX */
294 }
295
296 static void
297 l2tp_firm_ver_print(const u_char *dat, u_int length)
298 {
299 print_short((u_short *)dat);
300 }
301
302 static void
303 l2tp_host_name_print(const u_char *dat, u_int length)
304 {
305 print_string(dat, length);
306 }
307
308 static void
309 l2tp_vendor_name_print(const u_char *dat, u_int length)
310 {
311 print_string(dat, length);
312 }
313
314 static void
315 l2tp_assnd_tun_id_print(const u_char *dat, u_int length)
316 {
317 print_short((u_short *)dat);
318 }
319
320 static void
321 l2tp_recv_win_size_print(const u_char *dat, u_int length)
322 {
323 print_short((u_short *)dat);
324 }
325
326 static void
327 l2tp_challenge_print(const u_char *dat, u_int length)
328 {
329 print_octets(dat, length);
330 }
331
332 static void
333 l2tp_q931_cc_print(const u_char *dat, u_int length)
334 {
335 print_short((u_short *)dat);
336 printf(",%02x", dat+2);
337 if (length > 3) {
338 printf(" ");
339 print_string(dat+3, length-3);
340 }
341 }
342
343 static void
344 l2tp_challenge_resp_print(const u_char *dat, u_int length)
345 {
346 print_octets(dat, 16); /* XXX length should be 16? */
347 }
348
349 static void
350 l2tp_assnd_sess_id_print(const u_char *dat, u_int length)
351 {
352 print_short((u_short *)dat);
353 }
354
355 static void
356 l2tp_call_ser_num_print(const u_char *dat, u_int length)
357 {
358 print_int((u_int *)dat);
359 }
360
361 static void
362 l2tp_minimum_bps_print(const u_char *dat, u_int length)
363 {
364 print_int((u_int *)dat);
365 }
366
367 static void
368 l2tp_maximum_bps_print(const u_char *dat, u_int length)
369 {
370 print_int((u_int *)dat);
371 }
372
373 static void
374 l2tp_bearer_type_print(const u_char *dat, u_int length)
375 {
376 u_int *ptr = (u_int *)dat;
377
378 if (ntohl(*ptr) & L2TP_BEARER_TYPE_ANALOG_MASK) {
379 printf("A");
380 }
381 if (ntohl(*ptr) & L2TP_BEARER_TYPE_DIGITAL_MASK) {
382 printf("D");
383 }
384 }
385
386 static void
387 l2tp_framing_type_print(const u_char *dat, u_int length)
388 {
389 u_int *ptr = (u_int *)dat;
390
391 if (ntohl(*ptr) & L2TP_FRAMING_TYPE_ASYNC_MASK) {
392 printf("A");
393 }
394 if (ntohl(*ptr) & L2TP_FRAMING_TYPE_SYNC_MASK) {
395 printf("S");
396 }
397 }
398
399 static void
400 l2tp_packet_proc_delay_print(const u_char *dat, u_int length)
401 {
402 printf("obsolete");
403 }
404
405 static void
406 l2tp_called_number_print(const u_char *dat, u_int length)
407 {
408 print_string(dat, length);
409 }
410
411 static void
412 l2tp_calling_number_print(const u_char *dat, u_int length)
413 {
414 print_string(dat, length);
415 }
416
417 static void
418 l2tp_sub_address_print(const u_char *dat, u_int length)
419 {
420 print_string(dat, length);
421 }
422
423 static void
424 l2tp_tx_conn_speed_print(const u_char *dat, u_int length)
425 {
426 print_int((u_int *)dat);
427 }
428
429 static void
430 l2tp_phy_channel_id_print(const u_char *dat, u_int length)
431 {
432 print_int((u_int *)dat);
433 }
434
435 static void
436 l2tp_ini_recv_lcp_print(const u_char *dat, u_int length)
437 {
438 print_octets(dat, length);
439 }
440
441 static void
442 l2tp_last_sent_lcp_print(const u_char *dat, u_int length)
443 {
444 print_octets(dat, length);
445 }
446
447 static void
448 l2tp_last_recv_lcp_print(const u_char *dat, u_int length)
449 {
450 print_octets(dat, length);
451 }
452
453 static void
454 l2tp_proxy_auth_type_print(const u_char *dat, u_int length)
455 {
456 u_short *ptr = (u_short *)dat;
457
458 switch (ntohs(*ptr)) {
459 case L2TP_AUTHEN_TYPE_RESERVED:
460 printf("Reserved");
461 break;
462 case L2TP_AUTHEN_TYPE_TEXTUAL:
463 printf("Textual");
464 break;
465 case L2TP_AUTHEN_TYPE_CHAP:
466 printf("CHAP");
467 break;
468 case L2TP_AUTHEN_TYPE_PAP:
469 printf("PAP");
470 break;
471 case L2TP_AUTHEN_TYPE_NO_AUTH:
472 printf("No Auth");
473 break;
474 case L2TP_AUTHEN_TYPE_MSCHAP:
475 printf("MS-CHAP");
476 break;
477 default:
478 printf("unknown");
479 }
480 }
481
482 static void
483 l2tp_proxy_auth_name_print(const u_char *dat, u_int length)
484 {
485 print_octets(dat, length);
486 }
487
488 static void
489 l2tp_proxy_auth_chal_print(const u_char *dat, u_int length)
490 {
491 print_octets(dat, length);
492 }
493
494 static void
495 l2tp_proxy_auth_id_print(const u_char *dat, u_int length)
496 {
497 u_short *ptr = (u_short *)dat;
498
499 printf("%d", ntohs(*ptr) & L2TP_PROXY_AUTH_ID_MASK);
500 }
501
502 static void
503 l2tp_proxy_auth_resp_print(const u_char *dat, u_int length)
504 {
505 print_octets(dat, length);
506 }
507
508 static void
509 l2tp_call_errors_print(const u_char *dat, u_int length)
510 {
511 struct l2tp_call_errors *ptr = (struct l2tp_call_errors *)dat;
512
513 printf("CRCErr=%d FrameErr=%d HardOver=%d BufOver=%d ",
514 ptr->crc_errs,
515 ptr->framing_errs,
516 ptr->hardware_overruns,
517 ptr->buffer_overruns);
518 printf("Timeout=%d AlingErr=%d",
519 ptr->timeout_errs,
520 ptr->alignment_errs);
521 }
522
523 static void
524 l2tp_accm_print(const u_char *dat, u_int length)
525 {
526 struct l2tp_accm *ptr = (struct l2tp_accm *)dat;
527
528 printf("send=%x recv=%x", ptr->send_accm, ptr->recv_accm);
529 }
530
531 static void
532 l2tp_random_vector_print(const u_char *dat, u_int length)
533 {
534 print_octets(dat, length);
535 }
536
537 static void
538 l2tp_private_grp_id_print(const u_char *dat, u_int length)
539 {
540 print_string(dat, length);
541 /* XXX print_octets is more appropriate?? */
542 }
543
544 static void
545 l2tp_rx_conn_speed_print(const u_char *dat, u_int length)
546 {
547 print_int((u_int *)dat);
548 }
549
550 static void
551 l2tp_seq_required_print(const u_char *dat, u_int length)
552 {
553 return;
554 }
555
556 static void
557 l2tp_avp_print(const u_char *dat, u_int length)
558 {
559 u_int len;
560 const u_short *ptr = (u_short *)dat;
561 int hidden = FALSE;
562
563 printf(" ");
564 if (length > 0 && (snapend - dat) >= 2) {
565 /* there must be at least two octets for the length
566 to be decoded */
567 if ((len = (ntohs(*ptr) & L2TP_AVP_HDR_LEN_MASK)) <=
568 (snapend - dat)) {
569 if (ntohs(*ptr) & L2TP_AVP_HDR_FLAG_MANDATORY) {
570 printf("*");
571 }
572 if (ntohs(*ptr) & L2TP_AVP_HDR_FLAG_HIDDEN) {
573 hidden = TRUE;
574 printf("?");
575 }
576 } else {
577 printf("|...");
578 return;
579 }
580 ptr++;
581
582 if (ntohs(*ptr)) { /* IETF == 0 */
583 printf("vendor=%04x", ntohs(*ptr));
584 }
585 ptr++;
586
587 if (ntohs(*ptr) < L2TP_MAX_AVP_INDEX) {
588 printf("%s", l2tp_avp[ntohs(*ptr)].name);
589 printf("(");
590 if (!hidden) {
591 (l2tp_avp[ntohs(*ptr)].print)
592 ((u_char *)ptr+2, len-6);
593 } else {
594 printf("???");
595 }
596 printf(")");
597 } else {
598 printf(" invalid AVP %s", ntohs(*ptr));
599 }
600
601 l2tp_avp_print(dat + len, length - len);
602 } else if (length == 0) {
603 return;
604 } else {
605 printf("|...");
606 }
607 }
608
609
610 void
611 l2tp_print(const u_char *dat, u_int length)
612 {
613 const u_short *ptr = (u_short *)dat;
614 u_int cnt = 0; /* total octets consumed */
615 u_short pad;
616 int flag_t, flag_l, flag_s, flag_o, flag_p;
617 u_short l2tp_len;
618
619 flag_t = flag_l = flag_s = flag_o = flag_p = FALSE;
620
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 */
624 printf("%s", tstr);
625 return;
626 }
627
628 if ((ntohs(*ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2TP) {
629 printf(" l2tp:");
630 } else if ((ntohs(*ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2F) {
631 printf(" l2f:");
632 return; /* nothing to do */
633 } else {
634 printf(" Unknown Version, neither L2F(1) nor L2TP(2)");
635 return; /* nothing we can do */
636 }
637
638 printf("[");
639 if (ntohs(*ptr) & L2TP_FLAG_TYPE) {
640 flag_t = TRUE;
641 printf("T");
642 }
643 if (ntohs(*ptr) & L2TP_FLAG_LENGTH) {
644 flag_l = TRUE;
645 printf("L");
646 }
647 if (ntohs(*ptr) & L2TP_FLAG_SEQUENCE) {
648 flag_s = TRUE;
649 printf("S");
650 }
651 if (ntohs(*ptr) & L2TP_FLAG_OFFSET) {
652 flag_o = TRUE;
653 printf("O");
654 }
655 if (ntohs(*ptr) & L2TP_FLAG_PRIORITY) {
656 flag_p = TRUE;
657 printf("P");
658 }
659 printf("]");
660
661 ptr++;
662 cnt += 2;
663
664 if (flag_l) {
665 l2tp_len = ntohs(*ptr++); /* XXX need to consider
666 truncation ?? */
667 cnt += 2;
668 } else {
669 l2tp_len = 0;
670 }
671
672 printf("(%d/", ntohs(*ptr++)); /* Tunnel ID */
673 printf("%d)", ntohs(*ptr++)); /* Session ID */
674 cnt += 4;
675
676 if (flag_s) {
677 printf("Ns=%d,", ntohs(*ptr++));
678 printf("Nr=%d", ntohs(*ptr++));
679 cnt += 4;
680 }
681
682 if (flag_o) {
683 pad = ntohs(*ptr++);
684 (u_char *)ptr += pad;
685 cnt += (2 + pad);
686 }
687
688 if (flag_t) {
689 if (length - cnt == 0) {
690 printf(" ZLB");
691 } else {
692 l2tp_avp_print((u_char *)ptr, length - cnt);
693 }
694 } else {
695 #if 0
696 printf(" {");
697 ppp_hdlc_print((u_char *)ptr, length - cnt);
698 printf("}");
699 #else
700 printf("[hdlc|]");
701 #endif
702 }
703 }