]>
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)
40 static const char rcsid
[] _U_
=
41 "@(#) $Header: /tcpdump/master/tcpdump/print-gre.c,v 1.25 2004-06-12 16:32:56 hannes Exp $ (LBL)";
48 #include <tcpdump-stdinc.h>
53 #include "interface.h"
54 #include "addrtoname.h"
58 #include "ethertype.h"
60 #define GRE_CP 0x8000 /* checksum present */
61 #define GRE_RP 0x4000 /* routing present */
62 #define GRE_KP 0x2000 /* key present */
63 #define GRE_SP 0x1000 /* sequence# present */
64 #define GRE_sP 0x0800 /* source routing */
65 #define GRE_RECRS 0x0700 /* recursion count */
66 #define GRE_AP 0x0080 /* acknowledgment# present */
67 #define GRE_VERS_MASK 0x0007 /* protocol version */
69 /* source route entry types */
70 #define GRESRE_IP 0x0800 /* IP */
71 #define GRESRE_ASN 0xfffe /* ASN */
73 void gre_print_0(const u_char
*, u_int
);
74 void gre_print_1(const u_char
*, u_int
);
75 void gre_sre_print(u_int16_t
, u_int8_t
, u_int8_t
, const u_char
*, u_int
);
76 void gre_sre_ip_print(u_int8_t
, u_int8_t
, const u_char
*, u_int
);
77 void gre_sre_asn_print(u_int8_t
, u_int8_t
, const u_char
*, u_int
);
80 gre_print(const u_char
*bp
, u_int length
)
82 u_int len
= length
, vers
;
88 vers
= EXTRACT_16BITS(bp
) & GRE_VERS_MASK
;
89 printf("GREv%u",vers
);
99 printf(" ERROR: unknown-version");
107 gre_print_0(const u_char
*bp
, u_int length
)
110 u_int16_t flags
, prot
;
112 flags
= EXTRACT_16BITS(bp
);
113 if (vflag
&& flags
) {
114 printf("[%s%s%s%s%s] ",
115 (flags
& GRE_CP
) ? "C" : "",
116 (flags
& GRE_RP
) ? "R" : "",
117 (flags
& GRE_KP
) ? "K" : "",
118 (flags
& GRE_SP
) ? "S" : "",
119 (flags
& GRE_sP
) ? "s" : "");
127 prot
= EXTRACT_16BITS(bp
);
131 if ((flags
& GRE_CP
) | (flags
& GRE_RP
)) {
135 printf("sum 0x%x ", EXTRACT_16BITS(bp
));
141 printf("off 0x%x ", EXTRACT_16BITS(bp
));
146 if (flags
& GRE_KP
) {
149 printf("key=0x%x ", EXTRACT_32BITS(bp
));
154 if (flags
& GRE_SP
) {
157 printf("seq %u ", EXTRACT_32BITS(bp
));
162 if (flags
& GRE_RP
) {
170 af
= EXTRACT_16BITS(bp
);
176 if (af
== 0 && srelen
== 0)
179 gre_sre_print(af
, sreoff
, srelen
, bp
, len
);
189 printf(", proto %s (0x%04x)",
190 tok2str(ethertype_values
,"unknown",prot
),
207 case ETHERTYPE_ATALK
:
208 atalk_print(bp
, len
);
210 case ETHERTYPE_GRE_ISO
:
211 isoclns_print(bp
, len
, len
);
214 printf("gre-proto-0x%x", prot
);
223 gre_print_1(const u_char
*bp
, u_int length
)
226 u_int16_t flags
, prot
;
228 flags
= EXTRACT_16BITS(bp
);
233 printf("[%s%s%s%s%s%s] ",
234 (flags
& GRE_CP
) ? "C" : "",
235 (flags
& GRE_RP
) ? "R" : "",
236 (flags
& GRE_KP
) ? "K" : "",
237 (flags
& GRE_SP
) ? "S" : "",
238 (flags
& GRE_sP
) ? "s" : "",
239 (flags
& GRE_AP
) ? "A" : "");
244 prot
= EXTRACT_16BITS(bp
);
248 if (flags
& GRE_CP
) {
252 if (flags
& GRE_RP
) {
256 if ((flags
& GRE_KP
) == 0) {
260 if (flags
& GRE_sP
) {
265 if (flags
& GRE_KP
) {
270 k
= EXTRACT_32BITS(bp
);
271 printf("call %d ", k
& 0xffff);
276 if (flags
& GRE_SP
) {
279 printf("seq %u ", EXTRACT_32BITS(bp
));
284 if (flags
& GRE_AP
) {
287 printf("ack %u ", EXTRACT_32BITS(bp
));
292 if ((flags
& GRE_SP
) == 0) {
293 printf("no-payload");
299 printf("gre-ppp-payload");
302 printf("gre-proto-0x%x", prot
);
312 gre_sre_print(u_int16_t af
, u_int8_t sreoff
, u_int8_t srelen
,
313 const u_char
*bp
, u_int len
)
318 gre_sre_ip_print(sreoff
, srelen
, bp
, len
);
323 gre_sre_asn_print(sreoff
, srelen
, bp
, len
);
327 printf("(rtaf=0x%x) ", af
);
331 gre_sre_ip_print(u_int8_t sreoff
, u_int8_t srelen
, const u_char
*bp
, u_int len
)
334 const u_char
*up
= bp
;
337 printf(" badoffset=%u", sreoff
);
341 printf(" badlength=%u", srelen
);
344 if (sreoff
>= srelen
) {
345 printf(" badoff/len=%u/%u", sreoff
, srelen
);
350 if (len
< 4 || srelen
== 0)
353 memcpy(&a
, bp
, sizeof(a
));
355 ((bp
- up
) == sreoff
) ? "*" : "",
365 gre_sre_asn_print(u_int8_t sreoff
, u_int8_t srelen
, const u_char
*bp
, u_int len
)
367 const u_char
*up
= bp
;
370 printf(" badoffset=%u", sreoff
);
374 printf(" badlength=%u", srelen
);
377 if (sreoff
>= srelen
) {
378 printf(" badoff/len=%u/%u", sreoff
, srelen
);
383 if (len
< 2 || srelen
== 0)
387 ((bp
- up
) == sreoff
) ? "*" : "",