mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #5093 from danielnorberg/do-not-create-bridge
net: do not create -b/--bridge specified bridge
This commit is contained in:
commit
f66082a443
1 changed files with 21 additions and 29 deletions
|
@ -68,24 +68,29 @@ func InitDriver(job *engine.Job) engine.Status {
|
||||||
}
|
}
|
||||||
|
|
||||||
bridgeIface = job.Getenv("BridgeIface")
|
bridgeIface = job.Getenv("BridgeIface")
|
||||||
|
usingDefaultBridge := false
|
||||||
if bridgeIface == "" {
|
if bridgeIface == "" {
|
||||||
|
usingDefaultBridge = true
|
||||||
bridgeIface = DefaultNetworkBridge
|
bridgeIface = DefaultNetworkBridge
|
||||||
}
|
}
|
||||||
|
|
||||||
addr, err := networkdriver.GetIfaceAddr(bridgeIface)
|
addr, err := networkdriver.GetIfaceAddr(bridgeIface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// If we're not using the default bridge, fail without trying to create it
|
||||||
|
if !usingDefaultBridge {
|
||||||
|
job.Logf("bridge not found: %s", bridgeIface)
|
||||||
|
return job.Error(err)
|
||||||
|
}
|
||||||
// If the iface is not found, try to create it
|
// If the iface is not found, try to create it
|
||||||
job.Logf("creating new bridge for %s", bridgeIface)
|
job.Logf("creating new bridge for %s", bridgeIface)
|
||||||
if err := createBridge(bridgeIP); err != nil {
|
if err := createBridge(bridgeIP); err != nil {
|
||||||
job.Error(err)
|
return job.Error(err)
|
||||||
return engine.StatusErr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
job.Logf("getting iface addr")
|
job.Logf("getting iface addr")
|
||||||
addr, err = networkdriver.GetIfaceAddr(bridgeIface)
|
addr, err = networkdriver.GetIfaceAddr(bridgeIface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
job.Error(err)
|
return job.Error(err)
|
||||||
return engine.StatusErr
|
|
||||||
}
|
}
|
||||||
network = addr.(*net.IPNet)
|
network = addr.(*net.IPNet)
|
||||||
} else {
|
} else {
|
||||||
|
@ -101,8 +106,7 @@ func InitDriver(job *engine.Job) engine.Status {
|
||||||
// Configure iptables for link support
|
// Configure iptables for link support
|
||||||
if enableIPTables {
|
if enableIPTables {
|
||||||
if err := setupIPTables(addr, icc); err != nil {
|
if err := setupIPTables(addr, icc); err != nil {
|
||||||
job.Error(err)
|
return job.Error(err)
|
||||||
return engine.StatusErr
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,15 +119,13 @@ func InitDriver(job *engine.Job) engine.Status {
|
||||||
|
|
||||||
// We can always try removing the iptables
|
// We can always try removing the iptables
|
||||||
if err := iptables.RemoveExistingChain("DOCKER"); err != nil {
|
if err := iptables.RemoveExistingChain("DOCKER"); err != nil {
|
||||||
job.Error(err)
|
return job.Error(err)
|
||||||
return engine.StatusErr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if enableIPTables {
|
if enableIPTables {
|
||||||
chain, err := iptables.NewChain("DOCKER", bridgeIface)
|
chain, err := iptables.NewChain("DOCKER", bridgeIface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
job.Error(err)
|
return job.Error(err)
|
||||||
return engine.StatusErr
|
|
||||||
}
|
}
|
||||||
portmapper.SetIptablesChain(chain)
|
portmapper.SetIptablesChain(chain)
|
||||||
}
|
}
|
||||||
|
@ -140,8 +142,7 @@ func InitDriver(job *engine.Job) engine.Status {
|
||||||
"link": LinkContainers,
|
"link": LinkContainers,
|
||||||
} {
|
} {
|
||||||
if err := job.Eng.Register(name, f); err != nil {
|
if err := job.Eng.Register(name, f); err != nil {
|
||||||
job.Error(err)
|
return job.Error(err)
|
||||||
return engine.StatusErr
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return engine.StatusOK
|
return engine.StatusOK
|
||||||
|
@ -302,8 +303,7 @@ func Allocate(job *engine.Job) engine.Status {
|
||||||
ip, err = ipallocator.RequestIP(bridgeNetwork, nil)
|
ip, err = ipallocator.RequestIP(bridgeNetwork, nil)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
job.Error(err)
|
return job.Error(err)
|
||||||
return engine.StatusErr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out := engine.Env{}
|
out := engine.Env{}
|
||||||
|
@ -387,8 +387,7 @@ func AllocatePort(job *engine.Job) engine.Status {
|
||||||
// host ip, proto, and host port
|
// host ip, proto, and host port
|
||||||
hostPort, err = portallocator.RequestPort(ip, proto, hostPort)
|
hostPort, err = portallocator.RequestPort(ip, proto, hostPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
job.Error(err)
|
return job.Error(err)
|
||||||
return engine.StatusErr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -406,9 +405,7 @@ func AllocatePort(job *engine.Job) engine.Status {
|
||||||
|
|
||||||
if err := portmapper.Map(container, ip, hostPort); err != nil {
|
if err := portmapper.Map(container, ip, hostPort); err != nil {
|
||||||
portallocator.ReleasePort(ip, proto, hostPort)
|
portallocator.ReleasePort(ip, proto, hostPort)
|
||||||
|
return job.Error(err)
|
||||||
job.Error(err)
|
|
||||||
return engine.StatusErr
|
|
||||||
}
|
}
|
||||||
network.PortMappings = append(network.PortMappings, host)
|
network.PortMappings = append(network.PortMappings, host)
|
||||||
|
|
||||||
|
@ -417,8 +414,7 @@ func AllocatePort(job *engine.Job) engine.Status {
|
||||||
out.SetInt("HostPort", hostPort)
|
out.SetInt("HostPort", hostPort)
|
||||||
|
|
||||||
if _, err := out.WriteTo(job.Stdout); err != nil {
|
if _, err := out.WriteTo(job.Stdout); err != nil {
|
||||||
job.Error(err)
|
return job.Error(err)
|
||||||
return engine.StatusErr
|
|
||||||
}
|
}
|
||||||
return engine.StatusOK
|
return engine.StatusOK
|
||||||
}
|
}
|
||||||
|
@ -445,11 +441,9 @@ func LinkContainers(job *engine.Job) engine.Status {
|
||||||
"--dport", port,
|
"--dport", port,
|
||||||
"-d", childIP,
|
"-d", childIP,
|
||||||
"-j", "ACCEPT"); !ignoreErrors && err != nil {
|
"-j", "ACCEPT"); !ignoreErrors && err != nil {
|
||||||
job.Error(err)
|
return job.Error(err)
|
||||||
return engine.StatusErr
|
|
||||||
} else if len(output) != 0 {
|
} else if len(output) != 0 {
|
||||||
job.Errorf("Error toggle iptables forward: %s", output)
|
return job.Errorf("Error toggle iptables forward: %s", output)
|
||||||
return engine.StatusErr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if output, err := iptables.Raw(action, "FORWARD",
|
if output, err := iptables.Raw(action, "FORWARD",
|
||||||
|
@ -459,11 +453,9 @@ func LinkContainers(job *engine.Job) engine.Status {
|
||||||
"--sport", port,
|
"--sport", port,
|
||||||
"-d", parentIP,
|
"-d", parentIP,
|
||||||
"-j", "ACCEPT"); !ignoreErrors && err != nil {
|
"-j", "ACCEPT"); !ignoreErrors && err != nil {
|
||||||
job.Error(err)
|
return job.Error(err)
|
||||||
return engine.StatusErr
|
|
||||||
} else if len(output) != 0 {
|
} else if len(output) != 0 {
|
||||||
job.Errorf("Error toggle iptables forward: %s", output)
|
return job.Errorf("Error toggle iptables forward: %s", output)
|
||||||
return engine.StatusErr
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return engine.StatusOK
|
return engine.StatusOK
|
||||||
|
|
Loading…
Add table
Reference in a new issue