]>
The Tcpdump Group git mirrors - tcpdump/blob - print-gre.c
1 /* $OpenBSD: print-gre.c,v 1.5 2002/09/18 20:40:06 jason 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
[] =
41 "@(#) $Header: /tcpdump/master/tcpdump/print-gre.c,v 1.17 2002-09-20 22:42:21 itojun 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 */
71 /* source route entry types */
72 #define GRESRE_IP 0x0800 /* IP */
73 #define GRESRE_ASN 0xfffe /* ASN */
75 void gre_print_0(const u_char
*, u_int
);
76 void gre_print_1(const u_char
*, u_int
);
77 void gre_sre_print(u_int16_t
, u_int8_t
, u_int8_t
, const u_char
*, u_int
);
78 void gre_sre_ip_print(u_int8_t
, u_int8_t
, const u_char
*, u_int
);
79 void gre_sre_asn_print(u_int8_t
, u_int8_t
, const u_char
*, u_int
);
82 gre_print(const u_char
*bp
, u_int length
)
84 u_int len
= length
, vers
;
90 vers
= EXTRACT_16BITS(bp
) & 7;
97 printf("gre-unknown-version=%u", vers
);
103 gre_print_0(const u_char
*bp
, u_int length
)
106 u_int16_t flags
, prot
;
108 flags
= EXTRACT_16BITS(bp
);
110 printf("[%s%s%s%s%s] ",
111 (flags
& GRE_CP
) ? "C" : "",
112 (flags
& GRE_RP
) ? "R" : "",
113 (flags
& GRE_KP
) ? "K" : "",
114 (flags
& GRE_SP
) ? "S" : "",
115 (flags
& GRE_sP
) ? "s" : "");
123 prot
= EXTRACT_16BITS(bp
);
127 if ((flags
& GRE_CP
) | (flags
& GRE_RP
)) {
131 printf("sum 0x%x ", EXTRACT_16BITS(bp
));
137 printf("off 0x%x ", EXTRACT_16BITS(bp
));
142 if (flags
& GRE_KP
) {
145 printf("key=0x%x ", EXTRACT_32BITS(bp
));
150 if (flags
& GRE_SP
) {
153 printf("seq=0x%x ", EXTRACT_32BITS(bp
));
158 if (flags
& GRE_RP
) {
166 af
= EXTRACT_16BITS(bp
);
172 if (af
== 0 && srelen
== 0)
175 gre_sre_print(af
, sreoff
, srelen
, bp
, len
);
189 printf("gre-proto-0x%x", prot
);
198 gre_print_1(const u_char
*bp
, u_int length
)
201 u_int16_t flags
, prot
;
203 flags
= EXTRACT_16BITS(bp
);
208 printf("[%s%s%s%s%s%s] ",
209 (flags
& GRE_CP
) ? "C" : "",
210 (flags
& GRE_RP
) ? "R" : "",
211 (flags
& GRE_KP
) ? "K" : "",
212 (flags
& GRE_SP
) ? "S" : "",
213 (flags
& GRE_sP
) ? "s" : "",
214 (flags
& GRE_AP
) ? "A" : "");
219 prot
= EXTRACT_16BITS(bp
);
223 if (flags
& GRE_CP
) {
227 if (flags
& GRE_RP
) {
231 if ((flags
& GRE_KP
) != 0) {
235 if (flags
& GRE_sP
) {
240 if (flags
& GRE_KP
) {
245 k
= EXTRACT_32BITS(bp
);
246 printf("key=0x%x call=0x%x ", (k
>> 16) & 0xffff, k
& 0xffff);
251 if (flags
& GRE_SP
) {
254 printf("seq=0x%x ", EXTRACT_32BITS(bp
));
259 if (flags
& GRE_AP
) {
262 printf("ack=0x%x ", EXTRACT_32BITS(bp
));
267 if ((flags
& GRE_SP
) == 0) {
268 printf("no-payload ");
274 printf("gre-ppp-payload ");
277 printf("gre-proto-0x%x ", prot
);
287 gre_sre_print(u_int16_t af
, u_int8_t sreoff
, u_int8_t srelen
,
288 const u_char
*bp
, u_int len
)
293 gre_sre_ip_print(sreoff
, srelen
, bp
, len
);
298 gre_sre_asn_print(sreoff
, srelen
, bp
, len
);
302 printf("(rtaf=0x%x) ", af
);
306 gre_sre_ip_print(u_int8_t sreoff
, u_int8_t srelen
, const u_char
*bp
, u_int len
)
309 const u_char
*up
= bp
;
312 printf(" badoffset=%u", sreoff
);
316 printf(" badlength=%u", srelen
);
319 if (sreoff
>= srelen
) {
320 printf(" badoff/len=%u/%u", sreoff
, srelen
);
325 if (len
< 4 || srelen
== 0)
328 memcpy(&a
, bp
, sizeof(a
));
330 ((bp
- up
) == sreoff
) ? "*" : "",
340 gre_sre_asn_print(u_int8_t sreoff
, u_int8_t srelen
, const u_char
*bp
, u_int len
)
342 const u_char
*up
= bp
;
345 printf(" badoffset=%u", sreoff
);
349 printf(" badlength=%u", srelen
);
352 if (sreoff
>= srelen
) {
353 printf(" badoff/len=%u/%u", sreoff
, srelen
);
358 if (len
< 2 || srelen
== 0)
362 ((bp
- up
) == sreoff
) ? "*" : "",