summaryrefslogtreecommitdiff
path: root/libnetwork/default_gateway.go
diff options
context:
space:
mode:
authorAlessandro Boch <aboch@docker.com>2016-04-06 09:11:45 -0700
committerAlessandro Boch <aboch@docker.com>2016-04-06 09:29:41 -0700
commita5aeffcb594f6ebe0f89dae9ddae73b434827d31 (patch)
treef07db613e528b327a330924d9f4896ad6b318031 /libnetwork/default_gateway.go
parentba5f3a039bcd583aab1224fc2cc32d3e6557b62c (diff)
downloaddocker-a5aeffcb594f6ebe0f89dae9ddae73b434827d31.tar.gz
Fix when connecting/disconnecting to/from default gw network
- Restoring original behavior where on disconnect from overlay network (only connected network), it also disconnects from default gw network. - On sandbox delete, the leave and delete of each endpoint is performed, regardless of whether the endpoint is the gw network endpoint. This endpoint is already automatically removed in endpoint.sbLeave() - Also do not let internal network dictate container does not need external connectivity. Before this fix, if a container was connected to an overlay and an internal network, it may not get attached to the default gw network. Signed-off-by: Alessandro Boch <aboch@docker.com>
Diffstat (limited to 'libnetwork/default_gateway.go')
-rw-r--r--libnetwork/default_gateway.go23
1 files changed, 11 insertions, 12 deletions
diff --git a/libnetwork/default_gateway.go b/libnetwork/default_gateway.go
index d8eb732701..31cf86d1d4 100644
--- a/libnetwork/default_gateway.go
+++ b/libnetwork/default_gateway.go
@@ -65,20 +65,13 @@ func (sb *sandbox) setupDefaultGW() error {
return nil
}
-// If present, removes the endpoint connecting the sandbox to the default gw network.
-// Unless it is the endpoint designated to provide the external connectivity.
-// If the sandbox is being deleted, removes the endpoint unconditionally.
+// If present, detach and remove the endpoint connecting the sandbox to the default gw network.
func (sb *sandbox) clearDefaultGW() error {
var ep *endpoint
if ep = sb.getEndpointInGWNetwork(); ep == nil {
return nil
}
-
- if ep == sb.getGatewayEndpoint() && !sb.inDelete {
- return nil
- }
-
if err := ep.sbLeave(sb, false); err != nil {
return fmt.Errorf("container %s: endpoint leaving GW Network failed: %v", sb.containerID, err)
}
@@ -88,21 +81,26 @@ func (sb *sandbox) clearDefaultGW() error {
return nil
}
+// Evaluate whether the sandbox requires a default gateway based
+// on the endpoints to which it is connected. It does not account
+// for the default gateway network endpoint.
+
func (sb *sandbox) needDefaultGW() bool {
var needGW bool
for _, ep := range sb.getConnectedEndpoints() {
if ep.endpointInGWNetwork() {
- return false
+ continue
}
if ep.getNetwork().Type() == "null" || ep.getNetwork().Type() == "host" {
continue
}
if ep.getNetwork().Internal() {
- return false
+ continue
}
- if ep.joinInfo.disableGatewayService {
- return false
+ // During stale sandbox cleanup, joinInfo may be nil
+ if ep.joinInfo != nil && ep.joinInfo.disableGatewayService {
+ continue
}
// TODO v6 needs to be handled.
if len(ep.Gateway()) > 0 {
@@ -115,6 +113,7 @@ func (sb *sandbox) needDefaultGW() bool {
}
needGW = true
}
+
return needGW
}