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