On 04/10/2017 04:17 PM, Frederic Lecaille wrote:
On 04/10/2017 01:42 PM, Павел Знаменский wrote:
Hello,
Hello,
I'm trying to add IPv6 address as a nameserver to able resolve addresses
in IPv6-only environment:
resolvers google_dns_10m
nameserver google_dns1 2001:4860:4860::8888:53
nameserver google_dns2 2001:4860:4860::8844:53
hold valid 10m
resolve_retries 2
But I getting error:
[ALERT] 099/133733 (10412) : Starting [google_dns_10m/google_dns1]
nameserver: can't connect socket.
As I understood resolver uses AF_INET when connecting to the nameserver
and that's why IPv6 doesn't work.
In fact, the address families used during socket() and connect() syscall
are different.
This is revealed by strace:
socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP) = 4
connect(4, {sa_family=AF_INET6, sin6_port=htons(53), inet_pton(AF_INET6,
"2001:4860:4860::8844", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0},
28) = -1 EAFNOSUPPORT (Address family not supported by protocol)
should be:
socket(PF_INET6, ...)
This patch fixes the issue.
>From 09fbee7c67dea87761165c35e8a1c0450575504c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20L=C3=A9caille?= <[email protected]>
Date: Tue, 11 Apr 2017 08:46:37 +0200
Subject: [PATCH] MINOR: dns: Wrong address family used when creating IPv6
sockets.
AF_INET address family was always used to create sockets to connect
to name servers. This prevented any connection over IPv6 from working.
---
src/dns.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/dns.c b/src/dns.c
index 075a701..a118598 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -1022,7 +1022,7 @@ int dns_init_resolvers(int close_socket)
dgram->data = &resolve_dgram_cb;
/* create network UDP socket for this nameserver */
- if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
+ if ((fd = socket(curnameserver->addr.ss_family, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
Alert("Starting [%s/%s] nameserver: can't create socket.\n", curr_resolvers->id,
curnameserver->id);
free(dgram);
--
2.1.4