From 6efa95ca98697264a4eeae63ef70c345cb711a67 Mon Sep 17 00:00:00 2001 From: Till Riedel Date: Tue, 1 Oct 2024 15:47:56 +0000 Subject: [PATCH] plugin/bind: add zone for link-local IPv6 instead of skipping (#6547) * add zone for link-local IPv6 instead of skipping Signed-off-by: Till Riedel * revert changed error handling for IPs Signed-off-by: Till Riedel --------- Signed-off-by: Till Riedel --- plugin/bind/README.md | 2 +- plugin/bind/setup.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/plugin/bind/README.md b/plugin/bind/README.md index 1c0f0c5f9..0633e95ef 100644 --- a/plugin/bind/README.md +++ b/plugin/bind/README.md @@ -13,7 +13,7 @@ If several addresses are provided, a listener will be open on each of the IP pro Each address has to be an IP or name of one of the interfaces of the host. Bind by interface name, binds to the IPs on that interface at the time of startup or reload (reload will happen with a SIGHUP or if the config file changes). -If the given argument is an interface name, and that interface has several IP addresses, CoreDNS will listen on all of the interface IP addresses (including IPv4 and IPv6), except for IPv6 link-local addresses on that interface. +If the given argument is an interface name, and that interface has several IP addresses, CoreDNS will listen on all of the interface IP addresses (including IPv4 and IPv6). ## Syntax diff --git a/plugin/bind/setup.go b/plugin/bind/setup.go index 1bd397585..2e64eea00 100644 --- a/plugin/bind/setup.go +++ b/plugin/bind/setup.go @@ -84,8 +84,15 @@ func listIP(args []string, ifaces []net.Interface) ([]string, error) { } for _, addr := range addrs { if ipnet, ok := addr.(*net.IPNet); ok { - if ipnet.IP.To4() != nil || (!ipnet.IP.IsLinkLocalMulticast() && !ipnet.IP.IsLinkLocalUnicast()) { - all = append(all, ipnet.IP.String()) + ipa, err := net.ResolveIPAddr("ip", ipnet.IP.String()) + if err == nil { + if len(ipnet.IP) == net.IPv6len && + (ipnet.IP.IsLinkLocalMulticast() || ipnet.IP.IsLinkLocalUnicast()) { + if ipa.Zone == "" { + ipa.Zone = iface.Name + } + } + all = append(all, ipa.String()) } } }