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.6 2005-01-27 10:17:58 hannes Exp $ (LBL)";
25 #include <tcpdump-stdinc.h>
30 #include "interface.h"
36 #define JUNIPER_BPF_OUT 0 /* Outgoing packet */
37 #define JUNIPER_BPF_IN 1 /* Incoming packet */
38 #define JUNIPER_BPF_PKT_IN 0x1 /* Incoming packet */
39 #define JUNIPER_BPF_NO_L2 0x2 /* L2 header stripped */
41 #define LS_COOKIE_ID 0x54
45 #define ATM2_PKT_TYPE_MASK 0x70
46 #define ATM2_GAP_COUNT_MASK 0x3F
48 int ip_heuristic_guess(register const u_char
*, u_int
);
49 int juniper_ppp_heuristic_guess(register const u_char
*, u_int
);
50 static int juniper_parse_header (const u_char
*, u_int8_t
*, u_int
);
53 juniper_mlfr_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
55 register u_int length
= h
->len
;
56 register u_int caplen
= h
->caplen
;
57 u_int8_t direction
,bundle
,cookie_len
;
58 u_int32_t cookie
,proto
,frelay_len
= 0;
60 if(juniper_parse_header(p
, &direction
,length
) == 0)
67 if (p
[0] == LS_COOKIE_ID
) {
68 cookie
=EXTRACT_32BITS(p
);
69 if (eflag
) printf("LSPIC-MLFR cookie 0x%08x, ",cookie
);
70 cookie_len
= LS_MLFR_LEN
;
71 bundle
= cookie
& 0xff;
73 cookie
=EXTRACT_16BITS(p
);
74 if (eflag
) printf("MLPIC-MLFR cookie 0x%04x, ",cookie
);
75 cookie_len
= ML_MLFR_LEN
;
76 bundle
= (cookie
>> 8) & 0xff;
79 proto
= EXTRACT_16BITS(p
+cookie_len
);
81 length
-= cookie_len
+2;
82 caplen
-= cookie_len
+2;
84 /* suppress Bundle-ID if frame was captured on a child-link */
85 if (eflag
&& cookie
!= 1) printf("Bundle-ID %u, ",bundle
);
90 isoclns_print(p
, length
, caplen
);
92 case (LLC_UI
<<8 | NLPID_Q933
):
93 case (LLC_UI
<<8 | NLPID_IP
):
94 case (LLC_UI
<<8 | NLPID_IP6
):
95 isoclns_print(p
-1, length
+1, caplen
+1); /* pass IP{4,6} to the OSI layer for proper link-layer printing */
98 printf("unknown protocol 0x%04x, length %u",proto
, length
);
101 return cookie_len
+ frelay_len
;
105 * ATM1 PIC cookie format
107 * +-----+-------------------------+-------------------------------+
108 * |fmtid| vc index | channel ID |
109 * +-----+-------------------------+-------------------------------+
113 juniper_atm1_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
115 register u_int length
= h
->len
;
116 register u_int caplen
= h
->caplen
;
117 u_int16_t extracted_ethertype
;
121 if(juniper_parse_header(p
, &direction
,length
) == 0)
128 cookie1
=EXTRACT_32BITS(p
);
131 /* FIXME decode channel-id, vc-index, fmt-id
132 for once lets just hexdump the cookie */
134 printf("ATM1 cookie 0x%08x, ", cookie1
);
141 if ((cookie1
>> 24) == 0x80) { /* OAM cell ? */
146 if (EXTRACT_24BITS(p
) == 0xfefe03 || /* NLPID encaps ? */
147 EXTRACT_24BITS(p
) == 0xaaaa03) { /* SNAP encaps ? */
149 if (llc_print(p
, length
, caplen
, NULL
, NULL
,
150 &extracted_ethertype
) != 0)
154 if (p
[0] == 0x03) { /* Cisco style NLPID encaps ? */
155 isoclns_print(p
+ 1, length
- 1, caplen
- 1);
156 /* FIXME check if frame was recognized */
160 if(ip_heuristic_guess(p
, length
) != 0) /* last try - vcmux encaps ? */
167 * ATM2 PIC cookie format
169 * +-------------------------------+---------+---+-----+-----------+
170 * | channel ID | reserv |AAL| CCRQ| gap cnt |
171 * +-------------------------------+---------+---+-----+-----------+
175 juniper_atm2_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
177 register u_int length
= h
->len
;
178 register u_int caplen
= h
->caplen
;
179 u_int16_t extracted_ethertype
;
181 u_int32_t cookie1
,cookie2
;
183 if(juniper_parse_header(p
, &direction
,length
) == 0)
190 cookie1
=EXTRACT_32BITS(p
);
191 cookie2
=EXTRACT_32BITS(p
+4);
194 /* FIXME decode channel, fmt-id, ccrq, aal, gap cnt
195 for once lets just hexdump the cookie */
197 printf("ATM2 cookie 0x%08x%08x, ",
199 EXTRACT_32BITS(p
+4));
206 if (cookie2
& ATM2_PKT_TYPE_MASK
) { /* OAM cell ? */
211 if (EXTRACT_24BITS(p
) == 0xfefe03 || /* NLPID encaps ? */
212 EXTRACT_24BITS(p
) == 0xaaaa03) { /* SNAP encaps ? */
214 if (llc_print(p
, length
, caplen
, NULL
, NULL
,
215 &extracted_ethertype
) != 0)
219 if (direction
!= JUNIPER_BPF_PKT_IN
&& /* ether-over-1483 encaps ? */
220 (cookie1
& ATM2_GAP_COUNT_MASK
)) {
221 ether_print(p
, length
, caplen
);
225 if (p
[0] == 0x03) { /* Cisco style NLPID encaps ? */
226 isoclns_print(p
+ 1, length
- 1, caplen
- 1);
227 /* FIXME check if frame was recognized */
231 if(juniper_ppp_heuristic_guess(p
, length
) != 0) /* PPPoA vcmux encaps ? */
234 if(ip_heuristic_guess(p
, length
) != 0) /* last try - vcmux encaps ? */
241 /* try to guess, based on all PPP protos that are supported in
242 * a juniper router if the payload data is encapsulated using PPP */
244 juniper_ppp_heuristic_guess(register const u_char
*p
, u_int length
) {
246 switch(EXTRACT_16BITS(p
)) {
249 case PPP_MPLS_UCAST
:
250 case PPP_MPLS_MCAST
:
262 ppp_print(p
, length
);
266 return 0; /* did not find a ppp header */
269 return 1; /* we printed a ppp packet */
273 ip_heuristic_guess(register const u_char
*p
, u_int length
) {
306 ip6_print(p
, length
);
310 return 0; /* did not find a ip header */
313 return 1; /* we printed an v4/v6 packet */
317 juniper_parse_header (const u_char
*p
, u_int8_t
*direction
, u_int length
) {
319 *direction
= p
[3]&JUNIPER_BPF_PKT_IN
;
321 if (EXTRACT_24BITS(p
) != 0x4d4743) /* magic number found ? */
324 if (*direction
== JUNIPER_BPF_PKT_IN
) {
326 printf("%3s ", "In");
330 printf("%3s ", "Out");
333 if ((p
[3] & JUNIPER_BPF_NO_L2
) == JUNIPER_BPF_NO_L2
) {
335 printf("no-L2-hdr, ");
337 /* there is no link-layer present -
338 * perform the v4/v6 heuristics
339 * to figure out what it is
341 if(ip_heuristic_guess(p
+8,length
-8) == 0)
342 printf("no IP-hdr found!");
344 return 0; /* stop parsing the output further */
347 return 1; /* everything went ok so far. continue parsing */