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.25 2005-07-29 23:51:16 guy 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_MGC_NUMBER 0x4d4743 /* = "MGC" */
45 #define JUNIPER_LSQ_COOKIE_RE (1 << 3)
46 #define JUNIPER_LSQ_COOKIE_DIR (1 << 2)
47 #define JUNIPER_LSQ_L3_PROTO_SHIFT 4
48 #define JUNIPER_LSQ_L3_PROTO_MASK (0x17 << JUNIPER_LSQ_L3_PROTO_SHIFT)
49 #define JUNIPER_LSQ_L3_PROTO_IPV4 (0 << JUNIPER_LSQ_L3_PROTO_SHIFT)
50 #define JUNIPER_LSQ_L3_PROTO_IPV6 (1 << JUNIPER_LSQ_L3_PROTO_SHIFT)
51 #define JUNIPER_LSQ_L3_PROTO_MPLS (2 << JUNIPER_LSQ_L3_PROTO_SHIFT)
52 #define JUNIPER_LSQ_L3_PROTO_ISO (3 << JUNIPER_LSQ_L3_PROTO_SHIFT)
53 #define AS_PIC_COOKIE_LEN 8
55 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE 1
56 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE 2
57 #define JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE 3
58 #define JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE 4
59 #define JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE 5
61 static struct tok juniper_ipsec_type_values
[] = {
62 { JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
, "ESP ENCR-AUTH" },
63 { JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
, "ESP ENCR-AH AUTH" },
64 { JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
, "ESP AUTH" },
65 { JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
, "AH AUTH" },
66 { JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
, "ESP ENCR" },
70 static struct tok juniper_direction_values
[] = {
71 { JUNIPER_BPF_IN
, "In"},
72 { JUNIPER_BPF_OUT
, "Out"},
76 struct juniper_cookie_table_t
{
77 u_int32_t pictype
; /* pic type */
78 u_int8_t cookie_len
; /* cookie len */
79 const char *s
; /* pic name */
82 static struct juniper_cookie_table_t juniper_cookie_table
[] = {
83 #ifdef DLT_JUNIPER_ATM1
84 { DLT_JUNIPER_ATM1
, 4, "ATM1"},
86 #ifdef DLT_JUNIPER_ATM2
87 { DLT_JUNIPER_ATM2
, 8, "ATM2"},
89 #ifdef DLT_JUNIPER_MLPPP
90 { DLT_JUNIPER_MLPPP
, 2, "MLPPP"},
92 #ifdef DLT_JUNIPER_MLFR
93 { DLT_JUNIPER_MLFR
, 2, "MLFR"},
95 #ifdef DLT_JUNIPER_MFR
96 { DLT_JUNIPER_MFR
, 4, "MFR"},
98 #ifdef DLT_JUNIPER_PPPOE
99 { DLT_JUNIPER_PPPOE
, 0, "PPPoE"},
101 #ifdef DLT_JUNIPER_PPPOE_ATM
102 { DLT_JUNIPER_PPPOE_ATM
, 0, "PPPoE ATM"},
104 #ifdef DLT_JUNIPER_GGSN
105 { DLT_JUNIPER_GGSN
, 8, "GGSN"},
107 #ifdef DLT_JUNIPER_MONITOR
108 { DLT_JUNIPER_MONITOR
, 8, "MONITOR"},
110 #ifdef DLT_JUNIPER_SERVICES
111 { DLT_JUNIPER_SERVICES
, 8, "AS"},
113 #ifdef DLT_JUNIPER_ES
114 { DLT_JUNIPER_ES
, 0, "ES"},
119 struct juniper_l2info_t
{
126 u_int8_t cookie_type
;
132 #define LS_COOKIE_ID 0x54
133 #define AS_COOKIE_ID 0x47
134 #define LS_MLFR_COOKIE_LEN 4
135 #define ML_MLFR_COOKIE_LEN 2
136 #define LS_MFR_COOKIE_LEN 6
137 #define ATM1_COOKIE_LEN 4
138 #define ATM2_COOKIE_LEN 8
140 #define ATM2_PKT_TYPE_MASK 0x70
141 #define ATM2_GAP_COUNT_MASK 0x3F
143 #define JUNIPER_PROTO_NULL 1
144 #define JUNIPER_PROTO_IPV4 2
145 #define JUNIPER_PROTO_IPV6 6
147 #define MFR_BE_MASK 0xc0
149 static struct tok juniper_protocol_values
[] = {
150 { JUNIPER_PROTO_NULL
, "Null" },
151 { JUNIPER_PROTO_IPV4
, "IPv4" },
152 { JUNIPER_PROTO_IPV6
, "IPv6" },
156 int ip_heuristic_guess(register const u_char
*, u_int
);
157 int juniper_ppp_heuristic_guess(register const u_char
*, u_int
);
158 static int juniper_parse_header (const u_char
*, const struct pcap_pkthdr
*, struct juniper_l2info_t
*);
160 #ifdef DLT_JUNIPER_GGSN
162 juniper_ggsn_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
164 struct juniper_l2info_t l2info
;
165 struct juniper_ggsn_header
{
173 const struct juniper_ggsn_header
*gh
;
175 l2info
.pictype
= DLT_JUNIPER_GGSN
;
176 if(juniper_parse_header(p
, h
, &l2info
) == 0)
177 return l2info
.header_len
;
179 p
+=l2info
.header_len
;
180 gh
= (struct juniper_ggsn_header
*)p
;
183 printf("proto %s (%u), vlan %u: ",
184 tok2str(juniper_protocol_values
,"Unknown",gh
->proto
),
186 EXTRACT_16BITS(&gh
->vlan_id
[0]));
189 case JUNIPER_PROTO_IPV4
:
190 ip_print(gndo
, p
, l2info
.length
);
193 case JUNIPER_PROTO_IPV6
:
194 ip6_print(p
, l2info
.length
);
199 printf("unknown GGSN proto (%u)", gh
->proto
);
202 return l2info
.header_len
;
206 #ifdef DLT_JUNIPER_ES
208 juniper_es_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
210 struct juniper_l2info_t l2info
;
211 struct juniper_ipsec_header
{
212 u_int8_t sa_index
[2];
219 u_int rewrite_len
,es_type_bundle
;
220 const struct juniper_ipsec_header
*ih
;
222 l2info
.pictype
= DLT_JUNIPER_ES
;
223 if(juniper_parse_header(p
, h
, &l2info
) == 0)
224 return l2info
.header_len
;
226 p
+=l2info
.header_len
;
227 ih
= (struct juniper_ipsec_header
*)p
;
230 case JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE
:
231 case JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE
:
235 case JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE
:
236 case JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE
:
237 case JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE
:
241 printf("ES Invalid type %u, length %u",
244 return l2info
.header_len
;
247 l2info
.length
-=rewrite_len
;
251 if (!es_type_bundle
) {
252 printf("ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n",
253 EXTRACT_16BITS(&ih
->sa_index
),
255 tok2str(juniper_ipsec_type_values
,"Unknown",ih
->type
),
257 EXTRACT_32BITS(&ih
->spi
),
258 ipaddr_string(EXTRACT_32BITS(&ih
->src_ip
)),
259 ipaddr_string(EXTRACT_32BITS(&ih
->dst_ip
)),
262 printf("ES SA, index %u, ttl %u type %s (%u), length %u\n",
263 EXTRACT_16BITS(&ih
->sa_index
),
265 tok2str(juniper_ipsec_type_values
,"Unknown",ih
->type
),
271 ip_print(gndo
, p
, l2info
.length
);
272 return l2info
.header_len
;
276 #ifdef DLT_JUNIPER_MONITOR
278 juniper_monitor_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
280 struct juniper_l2info_t l2info
;
281 struct juniper_monitor_header
{
285 u_int8_t service_id
[4];
287 const struct juniper_monitor_header
*mh
;
289 l2info
.pictype
= DLT_JUNIPER_MONITOR
;
290 if(juniper_parse_header(p
, h
, &l2info
) == 0)
291 return l2info
.header_len
;
293 p
+=l2info
.header_len
;
294 mh
= (struct juniper_monitor_header
*)p
;
297 printf("service-id %u, iif %u, pkt-type %u: ",
298 EXTRACT_32BITS(&mh
->service_id
),
299 EXTRACT_16BITS(&mh
->iif
),
302 /* no proto field - lets guess by first byte of IP header*/
303 ip_heuristic_guess(p
, l2info
.length
);
305 return l2info
.header_len
;
309 #ifdef DLT_JUNIPER_SERVICES
311 juniper_services_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
313 struct juniper_l2info_t l2info
;
314 struct juniper_services_header
{
317 u_int8_t svc_set_id
[2];
320 const struct juniper_services_header
*sh
;
322 l2info
.pictype
= DLT_JUNIPER_SERVICES
;
323 if(juniper_parse_header(p
, h
, &l2info
) == 0)
324 return l2info
.header_len
;
326 p
+=l2info
.header_len
;
327 sh
= (struct juniper_services_header
*)p
;
330 printf("service-id %u flags 0x%02x service-set-id 0x%04x iif %u: ",
333 EXTRACT_16BITS(&sh
->svc_set_id
),
334 EXTRACT_24BITS(&sh
->dir_iif
[1]));
336 /* no proto field - lets guess by first byte of IP header*/
337 ip_heuristic_guess(p
, l2info
.length
);
339 return l2info
.header_len
;
343 #ifdef DLT_JUNIPER_PPPOE
345 juniper_pppoe_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
347 struct juniper_l2info_t l2info
;
349 l2info
.pictype
= DLT_JUNIPER_PPPOE
;
350 if(juniper_parse_header(p
, h
, &l2info
) == 0)
351 return l2info
.header_len
;
353 p
+=l2info
.header_len
;
354 /* this DLT contains nothing but raw ethernet frames */
355 ether_print(p
, l2info
.length
, l2info
.caplen
);
356 return l2info
.header_len
;
360 #ifdef DLT_JUNIPER_PPPOE_ATM
362 juniper_pppoe_atm_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
364 struct juniper_l2info_t l2info
;
365 u_int16_t extracted_ethertype
;
367 l2info
.pictype
= DLT_JUNIPER_PPPOE_ATM
;
368 if(juniper_parse_header(p
, h
, &l2info
) == 0)
369 return l2info
.header_len
;
371 p
+=l2info
.header_len
;
373 extracted_ethertype
= EXTRACT_16BITS(p
);
374 /* this DLT contains nothing but raw PPPoE frames,
375 * prepended with a type field*/
376 if (ether_encap_print(extracted_ethertype
,
378 l2info
.length
-ETHERTYPE_LEN
,
379 l2info
.caplen
-ETHERTYPE_LEN
,
380 &extracted_ethertype
) == 0)
381 /* ether_type not known, probably it wasn't one */
382 printf("unknown ethertype 0x%04x", extracted_ethertype
);
384 return l2info
.header_len
;
388 #ifdef DLT_JUNIPER_MLPPP
390 juniper_mlppp_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
392 struct juniper_l2info_t l2info
;
394 l2info
.pictype
= DLT_JUNIPER_MLPPP
;
395 if(juniper_parse_header(p
, h
, &l2info
) == 0)
396 return l2info
.header_len
;
398 /* suppress Bundle-ID if frame was captured on a child-link
399 * best indicator if the cookie looks like a proto */
401 EXTRACT_16BITS(&l2info
.cookie
) != PPP_OSI
&&
402 EXTRACT_16BITS(&l2info
.cookie
) != (PPP_ADDRESS
<< 8 | PPP_CONTROL
))
403 printf("Bundle-ID %u: ",l2info
.bundle
);
405 p
+=l2info
.header_len
;
407 /* first try the LSQ protos */
408 switch(l2info
.proto
) {
409 case JUNIPER_LSQ_L3_PROTO_IPV4
:
410 /* IP traffic going to the RE would not have a cookie
411 * -> this must be incoming IS-IS over PPP
413 if (l2info
.cookie
[4] == (JUNIPER_LSQ_COOKIE_RE
|JUNIPER_LSQ_COOKIE_DIR
))
414 ppp_print(p
, l2info
.length
);
416 ip_print(gndo
, p
, l2info
.length
);
417 return l2info
.header_len
;
419 case JUNIPER_LSQ_L3_PROTO_IPV6
:
420 ip6_print(p
,l2info
.length
);
421 return l2info
.header_len
;
423 case JUNIPER_LSQ_L3_PROTO_MPLS
:
424 mpls_print(p
,l2info
.length
);
425 return l2info
.header_len
;
426 case JUNIPER_LSQ_L3_PROTO_ISO
:
427 isoclns_print(p
,l2info
.length
,l2info
.caplen
);
428 return l2info
.header_len
;
433 /* zero length cookie ? */
434 switch (EXTRACT_16BITS(&l2info
.cookie
)) {
436 ppp_print(p
-2,l2info
.length
+2);
438 case (PPP_ADDRESS
<< 8 | PPP_CONTROL
): /* fall through */
440 ppp_print(p
,l2info
.length
);
444 return l2info
.header_len
;
449 #ifdef DLT_JUNIPER_MFR
451 juniper_mfr_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
453 struct juniper_l2info_t l2info
;
455 l2info
.pictype
= DLT_JUNIPER_MFR
;
456 if(juniper_parse_header(p
, h
, &l2info
) == 0)
457 return l2info
.header_len
;
459 p
+=l2info
.header_len
;
462 if (l2info
.cookie_len
== 0) {
463 mfr_print(p
,l2info
.length
);
464 return l2info
.header_len
;
467 /* first try the LSQ protos */
468 if (l2info
.cookie_len
== AS_PIC_COOKIE_LEN
) {
469 switch(l2info
.proto
) {
470 case JUNIPER_LSQ_L3_PROTO_IPV4
:
471 ip_print(gndo
, p
, l2info
.length
);
472 return l2info
.header_len
;
474 case JUNIPER_LSQ_L3_PROTO_IPV6
:
475 ip6_print(p
,l2info
.length
);
476 return l2info
.header_len
;
478 case JUNIPER_LSQ_L3_PROTO_MPLS
:
479 mpls_print(p
,l2info
.length
);
480 return l2info
.header_len
;
481 case JUNIPER_LSQ_L3_PROTO_ISO
:
482 isoclns_print(p
,l2info
.length
,l2info
.caplen
);
483 return l2info
.header_len
;
487 return l2info
.header_len
;
490 /* suppress Bundle-ID if frame was captured on a child-link */
491 if (eflag
&& EXTRACT_32BITS(l2info
.cookie
) != 1) printf("Bundle-ID %u, ",l2info
.bundle
);
492 switch (l2info
.proto
) {
493 case (LLCSAP_ISONS
<<8 | LLCSAP_ISONS
):
494 isoclns_print(p
+1, l2info
.length
-1, l2info
.caplen
-1);
496 case (LLC_UI
<<8 | NLPID_Q933
):
497 case (LLC_UI
<<8 | NLPID_IP
):
498 case (LLC_UI
<<8 | NLPID_IP6
):
499 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
500 isoclns_print(p
-1, l2info
.length
+1, l2info
.caplen
+1);
503 printf("unknown protocol 0x%04x, length %u",l2info
.proto
, l2info
.length
);
506 return l2info
.header_len
;
510 #ifdef DLT_JUNIPER_MLFR
512 juniper_mlfr_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
514 struct juniper_l2info_t l2info
;
516 l2info
.pictype
= DLT_JUNIPER_MLFR
;
517 if(juniper_parse_header(p
, h
, &l2info
) == 0)
518 return l2info
.header_len
;
520 p
+=l2info
.header_len
;
522 /* suppress Bundle-ID if frame was captured on a child-link */
523 if (eflag
&& EXTRACT_32BITS(l2info
.cookie
) != 1) printf("Bundle-ID %u, ",l2info
.bundle
);
524 switch (l2info
.proto
) {
527 isoclns_print(p
, l2info
.length
, l2info
.caplen
);
529 case (LLC_UI
<<8 | NLPID_Q933
):
530 case (LLC_UI
<<8 | NLPID_IP
):
531 case (LLC_UI
<<8 | NLPID_IP6
):
532 /* pass IP{4,6} to the OSI layer for proper link-layer printing */
533 isoclns_print(p
-1, l2info
.length
+1, l2info
.caplen
+1);
536 printf("unknown protocol 0x%04x, length %u",l2info
.proto
, l2info
.length
);
539 return l2info
.header_len
;
544 * ATM1 PIC cookie format
546 * +-----+-------------------------+-------------------------------+
547 * |fmtid| vc index | channel ID |
548 * +-----+-------------------------+-------------------------------+
551 #ifdef DLT_JUNIPER_ATM1
553 juniper_atm1_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
555 u_int16_t extracted_ethertype
;
557 struct juniper_l2info_t l2info
;
559 l2info
.pictype
= DLT_JUNIPER_ATM1
;
560 if(juniper_parse_header(p
, h
, &l2info
) == 0)
561 return l2info
.header_len
;
563 p
+=l2info
.header_len
;
565 if (l2info
.cookie
[0] == 0x80) { /* OAM cell ? */
566 oam_print(p
,l2info
.length
,ATM_OAM_NOHEC
);
567 return l2info
.header_len
;
570 if (EXTRACT_24BITS(p
) == 0xfefe03 || /* NLPID encaps ? */
571 EXTRACT_24BITS(p
) == 0xaaaa03) { /* SNAP encaps ? */
573 if (llc_print(p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
,
574 &extracted_ethertype
) != 0)
575 return l2info
.header_len
;
578 if (p
[0] == 0x03) { /* Cisco style NLPID encaps ? */
579 isoclns_print(p
+ 1, l2info
.length
- 1, l2info
.caplen
- 1);
580 /* FIXME check if frame was recognized */
581 return l2info
.header_len
;
584 if(ip_heuristic_guess(p
, l2info
.length
) != 0) /* last try - vcmux encaps ? */
585 return l2info
.header_len
;
587 return l2info
.header_len
;
592 * ATM2 PIC cookie format
594 * +-------------------------------+---------+---+-----+-----------+
595 * | channel ID | reserv |AAL| CCRQ| gap cnt |
596 * +-------------------------------+---------+---+-----+-----------+
599 #ifdef DLT_JUNIPER_ATM2
601 juniper_atm2_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
603 u_int16_t extracted_ethertype
;
604 u_int32_t control_word
;
606 struct juniper_l2info_t l2info
;
608 l2info
.pictype
= DLT_JUNIPER_ATM2
;
609 if(juniper_parse_header(p
, h
, &l2info
) == 0)
610 return l2info
.header_len
;
612 p
+=l2info
.header_len
;
614 if (l2info
.cookie
[7] & ATM2_PKT_TYPE_MASK
) { /* OAM cell ? */
615 control_word
= EXTRACT_32BITS(p
);
616 if(control_word
== 0 || control_word
== 0x08000000) {
617 l2info
.header_len
+= 4;
621 oam_print(p
,l2info
.length
,ATM_OAM_NOHEC
);
622 return l2info
.header_len
;
625 if (EXTRACT_24BITS(p
) == 0xfefe03 || /* NLPID encaps ? */
626 EXTRACT_24BITS(p
) == 0xaaaa03) { /* SNAP encaps ? */
628 if (llc_print(p
, l2info
.length
, l2info
.caplen
, NULL
, NULL
,
629 &extracted_ethertype
) != 0)
630 return l2info
.header_len
;
633 if (l2info
.direction
!= JUNIPER_BPF_PKT_IN
&& /* ether-over-1483 encaps ? */
634 (EXTRACT_32BITS(l2info
.cookie
) & ATM2_GAP_COUNT_MASK
)) {
635 ether_print(p
, l2info
.length
, l2info
.caplen
);
636 return l2info
.header_len
;
639 if (p
[0] == 0x03) { /* Cisco style NLPID encaps ? */
640 isoclns_print(p
+ 1, l2info
.length
- 1, l2info
.caplen
- 1);
641 /* FIXME check if frame was recognized */
642 return l2info
.header_len
;
645 if(juniper_ppp_heuristic_guess(p
, l2info
.length
) != 0) /* PPPoA vcmux encaps ? */
646 return l2info
.header_len
;
648 if(ip_heuristic_guess(p
, l2info
.length
) != 0) /* last try - vcmux encaps ? */
649 return l2info
.header_len
;
651 return l2info
.header_len
;
656 /* try to guess, based on all PPP protos that are supported in
657 * a juniper router if the payload data is encapsulated using PPP */
659 juniper_ppp_heuristic_guess(register const u_char
*p
, u_int length
) {
661 switch(EXTRACT_16BITS(p
)) {
664 case PPP_MPLS_UCAST
:
665 case PPP_MPLS_MCAST
:
677 ppp_print(p
, length
);
681 return 0; /* did not find a ppp header */
684 return 1; /* we printed a ppp packet */
688 ip_heuristic_guess(register const u_char
*p
, u_int length
) {
702 ip_print(gndo
, p
, length
);
721 ip6_print(p
, length
);
725 return 0; /* did not find a ip header */
728 return 1; /* we printed an v4/v6 packet */
732 juniper_parse_header (const u_char
*p
, const struct pcap_pkthdr
*h
, struct juniper_l2info_t
*l2info
) {
734 struct juniper_cookie_table_t
*lp
= juniper_cookie_table
;
737 l2info
->header_len
= 0;
738 l2info
->cookie_len
= 0;
742 l2info
->length
= h
->len
;
743 l2info
->caplen
= h
->caplen
;
744 l2info
->direction
= p
[3]&JUNIPER_BPF_PKT_IN
;
747 if (EXTRACT_24BITS(p
) != JUNIPER_MGC_NUMBER
) { /* magic number found ? */
748 printf("no magic-number found!");
751 l2info
->header_len
= 4;
753 if (eflag
) /* print direction */
754 printf("%3s ",tok2str(juniper_direction_values
,"---",l2info
->direction
));
756 if ((p
[3] & JUNIPER_BPF_NO_L2
) == JUNIPER_BPF_NO_L2
) {
758 printf("no-L2-hdr, ");
760 /* there is no link-layer present -
761 * perform the v4/v6 heuristics
762 * to figure out what it is
765 if(ip_heuristic_guess(p
+8,l2info
->length
-8) == 0)
766 printf("no IP-hdr found!");
768 l2info
->header_len
+=4;
769 return 0; /* stop parsing the output further */
773 p
+=l2info
->header_len
;
774 l2info
->length
-= l2info
->header_len
;
775 l2info
->caplen
-= l2info
->header_len
;
777 /* search through the cookie table and copy values matching for our PIC type */
778 while (lp
->s
!= NULL
) {
779 if (lp
->pictype
== l2info
->pictype
) {
781 l2info
->cookie_len
+= lp
->cookie_len
;
785 l2info
->cookie_type
= LS_COOKIE_ID
;
786 l2info
->cookie_len
+= 2;
789 l2info
->cookie_type
= AS_COOKIE_ID
;
790 l2info
->cookie_len
= 8;
794 l2info
->bundle
= l2info
->cookie
[0];
799 #ifdef DLT_JUNIPER_MFR
800 /* MFR child links don't carry cookies */
801 if (l2info
->pictype
== DLT_JUNIPER_MFR
&&
802 (p
[0] & MFR_BE_MASK
) == MFR_BE_MASK
) {
803 l2info
->cookie_len
= 0;
807 l2info
->header_len
+= l2info
->cookie_len
;
808 l2info
->length
-= l2info
->cookie_len
;
809 l2info
->caplen
-= l2info
->cookie_len
;
812 printf("%s-PIC, cookie-len %u",
816 if (l2info
->cookie_len
> 0) {
817 TCHECK2(p
[0],l2info
->cookie_len
);
819 printf(", cookie 0x");
820 for (idx
= 0; idx
< l2info
->cookie_len
; idx
++) {
821 l2info
->cookie
[idx
] = p
[idx
]; /* copy cookie data */
822 if (eflag
) printf("%02x",p
[idx
]);
826 if (eflag
) printf(": "); /* print demarc b/w L2/L3*/
829 l2info
->proto
= EXTRACT_16BITS(p
+l2info
->cookie_len
);
834 p
+=l2info
->cookie_len
;
836 /* DLT_ specific parsing */
837 switch(l2info
->pictype
) {
838 #ifdef DLT_JUNIPER_MLPPP
839 case DLT_JUNIPER_MLPPP
:
840 switch (l2info
->cookie_type
) {
842 l2info
->bundle
= l2info
->cookie
[1];
845 l2info
->bundle
= (EXTRACT_16BITS(&l2info
->cookie
[6])>>3)&0xfff;
846 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
849 l2info
->bundle
= l2info
->cookie
[0];
854 #ifdef DLT_JUNIPER_MLFR
855 case DLT_JUNIPER_MLFR
:
856 switch (l2info
->cookie_type
) {
858 l2info
->bundle
= l2info
->cookie
[1];
859 l2info
->proto
= EXTRACT_16BITS(p
);
860 l2info
->header_len
+= 2;
865 l2info
->bundle
= (EXTRACT_16BITS(&l2info
->cookie
[6])>>3)&0xfff;
866 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
869 l2info
->bundle
= l2info
->cookie
[0];
870 l2info
->header_len
+= 2;
877 #ifdef DLT_JUNIPER_MFR
878 case DLT_JUNIPER_MFR
:
879 switch (l2info
->cookie_type
) {
881 l2info
->bundle
= l2info
->cookie
[1];
882 l2info
->proto
= EXTRACT_16BITS(p
);
883 l2info
->header_len
+= 2;
888 l2info
->bundle
= (EXTRACT_16BITS(&l2info
->cookie
[6])>>3)&0xfff;
889 l2info
->proto
= (l2info
->cookie
[5])&JUNIPER_LSQ_L3_PROTO_MASK
;
892 l2info
->bundle
= l2info
->cookie
[0];
897 #ifdef DLT_JUNIPER_ATM2
898 case DLT_JUNIPER_ATM2
:
900 /* ATM cell relay control word present ? */
901 if (l2info
->cookie
[7] & ATM2_PKT_TYPE_MASK
&& *p
& 0x08) {
902 l2info
->header_len
+= 4;
904 printf("control-word 0x%08x ",EXTRACT_32BITS(p
));
908 #ifdef DLT_JUNIPER_ATM1
909 case DLT_JUNIPER_ATM1
:
913 printf("Unknown Juniper DLT_ type %u: ", l2info
->pictype
);
918 printf("hlen %u, proto 0x%04x, ",l2info
->header_len
,l2info
->proto
);
920 return 1; /* everything went ok so far. continue parsing */
922 printf("[|juniper_hdr], length %u",h
->len
);
929 * c-style: whitesmith