2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that: (1) source code
4 * distributions retain the above copyright notice and this paragraph
5 * in its entirety, and (2) distributions including binary code include
6 * the above copyright notice and this paragraph in its entirety in
7 * the documentation or other materials provided with the distribution.
8 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
9 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
10 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
11 * FOR A PARTICULAR PURPOSE.
13 * Original code by Hannes Gredler (hannes@juniper.net)
17 static const char rcsid
[] _U_
=
18 "@(#) $Header: /tcpdump/master/tcpdump/print-juniper.c,v 1.26 2005-08-10 14:18:57 hannes Exp $ (LBL)";
25 #include <tcpdump-stdinc.h>
30 #include "interface.h"
31 #include "addrtoname.h"
36 #include "ethertype.h"
39 #define JUNIPER_BPF_OUT 0 /* Outgoing packet */
40 #define JUNIPER_BPF_IN 1 /* Incoming packet */
41 #define JUNIPER_BPF_PKT_IN 0x1 /* Incoming packet */
42 #define JUNIPER_BPF_NO_L2 0x2 /* L2 header stripped */
43 #define JUNIPER_BPF_EXT 0x80 /* extensions present */
44 #define JUNIPER_MGC_NUMBER 0x4d4743 /* = "MGC" */
46 #define JUNIPER_LSQ_COOKIE_RE (1 << 3)
47 #define JUNIPER_LSQ_COOKIE_DIR (1 << 2)
48 #define JUNIPER_LSQ_L3_PROTO_SHIFT 4
49 #define JUNIPER_LSQ_L3_PROTO_MASK (0x17 << JUNIPER_LSQ_L3_PROTO_SHIFT)
50 #define JUNIPER_LSQ_L3_PROTO_IPV4 (0 << JUNIPER_LSQ_L3_PROTO_SHIFT)
51 #define JUNIPER_LSQ_L3_PROTO_IPV6 (1 << JUNIPER_LSQ_L3_PROTO_SHIFT)
52 #define JUNIPER_LSQ_L3_PROTO_MPLS (2 << JUNIPER_LSQ_L3_PROTO_SHIFT)
53 #define JUNIPER_LSQ_L3_PROTO_ISO (3 << JUNIPER_LSQ_L3_PROTO_SHIFT)
54 #define AS_PIC_COOKIE_LEN 8
56 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE 1
57 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE 2
58 #define JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE 3
59 #define JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE 4
60 #define JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE 5
62 static struct tok juniper_ipsec_type_values
[] = {
63 { JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
, "ESP ENCR-AUTH" },
64 { JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
, "ESP ENCR-AH AUTH" },
65 { JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
, "ESP AUTH" },
66 { JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
, "AH AUTH" },
67 { JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
, "ESP ENCR" },
71 static struct tok juniper_direction_values
[] = {
72 { JUNIPER_BPF_IN
, "In"},
73 { JUNIPER_BPF_OUT
, "Out"},
77 struct juniper_cookie_table_t
{
78 u_int32_t pictype
; /* pic type */
79 u_int8_t cookie_len
; /* cookie len */
80 const char *s
; /* pic name */
83 static struct juniper_cookie_table_t juniper_cookie_table
[] = {
84 #ifdef DLT_JUNIPER_ATM1
85 { DLT_JUNIPER_ATM1
, 4, "ATM1"},
87 #ifdef DLT_JUNIPER_ATM2
88 { DLT_JUNIPER_ATM2
, 8, "ATM2"},
90 #ifdef DLT_JUNIPER_MLPPP
91 { DLT_JUNIPER_MLPPP
, 2, "MLPPP"},
93 #ifdef DLT_JUNIPER_MLFR
94 { DLT_JUNIPER_MLFR
, 2, "MLFR"},
96 #ifdef DLT_JUNIPER_MFR
97 { DLT_JUNIPER_MFR
, 4, "MFR"},
99 #ifdef DLT_JUNIPER_PPPOE
100 { DLT_JUNIPER_PPPOE
, 0, "PPPoE"},
102 #ifdef DLT_JUNIPER_PPPOE_ATM
103 { DLT_JUNIPER_PPPOE_ATM
, 0, "PPPoE ATM"},
105 #ifdef DLT_JUNIPER_GGSN
106 { DLT_JUNIPER_GGSN
, 8, "GGSN"},
108 #ifdef DLT_JUNIPER_MONITOR
109 { DLT_JUNIPER_MONITOR
, 8, "MONITOR"},
111 #ifdef DLT_JUNIPER_SERVICES
112 { DLT_JUNIPER_SERVICES
, 8, "AS"},
114 #ifdef DLT_JUNIPER_ES
115 { DLT_JUNIPER_ES
, 0, "ES"},
120 struct juniper_l2info_t
{
127 u_int8_t cookie_type
;
133 #define LS_COOKIE_ID 0x54
134 #define AS_COOKIE_ID 0x47
135 #define LS_MLFR_COOKIE_LEN 4
136 #define ML_MLFR_COOKIE_LEN 2
137 #define LS_MFR_COOKIE_LEN 6
138 #define ATM1_COOKIE_LEN 4
139 #define ATM2_COOKIE_LEN 8
141 #define ATM2_PKT_TYPE_MASK 0x70
142 #define ATM2_GAP_COUNT_MASK 0x3F
144 #define JUNIPER_PROTO_NULL 1
145 #define JUNIPER_PROTO_IPV4 2
146 #define JUNIPER_PROTO_IPV6 6
148 #define MFR_BE_MASK 0xc0
150 static struct tok juniper_protocol_values
[] = {
151 { JUNIPER_PROTO_NULL
, "Null" },
152 { JUNIPER_PROTO_IPV4
, "IPv4" },
153 { JUNIPER_PROTO_IPV6
, "IPv6" },
157 int ip_heuristic_guess(register const u_char
*, u_int
);
158 int juniper_ppp_heuristic_guess(register const u_char
*, u_int
);
159 static int juniper_parse_header (const u_char
*, const struct pcap_pkthdr
*, struct juniper_l2info_t
*);
161 #ifdef DLT_JUNIPER_GGSN
163 juniper_ggsn_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
165 struct juniper_l2info_t l2info
;
166 struct juniper_ggsn_header
{
174 const struct juniper_ggsn_header
*gh
;
176 l2info
.pictype
= DLT_JUNIPER_GGSN
;
177 if(juniper_parse_header(p
, h
, &l2info
) == 0)
178 return l2info
.header_len
;
180 p
+=l2info
.header_len
;
181 gh
= (struct juniper_ggsn_header
*)p
;
184 printf("proto %s (%u), vlan %u: ",
185 tok2str(juniper_protocol_values
,"Unknown",gh
->proto
),
187 EXTRACT_16BITS(&gh
->vlan_id
[0]));
190 case JUNIPER_PROTO_IPV4
:
191 ip_print(gndo
, p
, l2info
.length
);
194 case JUNIPER_PROTO_IPV6
:
195 ip6_print(p
, l2info
.length
);
200 printf("unknown GGSN proto (%u)", gh
->proto
);
203 return l2info
.header_len
;
207 #ifdef DLT_JUNIPER_ES
209 juniper_es_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
211 struct juniper_l2info_t l2info
;
212 struct juniper_ipsec_header
{
213 u_int8_t sa_index
[2];
220 u_int rewrite_len
,es_type_bundle
;
221 const struct juniper_ipsec_header
*ih
;
223 l2info
.pictype
= DLT_JUNIPER_ES
;
224 if(juniper_parse_header(p
, h
, &l2info
) == 0)
225 return l2info
.header_len
;
227 p
+=l2info
.header_len
;
228 ih
= (struct juniper_ipsec_header
*)p
;
231 case JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
:
232 case JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
:
236 case JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
:
237 case JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
:
238 case JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
:
242 printf("ES Invalid type %u, length %u",
245 return l2info
.header_len
;
248 l2info
.length
-=rewrite_len
;
252 if (!es_type_bundle
) {
253 printf("ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n",
254 EXTRACT_16BITS(&ih
->sa_index
),
256 tok2str(juniper_ipsec_type_values
,"Unknown",ih
->type
),
258 EXTRACT_32BITS(&ih
->spi
),
259 ipaddr_string(EXTRACT_32BITS(&ih
->src_ip
)),
260 ipaddr_string(EXTRACT_32BITS(&ih
->dst_ip
)),
263 printf("ES SA, index %u, ttl %u type %s (%u), length %u\n",
264 EXTRACT_16BITS(&ih
->sa_index
),
266 tok2str(juniper_ipsec_type_values
,"Unknown",ih
->type
),
272 ip_print(gndo
, p
, l2info
.length
);
273 return l2info
.header_len
;
277 #ifdef DLT_JUNIPER_MONITOR
279 juniper_monitor_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
281 struct juniper_l2info_t l2info
;
282 struct juniper_monitor_header
{
286 u_int8_t service_id
[4];
288 const struct juniper_monitor_header
*mh
;
290 l2info
.pictype
= DLT_JUNIPER_MONITOR
;
291 if(juniper_parse_header(p
, h
, &l2info
) == 0)
292 return l2info
.header_len
;
294 p
+=l2info
.header_len
;
295 mh
= (struct juniper_monitor_header
*)p
;
298 printf("service-id %u, iif %u, pkt-type %u: ",
299 EXTRACT_32BITS(&mh
->service_id
),
300 EXTRACT_16BITS(&mh
->iif
),
303 /* no proto field - lets guess by first byte of IP header*/
304 ip_heuristic_guess(p
, l2info
.length
);
306 return l2info
.header_len
;
310 #ifdef DLT_JUNIPER_SERVICES
312 juniper_services_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
314 struct juniper_l2info_t l2info
;
315 struct juniper_services_header
{
318 u_int8_t svc_set_id
[2];
321 const struct juniper_services_header
*sh
;
323 l2info
.pictype
= DLT_JUNIPER_SERVICES
;
324 if(juniper_parse_header(p
, h
, &l2info
) == 0)
325 return l2info
.header_len
;
327 p
+=l2info
.header_len
;
328 sh
= (struct juniper_services_header
*)p
;
331 printf("service-id %u flags 0x%02x service-set-id 0x%04x iif %u: ",
334 EXTRACT_16BITS(&sh
->svc_set_id
),
335 EXTRACT_24BITS(&sh
->dir_iif
[1]));
337 /* no proto field - lets guess by first byte of IP header*/
338 ip_heuristic_guess(p
, l2info
.length
);
340 return l2info
.header_len
;
344 #ifdef DLT_JUNIPER_PPPOE
346 juniper_pppoe_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
348 struct juniper_l2info_t l2info
;
350 l2info
.pictype
= DLT_JUNIPER_PPPOE
;
351 if(juniper_parse_header(p
, h
, &l2info
) == 0)
352 return l2info
.header_len
;
354 p
+=l2info
.header_len
;
355 /* this DLT contains nothing but raw ethernet frames */
356 ether_print(p
, l2info
.length
, l2info
.caplen
);
357 return l2info
.header_len
;
361 #ifdef DLT_JUNIPER_PPPOE_ATM
363 juniper_pppoe_atm_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
365 struct juniper_l2info_t l2info
;
366 u_int16_t extracted_ethertype
;
368 l2info
.pictype
= DLT_JUNIPER_PPPOE_ATM
;
369 if(juniper_parse_header(p
, h
, &l2info
) == 0)
370 return l2info
.header_len
;
372 p
+=l2info
.header_len
;
374 extracted_ethertype
= EXTRACT_16BITS(p
);
375 /* this DLT contains nothing but raw PPPoE frames,
376 * prepended with a type field*/
377 if (ether_encap_print(extracted_ethertype
,
379 l2info
.length
-ETHERTYPE_LEN
,
380 l2info
.caplen
-ETHERTYPE_LEN
,
381 &extracted_ethertype
) == 0)
382 /* ether_type not known, probably it wasn't one */
383 printf("unknown ethertype 0x%04x", extracted_ethertype
);
385 return l2info
.header_len
;
389 #ifdef DLT_JUNIPER_MLPPP
391 juniper_mlppp_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
393 struct juniper_l2info_t l2info
;
395 l2info
.pictype
= DLT_JUNIPER_MLPPP
;
396 if(juniper_parse_header(p
, h
, &l2info
) == 0)
397 return l2info
.header_len
;
399 /* suppress Bundle-ID if frame was captured on a child-link
400 * best indicator if the cookie looks like a proto */
402 EXTRACT_16BITS(&l2info
.cookie
) != PPP_OSI
&&
403 EXTRACT_16BITS(&l2info
.cookie
) != (PPP_ADDRESS
<< 8 | PPP_CONTROL
))
404 printf("Bundle-ID %u: ",l2info
.bundle
);
406 p
+=l2info
.header_len
;
408 /* first try the LSQ protos */
409 switch(l2info
.proto
) {
410 case JUNIPER_LSQ_L3_PROTO_IPV4
:
411 /* IP traffic going to the RE would not have a cookie
412 * -> this must be incoming IS-IS over PPP
414 if (l2info
.cookie
[4] == (JUNIPER_LSQ_COOKIE_RE
|JUNIPER_LSQ_COOKIE_DIR
))
415 ppp_print(p
, l2info
.length
);
417 ip_print(gndo
, p
, l2info
.length
);
418 return l2info
.header_len
;
420 case JUNIPER_LSQ_L3_PROTO_IPV6
:
421 ip6_print(p
,l2info
.length
);
422 return l2info
.header_len
;
424 case JUNIPER_LSQ_L3_PROTO_MPLS
:
425 mpls_print(p
,l2info
.length
);
426 return l2info
.header_len
;
427 case JUNIPER_LSQ_L3_PROTO_ISO
:
428 isoclns_print(p
,l2info
.length
,l2info
.caplen
);
429 return l2info
.header_len
;
434 /* zero length cookie ? */
435 switch (EXTRACT_16BITS(&l2info
.cookie
)) {
437 ppp_print(p
-2,l2info
.length
+2);
439 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
): /* fall through */
441 ppp_print(p
,l2info
.length
);
445 return l2info
.header_len
;
450 #ifdef DLT_JUNIPER_MFR
452 juniper_mfr_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
454 struct juniper_l2info_t l2info
;
456 l2info
.pictype
= DLT_JUNIPER_MFR
;
457 if(juniper_parse_header(p
, h
, &l2info
) == 0)
458 return l2info
.header_len
;
460 p
+=l2info
.header_len
;
463 if (l2info
.cookie_len
== 0) {
464 mfr_print(p
,l2info
.length
);
465 return l2info
.header_len
;
468 /* first try the LSQ protos */
469 if (l2info
.cookie_len
== AS_PIC_COOKIE_LEN
) {
470 switch(l2info
.proto
) {
471 case JUNIPER_LSQ_L3_PROTO_IPV4
:
472 ip_print(gndo
, p
, l2info
.length
);
473 return l2info
.header_len
;
475 case JUNIPER_LSQ_L3_PROTO_IPV6
:
476 ip6_print(p
,l2info
.length
);
477 return l2info
.header_len
;
479 case JUNIPER_LSQ_L3_PROTO_MPLS
:
480 mpls_print(p
,l2info
.length
);
481 return l2info
.header_len
;
482 case JUNIPER_LSQ_L3_PROTO_ISO
:
483 isoclns_print(p
,l2info
.length
,l2info
.caplen
);
484 return l2info
.header_len
;
488 return l2info
.header_len
;
491 /* suppress Bundle-ID if frame was captured on a child-link */
492 if (eflag
&& EXTRACT_32BITS(l2info
.cookie
) != 1) printf("Bundle-ID %u, ",l2info
.bundle
);
493 switch (l2info
.proto
) {
494 case (LLCSAP_ISONS
<<8 | LLCSAP_ISONS
):
495 isoclns_print(p
+1, l2info
.length
-1, l2info
.caplen
-1);
497 case (LLC_UI
<<8 | NLPID_Q933
):
498 case (LLC_UI
<<8 | NLPID_IP
):
499 case (LLC_UI
<<8 | NLPID_IP6
):
500 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
501 isoclns_print(p
-1, l2info
.length
+1, l2info
.caplen
+1);
504 printf("unknown protocol 0x%04x, length %u",l2info
.proto
, l2info
.length
);
507 return l2info
.header_len
;
511 #ifdef DLT_JUNIPER_MLFR
513 juniper_mlfr_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
515 struct juniper_l2info_t l2info
;
517 l2info
.pictype
= DLT_JUNIPER_MLFR
;
518 if(juniper_parse_header(p
, h
, &l2info
) == 0)
519 return l2info
.header_len
;
521 p
+=l2info
.header_len
;
523 /* suppress Bundle-ID if frame was captured on a child-link */
524 if (eflag
&& EXTRACT_32BITS(l2info
.cookie
) != 1) printf("Bundle-ID %u, ",l2info
.bundle
);
525 switch (l2info
.proto
) {
528 isoclns_print(p
, l2info
.length
, l2info
.caplen
);
530 case (LLC_UI
<<8 | NLPID_Q933
):
531 case (LLC_UI
<<8 | NLPID_IP
):
532 case (LLC_UI
<<8 | NLPID_IP6
):
533 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
534 isoclns_print(p
-1, l2info
.length
+1, l2info
.caplen
+1);
537 printf("unknown protocol 0x%04x, length %u",l2info
.proto
, l2info
.length
);
540 return l2info
.header_len
;
545 * ATM1 PIC cookie format
547 * +-----+-------------------------+-------------------------------+
548 * |fmtid| vc index | channel ID |
549 * +-----+-------------------------+-------------------------------+
552 #ifdef DLT_JUNIPER_ATM1
554 juniper_atm1_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
556 u_int16_t extracted_ethertype
;
558 struct juniper_l2info_t l2info
;
560 l2info
.pictype
= DLT_JUNIPER_ATM1
;
561 if(juniper_parse_header(p
, h
, &l2info
) == 0)
562 return l2info
.header_len
;
564 p
+=l2info
.header_len
;
566 if (l2info
.cookie
[0] == 0x80) { /* OAM cell ? */
567 oam_print(p
,l2info
.length
,ATM_OAM_NOHEC
);
568 return l2info
.header_len
;
571 if (EXTRACT_24BITS(p
) == 0xfefe03 || /* NLPID encaps ? */
572 EXTRACT_24BITS(p
) == 0xaaaa03) { /* SNAP encaps ? */
574 if (llc_print(p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
,
575 &extracted_ethertype
) != 0)
576 return l2info
.header_len
;
579 if (p
[0] == 0x03) { /* Cisco style NLPID encaps ? */
580 isoclns_print(p
+ 1, l2info
.length
- 1, l2info
.caplen
- 1);
581 /* FIXME check if frame was recognized */
582 return l2info
.header_len
;
585 if(ip_heuristic_guess(p
, l2info
.length
) != 0) /* last try - vcmux encaps ? */
586 return l2info
.header_len
;
588 return l2info
.header_len
;
593 * ATM2 PIC cookie format
595 * +-------------------------------+---------+---+-----+-----------+
596 * | channel ID | reserv |AAL| CCRQ| gap cnt |
597 * +-------------------------------+---------+---+-----+-----------+
600 #ifdef DLT_JUNIPER_ATM2
602 juniper_atm2_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
604 u_int16_t extracted_ethertype
;
605 u_int32_t control_word
;
607 struct juniper_l2info_t l2info
;
609 l2info
.pictype
= DLT_JUNIPER_ATM2
;
610 if(juniper_parse_header(p
, h
, &l2info
) == 0)
611 return l2info
.header_len
;
613 p
+=l2info
.header_len
;
615 if (l2info
.cookie
[7] & ATM2_PKT_TYPE_MASK
) { /* OAM cell ? */
616 control_word
= EXTRACT_32BITS(p
);
617 if(control_word
== 0 || control_word
== 0x08000000) {
618 l2info
.header_len
+= 4;
622 oam_print(p
,l2info
.length
,ATM_OAM_NOHEC
);
623 return l2info
.header_len
;
626 if (EXTRACT_24BITS(p
) == 0xfefe03 || /* NLPID encaps ? */
627 EXTRACT_24BITS(p
) == 0xaaaa03) { /* SNAP encaps ? */
629 if (llc_print(p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
,
630 &extracted_ethertype
) != 0)
631 return l2info
.header_len
;
634 if (l2info
.direction
!= JUNIPER_BPF_PKT_IN
&& /* ether-over-1483 encaps ? */
635 (EXTRACT_32BITS(l2info
.cookie
) & ATM2_GAP_COUNT_MASK
)) {
636 ether_print(p
, l2info
.length
, l2info
.caplen
);
637 return l2info
.header_len
;
640 if (p
[0] == 0x03) { /* Cisco style NLPID encaps ? */
641 isoclns_print(p
+ 1, l2info
.length
- 1, l2info
.caplen
- 1);
642 /* FIXME check if frame was recognized */
643 return l2info
.header_len
;
646 if(juniper_ppp_heuristic_guess(p
, l2info
.length
) != 0) /* PPPoA vcmux encaps ? */
647 return l2info
.header_len
;
649 if(ip_heuristic_guess(p
, l2info
.length
) != 0) /* last try - vcmux encaps ? */
650 return l2info
.header_len
;
652 return l2info
.header_len
;
657 /* try to guess, based on all PPP protos that are supported in
658 * a juniper router if the payload data is encapsulated using PPP */
660 juniper_ppp_heuristic_guess(register const u_char
*p
, u_int length
) {
662 switch(EXTRACT_16BITS(p
)) {
665 case PPP_MPLS_UCAST
:
666 case PPP_MPLS_MCAST
:
678 ppp_print(p
, length
);
682 return 0; /* did not find a ppp header */
685 return 1; /* we printed a ppp packet */
689 ip_heuristic_guess(register const u_char
*p
, u_int length
) {
703 ip_print(gndo
, p
, length
);
722 ip6_print(p
, length
);
726 return 0; /* did not find a ip header */
729 return 1; /* we printed an v4/v6 packet */
733 juniper_parse_header (const u_char
*p
, const struct pcap_pkthdr
*h
, struct juniper_l2info_t
*l2info
) {
735 struct juniper_cookie_table_t
*lp
= juniper_cookie_table
;
738 l2info
->header_len
= 0;
739 l2info
->cookie_len
= 0;
743 l2info
->length
= h
->len
;
744 l2info
->caplen
= h
->caplen
;
745 l2info
->direction
= p
[3]&JUNIPER_BPF_PKT_IN
;
748 if (EXTRACT_24BITS(p
) != JUNIPER_MGC_NUMBER
) { /* magic number found ? */
749 printf("no magic-number found!");
753 if (eflag
) /* print direction */
754 printf("%3s ",tok2str(juniper_direction_values
,"---",l2info
->direction
));
756 /* extensions present ? - calculate how much bytes to skip */
757 if ((p
[3] & JUNIPER_BPF_EXT
) == JUNIPER_BPF_EXT
) {
758 offset
= 6 + EXTRACT_16BITS(p
+4);
760 printf("ext-len %u, ",EXTRACT_16BITS(p
+4));
764 if ((p
[3] & JUNIPER_BPF_NO_L2
) == JUNIPER_BPF_NO_L2
) {
766 printf("no-L2-hdr, ");
768 /* there is no link-layer present -
769 * perform the v4/v6 heuristics
770 * to figure out what it is
772 TCHECK2(p
[offset
+4],1);
773 if(ip_heuristic_guess(p
+offset
+4,l2info
->length
-(offset
+4)) == 0)
774 printf("no IP-hdr found!");
776 l2info
->header_len
=offset
+4;
777 return 0; /* stop parsing the output further */
780 l2info
->header_len
= offset
;
781 p
+=l2info
->header_len
;
782 l2info
->length
-= l2info
->header_len
;
783 l2info
->caplen
-= l2info
->header_len
;
785 /* search through the cookie table and copy values matching for our PIC type */
786 while (lp
->s
!= NULL
) {
787 if (lp
->pictype
== l2info
->pictype
) {
789 l2info
->cookie_len
+= lp
->cookie_len
;
793 l2info
->cookie_type
= LS_COOKIE_ID
;
794 l2info
->cookie_len
+= 2;
797 l2info
->cookie_type
= AS_COOKIE_ID
;
798 l2info
->cookie_len
= 8;
802 l2info
->bundle
= l2info
->cookie
[0];
807 #ifdef DLT_JUNIPER_MFR
808 /* MFR child links don't carry cookies */
809 if (l2info
->pictype
== DLT_JUNIPER_MFR
&&
810 (p
[0] & MFR_BE_MASK
) == MFR_BE_MASK
) {
811 l2info
->cookie_len
= 0;
815 l2info
->header_len
+= l2info
->cookie_len
;
816 l2info
->length
-= l2info
->cookie_len
;
817 l2info
->caplen
-= l2info
->cookie_len
;
820 printf("%s-PIC, cookie-len %u",
824 if (l2info
->cookie_len
> 0) {
825 TCHECK2(p
[0],l2info
->cookie_len
);
827 printf(", cookie 0x");
828 for (idx
= 0; idx
< l2info
->cookie_len
; idx
++) {
829 l2info
->cookie
[idx
] = p
[idx
]; /* copy cookie data */
830 if (eflag
) printf("%02x",p
[idx
]);
834 if (eflag
) printf(": "); /* print demarc b/w L2/L3*/
837 l2info
->proto
= EXTRACT_16BITS(p
+l2info
->cookie_len
);
842 p
+=l2info
->cookie_len
;
844 /* DLT_ specific parsing */
845 switch(l2info
->pictype
) {
846 #ifdef DLT_JUNIPER_MLPPP
847 case DLT_JUNIPER_MLPPP
:
848 switch (l2info
->cookie_type
) {
850 l2info
->bundle
= l2info
->cookie
[1];
853 l2info
->bundle
= (EXTRACT_16BITS(&l2info
->cookie
[6])>>3)&0xfff;
854 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
857 l2info
->bundle
= l2info
->cookie
[0];
862 #ifdef DLT_JUNIPER_MLFR
863 case DLT_JUNIPER_MLFR
:
864 switch (l2info
->cookie_type
) {
866 l2info
->bundle
= l2info
->cookie
[1];
867 l2info
->proto
= EXTRACT_16BITS(p
);
868 l2info
->header_len
+= 2;
873 l2info
->bundle
= (EXTRACT_16BITS(&l2info
->cookie
[6])>>3)&0xfff;
874 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
877 l2info
->bundle
= l2info
->cookie
[0];
878 l2info
->header_len
+= 2;
885 #ifdef DLT_JUNIPER_MFR
886 case DLT_JUNIPER_MFR
:
887 switch (l2info
->cookie_type
) {
889 l2info
->bundle
= l2info
->cookie
[1];
890 l2info
->proto
= EXTRACT_16BITS(p
);
891 l2info
->header_len
+= 2;
896 l2info
->bundle
= (EXTRACT_16BITS(&l2info
->cookie
[6])>>3)&0xfff;
897 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
900 l2info
->bundle
= l2info
->cookie
[0];
905 #ifdef DLT_JUNIPER_ATM2
906 case DLT_JUNIPER_ATM2
:
908 /* ATM cell relay control word present ? */
909 if (l2info
->cookie
[7] & ATM2_PKT_TYPE_MASK
&& *p
& 0x08) {
910 l2info
->header_len
+= 4;
912 printf("control-word 0x%08x ",EXTRACT_32BITS(p
));
916 #ifdef DLT_JUNIPER_ATM1
917 case DLT_JUNIPER_ATM1
:
921 printf("Unknown Juniper DLT_ type %u: ", l2info
->pictype
);
926 printf("hlen %u, proto 0x%04x, ",l2info
->header_len
,l2info
->proto
);
928 return 1; /* everything went ok so far. continue parsing */
930 printf("[|juniper_hdr], length %u",h
->len
);
937 * c-style: whitesmith