xref: /dflybsd-src/contrib/tcpdump/print-gre.c (revision 59c07fbdf8168fa08c76c515186d561b5a92690c)
141c99275SPeter Avalos /*	$OpenBSD: print-gre.c,v 1.6 2002/10/30 03:04:04 fgsch Exp $	*/
241c99275SPeter Avalos 
341c99275SPeter Avalos /*
441c99275SPeter Avalos  * Copyright (c) 2002 Jason L. Wright (jason@thought.net)
541c99275SPeter Avalos  * All rights reserved.
641c99275SPeter Avalos  *
741c99275SPeter Avalos  * Redistribution and use in source and binary forms, with or without
841c99275SPeter Avalos  * modification, are permitted provided that the following conditions
941c99275SPeter Avalos  * are met:
1041c99275SPeter Avalos  * 1. Redistributions of source code must retain the above copyright
1141c99275SPeter Avalos  *    notice, this list of conditions and the following disclaimer.
1241c99275SPeter Avalos  * 2. Redistributions in binary form must reproduce the above copyright
1341c99275SPeter Avalos  *    notice, this list of conditions and the following disclaimer in the
1441c99275SPeter Avalos  *    documentation and/or other materials provided with the distribution.
1541c99275SPeter Avalos  *
1641c99275SPeter Avalos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1741c99275SPeter Avalos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1841c99275SPeter Avalos  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1941c99275SPeter Avalos  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
2041c99275SPeter Avalos  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2141c99275SPeter Avalos  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2241c99275SPeter Avalos  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2341c99275SPeter Avalos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2441c99275SPeter Avalos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
2541c99275SPeter Avalos  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2641c99275SPeter Avalos  * POSSIBILITY OF SUCH DAMAGE.
2741c99275SPeter Avalos  */
2841c99275SPeter Avalos 
29411677aeSAaron LI /* \summary: Generic Routing Encapsulation (GRE) printer */
30411677aeSAaron LI 
3141c99275SPeter Avalos /*
32411677aeSAaron LI  * netdissect printer for GRE - Generic Routing Encapsulation
3341c99275SPeter Avalos  * RFC1701 (GRE), RFC1702 (GRE IPv4), and RFC2637 (Enhanced GRE)
3441c99275SPeter Avalos  */
3541c99275SPeter Avalos 
3641c99275SPeter Avalos #ifdef HAVE_CONFIG_H
37*ed775ee7SAntonio Huete Jimenez #include <config.h>
3841c99275SPeter Avalos #endif
3941c99275SPeter Avalos 
40*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
4141c99275SPeter Avalos 
42411677aeSAaron LI #include "netdissect.h"
43411677aeSAaron LI #include "addrtostr.h"
4441c99275SPeter Avalos #include "extract.h"
4541c99275SPeter Avalos #include "ethertype.h"
4641c99275SPeter Avalos 
47411677aeSAaron LI 
4841c99275SPeter Avalos #define	GRE_CP		0x8000		/* checksum present */
4941c99275SPeter Avalos #define	GRE_RP		0x4000		/* routing present */
5041c99275SPeter Avalos #define	GRE_KP		0x2000		/* key present */
5141c99275SPeter Avalos #define	GRE_SP		0x1000		/* sequence# present */
5241c99275SPeter Avalos #define	GRE_sP		0x0800		/* source routing */
5341c99275SPeter Avalos #define	GRE_AP		0x0080		/* acknowledgment# present */
5441c99275SPeter Avalos 
55411677aeSAaron LI static const struct tok gre_flag_values[] = {
5641c99275SPeter Avalos     { GRE_CP, "checksum present"},
5741c99275SPeter Avalos     { GRE_RP, "routing present"},
5841c99275SPeter Avalos     { GRE_KP, "key present"},
5941c99275SPeter Avalos     { GRE_SP, "sequence# present"},
6041c99275SPeter Avalos     { GRE_sP, "source routing present"},
6141c99275SPeter Avalos     { GRE_AP, "ack present"},
6241c99275SPeter Avalos     { 0, NULL }
6341c99275SPeter Avalos };
6441c99275SPeter Avalos 
65*ed775ee7SAntonio Huete Jimenez #define	GRE_RECRS_MASK	0x0700		/* recursion count */
6641c99275SPeter Avalos #define	GRE_VERS_MASK	0x0007		/* protocol version */
6741c99275SPeter Avalos 
6841c99275SPeter Avalos /* source route entry types */
6941c99275SPeter Avalos #define	GRESRE_IP	0x0800		/* IP */
7041c99275SPeter Avalos #define	GRESRE_ASN	0xfffe		/* ASN */
7141c99275SPeter Avalos 
72411677aeSAaron LI static void gre_print_0(netdissect_options *, const u_char *, u_int);
73411677aeSAaron LI static void gre_print_1(netdissect_options *, const u_char *, u_int);
74411677aeSAaron LI static int gre_sre_print(netdissect_options *, uint16_t, uint8_t, uint8_t, const u_char *, u_int);
75411677aeSAaron LI static int gre_sre_ip_print(netdissect_options *, uint8_t, uint8_t, const u_char *, u_int);
76411677aeSAaron LI static int gre_sre_asn_print(netdissect_options *, uint8_t, uint8_t, const u_char *, u_int);
7741c99275SPeter Avalos 
7841c99275SPeter Avalos void
gre_print(netdissect_options * ndo,const u_char * bp,u_int length)79411677aeSAaron LI gre_print(netdissect_options *ndo, const u_char *bp, u_int length)
8041c99275SPeter Avalos {
8141c99275SPeter Avalos 	u_int len = length, vers;
8241c99275SPeter Avalos 
83*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "gre";
84*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_2(bp);
85411677aeSAaron LI 	if (len < 2)
86411677aeSAaron LI 		goto trunc;
87*ed775ee7SAntonio Huete Jimenez 	vers = GET_BE_U_2(bp) & GRE_VERS_MASK;
88*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("GREv%u",vers);
8941c99275SPeter Avalos 
9041c99275SPeter Avalos 	switch(vers) {
9141c99275SPeter Avalos 	case 0:
92411677aeSAaron LI 		gre_print_0(ndo, bp, len);
9341c99275SPeter Avalos 		break;
9441c99275SPeter Avalos 	case 1:
95411677aeSAaron LI 		gre_print_1(ndo, bp, len);
9641c99275SPeter Avalos 		break;
9741c99275SPeter Avalos 	default:
98*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" ERROR: unknown-version");
9941c99275SPeter Avalos 		break;
10041c99275SPeter Avalos 	}
10141c99275SPeter Avalos 	return;
10241c99275SPeter Avalos 
103411677aeSAaron LI trunc:
104*ed775ee7SAntonio Huete Jimenez 	nd_print_trunc(ndo);
10541c99275SPeter Avalos }
10641c99275SPeter Avalos 
107411677aeSAaron LI static void
gre_print_0(netdissect_options * ndo,const u_char * bp,u_int length)108411677aeSAaron LI gre_print_0(netdissect_options *ndo, const u_char *bp, u_int length)
10941c99275SPeter Avalos {
11041c99275SPeter Avalos 	u_int len = length;
111411677aeSAaron LI 	uint16_t flags, prot;
11241c99275SPeter Avalos 
113*ed775ee7SAntonio Huete Jimenez 	/* 16 bits ND_TCHECKed in gre_print() */
114*ed775ee7SAntonio Huete Jimenez 	flags = GET_BE_U_2(bp);
115411677aeSAaron LI 	if (ndo->ndo_vflag)
116*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", Flags [%s]",
117*ed775ee7SAntonio Huete Jimenez 			 bittok2str(gre_flag_values,"none",flags));
11841c99275SPeter Avalos 
11941c99275SPeter Avalos 	len -= 2;
12041c99275SPeter Avalos 	bp += 2;
12141c99275SPeter Avalos 
122*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_2(bp);
12341c99275SPeter Avalos 	if (len < 2)
12441c99275SPeter Avalos 		goto trunc;
125*ed775ee7SAntonio Huete Jimenez 	prot = GET_BE_U_2(bp);
12641c99275SPeter Avalos 	len -= 2;
12741c99275SPeter Avalos 	bp += 2;
12841c99275SPeter Avalos 
12941c99275SPeter Avalos 	if ((flags & GRE_CP) | (flags & GRE_RP)) {
130*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_2(bp);
13141c99275SPeter Avalos 		if (len < 2)
13241c99275SPeter Avalos 			goto trunc;
133411677aeSAaron LI 		if (ndo->ndo_vflag)
134*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(", sum 0x%x", GET_BE_U_2(bp));
13541c99275SPeter Avalos 		bp += 2;
13641c99275SPeter Avalos 		len -= 2;
13741c99275SPeter Avalos 
138*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_2(bp);
13941c99275SPeter Avalos 		if (len < 2)
14041c99275SPeter Avalos 			goto trunc;
141*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", off 0x%x", GET_BE_U_2(bp));
14241c99275SPeter Avalos 		bp += 2;
14341c99275SPeter Avalos 		len -= 2;
14441c99275SPeter Avalos 	}
14541c99275SPeter Avalos 
14641c99275SPeter Avalos 	if (flags & GRE_KP) {
147*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_4(bp);
14841c99275SPeter Avalos 		if (len < 4)
14941c99275SPeter Avalos 			goto trunc;
150*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", key=0x%x", GET_BE_U_4(bp));
15141c99275SPeter Avalos 		bp += 4;
15241c99275SPeter Avalos 		len -= 4;
15341c99275SPeter Avalos 	}
15441c99275SPeter Avalos 
15541c99275SPeter Avalos 	if (flags & GRE_SP) {
156*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_4(bp);
15741c99275SPeter Avalos 		if (len < 4)
15841c99275SPeter Avalos 			goto trunc;
159*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", seq %u", GET_BE_U_4(bp));
16041c99275SPeter Avalos 		bp += 4;
16141c99275SPeter Avalos 		len -= 4;
16241c99275SPeter Avalos 	}
16341c99275SPeter Avalos 
16441c99275SPeter Avalos 	if (flags & GRE_RP) {
16541c99275SPeter Avalos 		for (;;) {
166411677aeSAaron LI 			uint16_t af;
167411677aeSAaron LI 			uint8_t sreoff;
168411677aeSAaron LI 			uint8_t srelen;
16941c99275SPeter Avalos 
170*ed775ee7SAntonio Huete Jimenez 			ND_TCHECK_4(bp);
17141c99275SPeter Avalos 			if (len < 4)
17241c99275SPeter Avalos 				goto trunc;
173*ed775ee7SAntonio Huete Jimenez 			af = GET_BE_U_2(bp);
174*ed775ee7SAntonio Huete Jimenez 			sreoff = GET_U_1(bp + 2);
175*ed775ee7SAntonio Huete Jimenez 			srelen = GET_U_1(bp + 3);
17641c99275SPeter Avalos 			bp += 4;
17741c99275SPeter Avalos 			len -= 4;
17841c99275SPeter Avalos 
17941c99275SPeter Avalos 			if (af == 0 && srelen == 0)
18041c99275SPeter Avalos 				break;
18141c99275SPeter Avalos 
182411677aeSAaron LI 			if (!gre_sre_print(ndo, af, sreoff, srelen, bp, len))
183411677aeSAaron LI 				goto trunc;
18441c99275SPeter Avalos 
18541c99275SPeter Avalos 			if (len < srelen)
18641c99275SPeter Avalos 				goto trunc;
18741c99275SPeter Avalos 			bp += srelen;
18841c99275SPeter Avalos 			len -= srelen;
18941c99275SPeter Avalos 		}
19041c99275SPeter Avalos 	}
19141c99275SPeter Avalos 
192411677aeSAaron LI 	if (ndo->ndo_eflag)
193*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", proto %s (0x%04x)",
194*ed775ee7SAntonio Huete Jimenez 			 tok2str(ethertype_values,"unknown",prot), prot);
19541c99275SPeter Avalos 
196*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(", length %u",length);
19741c99275SPeter Avalos 
198411677aeSAaron LI 	if (ndo->ndo_vflag < 1)
199*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(": "); /* put in a colon as protocol demarc */
20041c99275SPeter Avalos 	else
201*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\n\t"); /* if verbose go multiline */
20241c99275SPeter Avalos 
20341c99275SPeter Avalos 	switch (prot) {
20441c99275SPeter Avalos 	case ETHERTYPE_IP:
205411677aeSAaron LI 		ip_print(ndo, bp, len);
20641c99275SPeter Avalos 		break;
20741c99275SPeter Avalos 	case ETHERTYPE_IPV6:
208411677aeSAaron LI 		ip6_print(ndo, bp, len);
20941c99275SPeter Avalos 		break;
21041c99275SPeter Avalos 	case ETHERTYPE_MPLS:
211411677aeSAaron LI 		mpls_print(ndo, bp, len);
21241c99275SPeter Avalos 		break;
21341c99275SPeter Avalos 	case ETHERTYPE_IPX:
214411677aeSAaron LI 		ipx_print(ndo, bp, len);
21541c99275SPeter Avalos 		break;
21641c99275SPeter Avalos 	case ETHERTYPE_ATALK:
217411677aeSAaron LI 		atalk_print(ndo, bp, len);
21841c99275SPeter Avalos 		break;
21941c99275SPeter Avalos 	case ETHERTYPE_GRE_ISO:
220411677aeSAaron LI 		isoclns_print(ndo, bp, len);
22141c99275SPeter Avalos 		break;
22227bfbee1SPeter Avalos 	case ETHERTYPE_TEB:
223*ed775ee7SAntonio Huete Jimenez 		ether_print(ndo, bp, len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
22427bfbee1SPeter Avalos 		break;
22541c99275SPeter Avalos 	default:
226*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("gre-proto-0x%x", prot);
22741c99275SPeter Avalos 	}
22841c99275SPeter Avalos 	return;
22941c99275SPeter Avalos 
23041c99275SPeter Avalos trunc:
231*ed775ee7SAntonio Huete Jimenez 	nd_print_trunc(ndo);
23241c99275SPeter Avalos }
23341c99275SPeter Avalos 
234411677aeSAaron LI static void
gre_print_1(netdissect_options * ndo,const u_char * bp,u_int length)235411677aeSAaron LI gre_print_1(netdissect_options *ndo, const u_char *bp, u_int length)
23641c99275SPeter Avalos {
23741c99275SPeter Avalos 	u_int len = length;
238411677aeSAaron LI 	uint16_t flags, prot;
23941c99275SPeter Avalos 
240*ed775ee7SAntonio Huete Jimenez 	/* 16 bits ND_TCHECKed in gre_print() */
241*ed775ee7SAntonio Huete Jimenez 	flags = GET_BE_U_2(bp);
24241c99275SPeter Avalos 	len -= 2;
24341c99275SPeter Avalos 	bp += 2;
24441c99275SPeter Avalos 
245411677aeSAaron LI 	if (ndo->ndo_vflag)
246*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", Flags [%s]",
247*ed775ee7SAntonio Huete Jimenez 			 bittok2str(gre_flag_values,"none",flags));
24841c99275SPeter Avalos 
249*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_2(bp);
25041c99275SPeter Avalos 	if (len < 2)
25141c99275SPeter Avalos 		goto trunc;
252*ed775ee7SAntonio Huete Jimenez 	prot = GET_BE_U_2(bp);
25341c99275SPeter Avalos 	len -= 2;
25441c99275SPeter Avalos 	bp += 2;
25541c99275SPeter Avalos 
25641c99275SPeter Avalos 
25741c99275SPeter Avalos 	if (flags & GRE_KP) {
258411677aeSAaron LI 		uint32_t k;
25941c99275SPeter Avalos 
260*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_4(bp);
26141c99275SPeter Avalos 		if (len < 4)
26241c99275SPeter Avalos 			goto trunc;
263*ed775ee7SAntonio Huete Jimenez 		k = GET_BE_U_4(bp);
264*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", call %u", k & 0xffff);
26541c99275SPeter Avalos 		len -= 4;
26641c99275SPeter Avalos 		bp += 4;
26741c99275SPeter Avalos 	}
26841c99275SPeter Avalos 
26941c99275SPeter Avalos 	if (flags & GRE_SP) {
270*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_4(bp);
27141c99275SPeter Avalos 		if (len < 4)
27241c99275SPeter Avalos 			goto trunc;
273*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", seq %u", GET_BE_U_4(bp));
27441c99275SPeter Avalos 		bp += 4;
27541c99275SPeter Avalos 		len -= 4;
27641c99275SPeter Avalos 	}
27741c99275SPeter Avalos 
27841c99275SPeter Avalos 	if (flags & GRE_AP) {
279*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_4(bp);
28041c99275SPeter Avalos 		if (len < 4)
28141c99275SPeter Avalos 			goto trunc;
282*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", ack %u", GET_BE_U_4(bp));
28341c99275SPeter Avalos 		bp += 4;
28441c99275SPeter Avalos 		len -= 4;
28541c99275SPeter Avalos 	}
28641c99275SPeter Avalos 
28741c99275SPeter Avalos 	if ((flags & GRE_SP) == 0)
288*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", no-payload");
28941c99275SPeter Avalos 
290411677aeSAaron LI 	if (ndo->ndo_eflag)
291*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", proto %s (0x%04x)",
292*ed775ee7SAntonio Huete Jimenez 			 tok2str(ethertype_values,"unknown",prot), prot);
29341c99275SPeter Avalos 
294*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(", length %u",length);
29541c99275SPeter Avalos 
29641c99275SPeter Avalos 	if ((flags & GRE_SP) == 0)
29741c99275SPeter Avalos 		return;
29841c99275SPeter Avalos 
299411677aeSAaron LI 	if (ndo->ndo_vflag < 1)
300*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(": "); /* put in a colon as protocol demarc */
30141c99275SPeter Avalos 	else
302*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\n\t"); /* if verbose go multiline */
30341c99275SPeter Avalos 
30441c99275SPeter Avalos 	switch (prot) {
30541c99275SPeter Avalos 	case ETHERTYPE_PPP:
306411677aeSAaron LI 		ppp_print(ndo, bp, len);
30741c99275SPeter Avalos 		break;
30841c99275SPeter Avalos 	default:
309*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("gre-proto-0x%x", prot);
31041c99275SPeter Avalos 		break;
31141c99275SPeter Avalos 	}
31241c99275SPeter Avalos 	return;
31341c99275SPeter Avalos 
31441c99275SPeter Avalos trunc:
315*ed775ee7SAntonio Huete Jimenez 	nd_print_trunc(ndo);
31641c99275SPeter Avalos }
31741c99275SPeter Avalos 
318411677aeSAaron LI static int
gre_sre_print(netdissect_options * ndo,uint16_t af,uint8_t sreoff,uint8_t srelen,const u_char * bp,u_int len)319411677aeSAaron LI gre_sre_print(netdissect_options *ndo, uint16_t af, uint8_t sreoff,
320411677aeSAaron LI 	      uint8_t srelen, const u_char *bp, u_int len)
32141c99275SPeter Avalos {
322411677aeSAaron LI 	int ret;
323411677aeSAaron LI 
32441c99275SPeter Avalos 	switch (af) {
32541c99275SPeter Avalos 	case GRESRE_IP:
326*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", (rtaf=ip");
327411677aeSAaron LI 		ret = gre_sre_ip_print(ndo, sreoff, srelen, bp, len);
328*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(")");
32941c99275SPeter Avalos 		break;
33041c99275SPeter Avalos 	case GRESRE_ASN:
331*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", (rtaf=asn");
332411677aeSAaron LI 		ret = gre_sre_asn_print(ndo, sreoff, srelen, bp, len);
333*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(")");
33441c99275SPeter Avalos 		break;
33541c99275SPeter Avalos 	default:
336*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", (rtaf=0x%x)", af);
337411677aeSAaron LI 		ret = 1;
33841c99275SPeter Avalos 	}
339411677aeSAaron LI 	return (ret);
34041c99275SPeter Avalos }
341411677aeSAaron LI 
342411677aeSAaron LI static int
gre_sre_ip_print(netdissect_options * ndo,uint8_t sreoff,uint8_t srelen,const u_char * bp,u_int len)343411677aeSAaron LI gre_sre_ip_print(netdissect_options *ndo, uint8_t sreoff, uint8_t srelen,
344411677aeSAaron LI 		 const u_char *bp, u_int len)
34541c99275SPeter Avalos {
34641c99275SPeter Avalos 	const u_char *up = bp;
347411677aeSAaron LI 	char buf[INET_ADDRSTRLEN];
34841c99275SPeter Avalos 
34941c99275SPeter Avalos 	if (sreoff & 3) {
350*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", badoffset=%u", sreoff);
351411677aeSAaron LI 		return (1);
35241c99275SPeter Avalos 	}
35341c99275SPeter Avalos 	if (srelen & 3) {
354*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", badlength=%u", srelen);
355411677aeSAaron LI 		return (1);
35641c99275SPeter Avalos 	}
35741c99275SPeter Avalos 	if (sreoff >= srelen) {
358*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", badoff/len=%u/%u", sreoff, srelen);
359411677aeSAaron LI 		return (1);
36041c99275SPeter Avalos 	}
36141c99275SPeter Avalos 
362411677aeSAaron LI 	while (srelen != 0) {
363*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_4(bp);
364411677aeSAaron LI 		if (len < 4)
365411677aeSAaron LI 			return (0);
36641c99275SPeter Avalos 
367411677aeSAaron LI 		addrtostr(bp, buf, sizeof(buf));
368*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" %s%s",
369*ed775ee7SAntonio Huete Jimenez 			 ((bp - up) == sreoff) ? "*" : "", buf);
37041c99275SPeter Avalos 
37141c99275SPeter Avalos 		bp += 4;
37241c99275SPeter Avalos 		len -= 4;
37341c99275SPeter Avalos 		srelen -= 4;
37441c99275SPeter Avalos 	}
375411677aeSAaron LI 	return (1);
376*ed775ee7SAntonio Huete Jimenez trunc:
377*ed775ee7SAntonio Huete Jimenez 	return 0;
37841c99275SPeter Avalos }
37941c99275SPeter Avalos 
380411677aeSAaron LI static int
gre_sre_asn_print(netdissect_options * ndo,uint8_t sreoff,uint8_t srelen,const u_char * bp,u_int len)381411677aeSAaron LI gre_sre_asn_print(netdissect_options *ndo, uint8_t sreoff, uint8_t srelen,
382411677aeSAaron LI 		  const u_char *bp, u_int len)
38341c99275SPeter Avalos {
38441c99275SPeter Avalos 	const u_char *up = bp;
38541c99275SPeter Avalos 
38641c99275SPeter Avalos 	if (sreoff & 1) {
387*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", badoffset=%u", sreoff);
388411677aeSAaron LI 		return (1);
38941c99275SPeter Avalos 	}
39041c99275SPeter Avalos 	if (srelen & 1) {
391*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", badlength=%u", srelen);
392411677aeSAaron LI 		return (1);
39341c99275SPeter Avalos 	}
39441c99275SPeter Avalos 	if (sreoff >= srelen) {
395*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(", badoff/len=%u/%u", sreoff, srelen);
396411677aeSAaron LI 		return (1);
39741c99275SPeter Avalos 	}
39841c99275SPeter Avalos 
399411677aeSAaron LI 	while (srelen != 0) {
400*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_2(bp);
401411677aeSAaron LI 		if (len < 2)
402411677aeSAaron LI 			return (0);
40341c99275SPeter Avalos 
404*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" %s%x",
405*ed775ee7SAntonio Huete Jimenez 			 ((bp - up) == sreoff) ? "*" : "", GET_BE_U_2(bp));
40641c99275SPeter Avalos 
40741c99275SPeter Avalos 		bp += 2;
40841c99275SPeter Avalos 		len -= 2;
40941c99275SPeter Avalos 		srelen -= 2;
41041c99275SPeter Avalos 	}
411411677aeSAaron LI 	return (1);
412*ed775ee7SAntonio Huete Jimenez trunc:
413*ed775ee7SAntonio Huete Jimenez 	return 0;
41441c99275SPeter Avalos }
415