diff options
author | 2018-09-19 07:29:37 +0100 | |
---|---|---|
committer | 2018-09-19 07:29:37 +0100 | |
commit | c349446a23440b336f4ca21900cce4d6a031cdf5 (patch) | |
tree | 983ab79eac59d59e36dfbf4a29fcf1bd811110d5 /plugin/forward/setup.go | |
parent | 2f1223c36a0294cd07e299aaa792a0b3f51f687a (diff) | |
download | coredns-c349446a23440b336f4ca21900cce4d6a031cdf5.tar.gz coredns-c349446a23440b336f4ca21900cce4d6a031cdf5.tar.zst coredns-c349446a23440b336f4ca21900cce4d6a031cdf5.zip |
Cleanup ParseHostOrFile (#2100)
Create plugin/pkg/transport that holds the transport related functions.
This needed to be a new pkg to prevent cyclic import errors.
This cleans up a bunch of duplicated code in core/dnsserver that also
tried to parse a transport (now all done in transport.Parse).
Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin/forward/setup.go')
-rw-r--r-- | plugin/forward/setup.go | 40 |
1 files changed, 7 insertions, 33 deletions
diff --git a/plugin/forward/setup.go b/plugin/forward/setup.go index 9fe8a6c38..6179b0d2d 100644 --- a/plugin/forward/setup.go +++ b/plugin/forward/setup.go @@ -2,7 +2,6 @@ package forward import ( "fmt" - "net" "strconv" "time" @@ -11,6 +10,7 @@ import ( "github.com/coredns/coredns/plugin/metrics" "github.com/coredns/coredns/plugin/pkg/dnsutil" pkgtls "github.com/coredns/coredns/plugin/pkg/tls" + "github.com/coredns/coredns/plugin/pkg/transport" "github.com/mholt/caddy" "github.com/mholt/caddy/caddyfile" @@ -93,8 +93,6 @@ func parseForward(c *caddy.Controller) (*Forward, error) { func ParseForwardStanza(c *caddyfile.Dispenser) (*Forward, error) { f := New() - protocols := map[int]int{} - if !c.Args(&f.from) { return f, c.ArgErr() } @@ -105,41 +103,17 @@ func ParseForwardStanza(c *caddyfile.Dispenser) (*Forward, error) { return f, c.ArgErr() } - // A bit fiddly, but first check if we've got protocols and if so add them back in when we create the proxies. - protocols = make(map[int]int) - for i := range to { - protocols[i], to[i] = protocol(to[i]) - } - - // If parseHostPortOrFile expands a file with a lot of nameserver our accounting in protocols doesn't make - // any sense anymore... For now: lets don't care. toHosts, err := dnsutil.ParseHostPortOrFile(to...) if err != nil { return f, err } - for i, h := range toHosts { - // Double check the port, if e.g. is 53 and the transport is TLS make it 853. - // This can be somewhat annoying because you *can't* have TLS on port 53 then. - switch protocols[i] { - case TLS: - h1, p, err := net.SplitHostPort(h) - if err != nil { - break - } - - // This is more of a bug in dnsutil.ParseHostPortOrFile that defaults to - // 53 because it doesn't know about the tls:// // and friends (that should be fixed). Hence - // Fix the port number here, back to what the user intended. - if p == "53" { - h = net.JoinHostPort(h1, "853") - } - } - - // We can't set tlsConfig here, because we haven't parsed it yet. - // We set it below at the end of parseBlock, use nil now. - p := NewProxy(h, protocols[i]) + transports := make([]string, len(toHosts)) + for i, host := range toHosts { + trans, h := transport.Parse(host) + p := NewProxy(h, trans) f.proxies = append(f.proxies, p) + transports[i] = trans } for c.NextBlock() { @@ -153,7 +127,7 @@ func ParseForwardStanza(c *caddyfile.Dispenser) (*Forward, error) { } for i := range f.proxies { // Only set this for proxies that need it. - if protocols[i] == TLS { + if transports[i] == transport.TLS { f.proxies[i].SetTLSConfig(f.tlsConfig) } f.proxies[i].SetExpire(f.expire) |