Browse code

Avoid default gateway collisions

Default gateways truncate the endpoint name to 12 characters. This can
make network endpoints ambiguous especially for load-balancing sandboxes
for networks with lenghty names (such as with our prefixes). Address
this by detecting an overflow in the sanbox name length and instead
opting to name the gateway endpoint "gateway_<id>" which should never
collide.

Signed-off-by: Chris Telfer <ctelfer@docker.com>

Chris Telfer authored on 2018/04/11 02:05:39
Showing 1 changed files
... ...
@@ -49,9 +49,11 @@ func (sb *sandbox) setupDefaultGW() error {
49 49
 
50 50
 	createOptions := []EndpointOption{CreateOptionAnonymous()}
51 51
 
52
-	eplen := gwEPlen
53
-	if len(sb.containerID) < gwEPlen {
54
-		eplen = len(sb.containerID)
52
+	var gwName string
53
+	if len(sb.containerID) <= gwEPlen {
54
+		gwName = "gateway_" + sb.containerID
55
+	} else {
56
+		gwName = "gateway_" + sb.id[:gwEPlen]
55 57
 	}
56 58
 
57 59
 	sbLabels := sb.Labels()
... ...
@@ -69,7 +71,7 @@ func (sb *sandbox) setupDefaultGW() error {
69 69
 		createOptions = append(createOptions, epOption)
70 70
 	}
71 71
 
72
-	newEp, err := n.CreateEndpoint("gateway_"+sb.containerID[0:eplen], createOptions...)
72
+	newEp, err := n.CreateEndpoint(gwName, createOptions...)
73 73
 	if err != nil {
74 74
 		return fmt.Errorf("container %s: endpoint create on GW Network failed: %v", sb.containerID, err)
75 75
 	}