|
|
f1dd77 |
commit f282cdbe7f436c75864e5640a409a10485e9abb2
|
|
|
f1dd77 |
Author: Florian Weimer <fweimer@redhat.com>
|
|
|
f1dd77 |
Date: Fri Jun 24 18:16:41 2022 +0200
|
|
|
f1dd77 |
|
|
|
f1dd77 |
resolv: Implement no-aaaa stub resolver option
|
|
|
f1dd77 |
|
|
|
f1dd77 |
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
|
|
|
f1dd77 |
|
|
|
f1dd77 |
Conflicts:
|
|
|
f1dd77 |
resolv/Makefile
|
|
|
f1dd77 |
(missing partial libresolv integration downstream)
|
|
|
f1dd77 |
resolv/res-noaaaa.c
|
|
|
f1dd77 |
(call ns_name_skip instead of __ns_name_skip (not available
|
|
|
f1dd77 |
downstream) and ns_name_unpack instead of __ns_name_unpack
|
|
|
f1dd77 |
(avoid PLT))
|
|
|
f1dd77 |
resolv/res_debug.c
|
|
|
f1dd77 |
resolv/res_init.c
|
|
|
f1dd77 |
resolv/resolv.h
|
|
|
f1dd77 |
resolv/tst-resolv-res_init-skeleton.c
|
|
|
f1dd77 |
(missing trust-ad support downstream)
|
|
|
f1dd77 |
|
|
|
f1dd77 |
diff --git a/resolv/Makefile b/resolv/Makefile
|
|
|
f1dd77 |
index cee5225f8933f245..ab8ad49b5318ad41 100644
|
|
|
f1dd77 |
--- a/resolv/Makefile
|
|
|
f1dd77 |
+++ b/resolv/Makefile
|
|
|
f1dd77 |
@@ -57,6 +57,7 @@ tests += \
|
|
|
f1dd77 |
tst-resolv-binary \
|
|
|
f1dd77 |
tst-resolv-edns \
|
|
|
f1dd77 |
tst-resolv-network \
|
|
|
f1dd77 |
+ tst-resolv-noaaaa \
|
|
|
f1dd77 |
tst-resolv-nondecimal \
|
|
|
f1dd77 |
tst-resolv-res_init-multi \
|
|
|
f1dd77 |
tst-resolv-search \
|
|
|
f1dd77 |
@@ -110,7 +111,7 @@ libresolv-routines := res_comp res_debug \
|
|
|
f1dd77 |
res_data res_mkquery res_query res_send \
|
|
|
f1dd77 |
inet_net_ntop inet_net_pton inet_neta base64 \
|
|
|
f1dd77 |
ns_parse ns_name ns_netint ns_ttl ns_print \
|
|
|
f1dd77 |
- ns_samedomain ns_date res_enable_icmp \
|
|
|
f1dd77 |
+ ns_samedomain ns_date res_enable_icmp res-noaaaa \
|
|
|
f1dd77 |
compat-hooks compat-gethnamaddr
|
|
|
f1dd77 |
|
|
|
f1dd77 |
libanl-routines := gai_cancel gai_error gai_misc gai_notify gai_suspend \
|
|
|
f1dd77 |
@@ -200,6 +201,7 @@ $(objpfx)tst-resolv-res_init-multi: $(objpfx)libresolv.so \
|
|
|
f1dd77 |
$(shared-thread-library)
|
|
|
f1dd77 |
$(objpfx)tst-resolv-res_init-thread: $(libdl) $(objpfx)libresolv.so \
|
|
|
f1dd77 |
$(shared-thread-library)
|
|
|
f1dd77 |
+$(objpfx)tst-resolv-noaaaa: $(objpfx)libresolv.so $(shared-thread-library)
|
|
|
f1dd77 |
$(objpfx)tst-resolv-nondecimal: $(objpfx)libresolv.so $(shared-thread-library)
|
|
|
f1dd77 |
$(objpfx)tst-resolv-qtypes: $(objpfx)libresolv.so $(shared-thread-library)
|
|
|
f1dd77 |
$(objpfx)tst-resolv-rotate: $(objpfx)libresolv.so $(shared-thread-library)
|
|
|
f1dd77 |
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
|
|
|
f1dd77 |
index 99c3b61e1cee4d42..ff0a0b6f7f1f4703 100644
|
|
|
f1dd77 |
--- a/resolv/nss_dns/dns-host.c
|
|
|
f1dd77 |
+++ b/resolv/nss_dns/dns-host.c
|
|
|
f1dd77 |
@@ -123,6 +123,14 @@ static enum nss_status gaih_getanswer (const querybuf *answer1, int anslen1,
|
|
|
f1dd77 |
char *buffer, size_t buflen,
|
|
|
f1dd77 |
int *errnop, int *h_errnop,
|
|
|
f1dd77 |
int32_t *ttlp);
|
|
|
f1dd77 |
+static enum nss_status gaih_getanswer_noaaaa (const querybuf *answer1,
|
|
|
f1dd77 |
+ int anslen1,
|
|
|
f1dd77 |
+ const char *qname,
|
|
|
f1dd77 |
+ struct gaih_addrtuple **pat,
|
|
|
f1dd77 |
+ char *buffer, size_t buflen,
|
|
|
f1dd77 |
+ int *errnop, int *h_errnop,
|
|
|
f1dd77 |
+ int32_t *ttlp);
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
|
|
|
f1dd77 |
static enum nss_status gethostbyname3_context (struct resolv_context *ctx,
|
|
|
f1dd77 |
const char *name, int af,
|
|
|
f1dd77 |
@@ -367,17 +375,31 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
|
|
|
f1dd77 |
int resplen2 = 0;
|
|
|
f1dd77 |
int ans2p_malloced = 0;
|
|
|
f1dd77 |
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
int olderr = errno;
|
|
|
f1dd77 |
- int n = __res_context_search (ctx, name, C_IN, T_QUERY_A_AND_AAAA,
|
|
|
f1dd77 |
+ int n;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ if ((ctx->resp->options & RES_NOAAAA) == 0)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ n = __res_context_search (ctx, name, C_IN, T_QUERY_A_AND_AAAA,
|
|
|
f1dd77 |
host_buffer.buf->buf, 2048, &host_buffer.ptr,
|
|
|
f1dd77 |
&ans2p, &nans2p, &resplen2, &ans2p_malloced);
|
|
|
f1dd77 |
- if (n >= 0)
|
|
|
f1dd77 |
- {
|
|
|
f1dd77 |
- status = gaih_getanswer (host_buffer.buf, n, (const querybuf *) ans2p,
|
|
|
f1dd77 |
- resplen2, name, pat, buffer, buflen,
|
|
|
f1dd77 |
- errnop, herrnop, ttlp);
|
|
|
f1dd77 |
+ if (n >= 0)
|
|
|
f1dd77 |
+ status = gaih_getanswer (host_buffer.buf, n, (const querybuf *) ans2p,
|
|
|
f1dd77 |
+ resplen2, name, pat, buffer, buflen,
|
|
|
f1dd77 |
+ errnop, herrnop, ttlp);
|
|
|
f1dd77 |
}
|
|
|
f1dd77 |
else
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ n = __res_context_search (ctx, name, C_IN, T_A,
|
|
|
f1dd77 |
+ host_buffer.buf->buf, 2048, NULL,
|
|
|
f1dd77 |
+ NULL, NULL, NULL, NULL);
|
|
|
f1dd77 |
+ if (n >= 0)
|
|
|
f1dd77 |
+ status = gaih_getanswer_noaaaa (host_buffer.buf, n,
|
|
|
f1dd77 |
+ name, pat, buffer, buflen,
|
|
|
f1dd77 |
+ errnop, herrnop, ttlp);
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ if (n < 0)
|
|
|
f1dd77 |
{
|
|
|
f1dd77 |
switch (errno)
|
|
|
f1dd77 |
{
|
|
|
f1dd77 |
@@ -1386,3 +1408,21 @@ gaih_getanswer (const querybuf *answer1, int anslen1, const querybuf *answer2,
|
|
|
f1dd77 |
|
|
|
f1dd77 |
return status;
|
|
|
f1dd77 |
}
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+/* Variant of gaih_getanswer without a second (AAAA) response. */
|
|
|
f1dd77 |
+static enum nss_status
|
|
|
f1dd77 |
+gaih_getanswer_noaaaa (const querybuf *answer1, int anslen1, const char *qname,
|
|
|
f1dd77 |
+ struct gaih_addrtuple **pat,
|
|
|
f1dd77 |
+ char *buffer, size_t buflen,
|
|
|
f1dd77 |
+ int *errnop, int *h_errnop, int32_t *ttlp)
|
|
|
f1dd77 |
+{
|
|
|
f1dd77 |
+ int first = 1;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ enum nss_status status = NSS_STATUS_NOTFOUND;
|
|
|
f1dd77 |
+ if (anslen1 > 0)
|
|
|
f1dd77 |
+ status = gaih_getanswer_slice (answer1, anslen1, qname,
|
|
|
f1dd77 |
+ &pat, &buffer, &buflen,
|
|
|
f1dd77 |
+ errnop, h_errnop, ttlp,
|
|
|
f1dd77 |
+ &first);
|
|
|
f1dd77 |
+ return status;
|
|
|
f1dd77 |
+}
|
|
|
f1dd77 |
diff --git a/resolv/res-noaaaa.c b/resolv/res-noaaaa.c
|
|
|
f1dd77 |
new file mode 100644
|
|
|
f1dd77 |
index 0000000000000000..e2a13cf38a74c160
|
|
|
f1dd77 |
--- /dev/null
|
|
|
f1dd77 |
+++ b/resolv/res-noaaaa.c
|
|
|
f1dd77 |
@@ -0,0 +1,143 @@
|
|
|
f1dd77 |
+/* Implement suppression of AAAA queries.
|
|
|
f1dd77 |
+ Copyright (C) 2022 Free Software Foundation, Inc.
|
|
|
f1dd77 |
+ This file is part of the GNU C Library.
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
f1dd77 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
f1dd77 |
+ License as published by the Free Software Foundation; either
|
|
|
f1dd77 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
f1dd77 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
f1dd77 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
f1dd77 |
+ Lesser General Public License for more details.
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
f1dd77 |
+ License along with the GNU C Library; if not, see
|
|
|
f1dd77 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+#include <resolv.h>
|
|
|
f1dd77 |
+#include <string.h>
|
|
|
f1dd77 |
+#include <resolv-internal.h>
|
|
|
f1dd77 |
+#include <resolv_context.h>
|
|
|
f1dd77 |
+#include <arpa/nameser.h>
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+/* Returns true if the question type at P matches EXPECTED, and the
|
|
|
f1dd77 |
+ class is IN. */
|
|
|
f1dd77 |
+static bool
|
|
|
f1dd77 |
+qtype_matches (const unsigned char *p, int expected)
|
|
|
f1dd77 |
+{
|
|
|
f1dd77 |
+ /* This assumes that T_A/C_IN constants are less than 256, which
|
|
|
f1dd77 |
+ they are. */
|
|
|
f1dd77 |
+ return p[0] == 0 && p[1] == expected && p[2] == 0 && p[3] == C_IN;
|
|
|
f1dd77 |
+}
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+/* Handle RES_NOAAAA translation of AAAA queries. To produce a Name
|
|
|
f1dd77 |
+ Error (NXDOMAIN) repsonse for domain names that do not exist, it is
|
|
|
f1dd77 |
+ still necessary to send a query. Using question type A is a
|
|
|
f1dd77 |
+ conservative choice. In the returned answer, it is necessary to
|
|
|
f1dd77 |
+ switch back the question type to AAAA. */
|
|
|
f1dd77 |
+bool
|
|
|
f1dd77 |
+__res_handle_no_aaaa (struct resolv_context *ctx,
|
|
|
f1dd77 |
+ const unsigned char *buf, int buflen,
|
|
|
f1dd77 |
+ unsigned char *ans, int anssiz, int *result)
|
|
|
f1dd77 |
+{
|
|
|
f1dd77 |
+ /* AAAA mode is not active, or the query looks invalid (will not be
|
|
|
f1dd77 |
+ able to be parsed). */
|
|
|
f1dd77 |
+ if ((ctx->resp->options & RES_NOAAAA) == 0
|
|
|
f1dd77 |
+ || buflen <= sizeof (HEADER))
|
|
|
f1dd77 |
+ return false;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* The replacement A query is produced here. */
|
|
|
f1dd77 |
+ struct
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ HEADER header;
|
|
|
f1dd77 |
+ unsigned char question[NS_MAXCDNAME + 4];
|
|
|
f1dd77 |
+ } replacement;
|
|
|
f1dd77 |
+ memcpy (&replacement.header, buf, sizeof (replacement.header));
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ if (replacement.header.qr
|
|
|
f1dd77 |
+ || replacement.header.opcode != 0
|
|
|
f1dd77 |
+ || replacement.header.rcode != 0
|
|
|
f1dd77 |
+ || ntohs (replacement.header.qdcount) != 1
|
|
|
f1dd77 |
+ || ntohs (replacement.header.ancount) != 0
|
|
|
f1dd77 |
+ || ntohs (replacement.header.nscount) != 0)
|
|
|
f1dd77 |
+ /* Not a well-formed question. Let the core resolver code produce
|
|
|
f1dd77 |
+ the proper error. */
|
|
|
f1dd77 |
+ return false;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* Disable EDNS0. */
|
|
|
f1dd77 |
+ replacement.header.arcount = htons (0);
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* Extract the QNAME. */
|
|
|
f1dd77 |
+ int ret = ns_name_unpack (buf, buf + buflen, buf + sizeof (HEADER),
|
|
|
f1dd77 |
+ replacement.question, NS_MAXCDNAME);
|
|
|
f1dd77 |
+ if (ret < 0)
|
|
|
f1dd77 |
+ /* Format error. */
|
|
|
f1dd77 |
+ return false;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* Compute the end of the question name. */
|
|
|
f1dd77 |
+ const unsigned char *after_question = buf + sizeof (HEADER) + ret;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* Check that we are dealing with an AAAA query. */
|
|
|
f1dd77 |
+ if (buf + buflen - after_question < 4
|
|
|
f1dd77 |
+ || !qtype_matches (after_question, T_AAAA))
|
|
|
f1dd77 |
+ return false;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* Find the place to store the type/class data in the replacement
|
|
|
f1dd77 |
+ query. */
|
|
|
f1dd77 |
+ after_question = replacement.question;
|
|
|
f1dd77 |
+ /* This cannot fail because ns_name_unpack above produced a valid
|
|
|
f1dd77 |
+ domain name. */
|
|
|
f1dd77 |
+ (void) ns_name_skip (&after_question, &replacement.question[NS_MAXCDNAME]);
|
|
|
f1dd77 |
+ unsigned char *start_of_query = (unsigned char *) &replacement;
|
|
|
f1dd77 |
+ const unsigned char *end_of_query = after_question + 4;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* Produce an A/IN query. */
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ unsigned char *p = (unsigned char *) after_question;
|
|
|
f1dd77 |
+ p[0] = 0;
|
|
|
f1dd77 |
+ p[1] = T_A;
|
|
|
f1dd77 |
+ p[2] = 0;
|
|
|
f1dd77 |
+ p[3] = C_IN;
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* Clear the output buffer, to avoid reading undefined data when
|
|
|
f1dd77 |
+ rewriting the result from A to AAAA. */
|
|
|
f1dd77 |
+ memset (ans, 0, anssiz);
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* Always perform the message translation, independent of the error
|
|
|
f1dd77 |
+ code. */
|
|
|
f1dd77 |
+ ret = __res_context_send (ctx,
|
|
|
f1dd77 |
+ start_of_query, end_of_query - start_of_query,
|
|
|
f1dd77 |
+ NULL, 0, ans, anssiz,
|
|
|
f1dd77 |
+ NULL, NULL, NULL, NULL, NULL);
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* Patch in the AAAA question type if there is room and the A query
|
|
|
f1dd77 |
+ type was received. */
|
|
|
f1dd77 |
+ after_question = ans + sizeof (HEADER);
|
|
|
f1dd77 |
+ if (ns_name_skip (&after_question, ans + anssiz) == 0
|
|
|
f1dd77 |
+ && ans + anssiz - after_question >= 4
|
|
|
f1dd77 |
+ && qtype_matches (after_question, T_A))
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ ((unsigned char *) after_question)[1] = T_AAAA;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* Create an aligned copy of the header. Hide all data except
|
|
|
f1dd77 |
+ the question from the response. Put back the header. There is
|
|
|
f1dd77 |
+ no need to change the response code. The zero answer count turns
|
|
|
f1dd77 |
+ a positive response with data into a no-data response. */
|
|
|
f1dd77 |
+ memcpy (&replacement.header, ans, sizeof (replacement.header));
|
|
|
f1dd77 |
+ replacement.header.ancount = htons (0);
|
|
|
f1dd77 |
+ replacement.header.nscount = htons (0);
|
|
|
f1dd77 |
+ replacement.header.arcount = htons (0);
|
|
|
f1dd77 |
+ memcpy (ans, &replacement.header, sizeof (replacement.header));
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* Truncate the reply. */
|
|
|
f1dd77 |
+ if (ret <= 0)
|
|
|
f1dd77 |
+ *result = ret;
|
|
|
f1dd77 |
+ else
|
|
|
f1dd77 |
+ *result = after_question - ans + 4;
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ return true;
|
|
|
f1dd77 |
+}
|
|
|
f1dd77 |
diff --git a/resolv/res_debug.c b/resolv/res_debug.c
|
|
|
f1dd77 |
index 7681ad4639d8a7bc..43b3b1bfe4afdcaf 100644
|
|
|
f1dd77 |
--- a/resolv/res_debug.c
|
|
|
f1dd77 |
+++ b/resolv/res_debug.c
|
|
|
f1dd77 |
@@ -615,6 +615,7 @@ p_option(u_long option) {
|
|
|
f1dd77 |
case RES_USE_DNSSEC: return "dnssec";
|
|
|
f1dd77 |
case RES_NOTLDQUERY: return "no-tld-query";
|
|
|
f1dd77 |
case RES_NORELOAD: return "no-reload";
|
|
|
f1dd77 |
+ case RES_NOAAAA: return "no-aaaa";
|
|
|
f1dd77 |
/* XXX nonreentrant */
|
|
|
f1dd77 |
default: sprintf(nbuf, "?0x%lx?", (u_long)option);
|
|
|
f1dd77 |
return (nbuf);
|
|
|
f1dd77 |
diff --git a/resolv/res_init.c b/resolv/res_init.c
|
|
|
f1dd77 |
index bb99ddeec4d6d47f..20434bfe147a3fb5 100644
|
|
|
f1dd77 |
--- a/resolv/res_init.c
|
|
|
f1dd77 |
+++ b/resolv/res_init.c
|
|
|
f1dd77 |
@@ -694,7 +694,8 @@ res_setoptions (struct resolv_conf_parser *parser, const char *options)
|
|
|
f1dd77 |
{ STRnLEN ("no_tld_query"), 0, RES_NOTLDQUERY },
|
|
|
f1dd77 |
{ STRnLEN ("no-tld-query"), 0, RES_NOTLDQUERY },
|
|
|
f1dd77 |
{ STRnLEN ("no-reload"), 0, RES_NORELOAD },
|
|
|
f1dd77 |
- { STRnLEN ("use-vc"), 0, RES_USEVC }
|
|
|
f1dd77 |
+ { STRnLEN ("use-vc"), 0, RES_USEVC },
|
|
|
f1dd77 |
+ { STRnLEN ("no-aaaa"), 0, RES_NOAAAA },
|
|
|
f1dd77 |
};
|
|
|
f1dd77 |
#define noptions (sizeof (options) / sizeof (options[0]))
|
|
|
f1dd77 |
for (int i = 0; i < noptions; ++i)
|
|
|
f1dd77 |
diff --git a/resolv/res_query.c b/resolv/res_query.c
|
|
|
f1dd77 |
index ebbe5a6a4ed86abe..d94966a47c3dac90 100644
|
|
|
f1dd77 |
--- a/resolv/res_query.c
|
|
|
f1dd77 |
+++ b/resolv/res_query.c
|
|
|
f1dd77 |
@@ -204,10 +204,26 @@ __res_context_query (struct resolv_context *ctx, const char *name,
|
|
|
f1dd77 |
free (buf);
|
|
|
f1dd77 |
return (n);
|
|
|
f1dd77 |
}
|
|
|
f1dd77 |
- assert (answerp == NULL || (void *) *answerp == (void *) answer);
|
|
|
f1dd77 |
- n = __res_context_send (ctx, query1, nquery1, query2, nquery2, answer,
|
|
|
f1dd77 |
- anslen, answerp, answerp2, nanswerp2, resplen2,
|
|
|
f1dd77 |
- answerp2_malloced);
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* Suppress AAAA lookups if required. __res_handle_no_aaaa
|
|
|
f1dd77 |
+ checks RES_NOAAAA first, so avoids parsing the
|
|
|
f1dd77 |
+ just-generated query packet in most cases. nss_dns avoids
|
|
|
f1dd77 |
+ using T_QUERY_A_AND_AAAA in RES_NOAAAA mode, so there is no
|
|
|
f1dd77 |
+ need to handle it here. */
|
|
|
f1dd77 |
+ if (type == T_AAAA && __res_handle_no_aaaa (ctx, query1, nquery1,
|
|
|
f1dd77 |
+ answer, anslen, &n))
|
|
|
f1dd77 |
+ /* There must be no second query for AAAA queries. The code
|
|
|
f1dd77 |
+ below is still needed to translate NODATA responses. */
|
|
|
f1dd77 |
+ assert (query2 == NULL);
|
|
|
f1dd77 |
+ else
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ assert (answerp == NULL || (void *) *answerp == (void *) answer);
|
|
|
f1dd77 |
+ n = __res_context_send (ctx, query1, nquery1, query2, nquery2,
|
|
|
f1dd77 |
+ answer, anslen,
|
|
|
f1dd77 |
+ answerp, answerp2, nanswerp2, resplen2,
|
|
|
f1dd77 |
+ answerp2_malloced);
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
if (use_malloc)
|
|
|
f1dd77 |
free (buf);
|
|
|
f1dd77 |
if (n < 0) {
|
|
|
f1dd77 |
diff --git a/resolv/res_send.c b/resolv/res_send.c
|
|
|
f1dd77 |
index 55e7fa438e7baac1..2e676bff0edf0cdc 100644
|
|
|
f1dd77 |
--- a/resolv/res_send.c
|
|
|
f1dd77 |
+++ b/resolv/res_send.c
|
|
|
f1dd77 |
@@ -550,8 +550,13 @@ context_send_common (struct resolv_context *ctx,
|
|
|
f1dd77 |
RES_SET_H_ERRNO (&_res, NETDB_INTERNAL);
|
|
|
f1dd77 |
return -1;
|
|
|
f1dd77 |
}
|
|
|
f1dd77 |
- int result = __res_context_send (ctx, buf, buflen, NULL, 0, ans, anssiz,
|
|
|
f1dd77 |
- NULL, NULL, NULL, NULL, NULL);
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ int result;
|
|
|
f1dd77 |
+ if (__res_handle_no_aaaa (ctx, buf, buflen, ans, anssiz, &result))
|
|
|
f1dd77 |
+ return result;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ result = __res_context_send (ctx, buf, buflen, NULL, 0, ans, anssiz,
|
|
|
f1dd77 |
+ NULL, NULL, NULL, NULL, NULL);
|
|
|
f1dd77 |
__resolv_context_put (ctx);
|
|
|
f1dd77 |
return result;
|
|
|
f1dd77 |
}
|
|
|
f1dd77 |
diff --git a/resolv/resolv-internal.h b/resolv/resolv-internal.h
|
|
|
f1dd77 |
index 0878f6830f2a08ff..4564f6ba2f7202f5 100644
|
|
|
f1dd77 |
--- a/resolv/resolv-internal.h
|
|
|
f1dd77 |
+++ b/resolv/resolv-internal.h
|
|
|
f1dd77 |
@@ -79,6 +79,14 @@ int __res_context_send (struct resolv_context *, const unsigned char *, int,
|
|
|
f1dd77 |
int, unsigned char **, unsigned char **,
|
|
|
f1dd77 |
int *, int *, int *) attribute_hidden;
|
|
|
f1dd77 |
|
|
|
f1dd77 |
+/* Return true if the query has been handled in RES_NOAAAA mode. For
|
|
|
f1dd77 |
+ that, RES_NOAAAA must be active, and the question type must be AAAA.
|
|
|
f1dd77 |
+ The caller is expected to return *RESULT as the return value. */
|
|
|
f1dd77 |
+bool __res_handle_no_aaaa (struct resolv_context *ctx,
|
|
|
f1dd77 |
+ const unsigned char *buf, int buflen,
|
|
|
f1dd77 |
+ unsigned char *ans, int anssiz, int *result)
|
|
|
f1dd77 |
+ attribute_hidden;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
/* Internal function similar to res_hostalias. */
|
|
|
f1dd77 |
const char *__res_context_hostalias (struct resolv_context *,
|
|
|
f1dd77 |
const char *, char *, size_t);
|
|
|
f1dd77 |
diff --git a/resolv/resolv.h b/resolv/resolv.h
|
|
|
f1dd77 |
index 80a523e5e40982ad..0f7298f395a829d3 100644
|
|
|
f1dd77 |
--- a/resolv/resolv.h
|
|
|
f1dd77 |
+++ b/resolv/resolv.h
|
|
|
f1dd77 |
@@ -135,6 +135,7 @@ struct res_sym {
|
|
|
f1dd77 |
#define RES_NOTLDQUERY 0x01000000 /* Do not look up unqualified name
|
|
|
f1dd77 |
as a TLD. */
|
|
|
f1dd77 |
#define RES_NORELOAD 0x02000000 /* No automatic configuration reload. */
|
|
|
f1dd77 |
+#define RES_NOAAAA 0x08000000 /* Suppress AAAA queries. */
|
|
|
f1dd77 |
|
|
|
f1dd77 |
#define RES_DEFAULT (RES_RECURSE|RES_DEFNAMES|RES_DNSRCH)
|
|
|
f1dd77 |
|
|
|
f1dd77 |
diff --git a/resolv/tst-resolv-noaaaa.c b/resolv/tst-resolv-noaaaa.c
|
|
|
f1dd77 |
new file mode 100644
|
|
|
f1dd77 |
index 0000000000000000..56b25f88a58ad286
|
|
|
f1dd77 |
--- /dev/null
|
|
|
f1dd77 |
+++ b/resolv/tst-resolv-noaaaa.c
|
|
|
f1dd77 |
@@ -0,0 +1,533 @@
|
|
|
f1dd77 |
+/* Test the RES_NOAAAA resolver option.
|
|
|
f1dd77 |
+ Copyright (C) 2022 Free Software Foundation, Inc.
|
|
|
f1dd77 |
+ This file is part of the GNU C Library.
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
f1dd77 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
f1dd77 |
+ License as published by the Free Software Foundation; either
|
|
|
f1dd77 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
f1dd77 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
f1dd77 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
f1dd77 |
+ Lesser General Public License for more details.
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
f1dd77 |
+ License along with the GNU C Library; if not, see
|
|
|
f1dd77 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+#include <errno.h>
|
|
|
f1dd77 |
+#include <netdb.h>
|
|
|
f1dd77 |
+#include <resolv.h>
|
|
|
f1dd77 |
+#include <stdlib.h>
|
|
|
f1dd77 |
+#include <support/check.h>
|
|
|
f1dd77 |
+#include <support/check_nss.h>
|
|
|
f1dd77 |
+#include <support/resolv_test.h>
|
|
|
f1dd77 |
+#include <support/support.h>
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+/* Used to keep track of the number of queries. */
|
|
|
f1dd77 |
+static volatile unsigned int queries;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+static void
|
|
|
f1dd77 |
+response (const struct resolv_response_context *ctx,
|
|
|
f1dd77 |
+ struct resolv_response_builder *b,
|
|
|
f1dd77 |
+ const char *qname, uint16_t qclass, uint16_t qtype)
|
|
|
f1dd77 |
+{
|
|
|
f1dd77 |
+ /* Each test should only send one query. */
|
|
|
f1dd77 |
+ ++queries;
|
|
|
f1dd77 |
+ TEST_COMPARE (queries, 1);
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* AAAA queries are supposed to be disabled. */
|
|
|
f1dd77 |
+ TEST_VERIFY (qtype != T_AAAA);
|
|
|
f1dd77 |
+ TEST_COMPARE (qclass, C_IN);
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* The only other query type besides A is PTR. */
|
|
|
f1dd77 |
+ if (qtype != T_A)
|
|
|
f1dd77 |
+ TEST_COMPARE (qtype, T_PTR);
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ int an, ns, ar;
|
|
|
f1dd77 |
+ char *tail;
|
|
|
f1dd77 |
+ if (sscanf (qname, "an%d.ns%d.ar%d.%ms", &an, &ns, &ar, &tail) != 4)
|
|
|
f1dd77 |
+ FAIL_EXIT1 ("invalid QNAME: %s\n", qname);
|
|
|
f1dd77 |
+ TEST_COMPARE_STRING (tail, "example");
|
|
|
f1dd77 |
+ free (tail);
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ if (an < 0 || ns < 0 || ar < 0)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ struct resolv_response_flags flags = { .rcode = NXDOMAIN, };
|
|
|
f1dd77 |
+ resolv_response_init (b, flags);
|
|
|
f1dd77 |
+ resolv_response_add_question (b, qname, qclass, qtype);
|
|
|
f1dd77 |
+ return;
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ struct resolv_response_flags flags = {};
|
|
|
f1dd77 |
+ resolv_response_init (b, flags);
|
|
|
f1dd77 |
+ resolv_response_add_question (b, qname, qclass, qtype);
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ resolv_response_section (b, ns_s_an);
|
|
|
f1dd77 |
+ for (int i = 0; i < an; ++i)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ resolv_response_open_record (b, qname, qclass, qtype, 60);
|
|
|
f1dd77 |
+ switch (qtype)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ case T_A:
|
|
|
f1dd77 |
+ char ipv4[4] = {192, 0, 2, i + 1};
|
|
|
f1dd77 |
+ resolv_response_add_data (b, &ipv4, sizeof (ipv4));
|
|
|
f1dd77 |
+ break;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ case T_PTR:
|
|
|
f1dd77 |
+ char *name = xasprintf ("ptr-%d", i);
|
|
|
f1dd77 |
+ resolv_response_add_name (b, name);
|
|
|
f1dd77 |
+ free (name);
|
|
|
f1dd77 |
+ break;
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ resolv_response_close_record (b);
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ resolv_response_section (b, ns_s_ns);
|
|
|
f1dd77 |
+ for (int i = 0; i < ns; ++i)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ resolv_response_open_record (b, qname, qclass, T_NS, 60);
|
|
|
f1dd77 |
+ char *name = xasprintf ("ns%d.example.net", i);
|
|
|
f1dd77 |
+ resolv_response_add_name (b, name);
|
|
|
f1dd77 |
+ free (name);
|
|
|
f1dd77 |
+ resolv_response_close_record (b);
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ resolv_response_section (b, ns_s_ar);
|
|
|
f1dd77 |
+ int addr = 1;
|
|
|
f1dd77 |
+ for (int i = 0; i < ns; ++i)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ char *name = xasprintf ("ns%d.example.net", i);
|
|
|
f1dd77 |
+ for (int j = 0; j < ar; ++j)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ resolv_response_open_record (b, name, qclass, T_A, 60);
|
|
|
f1dd77 |
+ char ipv4[4] = {192, 0, 2, addr};
|
|
|
f1dd77 |
+ resolv_response_add_data (b, &ipv4, sizeof (ipv4));
|
|
|
f1dd77 |
+ resolv_response_close_record (b);
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ resolv_response_open_record (b, name, qclass, T_AAAA, 60);
|
|
|
f1dd77 |
+ char ipv6[16]
|
|
|
f1dd77 |
+ = {0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, addr};
|
|
|
f1dd77 |
+ resolv_response_add_data (b, &ipv6, sizeof (ipv6));
|
|
|
f1dd77 |
+ resolv_response_close_record (b);
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ ++addr;
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ free (name);
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+}
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+/* Number of modes. Lowest bit encodes *n* function vs implicit _res
|
|
|
f1dd77 |
+ argument. The mode numbers themselves are arbitrary. */
|
|
|
f1dd77 |
+enum { mode_count = 8 };
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+/* res_send-like modes do not perform error translation. */
|
|
|
f1dd77 |
+enum { first_send_mode = 6 };
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+static int
|
|
|
f1dd77 |
+libresolv_query (unsigned int mode, const char *qname, uint16_t qtype,
|
|
|
f1dd77 |
+ unsigned char *buf, size_t buflen)
|
|
|
f1dd77 |
+{
|
|
|
f1dd77 |
+ int saved_errno = errno;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ TEST_VERIFY_EXIT (mode < mode_count);
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ switch (mode)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ case 0:
|
|
|
f1dd77 |
+ return res_query (qname, C_IN, qtype, buf, buflen);
|
|
|
f1dd77 |
+ case 1:
|
|
|
f1dd77 |
+ return res_nquery (&_res, qname, C_IN, qtype, buf, buflen);
|
|
|
f1dd77 |
+ case 2:
|
|
|
f1dd77 |
+ return res_search (qname, C_IN, qtype, buf, buflen);
|
|
|
f1dd77 |
+ case 3:
|
|
|
f1dd77 |
+ return res_nsearch (&_res, qname, C_IN, qtype, buf, buflen);
|
|
|
f1dd77 |
+ case 4:
|
|
|
f1dd77 |
+ return res_querydomain (qname, "", C_IN, qtype, buf, buflen);
|
|
|
f1dd77 |
+ case 5:
|
|
|
f1dd77 |
+ return res_nquerydomain (&_res, qname, "", C_IN, qtype, buf, buflen);
|
|
|
f1dd77 |
+ case 6:
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ unsigned char querybuf[512];
|
|
|
f1dd77 |
+ int ret = res_mkquery (QUERY, qname, C_IN, qtype,
|
|
|
f1dd77 |
+ NULL, 0, NULL, querybuf, sizeof (querybuf));
|
|
|
f1dd77 |
+ TEST_VERIFY_EXIT (ret > 0);
|
|
|
f1dd77 |
+ errno = saved_errno;
|
|
|
f1dd77 |
+ return res_send (querybuf, ret, buf, buflen);
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ case 7:
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ unsigned char querybuf[512];
|
|
|
f1dd77 |
+ int ret = res_nmkquery (&_res, QUERY, qname, C_IN, qtype,
|
|
|
f1dd77 |
+ NULL, 0, NULL, querybuf, sizeof (querybuf));
|
|
|
f1dd77 |
+ TEST_VERIFY_EXIT (ret > 0);
|
|
|
f1dd77 |
+ errno = saved_errno;
|
|
|
f1dd77 |
+ return res_nsend (&_res, querybuf, ret, buf, buflen);
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ __builtin_unreachable ();
|
|
|
f1dd77 |
+}
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+static int
|
|
|
f1dd77 |
+do_test (void)
|
|
|
f1dd77 |
+{
|
|
|
f1dd77 |
+ struct resolv_test *obj = resolv_test_start
|
|
|
f1dd77 |
+ ((struct resolv_redirect_config)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ .response_callback = response
|
|
|
f1dd77 |
+ });
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ _res.options |= RES_NOAAAA;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ check_hostent ("an1.ns2.ar1.example",
|
|
|
f1dd77 |
+ gethostbyname ("an1.ns2.ar1.example"),
|
|
|
f1dd77 |
+ "name: an1.ns2.ar1.example\n"
|
|
|
f1dd77 |
+ "address: 192.0.2.1\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+ check_hostent ("an0.ns2.ar1.example",
|
|
|
f1dd77 |
+ gethostbyname ("an0.ns2.ar1.example"),
|
|
|
f1dd77 |
+ "error: NO_ADDRESS\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+ check_hostent ("an-1.ns2.ar1.example",
|
|
|
f1dd77 |
+ gethostbyname ("an-1.ns2.ar1.example"),
|
|
|
f1dd77 |
+ "error: HOST_NOT_FOUND\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ check_hostent ("an1.ns2.ar1.example AF_INET",
|
|
|
f1dd77 |
+ gethostbyname2 ("an1.ns2.ar1.example", AF_INET),
|
|
|
f1dd77 |
+ "name: an1.ns2.ar1.example\n"
|
|
|
f1dd77 |
+ "address: 192.0.2.1\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+ check_hostent ("an0.ns2.ar1.example AF_INET",
|
|
|
f1dd77 |
+ gethostbyname2 ("an0.ns2.ar1.example", AF_INET),
|
|
|
f1dd77 |
+ "error: NO_ADDRESS\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+ check_hostent ("an-1.ns2.ar1.example AF_INET",
|
|
|
f1dd77 |
+ gethostbyname2 ("an-1.ns2.ar1.example", AF_INET),
|
|
|
f1dd77 |
+ "error: HOST_NOT_FOUND\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ check_hostent ("an1.ns2.ar1.example AF_INET6",
|
|
|
f1dd77 |
+ gethostbyname2 ("an1.ns2.ar1.example", AF_INET6),
|
|
|
f1dd77 |
+ "error: NO_ADDRESS\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+ check_hostent ("an0.ns2.ar1.example AF_INET6",
|
|
|
f1dd77 |
+ gethostbyname2 ("an0.ns2.ar1.example", AF_INET6),
|
|
|
f1dd77 |
+ "error: NO_ADDRESS\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+ check_hostent ("an-1.ns2.ar1.example AF_INET6",
|
|
|
f1dd77 |
+ gethostbyname2 ("an-1.ns2.ar1.example", AF_INET6),
|
|
|
f1dd77 |
+ "error: HOST_NOT_FOUND\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* Multiple addresses. */
|
|
|
f1dd77 |
+ check_hostent ("an2.ns0.ar0.example",
|
|
|
f1dd77 |
+ gethostbyname ("an2.ns0.ar0.example"),
|
|
|
f1dd77 |
+ "name: an2.ns0.ar0.example\n"
|
|
|
f1dd77 |
+ "address: 192.0.2.1\n"
|
|
|
f1dd77 |
+ "address: 192.0.2.2\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+ check_hostent ("an2.ns0.ar0.example AF_INET6",
|
|
|
f1dd77 |
+ gethostbyname2 ("an2.ns0.ar0.example", AF_INET6),
|
|
|
f1dd77 |
+ "error: NO_ADDRESS\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* getaddrinfo checks with one address. */
|
|
|
f1dd77 |
+ struct addrinfo *ai;
|
|
|
f1dd77 |
+ int ret;
|
|
|
f1dd77 |
+ ret = getaddrinfo ("an1.ns2.ar1.example", "80",
|
|
|
f1dd77 |
+ &(struct addrinfo)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ .ai_family = AF_INET,
|
|
|
f1dd77 |
+ .ai_socktype = SOCK_STREAM,
|
|
|
f1dd77 |
+ }, &ai;;
|
|
|
f1dd77 |
+ check_addrinfo ("an1.ns2.ar1.example (AF_INET)", ai, ret,
|
|
|
f1dd77 |
+ "address: STREAM/TCP 192.0.2.1 80\n");
|
|
|
f1dd77 |
+ freeaddrinfo (ai);
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+ ret = getaddrinfo ("an1.ns2.ar1.example", "80",
|
|
|
f1dd77 |
+ &(struct addrinfo)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ .ai_family = AF_INET6,
|
|
|
f1dd77 |
+ .ai_socktype = SOCK_STREAM,
|
|
|
f1dd77 |
+ }, &ai;;
|
|
|
f1dd77 |
+ check_addrinfo ("an1.ns2.ar1.example (AF_INET6)", ai, ret,
|
|
|
f1dd77 |
+ "error: No address associated with hostname\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+ ret = getaddrinfo ("an1.ns2.ar1.example", "80",
|
|
|
f1dd77 |
+ &(struct addrinfo)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ .ai_family = AF_UNSPEC,
|
|
|
f1dd77 |
+ .ai_socktype = SOCK_STREAM,
|
|
|
f1dd77 |
+ }, &ai;;
|
|
|
f1dd77 |
+ check_addrinfo ("an1.ns2.ar1.example (AF_UNSPEC)", ai, ret,
|
|
|
f1dd77 |
+ "address: STREAM/TCP 192.0.2.1 80\n");
|
|
|
f1dd77 |
+ freeaddrinfo (ai);
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* getaddrinfo checks with three addresses. */
|
|
|
f1dd77 |
+ ret = getaddrinfo ("an3.ns2.ar1.example", "80",
|
|
|
f1dd77 |
+ &(struct addrinfo)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ .ai_family = AF_INET,
|
|
|
f1dd77 |
+ .ai_socktype = SOCK_STREAM,
|
|
|
f1dd77 |
+ }, &ai;;
|
|
|
f1dd77 |
+ check_addrinfo ("an3.ns2.ar1.example (AF_INET)", ai, ret,
|
|
|
f1dd77 |
+ "address: STREAM/TCP 192.0.2.1 80\n"
|
|
|
f1dd77 |
+ "address: STREAM/TCP 192.0.2.2 80\n"
|
|
|
f1dd77 |
+ "address: STREAM/TCP 192.0.2.3 80\n");
|
|
|
f1dd77 |
+ freeaddrinfo (ai);
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+ ret = getaddrinfo ("an3.ns2.ar1.example", "80",
|
|
|
f1dd77 |
+ &(struct addrinfo)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ .ai_family = AF_INET6,
|
|
|
f1dd77 |
+ .ai_socktype = SOCK_STREAM,
|
|
|
f1dd77 |
+ }, &ai;;
|
|
|
f1dd77 |
+ check_addrinfo ("an3.ns2.ar1.example (AF_INET6)", ai, ret,
|
|
|
f1dd77 |
+ "error: No address associated with hostname\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+ ret = getaddrinfo ("an3.ns2.ar1.example", "80",
|
|
|
f1dd77 |
+ &(struct addrinfo)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ .ai_family = AF_UNSPEC,
|
|
|
f1dd77 |
+ .ai_socktype = SOCK_STREAM,
|
|
|
f1dd77 |
+ }, &ai;;
|
|
|
f1dd77 |
+ check_addrinfo ("an3.ns2.ar1.example (AF_UNSPEC)", ai, ret,
|
|
|
f1dd77 |
+ "address: STREAM/TCP 192.0.2.1 80\n"
|
|
|
f1dd77 |
+ "address: STREAM/TCP 192.0.2.2 80\n"
|
|
|
f1dd77 |
+ "address: STREAM/TCP 192.0.2.3 80\n");
|
|
|
f1dd77 |
+ freeaddrinfo (ai);
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* getaddrinfo checks with no address. */
|
|
|
f1dd77 |
+ ret = getaddrinfo ("an0.ns2.ar1.example", "80",
|
|
|
f1dd77 |
+ &(struct addrinfo)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ .ai_family = AF_INET,
|
|
|
f1dd77 |
+ .ai_socktype = SOCK_STREAM,
|
|
|
f1dd77 |
+ }, &ai;;
|
|
|
f1dd77 |
+ check_addrinfo ("an0.ns2.ar1.example (AF_INET)", ai, ret,
|
|
|
f1dd77 |
+ "error: No address associated with hostname\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+ ret = getaddrinfo ("an0.ns2.ar1.example", "80",
|
|
|
f1dd77 |
+ &(struct addrinfo)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ .ai_family = AF_INET6,
|
|
|
f1dd77 |
+ .ai_socktype = SOCK_STREAM,
|
|
|
f1dd77 |
+ }, &ai;;
|
|
|
f1dd77 |
+ check_addrinfo ("an0.ns2.ar1.example (AF_INET6)", ai, ret,
|
|
|
f1dd77 |
+ "error: No address associated with hostname\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+ ret = getaddrinfo ("an0.ns2.ar1.example", "80",
|
|
|
f1dd77 |
+ &(struct addrinfo)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ .ai_family = AF_UNSPEC,
|
|
|
f1dd77 |
+ .ai_socktype = SOCK_STREAM,
|
|
|
f1dd77 |
+ }, &ai;;
|
|
|
f1dd77 |
+ check_addrinfo ("an-1.ns2.ar1.example (AF_UNSPEC)", ai, ret,
|
|
|
f1dd77 |
+ "error: No address associated with hostname\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* getaddrinfo checks with NXDOMAIN. */
|
|
|
f1dd77 |
+ ret = getaddrinfo ("an-1.ns2.ar1.example", "80",
|
|
|
f1dd77 |
+ &(struct addrinfo)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ .ai_family = AF_INET,
|
|
|
f1dd77 |
+ .ai_socktype = SOCK_STREAM,
|
|
|
f1dd77 |
+ }, &ai;;
|
|
|
f1dd77 |
+ check_addrinfo ("an-1.ns2.ar1.example (AF_INET)", ai, ret,
|
|
|
f1dd77 |
+ "error: Name or service not known\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+ ret = getaddrinfo ("an-1.ns2.ar1.example", "80",
|
|
|
f1dd77 |
+ &(struct addrinfo)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ .ai_family = AF_INET6,
|
|
|
f1dd77 |
+ .ai_socktype = SOCK_STREAM,
|
|
|
f1dd77 |
+ }, &ai;;
|
|
|
f1dd77 |
+ check_addrinfo ("an-1.ns2.ar1.example (AF_INET6)", ai, ret,
|
|
|
f1dd77 |
+ "error: Name or service not known\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+ ret = getaddrinfo ("an-1.ns2.ar1.example", "80",
|
|
|
f1dd77 |
+ &(struct addrinfo)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ .ai_family = AF_UNSPEC,
|
|
|
f1dd77 |
+ .ai_socktype = SOCK_STREAM,
|
|
|
f1dd77 |
+ }, &ai;;
|
|
|
f1dd77 |
+ check_addrinfo ("an-1.ns2.ar1.example (AF_UNSPEC)", ai, ret,
|
|
|
f1dd77 |
+ "error: Name or service not known\n");
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ for (unsigned int mode = 0; mode < mode_count; ++mode)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ unsigned char *buf;
|
|
|
f1dd77 |
+ int ret;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* Response for A. */
|
|
|
f1dd77 |
+ buf = malloc (512);
|
|
|
f1dd77 |
+ ret = libresolv_query (mode, "an1.ns2.ar1.example", T_A, buf, 512);
|
|
|
f1dd77 |
+ TEST_VERIFY_EXIT (ret > 0);
|
|
|
f1dd77 |
+ check_dns_packet ("an1.ns2.ar1.example A", buf, ret,
|
|
|
f1dd77 |
+ "name: an1.ns2.ar1.example\n"
|
|
|
f1dd77 |
+ "address: 192.0.2.1\n");
|
|
|
f1dd77 |
+ free (buf);
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* NODATA response for A. */
|
|
|
f1dd77 |
+ buf = malloc (512);
|
|
|
f1dd77 |
+ errno = 0;
|
|
|
f1dd77 |
+ ret = libresolv_query (mode, "an0.ns2.ar1.example", T_A, buf, 512);
|
|
|
f1dd77 |
+ if (mode < first_send_mode)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ TEST_COMPARE (ret, -1);
|
|
|
f1dd77 |
+ TEST_COMPARE (errno, 0);
|
|
|
f1dd77 |
+ TEST_COMPARE (h_errno, NO_ADDRESS);
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ else
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ TEST_VERIFY_EXIT (ret > 0);
|
|
|
f1dd77 |
+ TEST_COMPARE (((HEADER *)buf)->rcode, 0);
|
|
|
f1dd77 |
+ check_dns_packet ("an1.ns2.ar1.example A", buf, ret,
|
|
|
f1dd77 |
+ "name: an0.ns2.ar1.example\n");
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ free (buf);
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* NXDOMAIN response for A. */
|
|
|
f1dd77 |
+ buf = malloc (512);
|
|
|
f1dd77 |
+ errno = 0;
|
|
|
f1dd77 |
+ ret = libresolv_query (mode, "an-1.ns2.ar1.example", T_A, buf, 512);
|
|
|
f1dd77 |
+ if (mode < first_send_mode)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ TEST_COMPARE (ret, -1);
|
|
|
f1dd77 |
+ TEST_COMPARE (errno, 0);
|
|
|
f1dd77 |
+ TEST_COMPARE (h_errno, HOST_NOT_FOUND);
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ else
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ TEST_VERIFY_EXIT (ret > 0);
|
|
|
f1dd77 |
+ TEST_COMPARE (((HEADER *)buf)->rcode, NXDOMAIN);
|
|
|
f1dd77 |
+ check_dns_packet ("an1.ns2.ar1.example A", buf, ret,
|
|
|
f1dd77 |
+ "name: an-1.ns2.ar1.example\n");
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ free (buf);
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* Response for PTR. */
|
|
|
f1dd77 |
+ buf = malloc (512);
|
|
|
f1dd77 |
+ ret = libresolv_query (mode, "an1.ns2.ar1.example", T_PTR, buf, 512);
|
|
|
f1dd77 |
+ TEST_VERIFY_EXIT (ret > 0);
|
|
|
f1dd77 |
+ check_dns_packet ("an1.ns2.ar1.example PTR", buf, ret,
|
|
|
f1dd77 |
+ "name: an1.ns2.ar1.example\n"
|
|
|
f1dd77 |
+ "data: an1.ns2.ar1.example PTR ptr-0\n");
|
|
|
f1dd77 |
+ free (buf);
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* NODATA response for PTR. */
|
|
|
f1dd77 |
+ buf = malloc (512);
|
|
|
f1dd77 |
+ errno = 0;
|
|
|
f1dd77 |
+ ret = libresolv_query (mode, "an0.ns2.ar1.example", T_PTR, buf, 512);
|
|
|
f1dd77 |
+ if (mode < first_send_mode)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ TEST_COMPARE (ret, -1);
|
|
|
f1dd77 |
+ TEST_COMPARE (errno, 0);
|
|
|
f1dd77 |
+ TEST_COMPARE (h_errno, NO_ADDRESS);
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ else
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ TEST_VERIFY_EXIT (ret > 0);
|
|
|
f1dd77 |
+ TEST_COMPARE (((HEADER *)buf)->rcode, 0);
|
|
|
f1dd77 |
+ check_dns_packet ("an1.ns2.ar1.example PTR", buf, ret,
|
|
|
f1dd77 |
+ "name: an0.ns2.ar1.example\n");
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ free (buf);
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* NXDOMAIN response for PTR. */
|
|
|
f1dd77 |
+ buf = malloc (512);
|
|
|
f1dd77 |
+ errno = 0;
|
|
|
f1dd77 |
+ ret = libresolv_query (mode, "an-1.ns2.ar1.example", T_PTR, buf, 512);
|
|
|
f1dd77 |
+ if (mode < first_send_mode)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ TEST_COMPARE (ret, -1);
|
|
|
f1dd77 |
+ TEST_COMPARE (errno, 0);
|
|
|
f1dd77 |
+ TEST_COMPARE (h_errno, HOST_NOT_FOUND);
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ else
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ TEST_VERIFY_EXIT (ret > 0);
|
|
|
f1dd77 |
+ TEST_COMPARE (((HEADER *)buf)->rcode, NXDOMAIN);
|
|
|
f1dd77 |
+ check_dns_packet ("an1.ns2.ar1.example PTR", buf, ret,
|
|
|
f1dd77 |
+ "name: an-1.ns2.ar1.example\n");
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ free (buf);
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* NODATA response for AAAA. */
|
|
|
f1dd77 |
+ buf = malloc (512);
|
|
|
f1dd77 |
+ errno = 0;
|
|
|
f1dd77 |
+ ret = libresolv_query (mode, "an1.ns2.ar1.example", T_AAAA, buf, 512);
|
|
|
f1dd77 |
+ if (mode < first_send_mode)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ TEST_COMPARE (ret, -1);
|
|
|
f1dd77 |
+ TEST_COMPARE (errno, 0);
|
|
|
f1dd77 |
+ TEST_COMPARE (h_errno, NO_ADDRESS);
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ else
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ TEST_VERIFY_EXIT (ret > 0);
|
|
|
f1dd77 |
+ TEST_COMPARE (((HEADER *)buf)->rcode, 0);
|
|
|
f1dd77 |
+ check_dns_packet ("an1.ns2.ar1.example A", buf, ret,
|
|
|
f1dd77 |
+ "name: an1.ns2.ar1.example\n");
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ free (buf);
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* NODATA response for AAAA (original is already NODATA). */
|
|
|
f1dd77 |
+ buf = malloc (512);
|
|
|
f1dd77 |
+ errno = 0;
|
|
|
f1dd77 |
+ ret = libresolv_query (mode, "an0.ns2.ar1.example", T_AAAA, buf, 512);
|
|
|
f1dd77 |
+ if (mode < first_send_mode)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ TEST_COMPARE (ret, -1);
|
|
|
f1dd77 |
+ TEST_COMPARE (errno, 0);
|
|
|
f1dd77 |
+ TEST_COMPARE (h_errno, NO_ADDRESS);
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ else
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ TEST_VERIFY_EXIT (ret > 0);
|
|
|
f1dd77 |
+ TEST_COMPARE (((HEADER *)buf)->rcode, 0);
|
|
|
f1dd77 |
+ check_dns_packet ("an0.ns2.ar1.example A", buf, ret,
|
|
|
f1dd77 |
+ "name: an0.ns2.ar1.example\n");
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ free (buf);
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ /* NXDOMAIN response. */
|
|
|
f1dd77 |
+ buf = malloc (512);
|
|
|
f1dd77 |
+ errno = 0;
|
|
|
f1dd77 |
+ ret = libresolv_query (mode, "an-1.ns2.ar1.example", T_AAAA, buf, 512);
|
|
|
f1dd77 |
+ if (mode < first_send_mode)
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ TEST_COMPARE (ret, -1);
|
|
|
f1dd77 |
+ TEST_COMPARE (errno, 0);
|
|
|
f1dd77 |
+ TEST_COMPARE (h_errno, HOST_NOT_FOUND);
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ else
|
|
|
f1dd77 |
+ {
|
|
|
f1dd77 |
+ TEST_VERIFY_EXIT (ret > 0);
|
|
|
f1dd77 |
+ TEST_COMPARE (((HEADER *)buf)->rcode, NXDOMAIN);
|
|
|
f1dd77 |
+ check_dns_packet ("an-1.ns2.ar1.example A", buf, ret,
|
|
|
f1dd77 |
+ "name: an-1.ns2.ar1.example\n");
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+ free (buf);
|
|
|
f1dd77 |
+ queries = 0;
|
|
|
f1dd77 |
+ }
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ resolv_test_end (obj);
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+ return 0;
|
|
|
f1dd77 |
+}
|
|
|
f1dd77 |
+
|
|
|
f1dd77 |
+#include <support/test-driver.c>
|
|
|
f1dd77 |
diff --git a/resolv/tst-resolv-res_init-skeleton.c b/resolv/tst-resolv-res_init-skeleton.c
|
|
|
f1dd77 |
index a5061e6d4fb98311..7d8758a99e180d97 100644
|
|
|
f1dd77 |
--- a/resolv/tst-resolv-res_init-skeleton.c
|
|
|
f1dd77 |
+++ b/resolv/tst-resolv-res_init-skeleton.c
|
|
|
f1dd77 |
@@ -129,6 +129,7 @@ print_resp (FILE *fp, res_state resp)
|
|
|
f1dd77 |
"single-request-reopen");
|
|
|
f1dd77 |
print_option_flag (fp, &options, RES_NOTLDQUERY, "no-tld-query");
|
|
|
f1dd77 |
print_option_flag (fp, &options, RES_NORELOAD, "no-reload");
|
|
|
f1dd77 |
+ print_option_flag (fp, &options, RES_NOAAAA, "no-aaaa");
|
|
|
f1dd77 |
fputc ('\n', fp);
|
|
|
f1dd77 |
if (options != 0)
|
|
|
f1dd77 |
fprintf (fp, "; error: unresolved option bits: 0x%x\n", options);
|
|
|
f1dd77 |
@@ -713,6 +714,15 @@ struct test_case test_cases[] =
|
|
|
f1dd77 |
"nameserver 192.0.2.1\n"
|
|
|
f1dd77 |
"; nameserver[0]: [192.0.2.1]:53\n"
|
|
|
f1dd77 |
},
|
|
|
f1dd77 |
+ {.name = "no-aaaa flag",
|
|
|
f1dd77 |
+ .conf = "options no-aaaa\n"
|
|
|
f1dd77 |
+ "nameserver 192.0.2.1\n",
|
|
|
f1dd77 |
+ .expected = "options no-aaaa\n"
|
|
|
f1dd77 |
+ "search example.com\n"
|
|
|
f1dd77 |
+ "; search[0]: example.com\n"
|
|
|
f1dd77 |
+ "nameserver 192.0.2.1\n"
|
|
|
f1dd77 |
+ "; nameserver[0]: [192.0.2.1]:53\n"
|
|
|
f1dd77 |
+ },
|
|
|
f1dd77 |
{ NULL }
|
|
|
f1dd77 |
};
|
|
|
f1dd77 |
|