blob: 0c13d2a75734f54ebfc5718b07b2475dd4757c0b [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.
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.
20 *
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.
32 */
33
Elliott Hughese2e3bd12017-05-15 10:59:29 -070034/* \summary: Generic Routing Encapsulation (GRE) printer */
35
The Android Open Source Project2949f582009-03-03 19:30:46 -080036/*
Elliott Hughese2e3bd12017-05-15 10:59:29 -070037 * netdissect printer for GRE - Generic Routing Encapsulation
The Android Open Source Project2949f582009-03-03 19:30:46 -080038 * RFC1701 (GRE), RFC1702 (GRE IPv4), and RFC2637 (Enhanced GRE)
39 */
40
The Android Open Source Project2949f582009-03-03 19:30:46 -080041#ifdef HAVE_CONFIG_H
42#include "config.h"
43#endif
44
Elliott Hughese2e3bd12017-05-15 10:59:29 -070045#include <netdissect-stdinc.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080046
The Android Open Source Project2949f582009-03-03 19:30:46 -080047#include <string.h>
48
Elliott Hughese2e3bd12017-05-15 10:59:29 -070049#include "netdissect.h"
50#include "addrtostr.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080051#include "extract.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080052#include "ethertype.h"
53
Elliott Hughes892a68b2015-10-19 14:43:53 -070054static const char tstr[] = "[|gre]";
55
The Android Open Source Project2949f582009-03-03 19:30:46 -080056#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 */
63
JP Abgrall53f17a92014-02-12 14:02:41 -080064static const struct tok gre_flag_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080065 { GRE_CP, "checksum present"},
Elliott Hughes892a68b2015-10-19 14:43:53 -070066 { GRE_RP, "routing present"},
67 { GRE_KP, "key present"},
68 { GRE_SP, "sequence# present"},
The Android Open Source Project2949f582009-03-03 19:30:46 -080069 { GRE_sP, "source routing present"},
70 { GRE_RECRS, "recursion count"},
71 { GRE_AP, "ack present"},
72 { 0, NULL }
73};
74
75#define GRE_VERS_MASK 0x0007 /* protocol version */
76
77/* source route entry types */
78#define GRESRE_IP 0x0800 /* IP */
79#define GRESRE_ASN 0xfffe /* ASN */
80
Elliott Hughes892a68b2015-10-19 14:43:53 -070081static void gre_print_0(netdissect_options *, const u_char *, u_int);
82static void gre_print_1(netdissect_options *, const u_char *, u_int);
Elliott Hughese2e3bd12017-05-15 10:59:29 -070083static int gre_sre_print(netdissect_options *, uint16_t, uint8_t, uint8_t, const u_char *, u_int);
84static int gre_sre_ip_print(netdissect_options *, uint8_t, uint8_t, const u_char *, u_int);
85static 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 -080086
87void
Elliott Hughes892a68b2015-10-19 14:43:53 -070088gre_print(netdissect_options *ndo, const u_char *bp, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -080089{
90 u_int len = length, vers;
91
Elliott Hughese2e3bd12017-05-15 10:59:29 -070092 ND_TCHECK2(*bp, 2);
93 if (len < 2)
94 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -080095 vers = EXTRACT_16BITS(bp) & GRE_VERS_MASK;
Elliott Hughes892a68b2015-10-19 14:43:53 -070096 ND_PRINT((ndo, "GREv%u",vers));
The Android Open Source Project2949f582009-03-03 19:30:46 -080097
98 switch(vers) {
99 case 0:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700100 gre_print_0(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800101 break;
102 case 1:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700103 gre_print_1(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800104 break;
105 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700106 ND_PRINT((ndo, " ERROR: unknown-version"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800107 break;
108 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700109 return;
110
111trunc:
112 ND_PRINT((ndo, "%s", tstr));
113 return;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800114}
115
Elliott Hughes892a68b2015-10-19 14:43:53 -0700116static void
117gre_print_0(netdissect_options *ndo, const u_char *bp, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800118{
119 u_int len = length;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700120 uint16_t flags, prot;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800121
122 flags = EXTRACT_16BITS(bp);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700123 if (ndo->ndo_vflag)
124 ND_PRINT((ndo, ", Flags [%s]",
125 bittok2str(gre_flag_values,"none",flags)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800126
127 len -= 2;
128 bp += 2;
129
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700130 ND_TCHECK2(*bp, 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800131 if (len < 2)
132 goto trunc;
133 prot = EXTRACT_16BITS(bp);
134 len -= 2;
135 bp += 2;
136
137 if ((flags & GRE_CP) | (flags & GRE_RP)) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700138 ND_TCHECK2(*bp, 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800139 if (len < 2)
140 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700141 if (ndo->ndo_vflag)
142 ND_PRINT((ndo, ", sum 0x%x", EXTRACT_16BITS(bp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800143 bp += 2;
144 len -= 2;
145
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700146 ND_TCHECK2(*bp, 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800147 if (len < 2)
148 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700149 ND_PRINT((ndo, ", off 0x%x", EXTRACT_16BITS(bp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800150 bp += 2;
151 len -= 2;
152 }
153
154 if (flags & GRE_KP) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700155 ND_TCHECK2(*bp, 4);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800156 if (len < 4)
157 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700158 ND_PRINT((ndo, ", key=0x%x", EXTRACT_32BITS(bp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800159 bp += 4;
160 len -= 4;
161 }
162
163 if (flags & GRE_SP) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700164 ND_TCHECK2(*bp, 4);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800165 if (len < 4)
166 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700167 ND_PRINT((ndo, ", seq %u", EXTRACT_32BITS(bp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800168 bp += 4;
169 len -= 4;
170 }
171
172 if (flags & GRE_RP) {
173 for (;;) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700174 uint16_t af;
175 uint8_t sreoff;
176 uint8_t srelen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800177
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700178 ND_TCHECK2(*bp, 4);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800179 if (len < 4)
180 goto trunc;
181 af = EXTRACT_16BITS(bp);
182 sreoff = *(bp + 2);
183 srelen = *(bp + 3);
184 bp += 4;
185 len -= 4;
186
187 if (af == 0 && srelen == 0)
188 break;
189
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700190 if (!gre_sre_print(ndo, af, sreoff, srelen, bp, len))
191 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800192
193 if (len < srelen)
194 goto trunc;
195 bp += srelen;
196 len -= srelen;
197 }
198 }
199
Elliott Hughes892a68b2015-10-19 14:43:53 -0700200 if (ndo->ndo_eflag)
201 ND_PRINT((ndo, ", proto %s (0x%04x)",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800202 tok2str(ethertype_values,"unknown",prot),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700203 prot));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800204
Elliott Hughes892a68b2015-10-19 14:43:53 -0700205 ND_PRINT((ndo, ", length %u",length));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800206
Elliott Hughes892a68b2015-10-19 14:43:53 -0700207 if (ndo->ndo_vflag < 1)
208 ND_PRINT((ndo, ": ")); /* put in a colon as protocol demarc */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800209 else
Elliott Hughes892a68b2015-10-19 14:43:53 -0700210 ND_PRINT((ndo, "\n\t")); /* if verbose go multiline */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800211
212 switch (prot) {
213 case ETHERTYPE_IP:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700214 ip_print(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800215 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800216 case ETHERTYPE_IPV6:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700217 ip6_print(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800218 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800219 case ETHERTYPE_MPLS:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700220 mpls_print(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800221 break;
222 case ETHERTYPE_IPX:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700223 ipx_print(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800224 break;
225 case ETHERTYPE_ATALK:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700226 atalk_print(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800227 break;
228 case ETHERTYPE_GRE_ISO:
Elliott Hughescec480a2017-12-19 16:54:57 -0800229 isoclns_print(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800230 break;
JP Abgrall53f17a92014-02-12 14:02:41 -0800231 case ETHERTYPE_TEB:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700232 ether_print(ndo, bp, len, ndo->ndo_snapend - bp, NULL, NULL);
JP Abgrall53f17a92014-02-12 14:02:41 -0800233 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800234 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700235 ND_PRINT((ndo, "gre-proto-0x%x", prot));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800236 }
237 return;
238
239trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700240 ND_PRINT((ndo, "%s", tstr));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800241}
242
Elliott Hughes892a68b2015-10-19 14:43:53 -0700243static void
244gre_print_1(netdissect_options *ndo, const u_char *bp, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800245{
246 u_int len = length;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700247 uint16_t flags, prot;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800248
249 flags = EXTRACT_16BITS(bp);
250 len -= 2;
251 bp += 2;
252
Elliott Hughes892a68b2015-10-19 14:43:53 -0700253 if (ndo->ndo_vflag)
254 ND_PRINT((ndo, ", Flags [%s]",
255 bittok2str(gre_flag_values,"none",flags)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800256
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700257 ND_TCHECK2(*bp, 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800258 if (len < 2)
259 goto trunc;
260 prot = EXTRACT_16BITS(bp);
261 len -= 2;
262 bp += 2;
263
264
265 if (flags & GRE_KP) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700266 uint32_t k;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800267
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700268 ND_TCHECK2(*bp, 4);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800269 if (len < 4)
270 goto trunc;
271 k = EXTRACT_32BITS(bp);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700272 ND_PRINT((ndo, ", call %d", k & 0xffff));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800273 len -= 4;
274 bp += 4;
275 }
276
277 if (flags & GRE_SP) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700278 ND_TCHECK2(*bp, 4);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800279 if (len < 4)
280 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700281 ND_PRINT((ndo, ", seq %u", EXTRACT_32BITS(bp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800282 bp += 4;
283 len -= 4;
284 }
285
286 if (flags & GRE_AP) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700287 ND_TCHECK2(*bp, 4);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800288 if (len < 4)
289 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700290 ND_PRINT((ndo, ", ack %u", EXTRACT_32BITS(bp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800291 bp += 4;
292 len -= 4;
293 }
294
295 if ((flags & GRE_SP) == 0)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700296 ND_PRINT((ndo, ", no-payload"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800297
Elliott Hughes892a68b2015-10-19 14:43:53 -0700298 if (ndo->ndo_eflag)
299 ND_PRINT((ndo, ", proto %s (0x%04x)",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800300 tok2str(ethertype_values,"unknown",prot),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700301 prot));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800302
Elliott Hughes892a68b2015-10-19 14:43:53 -0700303 ND_PRINT((ndo, ", length %u",length));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800304
305 if ((flags & GRE_SP) == 0)
306 return;
307
Elliott Hughes892a68b2015-10-19 14:43:53 -0700308 if (ndo->ndo_vflag < 1)
309 ND_PRINT((ndo, ": ")); /* put in a colon as protocol demarc */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800310 else
Elliott Hughes892a68b2015-10-19 14:43:53 -0700311 ND_PRINT((ndo, "\n\t")); /* if verbose go multiline */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800312
313 switch (prot) {
314 case ETHERTYPE_PPP:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700315 ppp_print(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800316 break;
317 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700318 ND_PRINT((ndo, "gre-proto-0x%x", prot));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800319 break;
320 }
321 return;
322
323trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700324 ND_PRINT((ndo, "%s", tstr));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800325}
326
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700327static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700328gre_sre_print(netdissect_options *ndo, uint16_t af, uint8_t sreoff,
329 uint8_t srelen, const u_char *bp, u_int len)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800330{
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700331 int ret;
332
The Android Open Source Project2949f582009-03-03 19:30:46 -0800333 switch (af) {
334 case GRESRE_IP:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700335 ND_PRINT((ndo, ", (rtaf=ip"));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700336 ret = gre_sre_ip_print(ndo, sreoff, srelen, bp, len);
337 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800338 break;
339 case GRESRE_ASN:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700340 ND_PRINT((ndo, ", (rtaf=asn"));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700341 ret = gre_sre_asn_print(ndo, sreoff, srelen, bp, len);
342 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800343 break;
344 default:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700345 ND_PRINT((ndo, ", (rtaf=0x%x)", af));
346 ret = 1;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800347 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700348 return (ret);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800349}
Elliott Hughes892a68b2015-10-19 14:43:53 -0700350
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700351static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700352gre_sre_ip_print(netdissect_options *ndo, uint8_t sreoff, uint8_t srelen,
353 const u_char *bp, u_int len)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800354{
The Android Open Source Project2949f582009-03-03 19:30:46 -0800355 const u_char *up = bp;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700356 char buf[INET_ADDRSTRLEN];
The Android Open Source Project2949f582009-03-03 19:30:46 -0800357
358 if (sreoff & 3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700359 ND_PRINT((ndo, ", badoffset=%u", sreoff));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700360 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800361 }
362 if (srelen & 3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700363 ND_PRINT((ndo, ", badlength=%u", srelen));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700364 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800365 }
366 if (sreoff >= srelen) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700367 ND_PRINT((ndo, ", badoff/len=%u/%u", sreoff, srelen));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700368 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800369 }
370
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700371 while (srelen != 0) {
372 if (!ND_TTEST2(*bp, 4))
373 return (0);
374 if (len < 4)
375 return (0);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800376
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700377 addrtostr(bp, buf, sizeof(buf));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700378 ND_PRINT((ndo, " %s%s",
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700379 ((bp - up) == sreoff) ? "*" : "", buf));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800380
381 bp += 4;
382 len -= 4;
383 srelen -= 4;
384 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700385 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800386}
387
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700388static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700389gre_sre_asn_print(netdissect_options *ndo, uint8_t sreoff, uint8_t srelen,
390 const u_char *bp, u_int len)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800391{
392 const u_char *up = bp;
393
394 if (sreoff & 1) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700395 ND_PRINT((ndo, ", badoffset=%u", sreoff));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700396 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800397 }
398 if (srelen & 1) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700399 ND_PRINT((ndo, ", badlength=%u", srelen));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700400 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800401 }
402 if (sreoff >= srelen) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700403 ND_PRINT((ndo, ", badoff/len=%u/%u", sreoff, srelen));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700404 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800405 }
406
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700407 while (srelen != 0) {
408 if (!ND_TTEST2(*bp, 2))
409 return (0);
410 if (len < 2)
411 return (0);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800412
Elliott Hughes892a68b2015-10-19 14:43:53 -0700413 ND_PRINT((ndo, " %s%x",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800414 ((bp - up) == sreoff) ? "*" : "",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700415 EXTRACT_16BITS(bp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800416
417 bp += 2;
418 len -= 2;
419 srelen -= 2;
420 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700421 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800422}