mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Use ioctls to create bridge
The netlink way of creating bridge has problems in older kernels like the one used on RHEL 6 (which is a supported one). So trying to use ioctl method to create bridge so that it works on any version. Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
parent
a35025569e
commit
885056b243
1 changed files with 5 additions and 10 deletions
|
@ -1,15 +1,15 @@
|
|||
package bridge
|
||||
|
||||
import (
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/pkg/parsers/kernel"
|
||||
"github.com/docker/libnetwork/netutils"
|
||||
"github.com/docker/libnetwork/types"
|
||||
bri "github.com/docker/libcontainer/netlink"
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
// SetupDevice create a new bridge interface/
|
||||
func setupDevice(config *networkConfiguration, i *bridgeInterface) error {
|
||||
var setMac bool
|
||||
|
||||
// We only attempt to create the bridge when the requested device name is
|
||||
// the default one.
|
||||
if config.BridgeName != DefaultBridgeName && !config.AllowNonDefaultBridge {
|
||||
|
@ -27,15 +27,10 @@ func setupDevice(config *networkConfiguration, i *bridgeInterface) error {
|
|||
// was not supported before that.
|
||||
kv, err := kernel.GetKernelVersion()
|
||||
if err == nil && (kv.Kernel >= 3 && kv.Major >= 3) {
|
||||
i.Link.Attrs().HardwareAddr = netutils.GenerateRandomMAC()
|
||||
log.Debugf("Setting bridge mac address to %s", i.Link.Attrs().HardwareAddr)
|
||||
setMac = true
|
||||
}
|
||||
|
||||
// Call out to netlink to create the device.
|
||||
if err = netlink.LinkAdd(i.Link); err != nil {
|
||||
return types.InternalErrorf("Failed to program bridge link: %s", err.Error())
|
||||
}
|
||||
return nil
|
||||
return bri.CreateBridge(config.BridgeName, setMac)
|
||||
}
|
||||
|
||||
// SetupDeviceUp ups the given bridge interface.
|
||||
|
|
Loading…
Add table
Reference in a new issue