blob: c237e482a01e6882571767ce13d28fb05cecca0b [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
2 * Copyright (C) 2001 WIDE Project.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
Elliott Hughese2e3bd12017-05-15 10:59:29 -070030/* \summary: BIND9 Lightweight Resolver protocol printer */
31
The Android Open Source Project2949f582009-03-03 19:30:46 -080032#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070033#include <config.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080034#endif
35
Elliott Hughes820eced2021-08-20 18:00:50 -070036#include "netdissect-stdinc.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080037
Elliott Hughes820eced2021-08-20 18:00:50 -070038#define ND_LONGJMP_FROM_TCHECK
Elliott Hughese2e3bd12017-05-15 10:59:29 -070039#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080040#include "addrtoname.h"
Elliott Hughese2e3bd12017-05-15 10:59:29 -070041#include "extract.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080042
Elliott Hughes820eced2021-08-20 18:00:50 -070043#include "nameser.h"
44
The Android Open Source Project2949f582009-03-03 19:30:46 -080045/* BIND9 lib/lwres/include/lwres */
Elliott Hughes820eced2021-08-20 18:00:50 -070046/*
47 * Use nd_uint16_t for lwres_uint16_t
48 * Use nd_uint32_t for lwres_uint32_t
49*/
The Android Open Source Project2949f582009-03-03 19:30:46 -080050
51struct lwres_lwpacket {
Elliott Hughes820eced2021-08-20 18:00:50 -070052 nd_uint32_t length;
53 nd_uint16_t version;
54 nd_uint16_t pktflags;
55 nd_uint32_t serial;
56 nd_uint32_t opcode;
57 nd_uint32_t result;
58 nd_uint32_t recvlength;
59 nd_uint16_t authtype;
60 nd_uint16_t authlength;
The Android Open Source Project2949f582009-03-03 19:30:46 -080061};
62
63#define LWRES_LWPACKETFLAG_RESPONSE 0x0001U /* if set, pkt is a response */
64
65#define LWRES_LWPACKETVERSION_0 0
66
67#define LWRES_FLAG_TRUSTNOTREQUIRED 0x00000001U
68#define LWRES_FLAG_SECUREDATA 0x00000002U
69
70/*
71 * no-op
72 */
73#define LWRES_OPCODE_NOOP 0x00000000U
74
75typedef struct {
76 /* public */
Elliott Hughes820eced2021-08-20 18:00:50 -070077 nd_uint16_t datalength;
The Android Open Source Project2949f582009-03-03 19:30:46 -080078 /* data follows */
79} lwres_nooprequest_t;
80
81typedef struct {
82 /* public */
Elliott Hughes820eced2021-08-20 18:00:50 -070083 nd_uint16_t datalength;
The Android Open Source Project2949f582009-03-03 19:30:46 -080084 /* data follows */
85} lwres_noopresponse_t;
86
87/*
88 * get addresses by name
89 */
90#define LWRES_OPCODE_GETADDRSBYNAME 0x00010001U
91
92typedef struct lwres_addr lwres_addr_t;
93
94struct lwres_addr {
Elliott Hughes820eced2021-08-20 18:00:50 -070095 nd_uint32_t family;
96 nd_uint16_t length;
97 /* address follows */
The Android Open Source Project2949f582009-03-03 19:30:46 -080098};
Elliott Hughes820eced2021-08-20 18:00:50 -070099#define LWRES_ADDR_LEN 6
The Android Open Source Project2949f582009-03-03 19:30:46 -0800100
101typedef struct {
102 /* public */
Elliott Hughes820eced2021-08-20 18:00:50 -0700103 nd_uint32_t flags;
104 nd_uint32_t addrtypes;
105 nd_uint16_t namelen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800106 /* name follows */
107} lwres_gabnrequest_t;
Elliott Hughes820eced2021-08-20 18:00:50 -0700108#define LWRES_GABNREQUEST_LEN 10
The Android Open Source Project2949f582009-03-03 19:30:46 -0800109
110typedef struct {
111 /* public */
Elliott Hughes820eced2021-08-20 18:00:50 -0700112 nd_uint32_t flags;
113 nd_uint16_t naliases;
114 nd_uint16_t naddrs;
115 nd_uint16_t realnamelen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800116 /* aliases follows */
117 /* addrs follows */
118 /* realname follows */
119} lwres_gabnresponse_t;
Elliott Hughes820eced2021-08-20 18:00:50 -0700120#define LWRES_GABNRESPONSE_LEN 10
The Android Open Source Project2949f582009-03-03 19:30:46 -0800121
122/*
123 * get name by address
124 */
125#define LWRES_OPCODE_GETNAMEBYADDR 0x00010002U
126typedef struct {
127 /* public */
Elliott Hughes820eced2021-08-20 18:00:50 -0700128 nd_uint32_t flags;
129 /* addr follows */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800130} lwres_gnbarequest_t;
Elliott Hughes820eced2021-08-20 18:00:50 -0700131#define LWRES_GNBAREQUEST_LEN 4
The Android Open Source Project2949f582009-03-03 19:30:46 -0800132
133typedef struct {
134 /* public */
Elliott Hughes820eced2021-08-20 18:00:50 -0700135 nd_uint32_t flags;
136 nd_uint16_t naliases;
137 nd_uint16_t realnamelen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800138 /* aliases follows */
139 /* realname follows */
140} lwres_gnbaresponse_t;
Elliott Hughes820eced2021-08-20 18:00:50 -0700141#define LWRES_GNBARESPONSE_LEN 8
The Android Open Source Project2949f582009-03-03 19:30:46 -0800142
143/*
144 * get rdata by name
145 */
146#define LWRES_OPCODE_GETRDATABYNAME 0x00010003U
147
148typedef struct {
149 /* public */
Elliott Hughes820eced2021-08-20 18:00:50 -0700150 nd_uint32_t flags;
151 nd_uint16_t rdclass;
152 nd_uint16_t rdtype;
153 nd_uint16_t namelen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800154 /* name follows */
155} lwres_grbnrequest_t;
Elliott Hughes820eced2021-08-20 18:00:50 -0700156#define LWRES_GRBNREQUEST_LEN 10
The Android Open Source Project2949f582009-03-03 19:30:46 -0800157
158typedef struct {
159 /* public */
Elliott Hughes820eced2021-08-20 18:00:50 -0700160 nd_uint32_t flags;
161 nd_uint16_t rdclass;
162 nd_uint16_t rdtype;
163 nd_uint32_t ttl;
164 nd_uint16_t nrdatas;
165 nd_uint16_t nsigs;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800166 /* realname here (len + name) */
167 /* rdata here (len + name) */
168 /* signatures here (len + name) */
169} lwres_grbnresponse_t;
Elliott Hughes820eced2021-08-20 18:00:50 -0700170#define LWRES_GRBNRESPONSE_LEN 16
The Android Open Source Project2949f582009-03-03 19:30:46 -0800171
172#define LWRDATA_VALIDATED 0x00000001
173
174#define LWRES_ADDRTYPE_V4 0x00000001U /* ipv4 */
175#define LWRES_ADDRTYPE_V6 0x00000002U /* ipv6 */
176
177#define LWRES_MAX_ALIASES 16 /* max # of aliases */
178#define LWRES_MAX_ADDRS 64 /* max # of addrs */
179
JP Abgrall53f17a92014-02-12 14:02:41 -0800180static const struct tok opcode[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800181 { LWRES_OPCODE_NOOP, "noop", },
182 { LWRES_OPCODE_GETADDRSBYNAME, "getaddrsbyname", },
183 { LWRES_OPCODE_GETNAMEBYADDR, "getnamebyaddr", },
184 { LWRES_OPCODE_GETRDATABYNAME, "getrdatabyname", },
185 { 0, NULL, },
186};
187
188/* print-domain.c */
JP Abgrall53f17a92014-02-12 14:02:41 -0800189extern const struct tok ns_type2str[];
190extern const struct tok ns_class2str[];
The Android Open Source Project2949f582009-03-03 19:30:46 -0800191
Elliott Hughes820eced2021-08-20 18:00:50 -0700192static unsigned
Elliott Hughes892a68b2015-10-19 14:43:53 -0700193lwres_printname(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700194 size_t l, const u_char *p0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800195{
Elliott Hughes820eced2021-08-20 18:00:50 -0700196 ND_PRINT(" ");
197 (void)nd_printn(ndo, p0, l, NULL);
198 p0 += l;
199 if (GET_U_1(p0))
200 ND_PRINT(" (not NUL-terminated!)");
201 return l + 1;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800202}
203
Elliott Hughes820eced2021-08-20 18:00:50 -0700204static unsigned
Elliott Hughes892a68b2015-10-19 14:43:53 -0700205lwres_printnamelen(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700206 const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800207{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700208 uint16_t l;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800209 int advance;
210
Elliott Hughes820eced2021-08-20 18:00:50 -0700211 l = GET_BE_U_2(p);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700212 advance = lwres_printname(ndo, l, p + 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800213 return 2 + advance;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800214}
215
Elliott Hughes820eced2021-08-20 18:00:50 -0700216static unsigned
Elliott Hughes892a68b2015-10-19 14:43:53 -0700217lwres_printbinlen(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700218 const u_char *p0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800219{
Elliott Hughes820eced2021-08-20 18:00:50 -0700220 const u_char *p;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700221 uint16_t l;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800222 int i;
223
224 p = p0;
Elliott Hughes820eced2021-08-20 18:00:50 -0700225 l = GET_BE_U_2(p);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800226 p += 2;
Elliott Hughes820eced2021-08-20 18:00:50 -0700227 for (i = 0; i < l; i++) {
228 ND_PRINT("%02x", GET_U_1(p));
229 p++;
230 }
231 return 2 + l;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800232}
233
234static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700235lwres_printaddr(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700236 const u_char *p0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800237{
Elliott Hughes820eced2021-08-20 18:00:50 -0700238 const u_char *p;
239 const lwres_addr_t *ap;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700240 uint16_t l;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800241 int i;
242
Elliott Hughes820eced2021-08-20 18:00:50 -0700243 p = p0;
244 ap = (const lwres_addr_t *)p;
245 l = GET_BE_U_2(ap->length);
246 p += LWRES_ADDR_LEN;
247 ND_TCHECK_LEN(p, l);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800248
Elliott Hughes820eced2021-08-20 18:00:50 -0700249 switch (GET_BE_U_4(ap->family)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800250 case 1: /* IPv4 */
251 if (l < 4)
252 return -1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700253 ND_PRINT(" %s", GET_IPADDR_STRING(p));
254 p += sizeof(nd_ipv4);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800255 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800256 case 2: /* IPv6 */
257 if (l < 16)
258 return -1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700259 ND_PRINT(" %s", GET_IP6ADDR_STRING(p));
260 p += sizeof(nd_ipv6);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800261 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800262 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700263 ND_PRINT(" %u/", GET_BE_U_4(ap->family));
264 for (i = 0; i < l; i++) {
265 ND_PRINT("%02x", GET_U_1(p));
266 p++;
267 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800268 }
269
Elliott Hughes820eced2021-08-20 18:00:50 -0700270 return ND_BYTES_BETWEEN(p, p0);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800271}
272
273void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700274lwres_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700275 const u_char *bp, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800276{
Elliott Hughes820eced2021-08-20 18:00:50 -0700277 const u_char *p;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800278 const struct lwres_lwpacket *np;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700279 uint32_t v;
Elliott Hughes820eced2021-08-20 18:00:50 -0700280 const u_char *s;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800281 int response;
282 int advance;
283 int unsupported = 0;
284
Elliott Hughes820eced2021-08-20 18:00:50 -0700285 ndo->ndo_protocol = "lwres";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800286 np = (const struct lwres_lwpacket *)bp;
Elliott Hughes820eced2021-08-20 18:00:50 -0700287 ND_TCHECK_2(np->authlength);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800288
Elliott Hughes820eced2021-08-20 18:00:50 -0700289 ND_PRINT(" lwres");
290 v = GET_BE_U_2(np->version);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700291 if (ndo->ndo_vflag || v != LWRES_LWPACKETVERSION_0)
Elliott Hughes820eced2021-08-20 18:00:50 -0700292 ND_PRINT(" v%u", v);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800293 if (v != LWRES_LWPACKETVERSION_0) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700294 s = bp + GET_BE_U_4(np->length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800295 goto tail;
296 }
297
Elliott Hughes820eced2021-08-20 18:00:50 -0700298 response = GET_BE_U_2(np->pktflags) & LWRES_LWPACKETFLAG_RESPONSE;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800299
300 /* opcode and pktflags */
Elliott Hughes820eced2021-08-20 18:00:50 -0700301 v = GET_BE_U_4(np->opcode);
302 ND_PRINT(" %s%s", tok2str(opcode, "#0x%x", v), response ? "" : "?");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800303
304 /* pktflags */
Elliott Hughes820eced2021-08-20 18:00:50 -0700305 v = GET_BE_U_2(np->pktflags);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800306 if (v & ~LWRES_LWPACKETFLAG_RESPONSE)
Elliott Hughes820eced2021-08-20 18:00:50 -0700307 ND_PRINT("[0x%x]", v);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800308
Elliott Hughes892a68b2015-10-19 14:43:53 -0700309 if (ndo->ndo_vflag > 1) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700310 ND_PRINT(" ("); /*)*/
311 ND_PRINT("serial:0x%x", GET_BE_U_4(np->serial));
312 ND_PRINT(" result:0x%x", GET_BE_U_4(np->result));
313 ND_PRINT(" recvlen:%u", GET_BE_U_4(np->recvlength));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800314 /* BIND910: not used */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700315 if (ndo->ndo_vflag > 2) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700316 ND_PRINT(" authtype:0x%x", GET_BE_U_2(np->authtype));
317 ND_PRINT(" authlen:%u", GET_BE_U_2(np->authlength));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800318 }
319 /*(*/
Elliott Hughes820eced2021-08-20 18:00:50 -0700320 ND_PRINT(")");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800321 }
322
323 /* per-opcode content */
324 if (!response) {
325 /*
326 * queries
327 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700328 const lwres_gabnrequest_t *gabn;
329 const lwres_gnbarequest_t *gnba;
330 const lwres_grbnrequest_t *grbn;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700331 uint32_t l;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800332
333 gabn = NULL;
334 gnba = NULL;
335 grbn = NULL;
336
Elliott Hughes820eced2021-08-20 18:00:50 -0700337 p = (const u_char *)(np + 1);
338 switch (GET_BE_U_4(np->opcode)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800339 case LWRES_OPCODE_NOOP:
Elliott Hughes820eced2021-08-20 18:00:50 -0700340 s = p;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800341 break;
342 case LWRES_OPCODE_GETADDRSBYNAME:
Elliott Hughes820eced2021-08-20 18:00:50 -0700343 gabn = (const lwres_gabnrequest_t *)p;
344 ND_TCHECK_2(gabn->namelen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800345
346 /* BIND910: not used */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700347 if (ndo->ndo_vflag > 2) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700348 ND_PRINT(" flags:0x%x",
349 GET_BE_U_4(gabn->flags));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800350 }
351
Elliott Hughes820eced2021-08-20 18:00:50 -0700352 v = GET_BE_U_4(gabn->addrtypes);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800353 switch (v & (LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6)) {
354 case LWRES_ADDRTYPE_V4:
Elliott Hughes820eced2021-08-20 18:00:50 -0700355 ND_PRINT(" IPv4");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800356 break;
357 case LWRES_ADDRTYPE_V6:
Elliott Hughes820eced2021-08-20 18:00:50 -0700358 ND_PRINT(" IPv6");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800359 break;
360 case LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6:
Elliott Hughes820eced2021-08-20 18:00:50 -0700361 ND_PRINT(" IPv4/6");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800362 break;
363 }
364 if (v & ~(LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6))
Elliott Hughes820eced2021-08-20 18:00:50 -0700365 ND_PRINT("[0x%x]", v);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800366
Elliott Hughes820eced2021-08-20 18:00:50 -0700367 s = p + LWRES_GABNREQUEST_LEN;
368 l = GET_BE_U_2(gabn->namelen);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700369 advance = lwres_printname(ndo, l, s);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800370 s += advance;
371 break;
372 case LWRES_OPCODE_GETNAMEBYADDR:
Elliott Hughes820eced2021-08-20 18:00:50 -0700373 gnba = (const lwres_gnbarequest_t *)p;
374 ND_TCHECK_4(gnba->flags);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800375
376 /* BIND910: not used */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700377 if (ndo->ndo_vflag > 2) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700378 ND_PRINT(" flags:0x%x",
379 GET_BE_U_4(gnba->flags));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800380 }
381
Elliott Hughes820eced2021-08-20 18:00:50 -0700382 s = p + LWRES_GNBAREQUEST_LEN;
383 advance = lwres_printaddr(ndo, s);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800384 if (advance < 0)
Elliott Hughes820eced2021-08-20 18:00:50 -0700385 goto invalid;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800386 s += advance;
387 break;
388 case LWRES_OPCODE_GETRDATABYNAME:
389 /* XXX no trace, not tested */
Elliott Hughes820eced2021-08-20 18:00:50 -0700390 grbn = (const lwres_grbnrequest_t *)p;
391 ND_TCHECK_2(grbn->namelen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800392
393 /* BIND910: not used */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700394 if (ndo->ndo_vflag > 2) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700395 ND_PRINT(" flags:0x%x",
396 GET_BE_U_4(grbn->flags));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800397 }
398
Elliott Hughes820eced2021-08-20 18:00:50 -0700399 ND_PRINT(" %s", tok2str(ns_type2str, "Type%u",
400 GET_BE_U_2(grbn->rdtype)));
401 if (GET_BE_U_2(grbn->rdclass) != C_IN) {
402 ND_PRINT(" %s", tok2str(ns_class2str, "Class%u",
403 GET_BE_U_2(grbn->rdclass)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800404 }
405
Elliott Hughes820eced2021-08-20 18:00:50 -0700406 s = p + LWRES_GRBNREQUEST_LEN;
407 l = GET_BE_U_2(grbn->namelen);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700408 advance = lwres_printname(ndo, l, s);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800409 s += advance;
410 break;
411 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700412 s = p;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800413 unsupported++;
414 break;
415 }
416 } else {
417 /*
418 * responses
419 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700420 const lwres_gabnresponse_t *gabn;
421 const lwres_gnbaresponse_t *gnba;
422 const lwres_grbnresponse_t *grbn;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700423 uint32_t l, na;
424 uint32_t i;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800425
426 gabn = NULL;
427 gnba = NULL;
428 grbn = NULL;
429
Elliott Hughes820eced2021-08-20 18:00:50 -0700430 p = (const u_char *)(np + 1);
431 switch (GET_BE_U_4(np->opcode)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800432 case LWRES_OPCODE_NOOP:
Elliott Hughes820eced2021-08-20 18:00:50 -0700433 s = p;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800434 break;
435 case LWRES_OPCODE_GETADDRSBYNAME:
Elliott Hughes820eced2021-08-20 18:00:50 -0700436 gabn = (const lwres_gabnresponse_t *)p;
437 ND_TCHECK_2(gabn->realnamelen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800438
439 /* BIND910: not used */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700440 if (ndo->ndo_vflag > 2) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700441 ND_PRINT(" flags:0x%x",
442 GET_BE_U_4(gabn->flags));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800443 }
444
Elliott Hughes820eced2021-08-20 18:00:50 -0700445 ND_PRINT(" %u/%u", GET_BE_U_2(gabn->naliases),
446 GET_BE_U_2(gabn->naddrs));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800447
Elliott Hughes820eced2021-08-20 18:00:50 -0700448 s = p + LWRES_GABNRESPONSE_LEN;
449 l = GET_BE_U_2(gabn->realnamelen);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700450 advance = lwres_printname(ndo, l, s);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800451 s += advance;
452
453 /* aliases */
Elliott Hughes820eced2021-08-20 18:00:50 -0700454 na = GET_BE_U_2(gabn->naliases);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800455 for (i = 0; i < na; i++) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700456 advance = lwres_printnamelen(ndo, s);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800457 s += advance;
458 }
459
460 /* addrs */
Elliott Hughes820eced2021-08-20 18:00:50 -0700461 na = GET_BE_U_2(gabn->naddrs);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800462 for (i = 0; i < na; i++) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700463 advance = lwres_printaddr(ndo, s);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800464 if (advance < 0)
Elliott Hughes820eced2021-08-20 18:00:50 -0700465 goto invalid;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800466 s += advance;
467 }
468 break;
469 case LWRES_OPCODE_GETNAMEBYADDR:
Elliott Hughes820eced2021-08-20 18:00:50 -0700470 gnba = (const lwres_gnbaresponse_t *)p;
471 ND_TCHECK_2(gnba->realnamelen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800472
473 /* BIND910: not used */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700474 if (ndo->ndo_vflag > 2) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700475 ND_PRINT(" flags:0x%x",
476 GET_BE_U_4(gnba->flags));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800477 }
478
Elliott Hughes820eced2021-08-20 18:00:50 -0700479 ND_PRINT(" %u", GET_BE_U_2(gnba->naliases));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800480
Elliott Hughes820eced2021-08-20 18:00:50 -0700481 s = p + LWRES_GNBARESPONSE_LEN;
482 l = GET_BE_U_2(gnba->realnamelen);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700483 advance = lwres_printname(ndo, l, s);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800484 s += advance;
485
486 /* aliases */
Elliott Hughes820eced2021-08-20 18:00:50 -0700487 na = GET_BE_U_2(gnba->naliases);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800488 for (i = 0; i < na; i++) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700489 advance = lwres_printnamelen(ndo, s);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800490 s += advance;
491 }
492 break;
493 case LWRES_OPCODE_GETRDATABYNAME:
494 /* XXX no trace, not tested */
Elliott Hughes820eced2021-08-20 18:00:50 -0700495 grbn = (const lwres_grbnresponse_t *)p;
496 ND_TCHECK_2(grbn->nsigs);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800497
498 /* BIND910: not used */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700499 if (ndo->ndo_vflag > 2) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700500 ND_PRINT(" flags:0x%x",
501 GET_BE_U_4(grbn->flags));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800502 }
503
Elliott Hughes820eced2021-08-20 18:00:50 -0700504 ND_PRINT(" %s", tok2str(ns_type2str, "Type%u",
505 GET_BE_U_2(grbn->rdtype)));
506 if (GET_BE_U_2(grbn->rdclass) != C_IN) {
507 ND_PRINT(" %s", tok2str(ns_class2str, "Class%u",
508 GET_BE_U_2(grbn->rdclass)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800509 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700510 ND_PRINT(" TTL ");
511 unsigned_relts_print(ndo,
512 GET_BE_U_4(grbn->ttl));
513 ND_PRINT(" %u/%u", GET_BE_U_2(grbn->nrdatas),
514 GET_BE_U_2(grbn->nsigs));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800515
Elliott Hughes820eced2021-08-20 18:00:50 -0700516 s = p + LWRES_GRBNRESPONSE_LEN;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700517 advance = lwres_printnamelen(ndo, s);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800518 s += advance;
519
520 /* rdatas */
Elliott Hughes820eced2021-08-20 18:00:50 -0700521 na = GET_BE_U_2(grbn->nrdatas);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800522 for (i = 0; i < na; i++) {
523 /* XXX should decode resource data */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700524 advance = lwres_printbinlen(ndo, s);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800525 s += advance;
526 }
527
528 /* sigs */
Elliott Hughes820eced2021-08-20 18:00:50 -0700529 na = GET_BE_U_2(grbn->nsigs);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800530 for (i = 0; i < na; i++) {
531 /* XXX how should we print it? */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700532 advance = lwres_printbinlen(ndo, s);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800533 s += advance;
534 }
535 break;
536 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700537 s = p;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800538 unsupported++;
539 break;
540 }
541 }
542
543 tail:
544 /* length mismatch */
Elliott Hughes820eced2021-08-20 18:00:50 -0700545 if (GET_BE_U_4(np->length) != length) {
546 ND_PRINT(" [len: %u != %u]", GET_BE_U_4(np->length),
547 length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800548 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700549 if (!unsupported && s < bp + GET_BE_U_4(np->length))
550 ND_PRINT("[extra]");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800551 return;
552
Elliott Hughes820eced2021-08-20 18:00:50 -0700553 invalid:
554 nd_print_invalid(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800555}