From: Alexey Izbyshev <izbyshev@ispras.ru>
To: musl@lists.openwall.com
Subject: [musl] [PATCH] dns: fix workaround for systems defaulting to ipv6-only sockets
Date: Sat, 25 Feb 2023 01:07:33 +0300 [thread overview]
Message-ID: <20230224220733.235207-1-izbyshev@ispras.ru> (raw)
When IPv6 nameservers are present, __res_msend_rc attempts to disable
IPV6_V6ONLY socket option to ensure that it can communicate with IPv4
nameservers (if they are present too) via IPv4-mapped IPv6 addresses.
However, this option can't be disabled on bound sockets, so setsockopt
always fails.
---
Given that this workaround never worked and nobody complained,
another alternative is to remove it altogether.
Alexey
---
src/network/res_msend.c | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/src/network/res_msend.c b/src/network/res_msend.c
index 2643be22..86c2fcf4 100644
--- a/src/network/res_msend.c
+++ b/src/network/res_msend.c
@@ -133,6 +133,22 @@ int __res_msend_rc(int nqueries, const unsigned char *const *queries,
family = AF_INET;
sl = sizeof sa.sin;
}
+
+ /* Convert any IPv4 addresses in a mixed environment to v4-mapped */
+ if (fd >= 0 && family == AF_INET6) {
+ setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &(int){0}, sizeof 0);
+ for (i=0; i<nns; i++) {
+ if (ns[i].sin.sin_family != AF_INET) continue;
+ memcpy(ns[i].sin6.sin6_addr.s6_addr+12,
+ &ns[i].sin.sin_addr, 4);
+ memcpy(ns[i].sin6.sin6_addr.s6_addr,
+ "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
+ ns[i].sin6.sin6_family = AF_INET6;
+ ns[i].sin6.sin6_flowinfo = 0;
+ ns[i].sin6.sin6_scope_id = 0;
+ }
+ }
+
sa.sin.sin_family = family;
if (fd < 0 || bind(fd, (void *)&sa, sl) < 0) {
if (fd >= 0) close(fd);
@@ -152,21 +168,6 @@ int __res_msend_rc(int nqueries, const unsigned char *const *queries,
pthread_cleanup_push(cleanup, pfd);
pthread_setcancelstate(cs, 0);
- /* Convert any IPv4 addresses in a mixed environment to v4-mapped */
- if (family == AF_INET6) {
- setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &(int){0}, sizeof 0);
- for (i=0; i<nns; i++) {
- if (ns[i].sin.sin_family != AF_INET) continue;
- memcpy(ns[i].sin6.sin6_addr.s6_addr+12,
- &ns[i].sin.sin_addr, 4);
- memcpy(ns[i].sin6.sin6_addr.s6_addr,
- "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
- ns[i].sin6.sin6_family = AF_INET6;
- ns[i].sin6.sin6_flowinfo = 0;
- ns[i].sin6.sin6_scope_id = 0;
- }
- }
-
memset(alens, 0, sizeof *alens * nqueries);
retry_interval = timeout / attempts;
--
2.39.1
reply other threads:[~2023-02-24 22:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230224220733.235207-1-izbyshev@ispras.ru \
--to=izbyshev@ispras.ru \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).