diff --git a/prog/weaveproxy/main.go b/prog/weaveproxy/main.go index 9db07cd50a..6de9a8b45e 100644 --- a/prog/weaveproxy/main.go +++ b/prog/weaveproxy/main.go @@ -40,6 +40,7 @@ func main() { mflag.BoolVar(&c.TLSConfig.Verify, []string{"#tlsverify", "-tlsverify"}, false, "Use TLS and verify the remote") mflag.BoolVar(&c.WithDNS, []string{"-with-dns", "w"}, false, "instruct created containers to always use weaveDNS as their nameserver") mflag.BoolVar(&c.WithoutDNS, []string{"-without-dns"}, false, "instruct created containers to never use weaveDNS as their nameserver") + mflag.BoolVar(&c.NoMulticastRoute, []string{"-no-multicast-route"}, false, "do not add a multicast route via the weave interface when attaching containers") mflag.Parse() if justVersion { diff --git a/proxy/common.go b/proxy/common.go index 16b43190c8..9a927cca70 100644 --- a/proxy/common.go +++ b/proxy/common.go @@ -25,16 +25,12 @@ var ( ) func callWeave(args ...string) ([]byte, []byte, error) { - return callWeaveEnv(nil, args...) -} - -func callWeaveEnv(env []string, args ...string) ([]byte, []byte, error) { args = append([]string{"--local"}, args...) cmd := exec.Command("./weave", args...) - cmd.Env = append([]string{ + cmd.Env = []string{ "PATH=/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "PROCFS=/hostproc", - }, env...) + } propagateEnv := func(key string) { if val := os.Getenv(key); val != "" { diff --git a/proxy/proxy.go b/proxy/proxy.go index 0287d27570..1ffe8f415c 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -60,6 +60,7 @@ type Config struct { Version string WithDNS bool WithoutDNS bool + NoMulticastRoute bool } type wait struct { @@ -430,11 +431,14 @@ func (proxy *Proxy) attach(container *docker.Container, orDie bool) error { } } } + if proxy.NoMulticastRoute { + args = append(args, "--no-multicast-route") + } if orDie { args = append(args, "--or-die") } args = append(args, container.ID) - if _, stderr, err := callWeaveEnv(weaveAttachEnv(container), args...); err != nil { + if _, stderr, err := callWeave(args...); err != nil { Log.Warningf("Attaching container %s to weave network failed: %s", container.ID, string(stderr)) return errors.New(string(stderr)) } else if len(stderr) > 0 { @@ -456,16 +460,6 @@ func (proxy *Proxy) attachRouter(container *docker.Container) error { return nil } -func weaveAttachEnv(container *docker.Container) []string { - attachEnv := []string{} - for _, e := range container.Config.Env { - if strings.HasPrefix(e, "WEAVE_NO_MULTICAST_ROUTE=") { - attachEnv = append(attachEnv, e) - } - } - return attachEnv -} - func (proxy *Proxy) weaveCIDRs(networkMode string, env []string) ([]string, error) { if networkMode == "host" || strings.HasPrefix(networkMode, "container:") { return nil, fmt.Errorf("the container has '--net=%s'", networkMode)