|
@@ -7,10 +7,11 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
const (
|
|
const (
|
|
- NetworkType = "simplebridge"
|
|
|
|
- VethPrefix = "veth"
|
|
|
|
|
|
+ networkType = "simplebridge"
|
|
|
|
+ vethPrefix = "veth"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+// Configuration info for the "simplebridge" driver.
|
|
type Configuration struct {
|
|
type Configuration struct {
|
|
BridgeName string
|
|
BridgeName string
|
|
AddressIPv4 *net.IPNet
|
|
AddressIPv4 *net.IPNet
|
|
@@ -22,58 +23,59 @@ type Configuration struct {
|
|
}
|
|
}
|
|
|
|
|
|
func init() {
|
|
func init() {
|
|
- libnetwork.RegisterNetworkType(NetworkType, Create, &Configuration{})
|
|
|
|
|
|
+ libnetwork.RegisterNetworkType(networkType, Create, &Configuration{})
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Create a new Network managed by the "simplebridge" driver.
|
|
func Create(name string, config *Configuration) (libnetwork.Network, error) {
|
|
func Create(name string, config *Configuration) (libnetwork.Network, error) {
|
|
- bridgeIntfc := NewInterface(config)
|
|
|
|
- bridgeSetup := NewBridgeSetup(bridgeIntfc)
|
|
|
|
|
|
+ bridgeIntfc := newInterface(config)
|
|
|
|
+ bridgeSetup := newBridgeSetup(bridgeIntfc)
|
|
|
|
|
|
// If the bridge interface doesn't exist, we need to start the setup steps
|
|
// If the bridge interface doesn't exist, we need to start the setup steps
|
|
// by creating a new device and assigning it an IPv4 address.
|
|
// by creating a new device and assigning it an IPv4 address.
|
|
- bridgeAlreadyExists := bridgeIntfc.Exists()
|
|
|
|
|
|
+ bridgeAlreadyExists := bridgeIntfc.exists()
|
|
if !bridgeAlreadyExists {
|
|
if !bridgeAlreadyExists {
|
|
- bridgeSetup.QueueStep(SetupDevice)
|
|
|
|
- bridgeSetup.QueueStep(SetupBridgeIPv4)
|
|
|
|
|
|
+ bridgeSetup.queueStep(setupDevice)
|
|
|
|
+ bridgeSetup.queueStep(setupBridgeIPv4)
|
|
}
|
|
}
|
|
|
|
|
|
// Conditionnally queue setup steps depending on configuration values.
|
|
// Conditionnally queue setup steps depending on configuration values.
|
|
for _, step := range []struct {
|
|
for _, step := range []struct {
|
|
Condition bool
|
|
Condition bool
|
|
- Fn SetupStep
|
|
|
|
|
|
+ Fn setupStep
|
|
}{
|
|
}{
|
|
// Enable IPv6 on the bridge if required. We do this even for a
|
|
// Enable IPv6 on the bridge if required. We do this even for a
|
|
// previously existing bridge, as it may be here from a previous
|
|
// previously existing bridge, as it may be here from a previous
|
|
// installation where IPv6 wasn't supported yet and needs to be
|
|
// installation where IPv6 wasn't supported yet and needs to be
|
|
// assigned an IPv6 link-local address.
|
|
// assigned an IPv6 link-local address.
|
|
- {config.EnableIPv6, SetupBridgeIPv6},
|
|
|
|
|
|
+ {config.EnableIPv6, setupBridgeIPv6},
|
|
|
|
|
|
// We ensure that the bridge has the expectedIPv4 and IPv6 addresses in
|
|
// We ensure that the bridge has the expectedIPv4 and IPv6 addresses in
|
|
// the case of a previously existing device.
|
|
// the case of a previously existing device.
|
|
- {bridgeAlreadyExists, SetupVerifyConfiguredAddresses},
|
|
|
|
|
|
+ {bridgeAlreadyExists, setupVerifyConfiguredAddresses},
|
|
|
|
|
|
// Setup the bridge to allocate containers IPv4 addresses in the
|
|
// Setup the bridge to allocate containers IPv4 addresses in the
|
|
// specified subnet.
|
|
// specified subnet.
|
|
- {config.FixedCIDR != nil, SetupFixedCIDRv4},
|
|
|
|
|
|
+ {config.FixedCIDR != nil, setupFixedCIDRv4},
|
|
|
|
|
|
// Setup the bridge to allocate containers global IPv6 addresses in the
|
|
// Setup the bridge to allocate containers global IPv6 addresses in the
|
|
// specified subnet.
|
|
// specified subnet.
|
|
- {config.FixedCIDRv6 != nil, SetupFixedCIDRv6},
|
|
|
|
|
|
+ {config.FixedCIDRv6 != nil, setupFixedCIDRv6},
|
|
|
|
|
|
// Setup IPTables.
|
|
// Setup IPTables.
|
|
- {config.EnableIPTables, SetupIPTables},
|
|
|
|
|
|
+ {config.EnableIPTables, setupIPTables},
|
|
|
|
|
|
// Setup IP forwarding.
|
|
// Setup IP forwarding.
|
|
- {config.EnableIPForwarding, SetupIPForwarding},
|
|
|
|
|
|
+ {config.EnableIPForwarding, setupIPForwarding},
|
|
} {
|
|
} {
|
|
if step.Condition {
|
|
if step.Condition {
|
|
- bridgeSetup.QueueStep(step.Fn)
|
|
|
|
|
|
+ bridgeSetup.queueStep(step.Fn)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Apply the prepared list of steps, and abort at the first error.
|
|
// Apply the prepared list of steps, and abort at the first error.
|
|
- bridgeSetup.QueueStep(SetupDeviceUp)
|
|
|
|
- if err := bridgeSetup.Apply(); err != nil {
|
|
|
|
|
|
+ bridgeSetup.queueStep(setupDeviceUp)
|
|
|
|
+ if err := bridgeSetup.apply(); err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|