]>
The Tcpdump Group git mirrors - tcpdump/blob - print-gre.c
1 /* $OpenBSD: print-gre.c,v 1.6 2002/10/30 03:04:04 fgsch Exp $ */
4 * Copyright (c) 2002 Jason L. Wright (jason@thought.net)
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Jason L. Wright
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
35 * tcpdump filter for GRE - Generic Routing Encapsulation
36 * RFC1701 (GRE), RFC1702 (GRE IPv4), and RFC2637 (Enhanced GRE)
43 #include <tcpdump-stdinc.h>
48 #include "interface.h"
49 #include "addrtoname.h"
53 #include "ethertype.h"
55 static const char tstr
[] = "[|gre]";
57 #define GRE_CP 0x8000 /* checksum present */
58 #define GRE_RP 0x4000 /* routing present */
59 #define GRE_KP 0x2000 /* key present */
60 #define GRE_SP 0x1000 /* sequence# present */
61 #define GRE_sP 0x0800 /* source routing */
62 #define GRE_RECRS 0x0700 /* recursion count */
63 #define GRE_AP 0x0080 /* acknowledgment# present */
65 static const struct tok gre_flag_values
[] = {
66 { GRE_CP
, "checksum present"},
67 { GRE_RP
, "routing present"},
68 { GRE_KP
, "key present"},
69 { GRE_SP
, "sequence# present"},
70 { GRE_sP
, "source routing present"},
71 { GRE_RECRS
, "recursion count"},
72 { GRE_AP
, "ack present"},
76 #define GRE_VERS_MASK 0x0007 /* protocol version */
78 /* source route entry types */
79 #define GRESRE_IP 0x0800 /* IP */
80 #define GRESRE_ASN 0xfffe /* ASN */
82 void gre_print_0(const u_char
*, u_int
);
83 void gre_print_1(const u_char
*, u_int
);
84 void gre_sre_print(u_int16_t
, u_int8_t
, u_int8_t
, const u_char
*, u_int
);
85 void gre_sre_ip_print(u_int8_t
, u_int8_t
, const u_char
*, u_int
);
86 void gre_sre_asn_print(u_int8_t
, u_int8_t
, const u_char
*, u_int
);
89 gre_print(const u_char
*bp
, u_int length
)
91 u_int len
= length
, vers
;
97 vers
= EXTRACT_16BITS(bp
) & GRE_VERS_MASK
;
98 printf("GREv%u",vers
);
102 gre_print_0(bp
, len
);
105 gre_print_1(bp
, len
);
108 printf(" ERROR: unknown-version");
116 gre_print_0(const u_char
*bp
, u_int length
)
119 u_int16_t flags
, prot
;
121 flags
= EXTRACT_16BITS(bp
);
123 printf(", Flags [%s]",
124 bittok2str(gre_flag_values
,"none",flags
));
131 prot
= EXTRACT_16BITS(bp
);
135 if ((flags
& GRE_CP
) | (flags
& GRE_RP
)) {
139 printf(", sum 0x%x", EXTRACT_16BITS(bp
));
145 printf(", off 0x%x", EXTRACT_16BITS(bp
));
150 if (flags
& GRE_KP
) {
153 printf(", key=0x%x", EXTRACT_32BITS(bp
));
158 if (flags
& GRE_SP
) {
161 printf(", seq %u", EXTRACT_32BITS(bp
));
166 if (flags
& GRE_RP
) {
174 af
= EXTRACT_16BITS(bp
);
180 if (af
== 0 && srelen
== 0)
183 gre_sre_print(af
, sreoff
, srelen
, bp
, len
);
193 printf(", proto %s (0x%04x)",
194 tok2str(ethertype_values
,"unknown",prot
),
197 printf(", length %u",length
);
200 printf(": "); /* put in a colon as protocol demarc */
202 printf("\n\t"); /* if verbose go multiline */
206 ip_print(gndo
, bp
, len
);
210 ip6_print(gndo
, bp
, len
);
219 case ETHERTYPE_ATALK
:
220 atalk_print(bp
, len
);
222 case ETHERTYPE_GRE_ISO
:
223 isoclns_print(bp
, len
, len
);
226 ether_print(gndo
, bp
, len
, len
, NULL
, NULL
);
229 printf("gre-proto-0x%x", prot
);
238 gre_print_1(const u_char
*bp
, u_int length
)
241 u_int16_t flags
, prot
;
243 flags
= EXTRACT_16BITS(bp
);
248 printf(", Flags [%s]",
249 bittok2str(gre_flag_values
,"none",flags
));
253 prot
= EXTRACT_16BITS(bp
);
258 if (flags
& GRE_KP
) {
263 k
= EXTRACT_32BITS(bp
);
264 printf(", call %d", k
& 0xffff);
269 if (flags
& GRE_SP
) {
272 printf(", seq %u", EXTRACT_32BITS(bp
));
277 if (flags
& GRE_AP
) {
280 printf(", ack %u", EXTRACT_32BITS(bp
));
285 if ((flags
& GRE_SP
) == 0)
286 printf(", no-payload");
289 printf(", proto %s (0x%04x)",
290 tok2str(ethertype_values
,"unknown",prot
),
293 printf(", length %u",length
);
295 if ((flags
& GRE_SP
) == 0)
299 printf(": "); /* put in a colon as protocol demarc */
301 printf("\n\t"); /* if verbose go multiline */
308 printf("gre-proto-0x%x", prot
);
318 gre_sre_print(u_int16_t af
, u_int8_t sreoff
, u_int8_t srelen
,
319 const u_char
*bp
, u_int len
)
323 printf(", (rtaf=ip");
324 gre_sre_ip_print(sreoff
, srelen
, bp
, len
);
328 printf(", (rtaf=asn");
329 gre_sre_asn_print(sreoff
, srelen
, bp
, len
);
333 printf(", (rtaf=0x%x) ", af
);
337 gre_sre_ip_print(u_int8_t sreoff
, u_int8_t srelen
, const u_char
*bp
, u_int len
)
340 const u_char
*up
= bp
;
343 printf(", badoffset=%u", sreoff
);
347 printf(", badlength=%u", srelen
);
350 if (sreoff
>= srelen
) {
351 printf(", badoff/len=%u/%u", sreoff
, srelen
);
356 if (len
< 4 || srelen
== 0)
359 memcpy(&a
, bp
, sizeof(a
));
361 ((bp
- up
) == sreoff
) ? "*" : "",
371 gre_sre_asn_print(u_int8_t sreoff
, u_int8_t srelen
, const u_char
*bp
, u_int len
)
373 const u_char
*up
= bp
;
376 printf(", badoffset=%u", sreoff
);
380 printf(", badlength=%u", srelen
);
383 if (sreoff
>= srelen
) {
384 printf(", badoff/len=%u/%u", sreoff
, srelen
);
389 if (len
< 2 || srelen
== 0)
393 ((bp
- up
) == sreoff
) ? "*" : "",