aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Brad P. Crochet <brad@redhat.com> 2020-01-16 14:47:39 -0500
committerGravatar Miek Gieben <miek@miek.nl> 2020-01-16 20:47:39 +0100
commitaa8c325d4a0fc7ac35b4a9b58f984ef6ee0bf3d1 (patch)
treef8841c4bb7916e178c24cef39748e174120cb5bc
parentb7977402d6c3ffd2a7e9b7da310db0579d8447a0 (diff)
downloadcoredns-aa8c325d4a0fc7ac35b4a9b58f984ef6ee0bf3d1.tar.gz
coredns-aa8c325d4a0fc7ac35b4a9b58f984ef6ee0bf3d1.tar.zst
coredns-aa8c325d4a0fc7ac35b4a9b58f984ef6ee0bf3d1.zip
Fix HostPortOrFile to support IPv6 addresses with zone (#3527)
1. The HostPortOrFile tests don't have any IPv6 tests. This adds some. 2. The HostPortOrFile breaks if any of the addresses have IPv6 zone defined. ParseIP does not handle %zone anymore. Signed-off-by: Brad P. Crochet <brad@redhat.com>
-rw-r--r--plugin/pkg/parse/host.go19
-rw-r--r--plugin/pkg/parse/host_test.go20
2 files changed, 35 insertions, 4 deletions
diff --git a/plugin/pkg/parse/host.go b/plugin/pkg/parse/host.go
index 87177125f..c1b7d23e0 100644
--- a/plugin/pkg/parse/host.go
+++ b/plugin/pkg/parse/host.go
@@ -4,12 +4,23 @@ import (
"fmt"
"net"
"os"
+ "strings"
"github.com/coredns/coredns/plugin/pkg/transport"
"github.com/miekg/dns"
)
+// Strips the zone, but preserves any port that comes after the zone
+func stripZone(host string) string {
+ if strings.Contains(host, "%") {
+ lastPercent := strings.LastIndex(host, "%")
+ newHost := host[:lastPercent]
+ return newHost
+ }
+ return host
+}
+
// HostPortOrFile parses the strings in s, each string can either be a
// address, [scheme://]address:port or a filename. The address part is checked
// and in case of filename a resolv.conf like file is (assumed) and parsed and
@@ -21,10 +32,11 @@ func HostPortOrFile(s ...string) ([]string, error) {
trans, host := Transport(h)
addr, _, err := net.SplitHostPort(host)
+
if err != nil {
// Parse didn't work, it is not a addr:port combo
- if net.ParseIP(host) == nil {
- // Not an IP address.
+ hostNoZone := stripZone(host)
+ if net.ParseIP(hostNoZone) == nil {
ss, err := tryFile(host)
if err == nil {
servers = append(servers, ss...)
@@ -47,8 +59,7 @@ func HostPortOrFile(s ...string) ([]string, error) {
continue
}
- if net.ParseIP(addr) == nil {
- // Not an IP address.
+ if net.ParseIP(stripZone(addr)) == nil {
ss, err := tryFile(host)
if err == nil {
servers = append(servers, ss...)
diff --git a/plugin/pkg/parse/host_test.go b/plugin/pkg/parse/host_test.go
index f6e771f29..1c23c5bee 100644
--- a/plugin/pkg/parse/host_test.go
+++ b/plugin/pkg/parse/host_test.go
@@ -34,6 +34,26 @@ func TestHostPortOrFile(t *testing.T) {
"127.0.0.1:53",
false,
},
+ {
+ "fe80::1",
+ "[fe80::1]:53",
+ false,
+ },
+ {
+ "fe80::1%ens3",
+ "[fe80::1%ens3]:53",
+ false,
+ },
+ {
+ "[fd01::1]:153",
+ "[fd01::1]:153",
+ false,
+ },
+ {
+ "[fd01::1%ens3]:153",
+ "[fd01::1%ens3]:153",
+ false,
+ },
}
err := ioutil.WriteFile("resolv.conf", []byte("nameserver 127.0.0.1\n"), 0600)