]> The Tcpdump Group git mirrors - tcpdump/blob - print-l2tp.c
eff002de0b76502787f9d1b5698c5ba8ee2c0e2a
[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.4 1999-11-21 09:36:55 fenner Exp $";
27 #endif
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
37
38 #include "l2tp.h"
39 #include "interface.h"
40
41 static char tstr[] = " [|l2tp]";
42
43 #ifndef TRUE
44 #define TRUE 1
45 #endif
46
47 #ifndef FALSE
48 #define FALSE 0
49 #endif
50
51 static char *l2tp_message_type_string[] = {
52 "RESERVED_0", /* 0 Reserved */
53 "SCCRQ", /* 1 Start-Control-Connection-Request */
54 "SCCRP", /* 2 Start-Control-Connection-Reply */
55 "SCCCN", /* 3 Start-Control-Connection-Connected */
56 "StopCCN", /* 4 Stop-Control-Connection-Notification */
57 "RESERVED_5", /* 5 Reserved */
58 "HELLO", /* 6 Hello */
59 "OCRQ", /* 7 Outgoing-Call-Request */
60 "OCRP", /* 8 Outgoing-Call-Reply */
61 "OCCN", /* 9 Outgoing-Call-Connected */
62 "ICRQ", /* 10 Incoming-Call-Request */
63 "ICRP", /* 11 Incoming-Call-Reply */
64 "ICCN", /* 12 Incoming-Call-Connected */
65 "RESERVED_13", /* 13 Reserved */
66 "CDN", /* 14 Call-Disconnect-Notify */
67 "WEN", /* 15 WAN-Error-Notify */
68 "SLI" /* 16 Set-Link-Info */
69 #define L2TP_MAX_MSGTYPE_INDEX 17
70 };
71
72 static void l2tp_msgtype_print(const u_char *dat, u_int length);
73 static void l2tp_result_code_print(const u_char *dat, u_int length);
74 static void l2tp_proto_ver_print(const u_char *dat, u_int length);
75 static void l2tp_framing_cap_print(const u_char *dat, u_int length);
76 static void l2tp_bearer_cap_print(const u_char *dat, u_int length);
77 static void l2tp_tie_breaker_print(const u_char *dat, u_int length);
78 static void l2tp_firm_ver_print(const u_char *dat, u_int length);
79 static void l2tp_host_name_print(const u_char *dat, u_int length);
80 static void l2tp_vendor_name_print(const u_char *dat, u_int length);
81 static void l2tp_assnd_tun_id_print(const u_char *dat, u_int length);
82 static void l2tp_recv_win_size_print(const u_char *dat, u_int length);
83 static void l2tp_challenge_print(const u_char *dat, u_int length);
84 static void l2tp_q931_cc_print(const u_char *dat, u_int length);
85 static void l2tp_challenge_resp_print(const u_char *dat, u_int length);
86 static void l2tp_assnd_sess_id_print(const u_char *dat, u_int length);
87 static void l2tp_call_ser_num_print(const u_char *dat, u_int length);
88 static void l2tp_minimum_bps_print(const u_char *dat, u_int length);
89 static void l2tp_maximum_bps_print(const u_char *dat, u_int length);
90 static void l2tp_bearer_type_print(const u_char *dat, u_int length);
91 static void l2tp_framing_type_print(const u_char *dat, u_int length);
92 static void l2tp_packet_proc_delay_print(const u_char *dat, u_int length);
93 static void l2tp_called_number_print(const u_char *dat, u_int length);
94 static void l2tp_calling_number_print(const u_char *dat, u_int length);
95 static void l2tp_sub_address_print(const u_char *dat, u_int length);
96 static void l2tp_tx_conn_speed_print(const u_char *dat, u_int length);
97 static void l2tp_phy_channel_id_print(const u_char *dat, u_int length);
98 static void l2tp_ini_recv_lcp_print(const u_char *dat, u_int length);
99 static void l2tp_last_sent_lcp_print(const u_char *dat, u_int length);
100 static void l2tp_last_recv_lcp_print(const u_char *dat, u_int length);
101 static void l2tp_proxy_auth_type_print(const u_char *dat, u_int length);
102 static void l2tp_proxy_auth_name_print(const u_char *dat, u_int length);
103 static void l2tp_proxy_auth_chal_print(const u_char *dat, u_int length);
104 static void l2tp_proxy_auth_id_print(const u_char *dat, u_int length);
105 static void l2tp_proxy_auth_resp_print(const u_char *dat, u_int length);
106 static void l2tp_call_errors_print(const u_char *dat, u_int length);
107 static void l2tp_accm_print(const u_char *dat, u_int length);
108 static void l2tp_random_vector_print(const u_char *dat, u_int length);
109 static void l2tp_private_grp_id_print(const u_char *dat, u_int length);
110 static void l2tp_rx_conn_speed_print(const u_char *dat, u_int length);
111 static void l2tp_seq_required_print(const u_char *dat, u_int length);
112 static void l2tp_avp_print(const u_char *dat, u_int length);
113
114 static struct l2tp_avp_vec l2tp_avp[] = {
115 {"MSGTYPE", l2tp_msgtype_print}, /* 0 Message Type */
116 {"RESULT_CODE", l2tp_result_code_print}, /* 1 Result Code */
117 {"PROTO_VER", l2tp_proto_ver_print}, /* 2 Protocol Version */
118 {"FRAMING_CAP", l2tp_framing_cap_print}, /* 3 Framing Capabilities */
119 {"BEARER_CAP", l2tp_bearer_cap_print}, /* 4 Bearer Capabilities */
120 {"TIE_BREAKER", l2tp_tie_breaker_print}, /* 5 Tie Breaker */
121 {"FIRM_VER", l2tp_firm_ver_print}, /* 6 Firmware Revision */
122 {"HOST_NAME", l2tp_host_name_print}, /* 7 Host Name */
123 {"VENDOR_NAME", l2tp_vendor_name_print}, /* 8 Vendor Name */
124 {"ASSND_TUN_ID", l2tp_assnd_tun_id_print}, /* 9 Assigned Tunnel ID */
125 {"RECV_WIN_SIZE", l2tp_recv_win_size_print}, /* 10 Receive Window Size */
126 {"CHALLENGE", l2tp_challenge_print}, /* 11 Challenge */
127 {"Q931_CC", l2tp_q931_cc_print}, /* 12 Q.931 Cause Code */
128 {"CHALLENGE_RESP", l2tp_challenge_resp_print},/* 13 Challenge Response */
129 {"ASSND_SESS_ID", l2tp_assnd_sess_id_print}, /* 14 Assigned Session ID */
130 {"CALL_SER_NUM", l2tp_call_ser_num_print}, /* 15 Call Serial Number */
131 {"MINIMUM_BPS", l2tp_minimum_bps_print},/* 16 Minimum BPS */
132 {"MAXIMUM_BPS", l2tp_maximum_bps_print}, /* 17 Maximum BPS */
133 {"BEARER_TYPE", l2tp_bearer_type_print},/* 18 Bearer Type */
134 {"FRAMING_TYPE", l2tp_framing_type_print}, /* 19 Framing Type */
135 {"PACKET_PROC_DELAY", l2tp_packet_proc_delay_print}, /* 20 Packet Processing Delay (OBSOLETE) */
136 {"CALLED_NUMBER", l2tp_called_number_print}, /* 21 Called Number */
137 {"CALLING_NUMBER", l2tp_calling_number_print},/* 22 Calling Number */
138 {"SUB_ADDRESS", l2tp_sub_address_print},/* 23 Sub-Address */
139 {"TX_CONN_SPEED", l2tp_tx_conn_speed_print}, /* 24 (Tx) Connect Speed */
140 {"PHY_CHANNEL_ID", l2tp_phy_channel_id_print},/* 25 Physical Channel ID */
141 {"INI_RECV_LCP", l2tp_ini_recv_lcp_print}, /* 26 Initial Received LCP CONFREQ */
142 {"LAST_SENT_LCP", l2tp_last_sent_lcp_print}, /* 27 Last Sent LCP CONFREQ */
143 {"LAST_RECV_LCP", l2tp_last_recv_lcp_print}, /* 28 Last Received LCP CONFREQ */
144 {"PROXY_AUTH_TYPE", l2tp_proxy_auth_type_print},/* 29 Proxy Authen Type */
145 {"PROXY_AUTH_NAME", l2tp_proxy_auth_name_print},/* 30 Proxy Authen Name */
146 {"PROXY_AUTH_CHAL", l2tp_proxy_auth_chal_print},/* 31 Proxy Authen Challenge */
147 {"PROXY_AUTH_ID", l2tp_proxy_auth_id_print}, /* 32 Proxy Authen ID */
148 {"PROXY_AUTH_RESP", l2tp_proxy_auth_resp_print},/* 33 Proxy Authen Response */
149 {"CALL_ERRORS", l2tp_call_errors_print}, /* 34 Call Errors */
150 {"ACCM", l2tp_accm_print}, /* 35 ACCM */
151 {"RANDOM_VECTOR", l2tp_random_vector_print}, /* 36 Random Vector */
152 {"PRIVATE_GRP_ID", l2tp_private_grp_id_print},/* 37 Private Group ID */
153 {"RX_CONN_SPEED", l2tp_rx_conn_speed_print}, /* 38 (Rx) Connect Speed */
154 {"SEQ_REQUIRED", l2tp_seq_required_print}, /* 39 Sequencing Required */
155 #define L2TP_MAX_AVP_INDEX 40
156 };
157
158 static char *l2tp_result_code_StopCCN[] = {
159 "Reserved",
160 "General request to clear control connection",
161 "General error--Error Code indicates the problem",
162 "Control channel already exists",
163 "Requester is not authorized to establish a control channel",
164 "The protocol version of the requester is not supported",
165 "Requester is being shut down",
166 "Finite State Machine error"
167 #define L2TP_MAX_RESULT_CODE_STOPCC_INDEX 8
168 };
169
170 static char *l2tp_result_code_CDN[] = {
171 "Reserved",
172 "Call disconnected due to loss of carrier",
173 "Call disconnected for the reason indicated in error code",
174 "Call disconnected for administrative reasons",
175 "Call failed due to lack of appropriate facilities being " \
176 "available (temporary condition)",
177 "Call failed due to lack of appropriate facilities being " \
178 "available (permanent condition)",
179 "Invalid destination",
180 "Call failed due to no carrier detected",
181 "Call failed due to detection of a busy signal",
182 "Call failed due to lack of a dial tone",
183 "Call was not established within time allotted by LAC",
184 "Call was connected but no appropriate framing was detected"
185 #define L2TP_MAX_RESULT_CODE_CDN_INDEX 12
186 };
187
188 static char *l2tp_error_code_general[] = {
189 "No general error",
190 "No control connection exists yet for this LAC-LNS pair",
191 "Length is wrong",
192 "One of the field values was out of range or " \
193 "reserved field was non-zero"
194 "Insufficient resources to handle this operation now",
195 "The Session ID is invalid in this context",
196 "A generic vendor-specific error occurred in the LAC",
197 "Try another"
198 #define L2TP_MAX_ERROR_CODE_GENERAL_INDEX 8
199 };
200
201 /******************************/
202 /* generic print out routines */
203 /******************************/
204 static void
205 print_string(const u_char *dat, u_int length)
206 {
207 int i;
208 for (i=0; i<length; i++) {
209 printf("%c", *dat++);
210 }
211 }
212
213 static void
214 print_octets(const u_char *dat, u_int length)
215 {
216 int i;
217 for (i=0; i<length; i++) {
218 printf("%02x", *dat++);
219 }
220 }
221
222 static void
223 print_short(const u_short *dat)
224 {
225 printf("%d", ntohs(*dat));
226 }
227
228 static void
229 print_int(const u_int *dat)
230 {
231 printf("%d", ntohl(*dat));
232 }
233
234 /**********************************/
235 /* AVP-specific print out routines*/
236 /**********************************/
237 static void
238 l2tp_msgtype_print(const u_char *dat, u_int length)
239 {
240 u_short *ptr = (u_short *)dat;
241
242 if (ntohs(*ptr) < L2TP_MAX_MSGTYPE_INDEX) {
243 printf("%s", l2tp_message_type_string[ntohs(*ptr)]);
244 }
245 }
246
247 static void
248 l2tp_result_code_print(const u_char *dat, u_int length)
249 {
250 /* we just print out the result and error code number */
251 u_short *ptr = (u_short *)dat;
252
253 if (length == 2) { /* result code */
254 printf("%d", ntohs(*ptr));
255 } else if (length == 4) { /* result & error code */
256 printf("%d/%d", ntohs(*ptr), ntohs(*(ptr+1)));
257 } else if (length > 4) { /* result & error code & msg */
258 printf("%d/%d %s", ntohs(*ptr), ntohs(*(ptr+1)));
259 print_string((u_char *)(ptr+2), length - 4);
260 }
261 }
262
263 static void
264 l2tp_proto_ver_print(const u_char *dat, u_int length)
265 {
266 printf("%d.%d", *dat, *(dat+1));
267 }
268
269
270 static void
271 l2tp_framing_cap_print(const u_char *dat, u_int length)
272 {
273 u_int *ptr = (u_int *)dat;
274
275 if (ntohl(*ptr) & L2TP_FRAMING_CAP_ASYNC_MASK) {
276 printf("A");
277 }
278 if (ntohl(*ptr) & L2TP_FRAMING_CAP_SYNC_MASK) {
279 printf("S");
280 }
281 }
282
283 static void
284 l2tp_bearer_cap_print(const u_char *dat, u_int length)
285 {
286 u_int *ptr = (u_int *)dat;
287
288 if (ntohl(*ptr) & L2TP_BEARER_CAP_ANALOG_MASK) {
289 printf("A");
290 }
291 if (ntohl(*ptr) & L2TP_BEARER_CAP_DIGITAL_MASK) {
292 printf("D");
293 }
294 }
295
296 static void
297 l2tp_tie_breaker_print(const u_char *dat, u_int length)
298 {
299 printf("%lx", *(u_long *)dat); /* XXX */
300 }
301
302 static void
303 l2tp_firm_ver_print(const u_char *dat, u_int length)
304 {
305 print_short((u_short *)dat);
306 }
307
308 static void
309 l2tp_host_name_print(const u_char *dat, u_int length)
310 {
311 print_string(dat, length);
312 }
313
314 static void
315 l2tp_vendor_name_print(const u_char *dat, u_int length)
316 {
317 print_string(dat, length);
318 }
319
320 static void
321 l2tp_assnd_tun_id_print(const u_char *dat, u_int length)
322 {
323 print_short((u_short *)dat);
324 }
325
326 static void
327 l2tp_recv_win_size_print(const u_char *dat, u_int length)
328 {
329 print_short((u_short *)dat);
330 }
331
332 static void
333 l2tp_challenge_print(const u_char *dat, u_int length)
334 {
335 print_octets(dat, length);
336 }
337
338 static void
339 l2tp_q931_cc_print(const u_char *dat, u_int length)
340 {
341 print_short((u_short *)dat);
342 printf(",%02x", dat+2);
343 if (length > 3) {
344 printf(" ");
345 print_string(dat+3, length-3);
346 }
347 }
348
349 static void
350 l2tp_challenge_resp_print(const u_char *dat, u_int length)
351 {
352 print_octets(dat, 16); /* XXX length should be 16? */
353 }
354
355 static void
356 l2tp_assnd_sess_id_print(const u_char *dat, u_int length)
357 {
358 print_short((u_short *)dat);
359 }
360
361 static void
362 l2tp_call_ser_num_print(const u_char *dat, u_int length)
363 {
364 print_int((u_int *)dat);
365 }
366
367 static void
368 l2tp_minimum_bps_print(const u_char *dat, u_int length)
369 {
370 print_int((u_int *)dat);
371 }
372
373 static void
374 l2tp_maximum_bps_print(const u_char *dat, u_int length)
375 {
376 print_int((u_int *)dat);
377 }
378
379 static void
380 l2tp_bearer_type_print(const u_char *dat, u_int length)
381 {
382 u_int *ptr = (u_int *)dat;
383
384 if (ntohl(*ptr) & L2TP_BEARER_TYPE_ANALOG_MASK) {
385 printf("A");
386 }
387 if (ntohl(*ptr) & L2TP_BEARER_TYPE_DIGITAL_MASK) {
388 printf("D");
389 }
390 }
391
392 static void
393 l2tp_framing_type_print(const u_char *dat, u_int length)
394 {
395 u_int *ptr = (u_int *)dat;
396
397 if (ntohl(*ptr) & L2TP_FRAMING_TYPE_ASYNC_MASK) {
398 printf("A");
399 }
400 if (ntohl(*ptr) & L2TP_FRAMING_TYPE_SYNC_MASK) {
401 printf("S");
402 }
403 }
404
405 static void
406 l2tp_packet_proc_delay_print(const u_char *dat, u_int length)
407 {
408 printf("obsolete");
409 }
410
411 static void
412 l2tp_called_number_print(const u_char *dat, u_int length)
413 {
414 print_string(dat, length);
415 }
416
417 static void
418 l2tp_calling_number_print(const u_char *dat, u_int length)
419 {
420 print_string(dat, length);
421 }
422
423 static void
424 l2tp_sub_address_print(const u_char *dat, u_int length)
425 {
426 print_string(dat, length);
427 }
428
429 static void
430 l2tp_tx_conn_speed_print(const u_char *dat, u_int length)
431 {
432 print_int((u_int *)dat);
433 }
434
435 static void
436 l2tp_phy_channel_id_print(const u_char *dat, u_int length)
437 {
438 print_int((u_int *)dat);
439 }
440
441 static void
442 l2tp_ini_recv_lcp_print(const u_char *dat, u_int length)
443 {
444 print_octets(dat, length);
445 }
446
447 static void
448 l2tp_last_sent_lcp_print(const u_char *dat, u_int length)
449 {
450 print_octets(dat, length);
451 }
452
453 static void
454 l2tp_last_recv_lcp_print(const u_char *dat, u_int length)
455 {
456 print_octets(dat, length);
457 }
458
459 static void
460 l2tp_proxy_auth_type_print(const u_char *dat, u_int length)
461 {
462 u_short *ptr = (u_short *)dat;
463
464 switch (ntohs(*ptr)) {
465 case L2TP_AUTHEN_TYPE_RESERVED:
466 printf("Reserved");
467 break;
468 case L2TP_AUTHEN_TYPE_TEXTUAL:
469 printf("Textual");
470 break;
471 case L2TP_AUTHEN_TYPE_CHAP:
472 printf("CHAP");
473 break;
474 case L2TP_AUTHEN_TYPE_PAP:
475 printf("PAP");
476 break;
477 case L2TP_AUTHEN_TYPE_NO_AUTH:
478 printf("No Auth");
479 break;
480 case L2TP_AUTHEN_TYPE_MSCHAP:
481 printf("MS-CHAP");
482 break;
483 default:
484 printf("unknown");
485 }
486 }
487
488 static void
489 l2tp_proxy_auth_name_print(const u_char *dat, u_int length)
490 {
491 print_octets(dat, length);
492 }
493
494 static void
495 l2tp_proxy_auth_chal_print(const u_char *dat, u_int length)
496 {
497 print_octets(dat, length);
498 }
499
500 static void
501 l2tp_proxy_auth_id_print(const u_char *dat, u_int length)
502 {
503 u_short *ptr = (u_short *)dat;
504
505 printf("%d", ntohs(*ptr) & L2TP_PROXY_AUTH_ID_MASK);
506 }
507
508 static void
509 l2tp_proxy_auth_resp_print(const u_char *dat, u_int length)
510 {
511 print_octets(dat, length);
512 }
513
514 static void
515 l2tp_call_errors_print(const u_char *dat, u_int length)
516 {
517 struct l2tp_call_errors *ptr = (struct l2tp_call_errors *)dat;
518
519 printf("CRCErr=%d FrameErr=%d HardOver=%d BufOver=%d ",
520 ptr->crc_errs,
521 ptr->framing_errs,
522 ptr->hardware_overruns,
523 ptr->buffer_overruns);
524 printf("Timeout=%d AlingErr=%d",
525 ptr->timeout_errs,
526 ptr->alignment_errs);
527 }
528
529 static void
530 l2tp_accm_print(const u_char *dat, u_int length)
531 {
532 struct l2tp_accm *ptr = (struct l2tp_accm *)dat;
533
534 printf("send=%x recv=%x", ptr->send_accm, ptr->recv_accm);
535 }
536
537 static void
538 l2tp_random_vector_print(const u_char *dat, u_int length)
539 {
540 print_octets(dat, length);
541 }
542
543 static void
544 l2tp_private_grp_id_print(const u_char *dat, u_int length)
545 {
546 print_string(dat, length);
547 /* XXX print_octets is more appropriate?? */
548 }
549
550 static void
551 l2tp_rx_conn_speed_print(const u_char *dat, u_int length)
552 {
553 print_int((u_int *)dat);
554 }
555
556 static void
557 l2tp_seq_required_print(const u_char *dat, u_int length)
558 {
559 return;
560 }
561
562 static void
563 l2tp_avp_print(const u_char *dat, u_int length)
564 {
565 u_int len;
566 const u_short *ptr = (u_short *)dat;
567 int hidden = FALSE;
568
569 printf(" ");
570 if (length > 0 && (snapend - dat) >= 2) {
571 /* there must be at least two octets for the length
572 to be decoded */
573 if ((len = (ntohs(*ptr) & L2TP_AVP_HDR_LEN_MASK)) <=
574 (snapend - dat)) {
575 if (ntohs(*ptr) & L2TP_AVP_HDR_FLAG_MANDATORY) {
576 printf("*");
577 }
578 if (ntohs(*ptr) & L2TP_AVP_HDR_FLAG_HIDDEN) {
579 hidden = TRUE;
580 printf("?");
581 }
582 } else {
583 printf("|...");
584 return;
585 }
586 ptr++;
587
588 if (ntohs(*ptr)) { /* IETF == 0 */
589 printf("vendor=%04x", ntohs(*ptr));
590 }
591 ptr++;
592
593 if (ntohs(*ptr) < L2TP_MAX_AVP_INDEX) {
594 printf("%s", l2tp_avp[ntohs(*ptr)].name);
595 printf("(");
596 if (!hidden) {
597 (l2tp_avp[ntohs(*ptr)].print)
598 ((u_char *)ptr+2, len-6);
599 } else {
600 printf("???");
601 }
602 printf(")");
603 } else {
604 printf(" invalid AVP %s", ntohs(*ptr));
605 }
606
607 l2tp_avp_print(dat + len, length - len);
608 } else if (length == 0) {
609 return;
610 } else {
611 printf("|...");
612 }
613 }
614
615
616 void
617 l2tp_print(const u_char *dat, u_int length)
618 {
619 const u_short *ptr = (u_short *)dat;
620 u_int cnt = 0; /* total octets consumed */
621 u_short pad;
622 int flag_t, flag_l, flag_s, flag_o, flag_p;
623 u_short l2tp_len;
624
625 flag_t = flag_l = flag_s = flag_o = flag_p = FALSE;
626
627 if (min(length, snapend - dat) - 6 < 0) {
628 /* flag/ver, tunnel_id, session_id must be present for
629 this packet to be properly decoded */
630 printf("%s", tstr);
631 return;
632 }
633
634 if ((ntohs(*ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2TP) {
635 printf(" l2tp:");
636 } else if ((ntohs(*ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2F) {
637 printf(" l2f:");
638 return; /* nothing to do */
639 } else {
640 printf(" Unknown Version, neither L2F(1) nor L2TP(2)");
641 return; /* nothing we can do */
642 }
643
644 printf("[");
645 if (ntohs(*ptr) & L2TP_FLAG_TYPE) {
646 flag_t = TRUE;
647 printf("T");
648 }
649 if (ntohs(*ptr) & L2TP_FLAG_LENGTH) {
650 flag_l = TRUE;
651 printf("L");
652 }
653 if (ntohs(*ptr) & L2TP_FLAG_SEQUENCE) {
654 flag_s = TRUE;
655 printf("S");
656 }
657 if (ntohs(*ptr) & L2TP_FLAG_OFFSET) {
658 flag_o = TRUE;
659 printf("O");
660 }
661 if (ntohs(*ptr) & L2TP_FLAG_PRIORITY) {
662 flag_p = TRUE;
663 printf("P");
664 }
665 printf("]");
666
667 ptr++;
668 cnt += 2;
669
670 if (flag_l) {
671 l2tp_len = ntohs(*ptr++); /* XXX need to consider
672 truncation ?? */
673 cnt += 2;
674 } else {
675 l2tp_len = 0;
676 }
677
678 printf("(%d/", ntohs(*ptr++)); /* Tunnel ID */
679 printf("%d)", ntohs(*ptr++)); /* Session ID */
680 cnt += 4;
681
682 if (flag_s) {
683 printf("Ns=%d,", ntohs(*ptr++));
684 printf("Nr=%d", ntohs(*ptr++));
685 cnt += 4;
686 }
687
688 if (flag_o) {
689 pad = ntohs(*ptr++);
690 ptr += pad / sizeof(*ptr);
691 cnt += (2 + pad);
692 }
693
694 if (flag_t) {
695 if (length - cnt == 0) {
696 printf(" ZLB");
697 } else {
698 l2tp_avp_print((u_char *)ptr, length - cnt);
699 }
700 } else {
701 #if 0
702 printf(" {");
703 ppp_hdlc_print((u_char *)ptr, length - cnt);
704 printf("}");
705 #else
706 printf("[hdlc|]");
707 #endif
708 }
709 }