From 5b6d8e356cea15ef35b47db1a5a605886494b80e Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Fri, 26 Apr 2024 13:12:25 -0400 Subject: [PATCH] [plugin/forward] Strip local zone from IPV6 nameservers (#6635) Signed-off-by: Alejandro de Brito Fontes --- plugin/forward/setup_test.go | 9 +++++++++ plugin/pkg/parse/host.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plugin/forward/setup_test.go b/plugin/forward/setup_test.go index cf046b486c8..95f642f6843 100644 --- a/plugin/forward/setup_test.go +++ b/plugin/forward/setup_test.go @@ -143,6 +143,13 @@ nameserver 10.10.255.253`), 0666); err != nil { } defer os.Remove(resolv) + const resolvIPV6 = "resolv-ipv6.conf" + if err := os.WriteFile(resolvIPV6, + []byte(`nameserver 0388:d254:7aec:6892:9f7f:e93b:5806:1b0f%en0`), 0666); err != nil { + t.Fatalf("Failed to write %v file: %s", resolvIPV6, err) + } + defer os.Remove(resolvIPV6) + tests := []struct { input string shouldErr bool @@ -153,6 +160,8 @@ nameserver 10.10.255.253`), 0666); err != nil { {`forward . ` + resolv, false, "", []string{"10.10.255.252:53", "10.10.255.253:53"}}, // fail {`forward . /dev/null`, true, "no nameservers", nil}, + // IPV6 with local zone + {`forward . ` + resolvIPV6, false, "", []string{"[0388:d254:7aec:6892:9f7f:e93b:5806:1b0f]:53"}}, } for i, test := range tests { diff --git a/plugin/pkg/parse/host.go b/plugin/pkg/parse/host.go index f90e4fc77ff..78f7cd93b79 100644 --- a/plugin/pkg/parse/host.go +++ b/plugin/pkg/parse/host.go @@ -99,7 +99,7 @@ func tryFile(s string) ([]string, error) { servers := []string{} for _, s := range c.Servers { - servers = append(servers, net.JoinHostPort(s, c.Port)) + servers = append(servers, net.JoinHostPort(stripZone(s), c.Port)) } return servers, nil }