blob: b1a814298b5571cb3bc292cf47e2cec0a5cd169b [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/* $OpenBSD: print-gre.c,v 1.6 2002/10/30 03:04:04 fgsch Exp $ */
2
3/*
4 * Copyright (c) 2002 Jason L. Wright (jason@thought.net)
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
The Android Open Source Project2949f582009-03-03 19:30:46 -080015 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
Elliott Hughese2e3bd12017-05-15 10:59:29 -070029/* \summary: Generic Routing Encapsulation (GRE) printer */
30
The Android Open Source Project2949f582009-03-03 19:30:46 -080031/*
Elliott Hughese2e3bd12017-05-15 10:59:29 -070032 * netdissect printer for GRE - Generic Routing Encapsulation
The Android Open Source Project2949f582009-03-03 19:30:46 -080033 * RFC1701 (GRE), RFC1702 (GRE IPv4), and RFC2637 (Enhanced GRE)
34 */
35
The Android Open Source Project2949f582009-03-03 19:30:46 -080036#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070037#include <config.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080038#endif
39
Elliott Hughes820eced2021-08-20 18:00:50 -070040#include "netdissect-stdinc.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080041
Elliott Hughese2e3bd12017-05-15 10:59:29 -070042#include "netdissect.h"
43#include "addrtostr.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080044#include "extract.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080045#include "ethertype.h"
46
Elliott Hughes892a68b2015-10-19 14:43:53 -070047
The Android Open Source Project2949f582009-03-03 19:30:46 -080048#define GRE_CP 0x8000 /* checksum present */
49#define GRE_RP 0x4000 /* routing present */
50#define GRE_KP 0x2000 /* key present */
51#define GRE_SP 0x1000 /* sequence# present */
52#define GRE_sP 0x0800 /* source routing */
The Android Open Source Project2949f582009-03-03 19:30:46 -080053#define GRE_AP 0x0080 /* acknowledgment# present */
54
JP Abgrall53f17a92014-02-12 14:02:41 -080055static const struct tok gre_flag_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080056 { GRE_CP, "checksum present"},
Elliott Hughes892a68b2015-10-19 14:43:53 -070057 { GRE_RP, "routing present"},
58 { GRE_KP, "key present"},
59 { GRE_SP, "sequence# present"},
The Android Open Source Project2949f582009-03-03 19:30:46 -080060 { GRE_sP, "source routing present"},
The Android Open Source Project2949f582009-03-03 19:30:46 -080061 { GRE_AP, "ack present"},
62 { 0, NULL }
63};
64
Elliott Hughes820eced2021-08-20 18:00:50 -070065#define GRE_RECRS_MASK 0x0700 /* recursion count */
The Android Open Source Project2949f582009-03-03 19:30:46 -080066#define GRE_VERS_MASK 0x0007 /* protocol version */
67
68/* source route entry types */
69#define GRESRE_IP 0x0800 /* IP */
70#define GRESRE_ASN 0xfffe /* ASN */
71
Elliott Hughes892a68b2015-10-19 14:43:53 -070072static void gre_print_0(netdissect_options *, const u_char *, u_int);
73static void gre_print_1(netdissect_options *, const u_char *, u_int);
Elliott Hughese2e3bd12017-05-15 10:59:29 -070074static int gre_sre_print(netdissect_options *, uint16_t, uint8_t, uint8_t, const u_char *, u_int);
75static int gre_sre_ip_print(netdissect_options *, uint8_t, uint8_t, const u_char *, u_int);
76static int gre_sre_asn_print(netdissect_options *, uint8_t, uint8_t, const u_char *, u_int);
The Android Open Source Project2949f582009-03-03 19:30:46 -080077
78void
Elliott Hughes892a68b2015-10-19 14:43:53 -070079gre_print(netdissect_options *ndo, const u_char *bp, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -080080{
81 u_int len = length, vers;
82
Elliott Hughes820eced2021-08-20 18:00:50 -070083 ndo->ndo_protocol = "gre";
84 ND_TCHECK_2(bp);
Elliott Hughese2e3bd12017-05-15 10:59:29 -070085 if (len < 2)
86 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -070087 vers = GET_BE_U_2(bp) & GRE_VERS_MASK;
88 ND_PRINT("GREv%u",vers);
The Android Open Source Project2949f582009-03-03 19:30:46 -080089
Elliott Hughes820eced2021-08-20 18:00:50 -070090 switch(vers) {
91 case 0:
92 gre_print_0(ndo, bp, len);
93 break;
94 case 1:
95 gre_print_1(ndo, bp, len);
96 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -080097 default:
Elliott Hughes820eced2021-08-20 18:00:50 -070098 ND_PRINT(" ERROR: unknown-version");
99 break;
100 }
101 return;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700102
103trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -0700104 nd_print_trunc(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800105}
106
Elliott Hughes892a68b2015-10-19 14:43:53 -0700107static void
108gre_print_0(netdissect_options *ndo, const u_char *bp, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800109{
110 u_int len = length;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700111 uint16_t flags, prot;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800112
Elliott Hughes820eced2021-08-20 18:00:50 -0700113 /* 16 bits ND_TCHECKed in gre_print() */
114 flags = GET_BE_U_2(bp);
115 if (ndo->ndo_vflag)
116 ND_PRINT(", Flags [%s]",
117 bittok2str(gre_flag_values,"none",flags));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800118
119 len -= 2;
120 bp += 2;
121
Elliott Hughes820eced2021-08-20 18:00:50 -0700122 ND_TCHECK_2(bp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800123 if (len < 2)
124 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700125 prot = GET_BE_U_2(bp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800126 len -= 2;
127 bp += 2;
128
129 if ((flags & GRE_CP) | (flags & GRE_RP)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700130 ND_TCHECK_2(bp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800131 if (len < 2)
132 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700133 if (ndo->ndo_vflag)
Elliott Hughes820eced2021-08-20 18:00:50 -0700134 ND_PRINT(", sum 0x%x", GET_BE_U_2(bp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800135 bp += 2;
136 len -= 2;
137
Elliott Hughes820eced2021-08-20 18:00:50 -0700138 ND_TCHECK_2(bp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800139 if (len < 2)
140 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700141 ND_PRINT(", off 0x%x", GET_BE_U_2(bp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800142 bp += 2;
143 len -= 2;
144 }
145
146 if (flags & GRE_KP) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700147 ND_TCHECK_4(bp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800148 if (len < 4)
149 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700150 ND_PRINT(", key=0x%x", GET_BE_U_4(bp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800151 bp += 4;
152 len -= 4;
153 }
154
155 if (flags & GRE_SP) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700156 ND_TCHECK_4(bp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800157 if (len < 4)
158 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700159 ND_PRINT(", seq %u", GET_BE_U_4(bp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800160 bp += 4;
161 len -= 4;
162 }
163
164 if (flags & GRE_RP) {
165 for (;;) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700166 uint16_t af;
167 uint8_t sreoff;
168 uint8_t srelen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800169
Elliott Hughes820eced2021-08-20 18:00:50 -0700170 ND_TCHECK_4(bp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800171 if (len < 4)
172 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700173 af = GET_BE_U_2(bp);
174 sreoff = GET_U_1(bp + 2);
175 srelen = GET_U_1(bp + 3);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800176 bp += 4;
177 len -= 4;
178
179 if (af == 0 && srelen == 0)
180 break;
181
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700182 if (!gre_sre_print(ndo, af, sreoff, srelen, bp, len))
183 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800184
185 if (len < srelen)
186 goto trunc;
187 bp += srelen;
188 len -= srelen;
189 }
190 }
191
Elliott Hughes820eced2021-08-20 18:00:50 -0700192 if (ndo->ndo_eflag)
193 ND_PRINT(", proto %s (0x%04x)",
194 tok2str(ethertype_values,"unknown",prot), prot);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800195
Elliott Hughes820eced2021-08-20 18:00:50 -0700196 ND_PRINT(", length %u",length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800197
Elliott Hughes820eced2021-08-20 18:00:50 -0700198 if (ndo->ndo_vflag < 1)
199 ND_PRINT(": "); /* put in a colon as protocol demarc */
200 else
201 ND_PRINT("\n\t"); /* if verbose go multiline */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800202
203 switch (prot) {
204 case ETHERTYPE_IP:
Elliott Hughes820eced2021-08-20 18:00:50 -0700205 ip_print(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800206 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800207 case ETHERTYPE_IPV6:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700208 ip6_print(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800209 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800210 case ETHERTYPE_MPLS:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700211 mpls_print(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800212 break;
213 case ETHERTYPE_IPX:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700214 ipx_print(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800215 break;
216 case ETHERTYPE_ATALK:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700217 atalk_print(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800218 break;
219 case ETHERTYPE_GRE_ISO:
Elliott Hughescec480a2017-12-19 16:54:57 -0800220 isoclns_print(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800221 break;
JP Abgrall53f17a92014-02-12 14:02:41 -0800222 case ETHERTYPE_TEB:
Elliott Hughes820eced2021-08-20 18:00:50 -0700223 ether_print(ndo, bp, len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
JP Abgrall53f17a92014-02-12 14:02:41 -0800224 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800225 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700226 ND_PRINT("gre-proto-0x%x", prot);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800227 }
228 return;
229
230trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -0700231 nd_print_trunc(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800232}
233
Elliott Hughes892a68b2015-10-19 14:43:53 -0700234static void
235gre_print_1(netdissect_options *ndo, const u_char *bp, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800236{
237 u_int len = length;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700238 uint16_t flags, prot;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800239
Elliott Hughes820eced2021-08-20 18:00:50 -0700240 /* 16 bits ND_TCHECKed in gre_print() */
241 flags = GET_BE_U_2(bp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800242 len -= 2;
243 bp += 2;
244
Elliott Hughes892a68b2015-10-19 14:43:53 -0700245 if (ndo->ndo_vflag)
Elliott Hughes820eced2021-08-20 18:00:50 -0700246 ND_PRINT(", Flags [%s]",
247 bittok2str(gre_flag_values,"none",flags));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800248
Elliott Hughes820eced2021-08-20 18:00:50 -0700249 ND_TCHECK_2(bp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800250 if (len < 2)
251 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700252 prot = GET_BE_U_2(bp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800253 len -= 2;
254 bp += 2;
255
256
257 if (flags & GRE_KP) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700258 uint32_t k;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800259
Elliott Hughes820eced2021-08-20 18:00:50 -0700260 ND_TCHECK_4(bp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800261 if (len < 4)
262 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700263 k = GET_BE_U_4(bp);
264 ND_PRINT(", call %u", k & 0xffff);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800265 len -= 4;
266 bp += 4;
267 }
268
269 if (flags & GRE_SP) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700270 ND_TCHECK_4(bp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800271 if (len < 4)
272 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700273 ND_PRINT(", seq %u", GET_BE_U_4(bp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800274 bp += 4;
275 len -= 4;
276 }
277
278 if (flags & GRE_AP) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700279 ND_TCHECK_4(bp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800280 if (len < 4)
281 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700282 ND_PRINT(", ack %u", GET_BE_U_4(bp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800283 bp += 4;
284 len -= 4;
285 }
286
287 if ((flags & GRE_SP) == 0)
Elliott Hughes820eced2021-08-20 18:00:50 -0700288 ND_PRINT(", no-payload");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800289
Elliott Hughes820eced2021-08-20 18:00:50 -0700290 if (ndo->ndo_eflag)
291 ND_PRINT(", proto %s (0x%04x)",
292 tok2str(ethertype_values,"unknown",prot), prot);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800293
Elliott Hughes820eced2021-08-20 18:00:50 -0700294 ND_PRINT(", length %u",length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800295
Elliott Hughes820eced2021-08-20 18:00:50 -0700296 if ((flags & GRE_SP) == 0)
297 return;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800298
Elliott Hughes820eced2021-08-20 18:00:50 -0700299 if (ndo->ndo_vflag < 1)
300 ND_PRINT(": "); /* put in a colon as protocol demarc */
301 else
302 ND_PRINT("\n\t"); /* if verbose go multiline */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800303
304 switch (prot) {
305 case ETHERTYPE_PPP:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700306 ppp_print(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800307 break;
308 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700309 ND_PRINT("gre-proto-0x%x", prot);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800310 break;
311 }
312 return;
313
314trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -0700315 nd_print_trunc(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800316}
317
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700318static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700319gre_sre_print(netdissect_options *ndo, uint16_t af, uint8_t sreoff,
Elliott Hughes820eced2021-08-20 18:00:50 -0700320 uint8_t srelen, const u_char *bp, u_int len)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800321{
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700322 int ret;
323
The Android Open Source Project2949f582009-03-03 19:30:46 -0800324 switch (af) {
325 case GRESRE_IP:
Elliott Hughes820eced2021-08-20 18:00:50 -0700326 ND_PRINT(", (rtaf=ip");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700327 ret = gre_sre_ip_print(ndo, sreoff, srelen, bp, len);
Elliott Hughes820eced2021-08-20 18:00:50 -0700328 ND_PRINT(")");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800329 break;
330 case GRESRE_ASN:
Elliott Hughes820eced2021-08-20 18:00:50 -0700331 ND_PRINT(", (rtaf=asn");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700332 ret = gre_sre_asn_print(ndo, sreoff, srelen, bp, len);
Elliott Hughes820eced2021-08-20 18:00:50 -0700333 ND_PRINT(")");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800334 break;
335 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700336 ND_PRINT(", (rtaf=0x%x)", af);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700337 ret = 1;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800338 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700339 return (ret);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800340}
Elliott Hughes892a68b2015-10-19 14:43:53 -0700341
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700342static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700343gre_sre_ip_print(netdissect_options *ndo, uint8_t sreoff, uint8_t srelen,
Elliott Hughes820eced2021-08-20 18:00:50 -0700344 const u_char *bp, u_int len)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800345{
The Android Open Source Project2949f582009-03-03 19:30:46 -0800346 const u_char *up = bp;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700347 char buf[INET_ADDRSTRLEN];
The Android Open Source Project2949f582009-03-03 19:30:46 -0800348
349 if (sreoff & 3) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700350 ND_PRINT(", badoffset=%u", sreoff);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700351 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800352 }
353 if (srelen & 3) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700354 ND_PRINT(", badlength=%u", srelen);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700355 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800356 }
357 if (sreoff >= srelen) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700358 ND_PRINT(", badoff/len=%u/%u", sreoff, srelen);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700359 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800360 }
361
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700362 while (srelen != 0) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700363 ND_TCHECK_4(bp);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700364 if (len < 4)
365 return (0);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800366
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700367 addrtostr(bp, buf, sizeof(buf));
Elliott Hughes820eced2021-08-20 18:00:50 -0700368 ND_PRINT(" %s%s",
369 ((bp - up) == sreoff) ? "*" : "", buf);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800370
371 bp += 4;
372 len -= 4;
373 srelen -= 4;
374 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700375 return (1);
Elliott Hughes820eced2021-08-20 18:00:50 -0700376trunc:
377 return 0;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800378}
379
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700380static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700381gre_sre_asn_print(netdissect_options *ndo, uint8_t sreoff, uint8_t srelen,
Elliott Hughes820eced2021-08-20 18:00:50 -0700382 const u_char *bp, u_int len)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800383{
384 const u_char *up = bp;
385
386 if (sreoff & 1) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700387 ND_PRINT(", badoffset=%u", sreoff);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700388 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800389 }
390 if (srelen & 1) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700391 ND_PRINT(", badlength=%u", srelen);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700392 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800393 }
394 if (sreoff >= srelen) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700395 ND_PRINT(", badoff/len=%u/%u", sreoff, srelen);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700396 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800397 }
398
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700399 while (srelen != 0) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700400 ND_TCHECK_2(bp);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700401 if (len < 2)
402 return (0);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800403
Elliott Hughes820eced2021-08-20 18:00:50 -0700404 ND_PRINT(" %s%x",
405 ((bp - up) == sreoff) ? "*" : "", GET_BE_U_2(bp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800406
407 bp += 2;
408 len -= 2;
409 srelen -= 2;
410 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700411 return (1);
Elliott Hughes820eced2021-08-20 18:00:50 -0700412trunc:
413 return 0;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800414}