Re-arrange MAC election code for sandbox iface

- in bridge.go

Signed-off-by: Alessandro Boch <aboch@docker.com>
This commit is contained in:
Alessandro Boch
2015-05-02 17:30:11 -07:00
parent e321761977
commit 3bb407a21f
+9 -6
View File
@@ -404,12 +404,8 @@ func (d *driver) CreateEndpoint(nid, eid types.UUID, epOptions map[string]interf
}
}()
mac := netutils.GenerateRandomMAC()
// Add user specified attributes
if epConfig != nil && epConfig.MacAddress != nil {
mac = epConfig.MacAddress
}
// Set the sbox's MAC. If specified, use the one configured by user, otherwise use a random one
mac := electMacAddress(epConfig)
err = netlink.LinkSetHardwareAddr(sbox, mac)
if err != nil {
return nil, err
@@ -613,6 +609,13 @@ func parseContainerOptions(cOptions interface{}) (*ContainerConfiguration, error
}
}
func electMacAddress(epConfig *EndpointConfiguration) net.HardwareAddr {
if epConfig != nil && epConfig.MacAddress != nil {
return epConfig.MacAddress
}
return netutils.GenerateRandomMAC()
}
// Generates a name to be used for a virtual ethernet
// interface. The name is constructed by 'veth' appended
// by a randomly generated hex value. (example: veth0f60e2c)