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.5 2005-01-25 09:59:40 hannes 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
>> 24) == 0x80) { /* OAM cell ? */
88 if (EXTRACT_24BITS(p
) == 0xfefe03 || /* NLPID encaps ? */
89 EXTRACT_24BITS(p
) == 0xaaaa03) { /* SNAP encaps ? */
91 if (llc_print(p
, length
, caplen
, NULL
, NULL
,
92 &extracted_ethertype
) != 0)
96 if (p
[0] == 0x03) { /* Cisco style NLPID encaps ? */
97 isoclns_print(p
+ 1, length
- 1, caplen
- 1);
98 /* FIXME check if frame was recognized */
102 if(ip_heuristic_guess(p
, length
) != 0) /* last try - vcmux encaps ? */
109 * ATM2 PIC cookie format
111 * +-------------------------------+---------+---+-----+-----------+
112 * | channel ID | reserv |AAL| CCRQ| gap cnt |
113 * +-------------------------------+---------+---+-----+-----------+
117 juniper_atm2_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
119 register u_int length
= h
->len
;
120 register u_int caplen
= h
->caplen
;
121 u_int16_t extracted_ethertype
;
123 u_int32_t cookie1
,cookie2
;
125 if(juniper_parse_header(p
, &direction
,length
) == 0)
132 cookie1
=EXTRACT_32BITS(p
);
133 cookie2
=EXTRACT_32BITS(p
+4);
136 /* FIXME decode channel, fmt-id, ccrq, aal, gap cnt
137 for once lets just hexdump the cookie */
139 printf("ATM2 cookie 0x%08x%08x, ",
141 EXTRACT_32BITS(p
+4));
148 if (cookie2
& ATM2_PKT_TYPE_MASK
) { /* OAM cell ? */
153 if (EXTRACT_24BITS(p
) == 0xfefe03 || /* NLPID encaps ? */
154 EXTRACT_24BITS(p
) == 0xaaaa03) { /* SNAP encaps ? */
156 if (llc_print(p
, length
, caplen
, NULL
, NULL
,
157 &extracted_ethertype
) != 0)
161 if (direction
!= JUNIPER_BPF_PKT_IN
&& /* ether-over-1483 encaps ? */
162 (cookie1
& ATM2_GAP_COUNT_MASK
)) {
163 ether_print(p
, length
, caplen
);
167 if (p
[0] == 0x03) { /* Cisco style NLPID encaps ? */
168 isoclns_print(p
+ 1, length
- 1, caplen
- 1);
169 /* FIXME check if frame was recognized */
173 if(juniper_ppp_heuristic_guess(p
, length
) != 0) /* PPPoA vcmux encaps ? */
176 if(ip_heuristic_guess(p
, length
) != 0) /* last try - vcmux encaps ? */
183 /* try to guess, based on all PPP protos that are supported in
184 * a juniper router if the payload data is encapsulated using PPP */
186 juniper_ppp_heuristic_guess(register const u_char
*p
, u_int length
) {
188 switch(EXTRACT_16BITS(p
)) {
191 case PPP_MPLS_UCAST
:
192 case PPP_MPLS_MCAST
:
204 ppp_print(p
, length
);
208 return 0; /* did not find a ppp header */
211 return 1; /* we printed a ppp packet */
215 ip_heuristic_guess(register const u_char
*p
, u_int length
) {
248 ip6_print(p
, length
);
252 return 0; /* did not find a ip header */
255 return 1; /* we printed an v4/v6 packet */
259 juniper_parse_header (const u_char
*p
, u_int8_t
*direction
, u_int length
) {
261 *direction
= p
[3]&JUNIPER_BPF_PKT_IN
;
263 if (EXTRACT_24BITS(p
) != 0x4d4743) /* magic number found ? */
266 if (*direction
== JUNIPER_BPF_PKT_IN
) {
268 printf("%3s ", "In");
272 printf("%3s ", "Out");
275 if ((p
[3] & JUNIPER_BPF_NO_L2
) == JUNIPER_BPF_NO_L2
) {
277 printf("no-L2-hdr, ");
279 /* there is no link-layer present -
280 * perform the v4/v6 heuristics
281 * to figure out what it is
283 if(ip_heuristic_guess(p
+8,length
-8) == 0)
284 printf("no IP-hdr found!");
286 return 0; /* stop parsing the output further */
289 return 1; /* everything went ok so far. continue parsing */