From e65006042dfa17c110609587aae8f5f2c77c6764 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sat, 9 Dec 2017 17:34:41 +0000 Subject: [PATCH 1/3] Remove obsolete --dns-effective-listen-address parameter it was needed when we ran inside a container network namespace --- prog/weaver/main.go | 29 ++++++++++++++++------------- weave | 1 - 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/prog/weaver/main.go b/prog/weaver/main.go index 89074327..3656b9fc 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -45,12 +45,20 @@ type ipamConfig struct { } type dnsConfig struct { - Domain string - ListenAddress string - TTL int - ClientTimeout time.Duration - EffectiveListenAddress string - ResolvConf string + Domain string + ListenAddress string + TTL int + ClientTimeout time.Duration + ResolvConf string +} + +// return the address part of the DNS listen address, without ":53" on the end +func (c dnsConfig) addressOnly() string { + addr, _, err := net.SplitHostPort(c.ListenAddress) + if err != nil { + Log.Fatalf("Error when parsing DNS listen address %q: %s", c.ListenAddress, err) + } + return addr } func (c *ipamConfig) Enabled() bool { @@ -193,7 +201,6 @@ func main() { mflag.StringVar(&dnsConfig.ListenAddress, []string{"-dns-listen-address"}, nameserver.DefaultListenAddress, "address to listen on for DNS requests") mflag.IntVar(&dnsConfig.TTL, []string{"-dns-ttl"}, nameserver.DefaultTTL, "TTL for DNS request from our domain") mflag.DurationVar(&dnsConfig.ClientTimeout, []string{"-dns-fallback-timeout"}, nameserver.DefaultClientTimeout, "timeout for fallback DNS requests") - mflag.StringVar(&dnsConfig.EffectiveListenAddress, []string{"-dns-effective-listen-address"}, "", "address DNS will actually be listening, after Docker port mapping") mflag.StringVar(&dnsConfig.ResolvConf, []string{"-resolv-conf"}, "", "path to resolver configuration for fallback DNS lookups") mflag.StringVar(&bridgeConfig.DatapathName, []string{"-datapath"}, "", "ODP datapath name") mflag.BoolVar(&bridgeConfig.NoFastdp, []string{"-no-fastdp"}, false, "Disable Fast Datapath") @@ -636,17 +643,13 @@ func createDNSServer(config dnsConfig, router *mesh.Router, isKnownPeer func(mes gossip, err := router.NewGossip("nameserver", ns) checkFatal(err) ns.SetGossip(gossip) - upstream := nameserver.NewUpstream(config.ResolvConf, config.EffectiveListenAddress) + upstream := nameserver.NewUpstream(config.ResolvConf, config.addressOnly()) dnsserver, err := nameserver.NewDNSServer(ns, config.Domain, config.ListenAddress, upstream, uint32(config.TTL), config.ClientTimeout) if err != nil { Log.Fatal("Unable to start dns server: ", err) } - listenAddr := config.ListenAddress - if config.EffectiveListenAddress != "" { - listenAddr = config.EffectiveListenAddress - } - Log.Println("Listening for DNS queries on", listenAddr) + Log.Println("Listening for DNS queries on", config.ListenAddress) return ns, dnsserver } diff --git a/weave b/weave index db80efe5..f644e4ea 100755 --- a/weave +++ b/weave @@ -1234,7 +1234,6 @@ launch() { --host-root=/host \ $(router_bridge_opts) \ --ipalloc-range "$IPRANGE" \ - --dns-effective-listen-address $DOCKER_BRIDGE_IP \ --dns-listen-address $DOCKER_BRIDGE_IP:53 \ --http-addr $HTTP_ADDR \ --status-addr $STATUS_ADDR \ From 86d2800b596b4eb5f7e35bf6cac31de2f417cbe3 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sat, 9 Dec 2017 17:41:38 +0000 Subject: [PATCH 2/3] Make proxy use configured WeaveDNS address rather than assuming it is listening on the weave bridge --- prog/weaver/main.go | 1 + proxy/proxy.go | 13 ++----------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/prog/weaver/main.go b/prog/weaver/main.go index 3656b9fc..be265c4b 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -271,6 +271,7 @@ func main() { var proxy *weaveproxy.Proxy var err error if proxyConfig.Enabled { + proxyConfig.DNSListenAddress = dnsConfig.addressOnly() if noDNS { proxyConfig.WithoutDNS = true } diff --git a/proxy/proxy.go b/proxy/proxy.go index 92e6f642..052e4222 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -61,6 +61,7 @@ type Config struct { NoRewriteHosts bool TLSConfig TLSConfig WithoutDNS bool + DNSListenAddress string NoMulticastRoute bool KeepTXOn bool DockerBridge string @@ -78,7 +79,6 @@ type Proxy struct { Config client *weavedocker.Client weave *weaveapi.Client - dockerBridgeIP string hostnameMatchRegexp *regexp.Regexp weaveWaitVolume string weaveWaitNoopVolume string @@ -158,15 +158,6 @@ func NewProxy(c Config) (*Proxy, error) { Log.Info(p.client.Info()) - if !p.WithoutDNS { - ip, err := weavenet.FindBridgeIP(c.DockerBridge, nil) - if err != nil { - return nil, err - } - p.dockerBridgeIP = ip.String() - Log.Infof("Using docker bridge IP for DNS: %v", p.dockerBridgeIP) - } - p.hostnameMatchRegexp, err = regexp.Compile(c.HostnameMatch) if err != nil { err := fmt.Errorf("Incorrect hostname match '%s': %s", c.HostnameMatch, err.Error()) @@ -595,7 +586,7 @@ func (proxy *Proxy) setWeaveDNS(hostConfig jsonObject, hostname, dnsDomain strin if err != nil { return err } - hostConfig["Dns"] = append(dns, proxy.dockerBridgeIP) + hostConfig["Dns"] = append(dns, proxy.DNSListenAddress) dnsSearch, err := hostConfig.StringArray("DnsSearch") if err != nil { From e7f30106c04e7237136aaf5ec3de2990f10f85b0 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sat, 9 Dec 2017 18:06:16 +0000 Subject: [PATCH 3/3] Pass the WeaveDNS Domain into the proxy instead of obtaining it via the http api --- prog/weaver/main.go | 1 + proxy/create_container_interceptor.go | 6 +++--- proxy/proxy.go | 9 +-------- proxy/start_container_interceptor.go | 4 ++-- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/prog/weaver/main.go b/prog/weaver/main.go index be265c4b..2beb205f 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -272,6 +272,7 @@ func main() { var err error if proxyConfig.Enabled { proxyConfig.DNSListenAddress = dnsConfig.addressOnly() + proxyConfig.DNSDomain = dnsConfig.Domain if noDNS { proxyConfig.WithoutDNS = true } diff --git a/proxy/create_container_interceptor.go b/proxy/create_container_interceptor.go index 2ca525ac..38afa748 100644 --- a/proxy/create_container_interceptor.go +++ b/proxy/create_container_interceptor.go @@ -68,11 +68,11 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error { if err != nil { return err } - if dnsDomain := i.proxy.getDNSDomain(); dnsDomain != "" { - if err := i.setHostname(container, hostname, dnsDomain); err != nil { + if !i.proxy.WithoutDNS { + if err := i.setHostname(container, hostname, i.proxy.DNSDomain); err != nil { return err } - if err := i.proxy.setWeaveDNS(hostConfig, hostname, dnsDomain); err != nil { + if err := i.proxy.setWeaveDNS(hostConfig, hostname, i.proxy.DNSDomain); err != nil { return err } } diff --git a/proxy/proxy.go b/proxy/proxy.go index 052e4222..91b61c58 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -62,6 +62,7 @@ type Config struct { TLSConfig TLSConfig WithoutDNS bool DNSListenAddress string + DNSDomain string NoMulticastRoute bool KeepTXOn bool DockerBridge string @@ -603,14 +604,6 @@ func (proxy *Proxy) setWeaveDNS(hostConfig jsonObject, hostname, dnsDomain strin return nil } -func (proxy *Proxy) getDNSDomain() string { - if proxy.WithoutDNS { - return "" - } - domain, _ := proxy.weave.DNSDomain() - return domain -} - func (proxy *Proxy) updateContainerNetworkSettings(container jsonObject) error { containerID, err := container.String("Id") if err != nil { diff --git a/proxy/start_container_interceptor.go b/proxy/start_container_interceptor.go index cec672dc..2cc1d6f7 100644 --- a/proxy/start_container_interceptor.go +++ b/proxy/start_container_interceptor.go @@ -50,8 +50,8 @@ func (i *startContainerInterceptor) InterceptRequest(r *http.Request) error { return err } } - if dnsDomain := i.proxy.getDNSDomain(); dnsDomain != "" { - if err := i.proxy.setWeaveDNS(hostConfig, container.Config.Hostname, dnsDomain); err != nil { + if !i.proxy.WithoutDNS { + if err := i.proxy.setWeaveDNS(hostConfig, container.Config.Hostname, i.proxy.DNSDomain); err != nil { return err } }