From 365de87f23a4943908604d7bd2057357b40f139c Mon Sep 17 00:00:00 2001 From: Jeremy Unruh Date: Sun, 5 Jun 2016 15:15:27 -0700 Subject: [PATCH] Allow stubzones to have multiple DNS servers since forwarder logic allows this. Ex: domain/1.1.1.1:543,2.2.2.2:53 --- main.go | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/main.go b/main.go index aa57bd5..2c2c6d4 100644 --- a/main.go +++ b/main.go @@ -255,28 +255,29 @@ func main() { log.Fatalf("The --stubzones argument is invalid") } - hostPort = segments[1] - hostPort = strings.TrimSpace(hostPort) - if strings.HasSuffix(hostPort, "]") { - hostPort += ":53" - } else if !strings.Contains(hostPort, ":") { - hostPort += ":53" - } + hosts := strings.Split(segments[1], ",") + for _, hostPort := range hosts { + hostPort = strings.TrimSpace(hostPort) + if strings.HasSuffix(hostPort, "]") { + hostPort += ":53" + } else if !strings.Contains(hostPort, ":") { + hostPort += ":53" + } - if err := validateHostPort(hostPort); err != nil { - log.Fatalf("This stubzones server address invalid: %s", err) - } + if err := validateHostPort(hostPort); err != nil { + log.Fatalf("This stubzones server address invalid: %s", err) + } - for _, sdomain := range strings.Split(segments[0], ",") { - if dns.CountLabel(sdomain) < 1 { - log.Fatalf("This stubzones domain is not a FQDN: %s", sdomain) + for _, sdomain := range strings.Split(segments[0], ",") { + if dns.CountLabel(sdomain) < 1 { + log.Fatalf("This stubzones domain is not a FQDN: %s", sdomain) + } + sdomain = strings.TrimSpace(sdomain) + sdomain = dns.Fqdn(sdomain) + stubmap[sdomain] = append(stubmap[sdomain], hostPort) } - sdomain = strings.TrimSpace(sdomain) - sdomain = dns.Fqdn(sdomain) - stubmap[sdomain] = append(stubmap[sdomain], hostPort) } } - config.Stub = &stubmap }