diff --git a/prog/weaveproxy/main.go b/prog/weaveproxy/main.go index 58dd29bc..b5bc3523 100644 --- a/prog/weaveproxy/main.go +++ b/prog/weaveproxy/main.go @@ -12,9 +12,10 @@ import ( ) var ( - version = "(unreleased version)" - defaultDockerHost = "unix:///var/run/docker.sock" - defaultProcPath = "/proc" + version = "(unreleased version)" + defaultDockerHost = "unix:///var/run/docker.sock" + defaultProcPath = "/proc" + defaultDockerBridge = "docker0" ) func main() { @@ -64,6 +65,11 @@ func main() { Log.Warning("--with-dns option has been removed; DNS is on by default") } + c.DockerBridge = defaultDockerBridge + if dockerBridge := os.Getenv("DOCKER_BRIDGE"); dockerBridge != "" { + c.DockerBridge = dockerBridge + } + c.DockerHost = defaultDockerHost if dockerHost := os.Getenv("DOCKER_HOST"); dockerHost != "" { c.DockerHost = dockerHost diff --git a/proxy/common.go b/proxy/common.go index 8903f60e..0bc2b28a 100644 --- a/proxy/common.go +++ b/proxy/common.go @@ -36,7 +36,6 @@ func callWeave(args ...string) ([]byte, []byte, error) { } } - propagateEnv("DOCKER_BRIDGE") propagateEnv("DOCKER_HOST") // Propagate WEAVE_DEBUG, to make debugging easier. diff --git a/proxy/proxy.go b/proxy/proxy.go index 460fa817..1f01e8cb 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -61,6 +61,7 @@ type Config struct { Version string WithoutDNS bool NoMulticastRoute bool + DockerBridge string DockerHost string ProcPath string } @@ -151,11 +152,14 @@ func NewProxy(c Config) (*Proxy, error) { p.client = client.Client if !p.WithoutDNS { - dockerBridgeIP, stderr, err := callWeave("docker-bridge-ip") + netDevs, err := GetBridgeNetDev(c.ProcPath, c.DockerBridge) if err != nil { - return nil, fmt.Errorf(string(stderr)) + return nil, err } - p.dockerBridgeIP = string(dockerBridgeIP) + if len(netDevs) != 1 || len(netDevs[0].CIDRs) != 1 { + return nil, fmt.Errorf("Could not obtain address of %s", c.DockerBridge) + } + p.dockerBridgeIP = netDevs[0].CIDRs[0].IP.String() } p.hostnameMatchRegexp, err = regexp.Compile(c.HostnameMatch)