]>
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.
34 /* \summary: Generic Routing Encapsulation (GRE) printer */
37 * netdissect printer for GRE - Generic Routing Encapsulation
38 * RFC1701 (GRE), RFC1702 (GRE IPv4), and RFC2637 (Enhanced GRE)
45 #include <netdissect-stdinc.h>
49 #include "netdissect.h"
50 #include "addrtostr.h"
52 #include "ethertype.h"
54 static const char tstr
[] = "[|gre]";
56 #define GRE_CP 0x8000 /* checksum present */
57 #define GRE_RP 0x4000 /* routing present */
58 #define GRE_KP 0x2000 /* key present */
59 #define GRE_SP 0x1000 /* sequence# present */
60 #define GRE_sP 0x0800 /* source routing */
61 #define GRE_RECRS 0x0700 /* recursion count */
62 #define GRE_AP 0x0080 /* acknowledgment# present */
64 static const struct tok gre_flag_values
[] = {
65 { GRE_CP
, "checksum present"},
66 { GRE_RP
, "routing present"},
67 { GRE_KP
, "key present"},
68 { GRE_SP
, "sequence# present"},
69 { GRE_sP
, "source routing present"},
70 { GRE_RECRS
, "recursion count"},
71 { GRE_AP
, "ack present"},
75 #define GRE_VERS_MASK 0x0007 /* protocol version */
77 /* source route entry types */
78 #define GRESRE_IP 0x0800 /* IP */
79 #define GRESRE_ASN 0xfffe /* ASN */
81 static void gre_print_0(netdissect_options
*, const u_char
*, u_int
);
82 static void gre_print_1(netdissect_options
*, const u_char
*, u_int
);
83 static int gre_sre_print(netdissect_options
*, uint16_t, uint8_t, uint8_t, const u_char
*, u_int
);
84 static int gre_sre_ip_print(netdissect_options
*, uint8_t, uint8_t, const u_char
*, u_int
);
85 static int gre_sre_asn_print(netdissect_options
*, uint8_t, uint8_t, const u_char
*, u_int
);
88 gre_print(netdissect_options
*ndo
, const u_char
*bp
, u_int length
)
90 u_int len
= length
, vers
;
95 vers
= EXTRACT_BE_U_2(bp
) & GRE_VERS_MASK
;
96 ND_PRINT("GREv%u",vers
);
100 gre_print_0(ndo
, bp
, len
);
103 gre_print_1(ndo
, bp
, len
);
106 ND_PRINT(" ERROR: unknown-version");
112 ND_PRINT("%s", tstr
);
117 gre_print_0(netdissect_options
*ndo
, const u_char
*bp
, u_int length
)
120 uint16_t flags
, prot
;
122 /* 16 bits ND_TCHECKed in gre_print() */
123 flags
= EXTRACT_BE_U_2(bp
);
125 ND_PRINT(", Flags [%s]",
126 bittok2str(gre_flag_values
,"none",flags
));
134 prot
= EXTRACT_BE_U_2(bp
);
138 if ((flags
& GRE_CP
) | (flags
& GRE_RP
)) {
143 ND_PRINT(", sum 0x%x", EXTRACT_BE_U_2(bp
));
150 ND_PRINT(", off 0x%x", EXTRACT_BE_U_2(bp
));
155 if (flags
& GRE_KP
) {
159 ND_PRINT(", key=0x%x", EXTRACT_BE_U_4(bp
));
164 if (flags
& GRE_SP
) {
168 ND_PRINT(", seq %u", EXTRACT_BE_U_4(bp
));
173 if (flags
& GRE_RP
) {
182 af
= EXTRACT_BE_U_2(bp
);
183 sreoff
= EXTRACT_U_1(bp
+ 2);
184 srelen
= EXTRACT_U_1(bp
+ 3);
188 if (af
== 0 && srelen
== 0)
191 if (!gre_sre_print(ndo
, af
, sreoff
, srelen
, bp
, len
))
202 ND_PRINT(", proto %s (0x%04x)",
203 tok2str(ethertype_values
,"unknown",prot
),
206 ND_PRINT(", length %u",length
);
208 if (ndo
->ndo_vflag
< 1)
209 ND_PRINT(": "); /* put in a colon as protocol demarc */
211 ND_PRINT("\n\t"); /* if verbose go multiline */
215 ip_print(ndo
, bp
, len
);
218 ip6_print(ndo
, bp
, len
);
221 mpls_print(ndo
, bp
, len
);
224 ipx_print(ndo
, bp
, len
);
226 case ETHERTYPE_ATALK
:
227 atalk_print(ndo
, bp
, len
);
229 case ETHERTYPE_GRE_ISO
:
230 isoclns_print(ndo
, bp
, len
);
233 ether_print(ndo
, bp
, len
, ndo
->ndo_snapend
- bp
, NULL
, NULL
);
236 ND_PRINT("gre-proto-0x%x", prot
);
241 ND_PRINT("%s", tstr
);
245 gre_print_1(netdissect_options
*ndo
, const u_char
*bp
, u_int length
)
248 uint16_t flags
, prot
;
250 /* 16 bits ND_TCHECKed in gre_print() */
251 flags
= EXTRACT_BE_U_2(bp
);
256 ND_PRINT(", Flags [%s]",
257 bittok2str(gre_flag_values
,"none",flags
));
262 prot
= EXTRACT_BE_U_2(bp
);
267 if (flags
& GRE_KP
) {
273 k
= EXTRACT_BE_U_4(bp
);
274 ND_PRINT(", call %u", k
& 0xffff);
279 if (flags
& GRE_SP
) {
283 ND_PRINT(", seq %u", EXTRACT_BE_U_4(bp
));
288 if (flags
& GRE_AP
) {
292 ND_PRINT(", ack %u", EXTRACT_BE_U_4(bp
));
297 if ((flags
& GRE_SP
) == 0)
298 ND_PRINT(", no-payload");
301 ND_PRINT(", proto %s (0x%04x)",
302 tok2str(ethertype_values
,"unknown",prot
),
305 ND_PRINT(", length %u",length
);
307 if ((flags
& GRE_SP
) == 0)
310 if (ndo
->ndo_vflag
< 1)
311 ND_PRINT(": "); /* put in a colon as protocol demarc */
313 ND_PRINT("\n\t"); /* if verbose go multiline */
317 ppp_print(ndo
, bp
, len
);
320 ND_PRINT("gre-proto-0x%x", prot
);
326 ND_PRINT("%s", tstr
);
330 gre_sre_print(netdissect_options
*ndo
, uint16_t af
, uint8_t sreoff
,
331 uint8_t srelen
, const u_char
*bp
, u_int len
)
337 ND_PRINT(", (rtaf=ip");
338 ret
= gre_sre_ip_print(ndo
, sreoff
, srelen
, bp
, len
);
342 ND_PRINT(", (rtaf=asn");
343 ret
= gre_sre_asn_print(ndo
, sreoff
, srelen
, bp
, len
);
347 ND_PRINT(", (rtaf=0x%x)", af
);
354 gre_sre_ip_print(netdissect_options
*ndo
, uint8_t sreoff
, uint8_t srelen
,
355 const u_char
*bp
, u_int len
)
357 const u_char
*up
= bp
;
358 char buf
[INET_ADDRSTRLEN
];
361 ND_PRINT(", badoffset=%u", sreoff
);
365 ND_PRINT(", badlength=%u", srelen
);
368 if (sreoff
>= srelen
) {
369 ND_PRINT(", badoff/len=%u/%u", sreoff
, srelen
);
373 while (srelen
!= 0) {
379 addrtostr(bp
, buf
, sizeof(buf
));
381 ((bp
- up
) == sreoff
) ? "*" : "", buf
);
391 gre_sre_asn_print(netdissect_options
*ndo
, uint8_t sreoff
, uint8_t srelen
,
392 const u_char
*bp
, u_int len
)
394 const u_char
*up
= bp
;
397 ND_PRINT(", badoffset=%u", sreoff
);
401 ND_PRINT(", badlength=%u", srelen
);
404 if (sreoff
>= srelen
) {
405 ND_PRINT(", badoff/len=%u/%u", sreoff
, srelen
);
409 while (srelen
!= 0) {
416 ((bp
- up
) == sreoff
) ? "*" : "",