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