From a4c96483d1e83981a1e0860d3a6f71fbe21d500c Mon Sep 17 00:00:00 2001 From: minux Date: Tue, 7 Apr 2020 19:08:04 +0900 Subject: [PATCH] Fix a bug where making IPv6 DnsQuestion when it's not supported (#10170) Motivation: Related https://github.com/line/armeria/issues/2463 Here is an example that an NIC has only link local address for IPv6. ``` $ ipaddr 1: lo: mtu 65536 qdisc noqueue qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 3: eth0@if18692: mtu 1460 qdisc noqueue link/ether 1a:5e:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff inet 10.xxx.xxx.xxx/24 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::xxxx:xxxx:xxxx:xxxx/64 scope link valid_lft forever preferred_lft forever ``` If the NICs have only local or link local addresses, We should not send IPv6 DNS queris. Modification: - Ignore link-local IPv6 addresses which may exist even on a machine without IPv6 network. Result: - `DnsNameResolver` does not send DNS queries for AAAA when IPv6 is not available. --- .../src/main/java/io/netty/resolver/dns/DnsNameResolver.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resolver-dns/src/main/java/io/netty/resolver/dns/DnsNameResolver.java b/resolver-dns/src/main/java/io/netty/resolver/dns/DnsNameResolver.java index 625320d398..1852e16934 100644 --- a/resolver-dns/src/main/java/io/netty/resolver/dns/DnsNameResolver.java +++ b/resolver-dns/src/main/java/io/netty/resolver/dns/DnsNameResolver.java @@ -160,7 +160,9 @@ public class DnsNameResolver extends InetNameResolver { NetworkInterface iface = interfaces.nextElement(); Enumeration addresses = iface.getInetAddresses(); while (addresses.hasMoreElements()) { - if (addresses.nextElement() instanceof Inet6Address) { + InetAddress inetAddress = addresses.nextElement(); + if (inetAddress instanceof Inet6Address && !inetAddress.isAnyLocalAddress() && + !inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress()) { return true; } }