]> The Tcpdump Group git mirrors - tcpdump/blob - print-juniper.c
fix the ATM1 PIC OAM cell dissecting
[tcpdump] / print-juniper.c
1 /*
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.
12 *
13 * Original code by Hannes Gredler (hannes@juniper.net)
14 */
15
16 #ifndef lint
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)";
19 #endif
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <tcpdump-stdinc.h>
26
27 #include <pcap.h>
28 #include <stdio.h>
29
30 #include "interface.h"
31 #include "extract.h"
32 #include "ppp.h"
33
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 */
38
39 #define ATM2_PKT_TYPE_MASK 0x70
40 #define ATM2_GAP_COUNT_MASK 0x3F
41
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);
45
46 /*
47 * ATM1 PIC cookie format
48 *
49 * +-----+-------------------------+-------------------------------+
50 * |fmtid| vc index | channel ID |
51 * +-----+-------------------------+-------------------------------+
52 */
53
54 u_int
55 juniper_atm1_print(const struct pcap_pkthdr *h, register const u_char *p)
56 {
57 register u_int length = h->len;
58 register u_int caplen = h->caplen;
59 u_int16_t extracted_ethertype;
60 u_int8_t direction;
61 u_int32_t cookie1;
62
63 if(juniper_parse_header(p, &direction,length) == 0)
64 return 0;
65
66 p+=4;
67 length-=4;
68 caplen-=4;
69
70 cookie1=EXTRACT_32BITS(p);
71
72 if (eflag) {
73 /* FIXME decode channel-id, vc-index, fmt-id
74 for once lets just hexdump the cookie */
75
76 printf("ATM1 cookie 0x%08x, ", EXTRACT_32BITS(p));
77 }
78
79 p+=4;
80 length-=4;
81 caplen-=4;
82
83 if ((cookie1 >> 24) == 0x80) { /* OAM cell ? */
84 oam_print(p,length);
85 return 0;
86 }
87
88 if (EXTRACT_24BITS(p) == 0xfefe03 || /* NLPID encaps ? */
89 EXTRACT_24BITS(p) == 0xaaaa03) { /* SNAP encaps ? */
90
91 if (llc_print(p, length, caplen, NULL, NULL,
92 &extracted_ethertype) != 0)
93 return 8;
94 }
95
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 */
99 return 8;
100 }
101
102 if(ip_heuristic_guess(p, length) != 0) /* last try - vcmux encaps ? */
103 return 0;
104
105 return (8);
106 }
107
108 /*
109 * ATM2 PIC cookie format
110 *
111 * +-------------------------------+---------+---+-----+-----------+
112 * | channel ID | reserv |AAL| CCRQ| gap cnt |
113 * +-------------------------------+---------+---+-----+-----------+
114 */
115
116 u_int
117 juniper_atm2_print(const struct pcap_pkthdr *h, register const u_char *p)
118 {
119 register u_int length = h->len;
120 register u_int caplen = h->caplen;
121 u_int16_t extracted_ethertype;
122 u_int8_t direction;
123 u_int32_t cookie1,cookie2;
124
125 if(juniper_parse_header(p, &direction,length) == 0)
126 return 0;
127
128 p+=4;
129 length-=4;
130 caplen-=4;
131
132 cookie1=EXTRACT_32BITS(p);
133 cookie2=EXTRACT_32BITS(p+4);
134
135 if (eflag) {
136 /* FIXME decode channel, fmt-id, ccrq, aal, gap cnt
137 for once lets just hexdump the cookie */
138
139 printf("ATM2 cookie 0x%08x%08x, ",
140 EXTRACT_32BITS(p),
141 EXTRACT_32BITS(p+4));
142 }
143
144 p+=8;
145 length-=8;
146 caplen-=8;
147
148 if (cookie2 & ATM2_PKT_TYPE_MASK) { /* OAM cell ? */
149 oam_print(p,length);
150 return 12;
151 }
152
153 if (EXTRACT_24BITS(p) == 0xfefe03 || /* NLPID encaps ? */
154 EXTRACT_24BITS(p) == 0xaaaa03) { /* SNAP encaps ? */
155
156 if (llc_print(p, length, caplen, NULL, NULL,
157 &extracted_ethertype) != 0)
158 return 12;
159 }
160
161 if (direction != JUNIPER_BPF_PKT_IN && /* ether-over-1483 encaps ? */
162 (cookie1 & ATM2_GAP_COUNT_MASK)) {
163 ether_print(p, length, caplen);
164 return 12;
165 }
166
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 */
170 return 12;
171 }
172
173 if(juniper_ppp_heuristic_guess(p, length) != 0) /* PPPoA vcmux encaps ? */
174 return 12;
175
176 if(ip_heuristic_guess(p, length) != 0) /* last try - vcmux encaps ? */
177 return 12;
178
179 return (12);
180 }
181
182
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 */
185 int
186 juniper_ppp_heuristic_guess(register const u_char *p, u_int length) {
187
188 switch(EXTRACT_16BITS(p)) {
189 case PPP_IP :
190 case PPP_OSI :
191 case PPP_MPLS_UCAST :
192 case PPP_MPLS_MCAST :
193 case PPP_IPCP :
194 case PPP_OSICP :
195 case PPP_MPLSCP :
196 case PPP_LCP :
197 case PPP_PAP :
198 case PPP_CHAP :
199 case PPP_ML :
200 #ifdef INET6
201 case PPP_IPV6 :
202 case PPP_IPV6CP :
203 #endif
204 ppp_print(p, length);
205 break;
206
207 default:
208 return 0; /* did not find a ppp header */
209 break;
210 }
211 return 1; /* we printed a ppp packet */
212 }
213
214 int
215 ip_heuristic_guess(register const u_char *p, u_int length) {
216
217 switch(p[0]) {
218 case 0x45:
219 case 0x46:
220 case 0x47:
221 case 0x48:
222 case 0x49:
223 case 0x4a:
224 case 0x4b:
225 case 0x4c:
226 case 0x4d:
227 case 0x4e:
228 case 0x4f:
229 ip_print(p, length);
230 break;
231 #ifdef INET6
232 case 0x60:
233 case 0x61:
234 case 0x62:
235 case 0x63:
236 case 0x64:
237 case 0x65:
238 case 0x66:
239 case 0x67:
240 case 0x68:
241 case 0x69:
242 case 0x6a:
243 case 0x6b:
244 case 0x6c:
245 case 0x6d:
246 case 0x6e:
247 case 0x6f:
248 ip6_print(p, length);
249 break;
250 #endif
251 default:
252 return 0; /* did not find a ip header */
253 break;
254 }
255 return 1; /* we printed an v4/v6 packet */
256 }
257
258 static int
259 juniper_parse_header (const u_char *p, u_int8_t *direction, u_int length) {
260
261 *direction = p[3]&JUNIPER_BPF_PKT_IN;
262
263 if (EXTRACT_24BITS(p) != 0x4d4743) /* magic number found ? */
264 return -1;
265
266 if (*direction == JUNIPER_BPF_PKT_IN) {
267 if (eflag)
268 printf("%3s ", "In");
269 }
270 else {
271 if (eflag)
272 printf("%3s ", "Out");
273 }
274
275 if ((p[3] & JUNIPER_BPF_NO_L2 ) == JUNIPER_BPF_NO_L2 ) {
276 if (eflag)
277 printf("no-L2-hdr, ");
278
279 /* there is no link-layer present -
280 * perform the v4/v6 heuristics
281 * to figure out what it is
282 */
283 if(ip_heuristic_guess(p+8,length-8) == 0)
284 printf("no IP-hdr found!");
285
286 return 0; /* stop parsing the output further */
287
288 }
289 return 1; /* everything went ok so far. continue parsing */
290 }