print-lwres.c revision 1.7 1 1.1 christos /*
2 1.1 christos * Copyright (C) 2001 WIDE Project.
3 1.1 christos * All rights reserved.
4 1.1 christos *
5 1.1 christos * Redistribution and use in source and binary forms, with or without
6 1.1 christos * modification, are permitted provided that the following conditions
7 1.1 christos * are met:
8 1.1 christos * 1. Redistributions of source code must retain the above copyright
9 1.1 christos * notice, this list of conditions and the following disclaimer.
10 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 christos * notice, this list of conditions and the following disclaimer in the
12 1.1 christos * documentation and/or other materials provided with the distribution.
13 1.1 christos * 3. Neither the name of the project nor the names of its contributors
14 1.1 christos * may be used to endorse or promote products derived from this software
15 1.1 christos * without specific prior written permission.
16 1.1 christos *
17 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 1.1 christos * SUCH DAMAGE.
28 1.1 christos */
29 1.1 christos
30 1.2 christos #include <sys/cdefs.h>
31 1.1 christos #ifndef lint
32 1.7 spz __RCSID("$NetBSD: print-lwres.c,v 1.7 2017/02/05 04:05:05 spz Exp $");
33 1.1 christos #endif
34 1.1 christos
35 1.7 spz /* \summary: BIND9 Lightweight Resolver protocol printer */
36 1.7 spz
37 1.1 christos #ifdef HAVE_CONFIG_H
38 1.1 christos #include "config.h"
39 1.1 christos #endif
40 1.1 christos
41 1.6 christos #include <netdissect-stdinc.h>
42 1.1 christos
43 1.1 christos #include "nameser.h"
44 1.1 christos
45 1.1 christos #include <stdio.h>
46 1.1 christos #include <string.h>
47 1.1 christos
48 1.6 christos #include "netdissect.h"
49 1.1 christos #include "addrtoname.h"
50 1.6 christos #include "extract.h"
51 1.1 christos
52 1.1 christos /* BIND9 lib/lwres/include/lwres */
53 1.5 christos typedef uint32_t lwres_uint32_t;
54 1.5 christos typedef uint16_t lwres_uint16_t;
55 1.5 christos typedef uint8_t lwres_uint8_t;
56 1.1 christos
57 1.1 christos struct lwres_lwpacket {
58 1.1 christos lwres_uint32_t length;
59 1.1 christos lwres_uint16_t version;
60 1.1 christos lwres_uint16_t pktflags;
61 1.1 christos lwres_uint32_t serial;
62 1.1 christos lwres_uint32_t opcode;
63 1.1 christos lwres_uint32_t result;
64 1.1 christos lwres_uint32_t recvlength;
65 1.1 christos lwres_uint16_t authtype;
66 1.1 christos lwres_uint16_t authlength;
67 1.1 christos };
68 1.1 christos
69 1.1 christos #define LWRES_LWPACKETFLAG_RESPONSE 0x0001U /* if set, pkt is a response */
70 1.1 christos
71 1.1 christos #define LWRES_LWPACKETVERSION_0 0
72 1.1 christos
73 1.1 christos #define LWRES_FLAG_TRUSTNOTREQUIRED 0x00000001U
74 1.1 christos #define LWRES_FLAG_SECUREDATA 0x00000002U
75 1.1 christos
76 1.1 christos /*
77 1.1 christos * no-op
78 1.1 christos */
79 1.1 christos #define LWRES_OPCODE_NOOP 0x00000000U
80 1.1 christos
81 1.1 christos typedef struct {
82 1.1 christos /* public */
83 1.1 christos lwres_uint16_t datalength;
84 1.1 christos /* data follows */
85 1.1 christos } lwres_nooprequest_t;
86 1.1 christos
87 1.1 christos typedef struct {
88 1.1 christos /* public */
89 1.1 christos lwres_uint16_t datalength;
90 1.1 christos /* data follows */
91 1.1 christos } lwres_noopresponse_t;
92 1.1 christos
93 1.1 christos /*
94 1.1 christos * get addresses by name
95 1.1 christos */
96 1.1 christos #define LWRES_OPCODE_GETADDRSBYNAME 0x00010001U
97 1.1 christos
98 1.1 christos typedef struct lwres_addr lwres_addr_t;
99 1.1 christos
100 1.1 christos struct lwres_addr {
101 1.1 christos lwres_uint32_t family;
102 1.1 christos lwres_uint16_t length;
103 1.1 christos /* address folows */
104 1.1 christos };
105 1.1 christos
106 1.1 christos typedef struct {
107 1.1 christos /* public */
108 1.1 christos lwres_uint32_t flags;
109 1.1 christos lwres_uint32_t addrtypes;
110 1.1 christos lwres_uint16_t namelen;
111 1.1 christos /* name follows */
112 1.1 christos } lwres_gabnrequest_t;
113 1.1 christos
114 1.1 christos typedef struct {
115 1.1 christos /* public */
116 1.1 christos lwres_uint32_t flags;
117 1.1 christos lwres_uint16_t naliases;
118 1.1 christos lwres_uint16_t naddrs;
119 1.1 christos lwres_uint16_t realnamelen;
120 1.1 christos /* aliases follows */
121 1.1 christos /* addrs follows */
122 1.1 christos /* realname follows */
123 1.1 christos } lwres_gabnresponse_t;
124 1.1 christos
125 1.1 christos /*
126 1.1 christos * get name by address
127 1.1 christos */
128 1.1 christos #define LWRES_OPCODE_GETNAMEBYADDR 0x00010002U
129 1.1 christos typedef struct {
130 1.1 christos /* public */
131 1.1 christos lwres_uint32_t flags;
132 1.1 christos lwres_addr_t addr;
133 1.1 christos /* addr body follows */
134 1.1 christos } lwres_gnbarequest_t;
135 1.1 christos
136 1.1 christos typedef struct {
137 1.1 christos /* public */
138 1.1 christos lwres_uint32_t flags;
139 1.1 christos lwres_uint16_t naliases;
140 1.1 christos lwres_uint16_t realnamelen;
141 1.1 christos /* aliases follows */
142 1.1 christos /* realname follows */
143 1.1 christos } lwres_gnbaresponse_t;
144 1.1 christos
145 1.1 christos /*
146 1.1 christos * get rdata by name
147 1.1 christos */
148 1.1 christos #define LWRES_OPCODE_GETRDATABYNAME 0x00010003U
149 1.1 christos
150 1.1 christos typedef struct {
151 1.1 christos /* public */
152 1.1 christos lwres_uint32_t flags;
153 1.1 christos lwres_uint16_t rdclass;
154 1.1 christos lwres_uint16_t rdtype;
155 1.1 christos lwres_uint16_t namelen;
156 1.1 christos /* name follows */
157 1.1 christos } lwres_grbnrequest_t;
158 1.1 christos
159 1.1 christos typedef struct {
160 1.1 christos /* public */
161 1.1 christos lwres_uint32_t flags;
162 1.1 christos lwres_uint16_t rdclass;
163 1.1 christos lwres_uint16_t rdtype;
164 1.1 christos lwres_uint32_t ttl;
165 1.1 christos lwres_uint16_t nrdatas;
166 1.1 christos lwres_uint16_t nsigs;
167 1.1 christos /* realname here (len + name) */
168 1.1 christos /* rdata here (len + name) */
169 1.1 christos /* signatures here (len + name) */
170 1.1 christos } lwres_grbnresponse_t;
171 1.1 christos
172 1.1 christos #define LWRDATA_VALIDATED 0x00000001
173 1.1 christos
174 1.1 christos #define LWRES_ADDRTYPE_V4 0x00000001U /* ipv4 */
175 1.1 christos #define LWRES_ADDRTYPE_V6 0x00000002U /* ipv6 */
176 1.1 christos
177 1.1 christos #define LWRES_MAX_ALIASES 16 /* max # of aliases */
178 1.1 christos #define LWRES_MAX_ADDRS 64 /* max # of addrs */
179 1.1 christos
180 1.4 christos static const struct tok opcode[] = {
181 1.1 christos { LWRES_OPCODE_NOOP, "noop", },
182 1.1 christos { LWRES_OPCODE_GETADDRSBYNAME, "getaddrsbyname", },
183 1.1 christos { LWRES_OPCODE_GETNAMEBYADDR, "getnamebyaddr", },
184 1.1 christos { LWRES_OPCODE_GETRDATABYNAME, "getrdatabyname", },
185 1.1 christos { 0, NULL, },
186 1.1 christos };
187 1.1 christos
188 1.1 christos /* print-domain.c */
189 1.4 christos extern const struct tok ns_type2str[];
190 1.4 christos extern const struct tok ns_class2str[];
191 1.1 christos
192 1.1 christos static int
193 1.5 christos lwres_printname(netdissect_options *ndo,
194 1.5 christos size_t l, const char *p0)
195 1.1 christos {
196 1.1 christos const char *p;
197 1.1 christos size_t i;
198 1.1 christos
199 1.1 christos p = p0;
200 1.1 christos /* + 1 for terminating \0 */
201 1.5 christos if (p + l + 1 > (const char *)ndo->ndo_snapend)
202 1.1 christos goto trunc;
203 1.1 christos
204 1.5 christos ND_PRINT((ndo, " "));
205 1.1 christos for (i = 0; i < l; i++)
206 1.5 christos safeputchar(ndo, *p++);
207 1.1 christos p++; /* skip terminating \0 */
208 1.1 christos
209 1.1 christos return p - p0;
210 1.1 christos
211 1.1 christos trunc:
212 1.1 christos return -1;
213 1.1 christos }
214 1.1 christos
215 1.1 christos static int
216 1.5 christos lwres_printnamelen(netdissect_options *ndo,
217 1.5 christos const char *p)
218 1.1 christos {
219 1.5 christos uint16_t l;
220 1.1 christos int advance;
221 1.1 christos
222 1.5 christos if (p + 2 > (const char *)ndo->ndo_snapend)
223 1.1 christos goto trunc;
224 1.1 christos l = EXTRACT_16BITS(p);
225 1.5 christos advance = lwres_printname(ndo, l, p + 2);
226 1.1 christos if (advance < 0)
227 1.1 christos goto trunc;
228 1.1 christos return 2 + advance;
229 1.1 christos
230 1.1 christos trunc:
231 1.1 christos return -1;
232 1.1 christos }
233 1.1 christos
234 1.1 christos static int
235 1.5 christos lwres_printbinlen(netdissect_options *ndo,
236 1.5 christos const char *p0)
237 1.1 christos {
238 1.1 christos const char *p;
239 1.5 christos uint16_t l;
240 1.1 christos int i;
241 1.1 christos
242 1.1 christos p = p0;
243 1.5 christos if (p + 2 > (const char *)ndo->ndo_snapend)
244 1.1 christos goto trunc;
245 1.1 christos l = EXTRACT_16BITS(p);
246 1.5 christos if (p + 2 + l > (const char *)ndo->ndo_snapend)
247 1.1 christos goto trunc;
248 1.1 christos p += 2;
249 1.1 christos for (i = 0; i < l; i++)
250 1.5 christos ND_PRINT((ndo, "%02x", *p++));
251 1.1 christos return p - p0;
252 1.1 christos
253 1.1 christos trunc:
254 1.1 christos return -1;
255 1.1 christos }
256 1.1 christos
257 1.1 christos static int
258 1.5 christos lwres_printaddr(netdissect_options *ndo,
259 1.6 christos const lwres_addr_t *ap)
260 1.1 christos {
261 1.5 christos uint16_t l;
262 1.1 christos const char *p;
263 1.1 christos int i;
264 1.1 christos
265 1.5 christos ND_TCHECK(ap->length);
266 1.1 christos l = EXTRACT_16BITS(&ap->length);
267 1.1 christos /* XXX ap points to packed struct */
268 1.1 christos p = (const char *)&ap->length + sizeof(ap->length);
269 1.5 christos ND_TCHECK2(*p, l);
270 1.1 christos
271 1.1 christos switch (EXTRACT_32BITS(&ap->family)) {
272 1.1 christos case 1: /* IPv4 */
273 1.1 christos if (l < 4)
274 1.1 christos return -1;
275 1.5 christos ND_PRINT((ndo, " %s", ipaddr_string(ndo, p)));
276 1.1 christos p += sizeof(struct in_addr);
277 1.1 christos break;
278 1.1 christos case 2: /* IPv6 */
279 1.1 christos if (l < 16)
280 1.1 christos return -1;
281 1.5 christos ND_PRINT((ndo, " %s", ip6addr_string(ndo, p)));
282 1.1 christos p += sizeof(struct in6_addr);
283 1.1 christos break;
284 1.1 christos default:
285 1.5 christos ND_PRINT((ndo, " %u/", EXTRACT_32BITS(&ap->family)));
286 1.1 christos for (i = 0; i < l; i++)
287 1.5 christos ND_PRINT((ndo, "%02x", *p++));
288 1.1 christos }
289 1.1 christos
290 1.1 christos return p - (const char *)ap;
291 1.1 christos
292 1.1 christos trunc:
293 1.1 christos return -1;
294 1.1 christos }
295 1.1 christos
296 1.1 christos void
297 1.5 christos lwres_print(netdissect_options *ndo,
298 1.5 christos register const u_char *bp, u_int length)
299 1.1 christos {
300 1.1 christos const struct lwres_lwpacket *np;
301 1.5 christos uint32_t v;
302 1.1 christos const char *s;
303 1.1 christos int response;
304 1.1 christos int advance;
305 1.1 christos int unsupported = 0;
306 1.1 christos
307 1.1 christos np = (const struct lwres_lwpacket *)bp;
308 1.5 christos ND_TCHECK(np->authlength);
309 1.1 christos
310 1.5 christos ND_PRINT((ndo, " lwres"));
311 1.1 christos v = EXTRACT_16BITS(&np->version);
312 1.5 christos if (ndo->ndo_vflag || v != LWRES_LWPACKETVERSION_0)
313 1.5 christos ND_PRINT((ndo, " v%u", v));
314 1.1 christos if (v != LWRES_LWPACKETVERSION_0) {
315 1.1 christos s = (const char *)np + EXTRACT_32BITS(&np->length);
316 1.1 christos goto tail;
317 1.1 christos }
318 1.1 christos
319 1.1 christos response = EXTRACT_16BITS(&np->pktflags) & LWRES_LWPACKETFLAG_RESPONSE;
320 1.1 christos
321 1.1 christos /* opcode and pktflags */
322 1.1 christos v = EXTRACT_32BITS(&np->opcode);
323 1.1 christos s = tok2str(opcode, "#0x%x", v);
324 1.5 christos ND_PRINT((ndo, " %s%s", s, response ? "" : "?"));
325 1.1 christos
326 1.1 christos /* pktflags */
327 1.1 christos v = EXTRACT_16BITS(&np->pktflags);
328 1.1 christos if (v & ~LWRES_LWPACKETFLAG_RESPONSE)
329 1.5 christos ND_PRINT((ndo, "[0x%x]", v));
330 1.1 christos
331 1.5 christos if (ndo->ndo_vflag > 1) {
332 1.5 christos ND_PRINT((ndo, " (")); /*)*/
333 1.5 christos ND_PRINT((ndo, "serial:0x%x", EXTRACT_32BITS(&np->serial)));
334 1.5 christos ND_PRINT((ndo, " result:0x%x", EXTRACT_32BITS(&np->result)));
335 1.5 christos ND_PRINT((ndo, " recvlen:%u", EXTRACT_32BITS(&np->recvlength)));
336 1.1 christos /* BIND910: not used */
337 1.5 christos if (ndo->ndo_vflag > 2) {
338 1.5 christos ND_PRINT((ndo, " authtype:0x%x", EXTRACT_16BITS(&np->authtype)));
339 1.5 christos ND_PRINT((ndo, " authlen:%u", EXTRACT_16BITS(&np->authlength)));
340 1.1 christos }
341 1.1 christos /*(*/
342 1.5 christos ND_PRINT((ndo, ")"));
343 1.1 christos }
344 1.1 christos
345 1.1 christos /* per-opcode content */
346 1.1 christos if (!response) {
347 1.1 christos /*
348 1.1 christos * queries
349 1.1 christos */
350 1.6 christos const lwres_gabnrequest_t *gabn;
351 1.6 christos const lwres_gnbarequest_t *gnba;
352 1.6 christos const lwres_grbnrequest_t *grbn;
353 1.5 christos uint32_t l;
354 1.1 christos
355 1.1 christos gabn = NULL;
356 1.1 christos gnba = NULL;
357 1.1 christos grbn = NULL;
358 1.1 christos
359 1.1 christos switch (EXTRACT_32BITS(&np->opcode)) {
360 1.1 christos case LWRES_OPCODE_NOOP:
361 1.1 christos break;
362 1.1 christos case LWRES_OPCODE_GETADDRSBYNAME:
363 1.6 christos gabn = (const lwres_gabnrequest_t *)(np + 1);
364 1.5 christos ND_TCHECK(gabn->namelen);
365 1.1 christos /* XXX gabn points to packed struct */
366 1.1 christos s = (const char *)&gabn->namelen +
367 1.1 christos sizeof(gabn->namelen);
368 1.1 christos l = EXTRACT_16BITS(&gabn->namelen);
369 1.1 christos
370 1.1 christos /* BIND910: not used */
371 1.5 christos if (ndo->ndo_vflag > 2) {
372 1.5 christos ND_PRINT((ndo, " flags:0x%x",
373 1.5 christos EXTRACT_32BITS(&gabn->flags)));
374 1.1 christos }
375 1.1 christos
376 1.1 christos v = EXTRACT_32BITS(&gabn->addrtypes);
377 1.1 christos switch (v & (LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6)) {
378 1.1 christos case LWRES_ADDRTYPE_V4:
379 1.5 christos ND_PRINT((ndo, " IPv4"));
380 1.1 christos break;
381 1.1 christos case LWRES_ADDRTYPE_V6:
382 1.5 christos ND_PRINT((ndo, " IPv6"));
383 1.1 christos break;
384 1.1 christos case LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6:
385 1.5 christos ND_PRINT((ndo, " IPv4/6"));
386 1.1 christos break;
387 1.1 christos }
388 1.1 christos if (v & ~(LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6))
389 1.5 christos ND_PRINT((ndo, "[0x%x]", v));
390 1.1 christos
391 1.5 christos advance = lwres_printname(ndo, l, s);
392 1.1 christos if (advance < 0)
393 1.1 christos goto trunc;
394 1.1 christos s += advance;
395 1.1 christos break;
396 1.1 christos case LWRES_OPCODE_GETNAMEBYADDR:
397 1.6 christos gnba = (const lwres_gnbarequest_t *)(np + 1);
398 1.5 christos ND_TCHECK(gnba->addr);
399 1.1 christos
400 1.1 christos /* BIND910: not used */
401 1.5 christos if (ndo->ndo_vflag > 2) {
402 1.5 christos ND_PRINT((ndo, " flags:0x%x",
403 1.5 christos EXTRACT_32BITS(&gnba->flags)));
404 1.1 christos }
405 1.1 christos
406 1.1 christos s = (const char *)&gnba->addr;
407 1.1 christos
408 1.5 christos advance = lwres_printaddr(ndo, &gnba->addr);
409 1.1 christos if (advance < 0)
410 1.1 christos goto trunc;
411 1.1 christos s += advance;
412 1.1 christos break;
413 1.1 christos case LWRES_OPCODE_GETRDATABYNAME:
414 1.1 christos /* XXX no trace, not tested */
415 1.6 christos grbn = (const lwres_grbnrequest_t *)(np + 1);
416 1.5 christos ND_TCHECK(grbn->namelen);
417 1.1 christos
418 1.1 christos /* BIND910: not used */
419 1.5 christos if (ndo->ndo_vflag > 2) {
420 1.5 christos ND_PRINT((ndo, " flags:0x%x",
421 1.5 christos EXTRACT_32BITS(&grbn->flags)));
422 1.1 christos }
423 1.1 christos
424 1.5 christos ND_PRINT((ndo, " %s", tok2str(ns_type2str, "Type%d",
425 1.5 christos EXTRACT_16BITS(&grbn->rdtype))));
426 1.1 christos if (EXTRACT_16BITS(&grbn->rdclass) != C_IN) {
427 1.5 christos ND_PRINT((ndo, " %s", tok2str(ns_class2str, "Class%d",
428 1.5 christos EXTRACT_16BITS(&grbn->rdclass))));
429 1.1 christos }
430 1.1 christos
431 1.1 christos /* XXX grbn points to packed struct */
432 1.1 christos s = (const char *)&grbn->namelen +
433 1.1 christos sizeof(grbn->namelen);
434 1.1 christos l = EXTRACT_16BITS(&grbn->namelen);
435 1.1 christos
436 1.5 christos advance = lwres_printname(ndo, l, s);
437 1.1 christos if (advance < 0)
438 1.1 christos goto trunc;
439 1.1 christos s += advance;
440 1.1 christos break;
441 1.1 christos default:
442 1.1 christos unsupported++;
443 1.1 christos break;
444 1.1 christos }
445 1.1 christos } else {
446 1.1 christos /*
447 1.1 christos * responses
448 1.1 christos */
449 1.6 christos const lwres_gabnresponse_t *gabn;
450 1.6 christos const lwres_gnbaresponse_t *gnba;
451 1.6 christos const lwres_grbnresponse_t *grbn;
452 1.5 christos uint32_t l, na;
453 1.5 christos uint32_t i;
454 1.1 christos
455 1.1 christos gabn = NULL;
456 1.1 christos gnba = NULL;
457 1.1 christos grbn = NULL;
458 1.1 christos
459 1.1 christos switch (EXTRACT_32BITS(&np->opcode)) {
460 1.1 christos case LWRES_OPCODE_NOOP:
461 1.1 christos break;
462 1.1 christos case LWRES_OPCODE_GETADDRSBYNAME:
463 1.6 christos gabn = (const lwres_gabnresponse_t *)(np + 1);
464 1.5 christos ND_TCHECK(gabn->realnamelen);
465 1.1 christos /* XXX gabn points to packed struct */
466 1.1 christos s = (const char *)&gabn->realnamelen +
467 1.1 christos sizeof(gabn->realnamelen);
468 1.1 christos l = EXTRACT_16BITS(&gabn->realnamelen);
469 1.1 christos
470 1.1 christos /* BIND910: not used */
471 1.5 christos if (ndo->ndo_vflag > 2) {
472 1.5 christos ND_PRINT((ndo, " flags:0x%x",
473 1.5 christos EXTRACT_32BITS(&gabn->flags)));
474 1.1 christos }
475 1.1 christos
476 1.5 christos ND_PRINT((ndo, " %u/%u", EXTRACT_16BITS(&gabn->naliases),
477 1.5 christos EXTRACT_16BITS(&gabn->naddrs)));
478 1.1 christos
479 1.5 christos advance = lwres_printname(ndo, l, s);
480 1.1 christos if (advance < 0)
481 1.1 christos goto trunc;
482 1.1 christos s += advance;
483 1.1 christos
484 1.1 christos /* aliases */
485 1.1 christos na = EXTRACT_16BITS(&gabn->naliases);
486 1.1 christos for (i = 0; i < na; i++) {
487 1.5 christos advance = lwres_printnamelen(ndo, s);
488 1.1 christos if (advance < 0)
489 1.1 christos goto trunc;
490 1.1 christos s += advance;
491 1.1 christos }
492 1.1 christos
493 1.1 christos /* addrs */
494 1.1 christos na = EXTRACT_16BITS(&gabn->naddrs);
495 1.1 christos for (i = 0; i < na; i++) {
496 1.6 christos advance = lwres_printaddr(ndo, (const lwres_addr_t *)s);
497 1.1 christos if (advance < 0)
498 1.1 christos goto trunc;
499 1.1 christos s += advance;
500 1.1 christos }
501 1.1 christos break;
502 1.1 christos case LWRES_OPCODE_GETNAMEBYADDR:
503 1.6 christos gnba = (const lwres_gnbaresponse_t *)(np + 1);
504 1.5 christos ND_TCHECK(gnba->realnamelen);
505 1.1 christos /* XXX gnba points to packed struct */
506 1.1 christos s = (const char *)&gnba->realnamelen +
507 1.1 christos sizeof(gnba->realnamelen);
508 1.1 christos l = EXTRACT_16BITS(&gnba->realnamelen);
509 1.1 christos
510 1.1 christos /* BIND910: not used */
511 1.5 christos if (ndo->ndo_vflag > 2) {
512 1.5 christos ND_PRINT((ndo, " flags:0x%x",
513 1.5 christos EXTRACT_32BITS(&gnba->flags)));
514 1.1 christos }
515 1.1 christos
516 1.5 christos ND_PRINT((ndo, " %u", EXTRACT_16BITS(&gnba->naliases)));
517 1.1 christos
518 1.5 christos advance = lwres_printname(ndo, l, s);
519 1.1 christos if (advance < 0)
520 1.1 christos goto trunc;
521 1.1 christos s += advance;
522 1.1 christos
523 1.1 christos /* aliases */
524 1.1 christos na = EXTRACT_16BITS(&gnba->naliases);
525 1.1 christos for (i = 0; i < na; i++) {
526 1.5 christos advance = lwres_printnamelen(ndo, s);
527 1.1 christos if (advance < 0)
528 1.1 christos goto trunc;
529 1.1 christos s += advance;
530 1.1 christos }
531 1.1 christos break;
532 1.1 christos case LWRES_OPCODE_GETRDATABYNAME:
533 1.1 christos /* XXX no trace, not tested */
534 1.6 christos grbn = (const lwres_grbnresponse_t *)(np + 1);
535 1.5 christos ND_TCHECK(grbn->nsigs);
536 1.1 christos
537 1.1 christos /* BIND910: not used */
538 1.5 christos if (ndo->ndo_vflag > 2) {
539 1.5 christos ND_PRINT((ndo, " flags:0x%x",
540 1.5 christos EXTRACT_32BITS(&grbn->flags)));
541 1.1 christos }
542 1.1 christos
543 1.5 christos ND_PRINT((ndo, " %s", tok2str(ns_type2str, "Type%d",
544 1.5 christos EXTRACT_16BITS(&grbn->rdtype))));
545 1.1 christos if (EXTRACT_16BITS(&grbn->rdclass) != C_IN) {
546 1.5 christos ND_PRINT((ndo, " %s", tok2str(ns_class2str, "Class%d",
547 1.5 christos EXTRACT_16BITS(&grbn->rdclass))));
548 1.1 christos }
549 1.5 christos ND_PRINT((ndo, " TTL "));
550 1.7 spz unsigned_relts_print(ndo, EXTRACT_32BITS(&grbn->ttl));
551 1.5 christos ND_PRINT((ndo, " %u/%u", EXTRACT_16BITS(&grbn->nrdatas),
552 1.5 christos EXTRACT_16BITS(&grbn->nsigs)));
553 1.1 christos
554 1.1 christos /* XXX grbn points to packed struct */
555 1.1 christos s = (const char *)&grbn->nsigs+ sizeof(grbn->nsigs);
556 1.1 christos
557 1.5 christos advance = lwres_printnamelen(ndo, s);
558 1.1 christos if (advance < 0)
559 1.1 christos goto trunc;
560 1.1 christos s += advance;
561 1.1 christos
562 1.1 christos /* rdatas */
563 1.1 christos na = EXTRACT_16BITS(&grbn->nrdatas);
564 1.1 christos for (i = 0; i < na; i++) {
565 1.1 christos /* XXX should decode resource data */
566 1.5 christos advance = lwres_printbinlen(ndo, s);
567 1.1 christos if (advance < 0)
568 1.1 christos goto trunc;
569 1.1 christos s += advance;
570 1.1 christos }
571 1.1 christos
572 1.1 christos /* sigs */
573 1.1 christos na = EXTRACT_16BITS(&grbn->nsigs);
574 1.1 christos for (i = 0; i < na; i++) {
575 1.1 christos /* XXX how should we print it? */
576 1.5 christos advance = lwres_printbinlen(ndo, s);
577 1.1 christos if (advance < 0)
578 1.1 christos goto trunc;
579 1.1 christos s += advance;
580 1.1 christos }
581 1.1 christos break;
582 1.1 christos default:
583 1.1 christos unsupported++;
584 1.1 christos break;
585 1.1 christos }
586 1.1 christos }
587 1.1 christos
588 1.1 christos tail:
589 1.1 christos /* length mismatch */
590 1.1 christos if (EXTRACT_32BITS(&np->length) != length) {
591 1.5 christos ND_PRINT((ndo, " [len: %u != %u]", EXTRACT_32BITS(&np->length),
592 1.5 christos length));
593 1.1 christos }
594 1.1 christos if (!unsupported && s < (const char *)np + EXTRACT_32BITS(&np->length))
595 1.5 christos ND_PRINT((ndo, "[extra]"));
596 1.1 christos return;
597 1.1 christos
598 1.1 christos trunc:
599 1.5 christos ND_PRINT((ndo, "[|lwres]"));
600 1.1 christos }
601