xref: /freebsd/contrib/tcpdump/print-lwres.c (revision 0a7e5f1f02aad2ff5fff1c60f44c6975fd07e1d9)
1a90e161bSBill Fenner /*
2a90e161bSBill Fenner  * Copyright (C) 2001 WIDE Project.
3a90e161bSBill Fenner  * All rights reserved.
4a90e161bSBill Fenner  *
5a90e161bSBill Fenner  * Redistribution and use in source and binary forms, with or without
6a90e161bSBill Fenner  * modification, are permitted provided that the following conditions
7a90e161bSBill Fenner  * are met:
8a90e161bSBill Fenner  * 1. Redistributions of source code must retain the above copyright
9a90e161bSBill Fenner  *    notice, this list of conditions and the following disclaimer.
10a90e161bSBill Fenner  * 2. Redistributions in binary form must reproduce the above copyright
11a90e161bSBill Fenner  *    notice, this list of conditions and the following disclaimer in the
12a90e161bSBill Fenner  *    documentation and/or other materials provided with the distribution.
13a90e161bSBill Fenner  * 3. Neither the name of the project nor the names of its contributors
14a90e161bSBill Fenner  *    may be used to endorse or promote products derived from this software
15a90e161bSBill Fenner  *    without specific prior written permission.
16a90e161bSBill Fenner  *
17a90e161bSBill Fenner  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18a90e161bSBill Fenner  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19a90e161bSBill Fenner  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20a90e161bSBill Fenner  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21a90e161bSBill Fenner  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22a90e161bSBill Fenner  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23a90e161bSBill Fenner  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24a90e161bSBill Fenner  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25a90e161bSBill Fenner  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26a90e161bSBill Fenner  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27a90e161bSBill Fenner  * SUCH DAMAGE.
28a90e161bSBill Fenner  */
29a90e161bSBill Fenner 
303340d773SGleb Smirnoff /* \summary: BIND9 Lightweight Resolver protocol printer */
313340d773SGleb Smirnoff 
32ee67461eSJoseph Mingrone #include <config.h>
33a90e161bSBill Fenner 
34ee67461eSJoseph Mingrone #include "netdissect-stdinc.h"
35a90e161bSBill Fenner 
36ee67461eSJoseph Mingrone #define ND_LONGJMP_FROM_TCHECK
373340d773SGleb Smirnoff #include "netdissect.h"
38a90e161bSBill Fenner #include "addrtoname.h"
393340d773SGleb Smirnoff #include "extract.h"
40a90e161bSBill Fenner 
41ee67461eSJoseph Mingrone #include "nameser.h"
42ee67461eSJoseph Mingrone 
43a90e161bSBill Fenner /* BIND9 lib/lwres/include/lwres */
44ee67461eSJoseph Mingrone /*
45ee67461eSJoseph Mingrone  * Use nd_uint16_t for lwres_uint16_t
46ee67461eSJoseph Mingrone  * Use nd_uint32_t for lwres_uint32_t
47ee67461eSJoseph Mingrone */
48a90e161bSBill Fenner 
49a90e161bSBill Fenner struct lwres_lwpacket {
50ee67461eSJoseph Mingrone 	nd_uint32_t		length;
51ee67461eSJoseph Mingrone 	nd_uint16_t		version;
52ee67461eSJoseph Mingrone 	nd_uint16_t		pktflags;
53ee67461eSJoseph Mingrone 	nd_uint32_t		serial;
54ee67461eSJoseph Mingrone 	nd_uint32_t		opcode;
55ee67461eSJoseph Mingrone 	nd_uint32_t		result;
56ee67461eSJoseph Mingrone 	nd_uint32_t		recvlength;
57ee67461eSJoseph Mingrone 	nd_uint16_t		authtype;
58ee67461eSJoseph Mingrone 	nd_uint16_t		authlength;
59a90e161bSBill Fenner };
60a90e161bSBill Fenner 
61a90e161bSBill Fenner #define LWRES_LWPACKETFLAG_RESPONSE	0x0001U	/* if set, pkt is a response */
62a90e161bSBill Fenner 
63a90e161bSBill Fenner #define LWRES_LWPACKETVERSION_0		0
64a90e161bSBill Fenner 
65a90e161bSBill Fenner #define LWRES_FLAG_TRUSTNOTREQUIRED	0x00000001U
66a90e161bSBill Fenner #define LWRES_FLAG_SECUREDATA		0x00000002U
67a90e161bSBill Fenner 
68a90e161bSBill Fenner /*
69a90e161bSBill Fenner  * no-op
70a90e161bSBill Fenner  */
71a90e161bSBill Fenner #define LWRES_OPCODE_NOOP		0x00000000U
72a90e161bSBill Fenner 
73a90e161bSBill Fenner typedef struct {
74a90e161bSBill Fenner 	/* public */
75ee67461eSJoseph Mingrone 	nd_uint16_t			datalength;
76a90e161bSBill Fenner 	/* data follows */
77a90e161bSBill Fenner } lwres_nooprequest_t;
78a90e161bSBill Fenner 
79a90e161bSBill Fenner typedef struct {
80a90e161bSBill Fenner 	/* public */
81ee67461eSJoseph Mingrone 	nd_uint16_t			datalength;
82a90e161bSBill Fenner 	/* data follows */
83a90e161bSBill Fenner } lwres_noopresponse_t;
84a90e161bSBill Fenner 
85a90e161bSBill Fenner /*
86a90e161bSBill Fenner  * get addresses by name
87a90e161bSBill Fenner  */
88a90e161bSBill Fenner #define LWRES_OPCODE_GETADDRSBYNAME	0x00010001U
89a90e161bSBill Fenner 
90a90e161bSBill Fenner typedef struct lwres_addr lwres_addr_t;
91a90e161bSBill Fenner 
92a90e161bSBill Fenner struct lwres_addr {
93ee67461eSJoseph Mingrone 	nd_uint32_t			family;
94ee67461eSJoseph Mingrone 	nd_uint16_t			length;
95ee67461eSJoseph Mingrone 	/* address follows */
96a90e161bSBill Fenner };
97ee67461eSJoseph Mingrone #define LWRES_ADDR_LEN			6
98a90e161bSBill Fenner 
99a90e161bSBill Fenner typedef struct {
100a90e161bSBill Fenner 	/* public */
101ee67461eSJoseph Mingrone 	nd_uint32_t			flags;
102ee67461eSJoseph Mingrone 	nd_uint32_t			addrtypes;
103ee67461eSJoseph Mingrone 	nd_uint16_t			namelen;
104a90e161bSBill Fenner 	/* name follows */
105a90e161bSBill Fenner } lwres_gabnrequest_t;
106ee67461eSJoseph Mingrone #define LWRES_GABNREQUEST_LEN		10
107a90e161bSBill Fenner 
108a90e161bSBill Fenner typedef struct {
109a90e161bSBill Fenner 	/* public */
110ee67461eSJoseph Mingrone 	nd_uint32_t			flags;
111ee67461eSJoseph Mingrone 	nd_uint16_t			naliases;
112ee67461eSJoseph Mingrone 	nd_uint16_t			naddrs;
113ee67461eSJoseph Mingrone 	nd_uint16_t			realnamelen;
114a90e161bSBill Fenner 	/* aliases follows */
115a90e161bSBill Fenner 	/* addrs follows */
116a90e161bSBill Fenner 	/* realname follows */
117a90e161bSBill Fenner } lwres_gabnresponse_t;
118ee67461eSJoseph Mingrone #define LWRES_GABNRESPONSE_LEN		10
119a90e161bSBill Fenner 
120a90e161bSBill Fenner /*
121a90e161bSBill Fenner  * get name by address
122a90e161bSBill Fenner  */
123a90e161bSBill Fenner #define LWRES_OPCODE_GETNAMEBYADDR	0x00010002U
124a90e161bSBill Fenner typedef struct {
125a90e161bSBill Fenner 	/* public */
126ee67461eSJoseph Mingrone 	nd_uint32_t			flags;
127ee67461eSJoseph Mingrone 	/* addr follows */
128a90e161bSBill Fenner } lwres_gnbarequest_t;
129ee67461eSJoseph Mingrone #define LWRES_GNBAREQUEST_LEN		4
130a90e161bSBill Fenner 
131a90e161bSBill Fenner typedef struct {
132a90e161bSBill Fenner 	/* public */
133ee67461eSJoseph Mingrone 	nd_uint32_t			flags;
134ee67461eSJoseph Mingrone 	nd_uint16_t			naliases;
135ee67461eSJoseph Mingrone 	nd_uint16_t			realnamelen;
136a90e161bSBill Fenner 	/* aliases follows */
137a90e161bSBill Fenner 	/* realname follows */
138a90e161bSBill Fenner } lwres_gnbaresponse_t;
139ee67461eSJoseph Mingrone #define LWRES_GNBARESPONSE_LEN		8
140a90e161bSBill Fenner 
141a90e161bSBill Fenner /*
142a90e161bSBill Fenner  * get rdata by name
143a90e161bSBill Fenner  */
144a90e161bSBill Fenner #define LWRES_OPCODE_GETRDATABYNAME	0x00010003U
145a90e161bSBill Fenner 
146a90e161bSBill Fenner typedef struct {
147a90e161bSBill Fenner 	/* public */
148ee67461eSJoseph Mingrone 	nd_uint32_t			flags;
149ee67461eSJoseph Mingrone 	nd_uint16_t			rdclass;
150ee67461eSJoseph Mingrone 	nd_uint16_t			rdtype;
151ee67461eSJoseph Mingrone 	nd_uint16_t			namelen;
152a90e161bSBill Fenner 	/* name follows */
153a90e161bSBill Fenner } lwres_grbnrequest_t;
154ee67461eSJoseph Mingrone #define LWRES_GRBNREQUEST_LEN		10
155a90e161bSBill Fenner 
156a90e161bSBill Fenner typedef struct {
157a90e161bSBill Fenner 	/* public */
158ee67461eSJoseph Mingrone 	nd_uint32_t			flags;
159ee67461eSJoseph Mingrone 	nd_uint16_t			rdclass;
160ee67461eSJoseph Mingrone 	nd_uint16_t			rdtype;
161ee67461eSJoseph Mingrone 	nd_uint32_t			ttl;
162ee67461eSJoseph Mingrone 	nd_uint16_t			nrdatas;
163ee67461eSJoseph Mingrone 	nd_uint16_t			nsigs;
164a90e161bSBill Fenner 	/* realname here (len + name) */
165a90e161bSBill Fenner 	/* rdata here (len + name) */
166a90e161bSBill Fenner 	/* signatures here (len + name) */
167a90e161bSBill Fenner } lwres_grbnresponse_t;
168ee67461eSJoseph Mingrone #define LWRES_GRBNRESPONSE_LEN		16
169a90e161bSBill Fenner 
170a90e161bSBill Fenner #define LWRDATA_VALIDATED	0x00000001
171a90e161bSBill Fenner 
172a90e161bSBill Fenner #define LWRES_ADDRTYPE_V4		0x00000001U	/* ipv4 */
173a90e161bSBill Fenner #define LWRES_ADDRTYPE_V6		0x00000002U	/* ipv6 */
174a90e161bSBill Fenner 
175a90e161bSBill Fenner #define LWRES_MAX_ALIASES		16		/* max # of aliases */
176a90e161bSBill Fenner #define LWRES_MAX_ADDRS			64		/* max # of addrs */
177a90e161bSBill Fenner 
1783c602fabSXin LI static const struct tok opcode[] = {
179a90e161bSBill Fenner 	{ LWRES_OPCODE_NOOP,		"noop", },
180a90e161bSBill Fenner 	{ LWRES_OPCODE_GETADDRSBYNAME,	"getaddrsbyname", },
181a90e161bSBill Fenner 	{ LWRES_OPCODE_GETNAMEBYADDR,	"getnamebyaddr", },
182a90e161bSBill Fenner 	{ LWRES_OPCODE_GETRDATABYNAME,	"getrdatabyname", },
183a90e161bSBill Fenner 	{ 0,				NULL, },
184a90e161bSBill Fenner };
185a90e161bSBill Fenner 
186a90e161bSBill Fenner /* print-domain.c */
1873c602fabSXin LI extern const struct tok ns_type2str[];
1883c602fabSXin LI extern const struct tok ns_class2str[];
189a90e161bSBill Fenner 
190ee67461eSJoseph Mingrone static unsigned
lwres_printname(netdissect_options * ndo,u_int l,const u_char * p0)1913c602fabSXin LI lwres_printname(netdissect_options *ndo,
192ee67461eSJoseph Mingrone                 u_int l, const u_char *p0)
193a90e161bSBill Fenner {
194ee67461eSJoseph Mingrone 	ND_PRINT(" ");
195ee67461eSJoseph Mingrone 	(void)nd_printn(ndo, p0, l, NULL);
196ee67461eSJoseph Mingrone 	p0 += l;
197ee67461eSJoseph Mingrone 	if (GET_U_1(p0))
198ee67461eSJoseph Mingrone 		ND_PRINT(" (not NUL-terminated!)");
199ee67461eSJoseph Mingrone 	return l + 1;
200a90e161bSBill Fenner }
201a90e161bSBill Fenner 
202ee67461eSJoseph Mingrone static unsigned
lwres_printnamelen(netdissect_options * ndo,const u_char * p)2033c602fabSXin LI lwres_printnamelen(netdissect_options *ndo,
204ee67461eSJoseph Mingrone                    const u_char *p)
205a90e161bSBill Fenner {
2063c602fabSXin LI 	uint16_t l;
207a90e161bSBill Fenner 	int advance;
208a90e161bSBill Fenner 
209ee67461eSJoseph Mingrone 	l = GET_BE_U_2(p);
2103c602fabSXin LI 	advance = lwres_printname(ndo, l, p + 2);
211a90e161bSBill Fenner 	return 2 + advance;
212a90e161bSBill Fenner }
213a90e161bSBill Fenner 
214ee67461eSJoseph Mingrone static unsigned
lwres_printbinlen(netdissect_options * ndo,const u_char * p0)2153c602fabSXin LI lwres_printbinlen(netdissect_options *ndo,
216ee67461eSJoseph Mingrone                   const u_char *p0)
217a90e161bSBill Fenner {
218ee67461eSJoseph Mingrone 	const u_char *p;
2193c602fabSXin LI 	uint16_t l;
220a90e161bSBill Fenner 	int i;
221a90e161bSBill Fenner 
222a90e161bSBill Fenner 	p = p0;
223ee67461eSJoseph Mingrone 	l = GET_BE_U_2(p);
224a90e161bSBill Fenner 	p += 2;
225ee67461eSJoseph Mingrone 	for (i = 0; i < l; i++) {
226ee67461eSJoseph Mingrone 		ND_PRINT("%02x", GET_U_1(p));
227ee67461eSJoseph Mingrone 		p++;
228ee67461eSJoseph Mingrone 	}
229ee67461eSJoseph Mingrone 	return 2 + l;
230a90e161bSBill Fenner }
231a90e161bSBill Fenner 
232a90e161bSBill Fenner static int
lwres_printaddr(netdissect_options * ndo,const u_char * p0)2333c602fabSXin LI lwres_printaddr(netdissect_options *ndo,
234ee67461eSJoseph Mingrone                 const u_char *p0)
235a90e161bSBill Fenner {
236ee67461eSJoseph Mingrone 	const u_char *p;
237ee67461eSJoseph Mingrone 	const lwres_addr_t *ap;
2383c602fabSXin LI 	uint16_t l;
239a90e161bSBill Fenner 	int i;
240a90e161bSBill Fenner 
241ee67461eSJoseph Mingrone 	p = p0;
242ee67461eSJoseph Mingrone 	ap = (const lwres_addr_t *)p;
243ee67461eSJoseph Mingrone 	l = GET_BE_U_2(ap->length);
244ee67461eSJoseph Mingrone 	p += LWRES_ADDR_LEN;
245ee67461eSJoseph Mingrone 	ND_TCHECK_LEN(p, l);
246a90e161bSBill Fenner 
247ee67461eSJoseph Mingrone 	switch (GET_BE_U_4(ap->family)) {
248a90e161bSBill Fenner 	case 1:	/* IPv4 */
2495b0fe478SBruce M Simpson 		if (l < 4)
2505b0fe478SBruce M Simpson 			return -1;
251ee67461eSJoseph Mingrone 		ND_PRINT(" %s", GET_IPADDR_STRING(p));
252ee67461eSJoseph Mingrone 		p += sizeof(nd_ipv4);
253a90e161bSBill Fenner 		break;
254a90e161bSBill Fenner 	case 2:	/* IPv6 */
2555b0fe478SBruce M Simpson 		if (l < 16)
2565b0fe478SBruce M Simpson 			return -1;
257ee67461eSJoseph Mingrone 		ND_PRINT(" %s", GET_IP6ADDR_STRING(p));
258ee67461eSJoseph Mingrone 		p += sizeof(nd_ipv6);
259a90e161bSBill Fenner 		break;
260a90e161bSBill Fenner 	default:
261ee67461eSJoseph Mingrone 		ND_PRINT(" %u/", GET_BE_U_4(ap->family));
262ee67461eSJoseph Mingrone 		for (i = 0; i < l; i++) {
263ee67461eSJoseph Mingrone 			ND_PRINT("%02x", GET_U_1(p));
264ee67461eSJoseph Mingrone 			p++;
265ee67461eSJoseph Mingrone 		}
266a90e161bSBill Fenner 	}
267a90e161bSBill Fenner 
268*0a7e5f1fSJoseph Mingrone 	return ND_BYTES_BETWEEN(p0, p);
269a90e161bSBill Fenner }
270a90e161bSBill Fenner 
271a90e161bSBill Fenner void
lwres_print(netdissect_options * ndo,const u_char * bp,u_int length)2723c602fabSXin LI lwres_print(netdissect_options *ndo,
273ee67461eSJoseph Mingrone             const u_char *bp, u_int length)
274a90e161bSBill Fenner {
275ee67461eSJoseph Mingrone 	const u_char *p;
276a90e161bSBill Fenner 	const struct lwres_lwpacket *np;
2773c602fabSXin LI 	uint32_t v;
278ee67461eSJoseph Mingrone 	const u_char *s;
279a90e161bSBill Fenner 	int response;
280a90e161bSBill Fenner 	int advance;
281a90e161bSBill Fenner 	int unsupported = 0;
282a90e161bSBill Fenner 
283ee67461eSJoseph Mingrone 	ndo->ndo_protocol = "lwres";
284a90e161bSBill Fenner 	np = (const struct lwres_lwpacket *)bp;
285ee67461eSJoseph Mingrone 	ND_TCHECK_2(np->authlength);
286a90e161bSBill Fenner 
287ee67461eSJoseph Mingrone 	ND_PRINT(" lwres");
288ee67461eSJoseph Mingrone 	v = GET_BE_U_2(np->version);
2893c602fabSXin LI 	if (ndo->ndo_vflag || v != LWRES_LWPACKETVERSION_0)
290ee67461eSJoseph Mingrone 		ND_PRINT(" v%u", v);
291a90e161bSBill Fenner 	if (v != LWRES_LWPACKETVERSION_0) {
292*0a7e5f1fSJoseph Mingrone 		uint32_t pkt_len = GET_BE_U_4(np->length);
293*0a7e5f1fSJoseph Mingrone 		ND_TCHECK_LEN(bp, pkt_len);
294*0a7e5f1fSJoseph Mingrone 		s = bp + pkt_len;
295a90e161bSBill Fenner 		goto tail;
296a90e161bSBill Fenner 	}
297a90e161bSBill Fenner 
298ee67461eSJoseph Mingrone 	response = GET_BE_U_2(np->pktflags) & LWRES_LWPACKETFLAG_RESPONSE;
299a90e161bSBill Fenner 
300a90e161bSBill Fenner 	/* opcode and pktflags */
301ee67461eSJoseph Mingrone 	v = GET_BE_U_4(np->opcode);
302ee67461eSJoseph Mingrone 	ND_PRINT(" %s%s", tok2str(opcode, "#0x%x", v), response ? "" : "?");
303a90e161bSBill Fenner 
304a90e161bSBill Fenner 	/* pktflags */
305ee67461eSJoseph Mingrone 	v = GET_BE_U_2(np->pktflags);
306a90e161bSBill Fenner 	if (v & ~LWRES_LWPACKETFLAG_RESPONSE)
307ee67461eSJoseph Mingrone 		ND_PRINT("[0x%x]", v);
308a90e161bSBill Fenner 
3093c602fabSXin LI 	if (ndo->ndo_vflag > 1) {
310ee67461eSJoseph Mingrone 		ND_PRINT(" (");	/*)*/
311ee67461eSJoseph Mingrone 		ND_PRINT("serial:0x%x", GET_BE_U_4(np->serial));
312ee67461eSJoseph Mingrone 		ND_PRINT(" result:0x%x", GET_BE_U_4(np->result));
313ee67461eSJoseph Mingrone 		ND_PRINT(" recvlen:%u", GET_BE_U_4(np->recvlength));
314a90e161bSBill Fenner 		/* BIND910: not used */
3153c602fabSXin LI 		if (ndo->ndo_vflag > 2) {
316ee67461eSJoseph Mingrone 			ND_PRINT(" authtype:0x%x", GET_BE_U_2(np->authtype));
317ee67461eSJoseph Mingrone 			ND_PRINT(" authlen:%u", GET_BE_U_2(np->authlength));
318a90e161bSBill Fenner 		}
319a90e161bSBill Fenner 		/*(*/
320ee67461eSJoseph Mingrone 		ND_PRINT(")");
321a90e161bSBill Fenner 	}
322a90e161bSBill Fenner 
323a90e161bSBill Fenner 	/* per-opcode content */
324a90e161bSBill Fenner 	if (!response) {
325a90e161bSBill Fenner 		/*
326a90e161bSBill Fenner 		 * queries
327a90e161bSBill Fenner 		 */
3283340d773SGleb Smirnoff 		const lwres_gabnrequest_t *gabn;
3293340d773SGleb Smirnoff 		const lwres_gnbarequest_t *gnba;
3303340d773SGleb Smirnoff 		const lwres_grbnrequest_t *grbn;
3313c602fabSXin LI 		uint32_t l;
332a90e161bSBill Fenner 
333a90e161bSBill Fenner 		gabn = NULL;
334a90e161bSBill Fenner 		gnba = NULL;
335a90e161bSBill Fenner 		grbn = NULL;
336a90e161bSBill Fenner 
337ee67461eSJoseph Mingrone 		p = (const u_char *)(np + 1);
338ee67461eSJoseph Mingrone 		switch (GET_BE_U_4(np->opcode)) {
339a90e161bSBill Fenner 		case LWRES_OPCODE_NOOP:
340ee67461eSJoseph Mingrone 			s = p;
341a90e161bSBill Fenner 			break;
342a90e161bSBill Fenner 		case LWRES_OPCODE_GETADDRSBYNAME:
343ee67461eSJoseph Mingrone 			gabn = (const lwres_gabnrequest_t *)p;
344ee67461eSJoseph Mingrone 			ND_TCHECK_2(gabn->namelen);
345a90e161bSBill Fenner 
346a90e161bSBill Fenner 			/* BIND910: not used */
3473c602fabSXin LI 			if (ndo->ndo_vflag > 2) {
348ee67461eSJoseph Mingrone 				ND_PRINT(" flags:0x%x",
349ee67461eSJoseph Mingrone 				    GET_BE_U_4(gabn->flags));
350a90e161bSBill Fenner 			}
351a90e161bSBill Fenner 
352ee67461eSJoseph Mingrone 			v = GET_BE_U_4(gabn->addrtypes);
353a90e161bSBill Fenner 			switch (v & (LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6)) {
354a90e161bSBill Fenner 			case LWRES_ADDRTYPE_V4:
355ee67461eSJoseph Mingrone 				ND_PRINT(" IPv4");
356a90e161bSBill Fenner 				break;
357a90e161bSBill Fenner 			case LWRES_ADDRTYPE_V6:
358ee67461eSJoseph Mingrone 				ND_PRINT(" IPv6");
359a90e161bSBill Fenner 				break;
360a90e161bSBill Fenner 			case LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6:
361ee67461eSJoseph Mingrone 				ND_PRINT(" IPv4/6");
362a90e161bSBill Fenner 				break;
363a90e161bSBill Fenner 			}
364a90e161bSBill Fenner 			if (v & ~(LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6))
365ee67461eSJoseph Mingrone 				ND_PRINT("[0x%x]", v);
366a90e161bSBill Fenner 
367ee67461eSJoseph Mingrone 			s = p + LWRES_GABNREQUEST_LEN;
368ee67461eSJoseph Mingrone 			l = GET_BE_U_2(gabn->namelen);
3693c602fabSXin LI 			advance = lwres_printname(ndo, l, s);
370a90e161bSBill Fenner 			s += advance;
371a90e161bSBill Fenner 			break;
372a90e161bSBill Fenner 		case LWRES_OPCODE_GETNAMEBYADDR:
373ee67461eSJoseph Mingrone 			gnba = (const lwres_gnbarequest_t *)p;
374ee67461eSJoseph Mingrone 			ND_TCHECK_4(gnba->flags);
375a90e161bSBill Fenner 
376a90e161bSBill Fenner 			/* BIND910: not used */
3773c602fabSXin LI 			if (ndo->ndo_vflag > 2) {
378ee67461eSJoseph Mingrone 				ND_PRINT(" flags:0x%x",
379ee67461eSJoseph Mingrone 				    GET_BE_U_4(gnba->flags));
380a90e161bSBill Fenner 			}
381a90e161bSBill Fenner 
382ee67461eSJoseph Mingrone 			s = p + LWRES_GNBAREQUEST_LEN;
383ee67461eSJoseph Mingrone 			advance = lwres_printaddr(ndo, s);
384a90e161bSBill Fenner 			if (advance < 0)
385ee67461eSJoseph Mingrone 				goto invalid;
386a90e161bSBill Fenner 			s += advance;
387a90e161bSBill Fenner 			break;
388a90e161bSBill Fenner 		case LWRES_OPCODE_GETRDATABYNAME:
389a90e161bSBill Fenner 			/* XXX no trace, not tested */
390ee67461eSJoseph Mingrone 			grbn = (const lwres_grbnrequest_t *)p;
391ee67461eSJoseph Mingrone 			ND_TCHECK_2(grbn->namelen);
392a90e161bSBill Fenner 
393a90e161bSBill Fenner 			/* BIND910: not used */
3943c602fabSXin LI 			if (ndo->ndo_vflag > 2) {
395ee67461eSJoseph Mingrone 				ND_PRINT(" flags:0x%x",
396ee67461eSJoseph Mingrone 				    GET_BE_U_4(grbn->flags));
397a90e161bSBill Fenner 			}
398a90e161bSBill Fenner 
399ee67461eSJoseph Mingrone 			ND_PRINT(" %s", tok2str(ns_type2str, "Type%u",
400ee67461eSJoseph Mingrone 			    GET_BE_U_2(grbn->rdtype)));
401ee67461eSJoseph Mingrone 			if (GET_BE_U_2(grbn->rdclass) != C_IN) {
402ee67461eSJoseph Mingrone 				ND_PRINT(" %s", tok2str(ns_class2str, "Class%u",
403ee67461eSJoseph Mingrone 				    GET_BE_U_2(grbn->rdclass)));
4045b0fe478SBruce M Simpson 			}
405a90e161bSBill Fenner 
406ee67461eSJoseph Mingrone 			s = p + LWRES_GRBNREQUEST_LEN;
407ee67461eSJoseph Mingrone 			l = GET_BE_U_2(grbn->namelen);
4083c602fabSXin LI 			advance = lwres_printname(ndo, l, s);
409a90e161bSBill Fenner 			s += advance;
410a90e161bSBill Fenner 			break;
411a90e161bSBill Fenner 		default:
412ee67461eSJoseph Mingrone 			s = p;
413a90e161bSBill Fenner 			unsupported++;
414a90e161bSBill Fenner 			break;
415a90e161bSBill Fenner 		}
416a90e161bSBill Fenner 	} else {
417a90e161bSBill Fenner 		/*
418a90e161bSBill Fenner 		 * responses
419a90e161bSBill Fenner 		 */
4203340d773SGleb Smirnoff 		const lwres_gabnresponse_t *gabn;
4213340d773SGleb Smirnoff 		const lwres_gnbaresponse_t *gnba;
4223340d773SGleb Smirnoff 		const lwres_grbnresponse_t *grbn;
4233c602fabSXin LI 		uint32_t l, na;
4243c602fabSXin LI 		uint32_t i;
425a90e161bSBill Fenner 
426a90e161bSBill Fenner 		gabn = NULL;
427a90e161bSBill Fenner 		gnba = NULL;
428a90e161bSBill Fenner 		grbn = NULL;
429a90e161bSBill Fenner 
430ee67461eSJoseph Mingrone 		p = (const u_char *)(np + 1);
431ee67461eSJoseph Mingrone 		switch (GET_BE_U_4(np->opcode)) {
432a90e161bSBill Fenner 		case LWRES_OPCODE_NOOP:
433ee67461eSJoseph Mingrone 			s = p;
434a90e161bSBill Fenner 			break;
435a90e161bSBill Fenner 		case LWRES_OPCODE_GETADDRSBYNAME:
436ee67461eSJoseph Mingrone 			gabn = (const lwres_gabnresponse_t *)p;
437ee67461eSJoseph Mingrone 			ND_TCHECK_2(gabn->realnamelen);
438a90e161bSBill Fenner 
439a90e161bSBill Fenner 			/* BIND910: not used */
4403c602fabSXin LI 			if (ndo->ndo_vflag > 2) {
441ee67461eSJoseph Mingrone 				ND_PRINT(" flags:0x%x",
442ee67461eSJoseph Mingrone 				    GET_BE_U_4(gabn->flags));
443a90e161bSBill Fenner 			}
444a90e161bSBill Fenner 
445ee67461eSJoseph Mingrone 			ND_PRINT(" %u/%u", GET_BE_U_2(gabn->naliases),
446ee67461eSJoseph Mingrone 				  GET_BE_U_2(gabn->naddrs));
447a90e161bSBill Fenner 
448ee67461eSJoseph Mingrone 			s = p + LWRES_GABNRESPONSE_LEN;
449ee67461eSJoseph Mingrone 			l = GET_BE_U_2(gabn->realnamelen);
4503c602fabSXin LI 			advance = lwres_printname(ndo, l, s);
451a90e161bSBill Fenner 			s += advance;
452a90e161bSBill Fenner 
453a90e161bSBill Fenner 			/* aliases */
454ee67461eSJoseph Mingrone 			na = GET_BE_U_2(gabn->naliases);
455a90e161bSBill Fenner 			for (i = 0; i < na; i++) {
4563c602fabSXin LI 				advance = lwres_printnamelen(ndo, s);
457a90e161bSBill Fenner 				s += advance;
458a90e161bSBill Fenner 			}
459a90e161bSBill Fenner 
460a90e161bSBill Fenner 			/* addrs */
461ee67461eSJoseph Mingrone 			na = GET_BE_U_2(gabn->naddrs);
462a90e161bSBill Fenner 			for (i = 0; i < na; i++) {
463ee67461eSJoseph Mingrone 				advance = lwres_printaddr(ndo, s);
464a90e161bSBill Fenner 				if (advance < 0)
465ee67461eSJoseph Mingrone 					goto invalid;
466a90e161bSBill Fenner 				s += advance;
467a90e161bSBill Fenner 			}
468a90e161bSBill Fenner 			break;
469a90e161bSBill Fenner 		case LWRES_OPCODE_GETNAMEBYADDR:
470ee67461eSJoseph Mingrone 			gnba = (const lwres_gnbaresponse_t *)p;
471ee67461eSJoseph Mingrone 			ND_TCHECK_2(gnba->realnamelen);
472a90e161bSBill Fenner 
473a90e161bSBill Fenner 			/* BIND910: not used */
4743c602fabSXin LI 			if (ndo->ndo_vflag > 2) {
475ee67461eSJoseph Mingrone 				ND_PRINT(" flags:0x%x",
476ee67461eSJoseph Mingrone 				    GET_BE_U_4(gnba->flags));
477a90e161bSBill Fenner 			}
478a90e161bSBill Fenner 
479ee67461eSJoseph Mingrone 			ND_PRINT(" %u", GET_BE_U_2(gnba->naliases));
480a90e161bSBill Fenner 
481ee67461eSJoseph Mingrone 			s = p + LWRES_GNBARESPONSE_LEN;
482ee67461eSJoseph Mingrone 			l = GET_BE_U_2(gnba->realnamelen);
4833c602fabSXin LI 			advance = lwres_printname(ndo, l, s);
484a90e161bSBill Fenner 			s += advance;
485a90e161bSBill Fenner 
486a90e161bSBill Fenner 			/* aliases */
487ee67461eSJoseph Mingrone 			na = GET_BE_U_2(gnba->naliases);
488a90e161bSBill Fenner 			for (i = 0; i < na; i++) {
4893c602fabSXin LI 				advance = lwres_printnamelen(ndo, s);
490a90e161bSBill Fenner 				s += advance;
491a90e161bSBill Fenner 			}
492a90e161bSBill Fenner 			break;
493a90e161bSBill Fenner 		case LWRES_OPCODE_GETRDATABYNAME:
494a90e161bSBill Fenner 			/* XXX no trace, not tested */
495ee67461eSJoseph Mingrone 			grbn = (const lwres_grbnresponse_t *)p;
496ee67461eSJoseph Mingrone 			ND_TCHECK_2(grbn->nsigs);
497a90e161bSBill Fenner 
498a90e161bSBill Fenner 			/* BIND910: not used */
4993c602fabSXin LI 			if (ndo->ndo_vflag > 2) {
500ee67461eSJoseph Mingrone 				ND_PRINT(" flags:0x%x",
501ee67461eSJoseph Mingrone 				    GET_BE_U_4(grbn->flags));
502a90e161bSBill Fenner 			}
503a90e161bSBill Fenner 
504ee67461eSJoseph Mingrone 			ND_PRINT(" %s", tok2str(ns_type2str, "Type%u",
505ee67461eSJoseph Mingrone 			    GET_BE_U_2(grbn->rdtype)));
506ee67461eSJoseph Mingrone 			if (GET_BE_U_2(grbn->rdclass) != C_IN) {
507ee67461eSJoseph Mingrone 				ND_PRINT(" %s", tok2str(ns_class2str, "Class%u",
508ee67461eSJoseph Mingrone 				    GET_BE_U_2(grbn->rdclass)));
5095b0fe478SBruce M Simpson 			}
510ee67461eSJoseph Mingrone 			ND_PRINT(" TTL ");
511ee67461eSJoseph Mingrone 			unsigned_relts_print(ndo,
512ee67461eSJoseph Mingrone 					     GET_BE_U_4(grbn->ttl));
513ee67461eSJoseph Mingrone 			ND_PRINT(" %u/%u", GET_BE_U_2(grbn->nrdatas),
514ee67461eSJoseph Mingrone 				  GET_BE_U_2(grbn->nsigs));
515a90e161bSBill Fenner 
516ee67461eSJoseph Mingrone 			s = p + LWRES_GRBNRESPONSE_LEN;
5173c602fabSXin LI 			advance = lwres_printnamelen(ndo, s);
518a90e161bSBill Fenner 			s += advance;
519a90e161bSBill Fenner 
520a90e161bSBill Fenner 			/* rdatas */
521ee67461eSJoseph Mingrone 			na = GET_BE_U_2(grbn->nrdatas);
522a90e161bSBill Fenner 			for (i = 0; i < na; i++) {
523a90e161bSBill Fenner 				/* XXX should decode resource data */
5243c602fabSXin LI 				advance = lwres_printbinlen(ndo, s);
525a90e161bSBill Fenner 				s += advance;
526a90e161bSBill Fenner 			}
527a90e161bSBill Fenner 
528a90e161bSBill Fenner 			/* sigs */
529ee67461eSJoseph Mingrone 			na = GET_BE_U_2(grbn->nsigs);
530a90e161bSBill Fenner 			for (i = 0; i < na; i++) {
531a90e161bSBill Fenner 				/* XXX how should we print it? */
5323c602fabSXin LI 				advance = lwres_printbinlen(ndo, s);
533a90e161bSBill Fenner 				s += advance;
534a90e161bSBill Fenner 			}
535a90e161bSBill Fenner 			break;
536a90e161bSBill Fenner 		default:
537ee67461eSJoseph Mingrone 			s = p;
538a90e161bSBill Fenner 			unsupported++;
539a90e161bSBill Fenner 			break;
540a90e161bSBill Fenner 		}
541a90e161bSBill Fenner 	}
542a90e161bSBill Fenner 
543a90e161bSBill Fenner   tail:
544a90e161bSBill Fenner 	/* length mismatch */
545ee67461eSJoseph Mingrone 	if (GET_BE_U_4(np->length) != length) {
546ee67461eSJoseph Mingrone 		ND_PRINT(" [len: %u != %u]", GET_BE_U_4(np->length),
547ee67461eSJoseph Mingrone 			  length);
548a90e161bSBill Fenner 	}
549*0a7e5f1fSJoseph Mingrone 	if (!unsupported && ND_BYTES_BETWEEN(bp, s) < GET_BE_U_4(np->length))
550ee67461eSJoseph Mingrone 		ND_PRINT("[extra]");
551a90e161bSBill Fenner 	return;
552a90e161bSBill Fenner 
553ee67461eSJoseph Mingrone   invalid:
554ee67461eSJoseph Mingrone 	nd_print_invalid(ndo);
555a90e161bSBill Fenner }
556