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.4 2005-01-24 03:27:26 guy Exp $ (LBL)";
25 #include <tcpdump-stdinc.h>
30 #include "interface.h"
34 #define JUNIPER_BPF_OUT 0 /* Outgoing packet */
35 #define JUNIPER_BPF_IN 1 /* Incoming packet */
36 #define JUNIPER_BPF_PKT_IN 0x1 /* Incoming packet */
37 #define JUNIPER_BPF_NO_L2 0x2 /* L2 header stripped */
39 #define ATM2_PKT_TYPE_MASK 0x70
40 #define ATM2_GAP_COUNT_MASK 0x3F
42 int ip_heuristic_guess(register const u_char
*, u_int
);
43 int juniper_ppp_heuristic_guess(register const u_char
*, u_int
);
44 static int juniper_parse_header (const u_char
*, u_int8_t
*, u_int
);
47 * ATM1 PIC cookie format
49 * +-----+-------------------------+-------------------------------+
50 * |fmtid| vc index | channel ID |
51 * +-----+-------------------------+-------------------------------+
55 juniper_atm1_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
57 register u_int length
= h
->len
;
58 register u_int caplen
= h
->caplen
;
59 u_int16_t extracted_ethertype
;
63 if(juniper_parse_header(p
, &direction
,length
) == 0)
70 cookie1
=EXTRACT_32BITS(p
);
73 /* FIXME decode channel-id, vc-index, fmt-id
74 for once lets just hexdump the cookie */
76 printf("ATM1 cookie 0x%08x, ", EXTRACT_32BITS(p
));
83 if (cookie1
& 0x80000000) { /* OAM cell ? */
84 /* XXX - at least some packets are mis-identified as OAM
90 if (EXTRACT_24BITS(p
) == 0xfefe03 || /* NLPID encaps ? */
91 EXTRACT_24BITS(p
) == 0xaaaa03) { /* SNAP encaps ? */
93 if (llc_print(p
, length
, caplen
, NULL
, NULL
,
94 &extracted_ethertype
) != 0)
98 if (p
[0] == 0x03) { /* Cisco style NLPID encaps ? */
99 isoclns_print(p
+ 1, length
- 1, caplen
- 1);
100 /* FIXME check if frame was recognized */
104 if(ip_heuristic_guess(p
, length
) != 0) /* last try - vcmux encaps ? */
111 * ATM2 PIC cookie format
113 * +-------------------------------+---------+---+-----+-----------+
114 * | channel ID | reserv |AAL| CCRQ| gap cnt |
115 * +-------------------------------+---------+---+-----+-----------+
119 juniper_atm2_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
121 register u_int length
= h
->len
;
122 register u_int caplen
= h
->caplen
;
123 u_int16_t extracted_ethertype
;
125 u_int32_t cookie1
,cookie2
;
127 if(juniper_parse_header(p
, &direction
,length
) == 0)
134 cookie1
=EXTRACT_32BITS(p
);
135 cookie2
=EXTRACT_32BITS(p
+4);
138 /* FIXME decode channel, fmt-id, ccrq, aal, gap cnt
139 for once lets just hexdump the cookie */
141 printf("ATM2 cookie 0x%08x%08x, ",
143 EXTRACT_32BITS(p
+4));
150 if (cookie2
& ATM2_PKT_TYPE_MASK
) { /* OAM cell ? */
155 if (EXTRACT_24BITS(p
) == 0xfefe03 || /* NLPID encaps ? */
156 EXTRACT_24BITS(p
) == 0xaaaa03) { /* SNAP encaps ? */
158 if (llc_print(p
, length
, caplen
, NULL
, NULL
,
159 &extracted_ethertype
) != 0)
163 if (direction
!= JUNIPER_BPF_PKT_IN
&& /* ether-over-1483 encaps ? */
164 (cookie1
& ATM2_GAP_COUNT_MASK
)) {
165 ether_print(p
, length
, caplen
);
169 if (p
[0] == 0x03) { /* Cisco style NLPID encaps ? */
170 isoclns_print(p
+ 1, length
- 1, caplen
- 1);
171 /* FIXME check if frame was recognized */
175 if(juniper_ppp_heuristic_guess(p
, length
) != 0) /* PPPoA vcmux encaps ? */
178 if(ip_heuristic_guess(p
, length
) != 0) /* last try - vcmux encaps ? */
185 /* try to guess, based on all PPP protos that are supported in
186 * a juniper router if the payload data is encapsulated using PPP */
188 juniper_ppp_heuristic_guess(register const u_char
*p
, u_int length
) {
190 switch(EXTRACT_16BITS(p
)) {
193 case PPP_MPLS_UCAST
:
194 case PPP_MPLS_MCAST
:
206 ppp_print(p
, length
);
210 return 0; /* did not find a ppp header */
213 return 1; /* we printed a ppp packet */
217 ip_heuristic_guess(register const u_char
*p
, u_int length
) {
250 ip6_print(p
, length
);
254 return 0; /* did not find a ip header */
257 return 1; /* we printed an v4/v6 packet */
261 juniper_parse_header (const u_char
*p
, u_int8_t
*direction
, u_int length
) {
263 *direction
= p
[3]&JUNIPER_BPF_PKT_IN
;
265 if (EXTRACT_24BITS(p
) != 0x4d4743) /* magic number found ? */
268 if (*direction
== JUNIPER_BPF_PKT_IN
) {
270 printf("%3s ", "In");
274 printf("%3s ", "Out");
277 if ((p
[3] & JUNIPER_BPF_NO_L2
) == JUNIPER_BPF_NO_L2
) {
279 printf("no-L2-hdr, ");
281 /* there is no link-layer present -
282 * perform the v4/v6 heuristics
283 * to figure out what it is
285 if(ip_heuristic_guess(p
+8,length
-8) == 0)
286 printf("no IP-hdr found!");
288 return 0; /* stop parsing the output further */
291 return 1; /* everything went ok so far. continue parsing */