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.22.2.2 2003/11/16 08:51:24 guy Exp $ (LBL)";
48 #include <tcpdump-stdinc.h>
53 #include "interface.h"
54 #include "addrtoname.h"
59 #define GRE_CP 0x8000 /* checksum present */
60 #define GRE_RP 0x4000 /* routing present */
61 #define GRE_KP 0x2000 /* key present */
62 #define GRE_SP 0x1000 /* sequence# present */
63 #define GRE_sP 0x0800 /* source routing */
64 #define GRE_RECRS 0x0700 /* recursion count */
65 #define GRE_AP 0x0080 /* acknowledgment# present */
66 #define GRE_VERS 0x0007 /* protocol version */
68 #define GREPROTO_IP 0x0800 /* IP */
69 #define GREPROTO_PPP 0x880b /* PPTP */
70 #define GREPROTO_ISO 0x00fe /* OSI */
72 /* source route entry types */
73 #define GRESRE_IP 0x0800 /* IP */
74 #define GRESRE_ASN 0xfffe /* ASN */
76 void gre_print_0(const u_char *, u_int);
77 void gre_print_1(const u_char *, u_int);
78 void gre_sre_print(u_int16_t, u_int8_t, u_int8_t, const u_char *, u_int);
79 void gre_sre_ip_print(u_int8_t, u_int8_t, const u_char *, u_int);
80 void gre_sre_asn_print(u_int8_t, u_int8_t, const u_char *, u_int);
83 gre_print(const u_char *bp, u_int length)
85 u_int len = length, vers;
91 vers = EXTRACT_16BITS(bp) & 7;
98 printf("gre-unknown-version=%u", vers);
104 gre_print_0(const u_char *bp, u_int length)
107 u_int16_t flags, prot;
109 flags = EXTRACT_16BITS(bp);
111 printf("[%s%s%s%s%s] ",
112 (flags & GRE_CP) ? "C" : "",
113 (flags & GRE_RP) ? "R" : "",
114 (flags & GRE_KP) ? "K" : "",
115 (flags & GRE_SP) ? "S" : "",
116 (flags & GRE_sP) ? "s" : "");
124 prot = EXTRACT_16BITS(bp);
128 if ((flags & GRE_CP) | (flags & GRE_RP)) {
132 printf("sum 0x%x ", EXTRACT_16BITS(bp));
138 printf("off 0x%x ", EXTRACT_16BITS(bp));
143 if (flags & GRE_KP) {
146 printf("key=0x%x ", EXTRACT_32BITS(bp));
151 if (flags & GRE_SP) {
154 printf("seq %u ", EXTRACT_32BITS(bp));
159 if (flags & GRE_RP) {
167 af = EXTRACT_16BITS(bp);
173 if (af == 0 && srelen == 0)
176 gre_sre_print(af, sreoff, srelen, bp, len);
190 isoclns_print(bp, len, len);
193 printf("gre-proto-0x%x", prot);
202 gre_print_1(const u_char *bp, u_int length)
205 u_int16_t flags, prot;
207 flags = EXTRACT_16BITS(bp);
212 printf("[%s%s%s%s%s%s] ",
213 (flags & GRE_CP) ? "C" : "",
214 (flags & GRE_RP) ? "R" : "",
215 (flags & GRE_KP) ? "K" : "",
216 (flags & GRE_SP) ? "S" : "",
217 (flags & GRE_sP) ? "s" : "",
218 (flags & GRE_AP) ? "A" : "");
223 prot = EXTRACT_16BITS(bp);
227 if (flags & GRE_CP) {
231 if (flags & GRE_RP) {
235 if ((flags & GRE_KP) == 0) {
239 if (flags & GRE_sP) {
244 if (flags & GRE_KP) {
249 k = EXTRACT_32BITS(bp);
250 printf("call %d ", k & 0xffff);
255 if (flags & GRE_SP) {
258 printf("seq %u ", EXTRACT_32BITS(bp));
263 if (flags & GRE_AP) {
266 printf("ack %u ", EXTRACT_32BITS(bp));
271 if ((flags & GRE_SP) == 0) {
272 printf("no-payload");
278 printf("gre-ppp-payload");
281 printf("gre-proto-0x%x", prot);
291 gre_sre_print(u_int16_t af, u_int8_t sreoff, u_int8_t srelen,
292 const u_char *bp, u_int len)
297 gre_sre_ip_print(sreoff, srelen, bp, len);
302 gre_sre_asn_print(sreoff, srelen, bp, len);
306 printf("(rtaf=0x%x) ", af);
310 gre_sre_ip_print(u_int8_t sreoff, u_int8_t srelen, const u_char *bp, u_int len)
313 const u_char *up = bp;
316 printf(" badoffset=%u", sreoff);
320 printf(" badlength=%u", srelen);
323 if (sreoff >= srelen) {
324 printf(" badoff/len=%u/%u", sreoff, srelen);
329 if (len < 4 || srelen == 0)
332 memcpy(&a, bp, sizeof(a));
334 ((bp - up) == sreoff) ? "*" : "",
344 gre_sre_asn_print(u_int8_t sreoff, u_int8_t srelen, const u_char *bp, u_int len)
346 const u_char *up = bp;
349 printf(" badoffset=%u", sreoff);
353 printf(" badlength=%u", srelen);
356 if (sreoff >= srelen) {
357 printf(" badoff/len=%u/%u", sreoff, srelen);
362 if (len < 2 || srelen == 0)
366 ((bp - up) == sreoff) ? "*" : "",