mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
68ae284db5
- Added controller, network, endpoint and sandbox interfaces - Created netutils package for miscallaneous network utilities - Created driverapi package to break cyclic dependency b/w driver and libnetwork - Made libnetwork multithread safe - Made bridge driver multithread safe - Fixed README.md Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package bridge
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
log "github.com/Sirupsen/logrus"
|
|
"github.com/docker/docker/pkg/parsers/kernel"
|
|
"github.com/docker/libnetwork/netutils"
|
|
"github.com/vishvananda/netlink"
|
|
)
|
|
|
|
// SetupDevice create a new bridge interface/
|
|
func setupDevice(i *bridgeInterface) error {
|
|
// We only attempt to create the bridge when the requested device name is
|
|
// the default one.
|
|
if i.Config.BridgeName != DefaultBridgeName {
|
|
return fmt.Errorf("bridge device with non default name %q must be created manually", i.Config.BridgeName)
|
|
}
|
|
|
|
// Set the bridgeInterface netlink.Bridge.
|
|
i.Link = &netlink.Bridge{
|
|
LinkAttrs: netlink.LinkAttrs{
|
|
Name: i.Config.BridgeName,
|
|
},
|
|
}
|
|
|
|
// Only set the bridge's MAC address if the kernel version is > 3.3, as it
|
|
// 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)
|
|
}
|
|
|
|
// Call out to netlink to create the device.
|
|
return netlink.LinkAdd(i.Link)
|
|
}
|
|
|
|
// SetupDeviceUp ups the given bridge interface.
|
|
func setupDeviceUp(i *bridgeInterface) error {
|
|
err := netlink.LinkSetUp(i.Link)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Attempt to update the bridge interface to refresh the flags status,
|
|
// ignoring any failure to do so.
|
|
if lnk, err := netlink.LinkByName(i.Config.BridgeName); err == nil {
|
|
i.Link = lnk
|
|
}
|
|
return nil
|
|
}
|