mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
libnet/d/bridge: Register: pass a Configuration struct
Libnetwork passes a map[string]any to the bridge driver's Register function. This forces the daemon to convert its configuration into a map, and the driver to convert that map back into a struct. This is unnecessary complexity, and makes it harder to track down where and how bridge driver configuration fields are set. Refactor libnetwork to let the daemon register the bridge.Configuration directly through a new option `OptionBridgeConfig`. The bridge driver now takes a `Configuration` param that needs no special treatment. Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
@@ -35,7 +35,6 @@ import (
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/drivers/bridge"
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/netlabel"
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/nlwrap"
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/options"
|
||||
lntypes "github.com/moby/moby/v2/daemon/libnetwork/types"
|
||||
"github.com/moby/moby/v2/daemon/pkg/opts"
|
||||
volumemounts "github.com/moby/moby/v2/daemon/volume/mounts"
|
||||
@@ -927,17 +926,15 @@ func networkPlatformOptions(conf *config.Config) []nwconfig.Option {
|
||||
return []nwconfig.Option{
|
||||
nwconfig.OptionRootless(conf.Rootless),
|
||||
nwconfig.OptionUserlandProxy(conf.EnableUserlandProxy, conf.UserlandProxyPath),
|
||||
nwconfig.OptionDriverConfig("bridge", options.Generic{
|
||||
netlabel.GenericData: options.Generic{
|
||||
"EnableIPForwarding": conf.BridgeConfig.EnableIPForward,
|
||||
"DisableFilterForwardDrop": conf.BridgeConfig.DisableFilterForwardDrop,
|
||||
"EnableIPTables": conf.BridgeConfig.EnableIPTables,
|
||||
"EnableIP6Tables": conf.BridgeConfig.EnableIP6Tables,
|
||||
"EnableProxy": conf.EnableUserlandProxy && conf.UserlandProxyPath != "",
|
||||
"ProxyPath": conf.UserlandProxyPath,
|
||||
"AllowDirectRouting": conf.BridgeConfig.AllowDirectRouting,
|
||||
"AcceptFwMark": conf.BridgeConfig.BridgeAcceptFwMark,
|
||||
},
|
||||
nwconfig.OptionBridgeConfig(bridge.Configuration{
|
||||
EnableIPForwarding: conf.BridgeConfig.EnableIPForward,
|
||||
DisableFilterForwardDrop: conf.BridgeConfig.DisableFilterForwardDrop,
|
||||
EnableIPTables: conf.BridgeConfig.EnableIPTables,
|
||||
EnableIP6Tables: conf.BridgeConfig.EnableIP6Tables,
|
||||
EnableProxy: conf.EnableUserlandProxy && conf.UserlandProxyPath != "",
|
||||
ProxyPath: conf.UserlandProxyPath,
|
||||
AllowDirectRouting: conf.BridgeConfig.AllowDirectRouting,
|
||||
AcceptFwMark: conf.BridgeConfig.BridgeAcceptFwMark,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ const (
|
||||
|
||||
// Config encapsulates configurations of various Libnetwork components
|
||||
type Config struct {
|
||||
PlatformConfig
|
||||
|
||||
DataDir string
|
||||
// ExecRoot is the base-path for libnetwork external key listeners
|
||||
// (created in "<ExecRoot>/libnetwork/<Controller-Short-ID>.sock"),
|
||||
@@ -31,7 +33,6 @@ type Config struct {
|
||||
DefaultNetwork string
|
||||
DefaultDriver string
|
||||
Labels []string
|
||||
driverCfg map[string]map[string]any
|
||||
ClusterProvider cluster.Provider
|
||||
NetworkControlPlaneMTU int
|
||||
DefaultAddressPool []*ipamutils.NetworkToSplit
|
||||
@@ -47,7 +48,6 @@ type Config struct {
|
||||
// New creates a new Config and initializes it with the given Options.
|
||||
func New(opts ...Option) *Config {
|
||||
cfg := &Config{
|
||||
driverCfg: make(map[string]map[string]any),
|
||||
DatastoreBucket: datastore.DefaultBucket,
|
||||
}
|
||||
|
||||
@@ -60,10 +60,6 @@ func New(opts ...Option) *Config {
|
||||
return cfg
|
||||
}
|
||||
|
||||
func (c *Config) DriverConfig(name string) map[string]any {
|
||||
return c.driverCfg[name]
|
||||
}
|
||||
|
||||
// Option is an option setter function type used to pass various configurations
|
||||
// to the controller
|
||||
type Option func(c *Config)
|
||||
@@ -91,13 +87,6 @@ func OptionDefaultAddressPoolConfig(addressPool []*ipamutils.NetworkToSplit) Opt
|
||||
}
|
||||
}
|
||||
|
||||
// OptionDriverConfig returns an option setter for driver configuration.
|
||||
func OptionDriverConfig(networkType string, config map[string]any) Option {
|
||||
return func(c *Config) {
|
||||
c.driverCfg[networkType] = config
|
||||
}
|
||||
}
|
||||
|
||||
// OptionDataDir function returns an option setter for data folder
|
||||
func OptionDataDir(dataDir string) Option {
|
||||
return func(c *Config) {
|
||||
|
||||
@@ -1,6 +1,21 @@
|
||||
package config
|
||||
|
||||
import "github.com/moby/moby/v2/daemon/libnetwork/osl"
|
||||
import (
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/drivers/bridge"
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/osl"
|
||||
)
|
||||
|
||||
// PlatformConfig defines platform-specific configuration.
|
||||
type PlatformConfig struct {
|
||||
BridgeConfig bridge.Configuration
|
||||
}
|
||||
|
||||
// OptionBridgeConfig returns an option setter for bridge driver config.
|
||||
func OptionBridgeConfig(config bridge.Configuration) Option {
|
||||
return func(c *Config) {
|
||||
c.BridgeConfig = config
|
||||
}
|
||||
}
|
||||
|
||||
// optionExecRoot on Linux sets both the controller's ExecRoot and osl.basePath.
|
||||
func optionExecRoot(execRoot string) Option {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package config
|
||||
|
||||
// PlatformConfig defines platform-specific configuration.
|
||||
type PlatformConfig struct{}
|
||||
|
||||
// optionExecRoot is a no-op on non-unix platforms.
|
||||
func optionExecRoot(execRoot string) Option {
|
||||
return func(*Config) {}
|
||||
|
||||
@@ -46,7 +46,6 @@ package libnetwork
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"maps"
|
||||
"net"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -188,7 +187,7 @@ func New(ctx context.Context, cfgOptions ...config.Option) (_ *Controller, retEr
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := registerNetworkDrivers(&c.drvRegistry, c.store, &c.pmRegistry, c.makeDriverConfig); err != nil {
|
||||
if err := registerNetworkDrivers(&c.drvRegistry, c.cfg, c.store, &c.pmRegistry); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -384,10 +383,6 @@ func (c *Controller) agentStopComplete() {
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (c *Controller) makeDriverConfig(ntype string) map[string]any {
|
||||
return maps.Clone(c.cfg.DriverConfig(ntype))
|
||||
}
|
||||
|
||||
// ID returns the controller's unique identity.
|
||||
func (c *Controller) ID() string {
|
||||
return c.id
|
||||
|
||||
@@ -10,8 +10,6 @@ import (
|
||||
"github.com/moby/moby/api/types/system"
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/internal/nftables"
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/iptables"
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/netlabel"
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/options"
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/osl"
|
||||
)
|
||||
|
||||
@@ -34,24 +32,11 @@ func (c *Controller) FirewallBackend() *system.FirewallInfo {
|
||||
// enabledIptablesVersions returns the iptables versions that are enabled
|
||||
// for the controller.
|
||||
func (c *Controller) enabledIptablesVersions() []iptables.IPVersion {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if c.cfg == nil {
|
||||
return nil
|
||||
}
|
||||
// parse map cfg["bridge"]["generic"]["EnableIPTable"]
|
||||
cfgBridge := c.cfg.DriverConfig("bridge")
|
||||
cfgGeneric, ok := cfgBridge[netlabel.GenericData].(options.Generic)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
var versions []iptables.IPVersion
|
||||
if enabled, ok := cfgGeneric["EnableIPTables"].(bool); enabled || !ok {
|
||||
// iptables is enabled unless user explicitly disabled it
|
||||
if c.cfg.BridgeConfig.EnableIPTables {
|
||||
versions = append(versions, iptables.IPv4)
|
||||
}
|
||||
if enabled, _ := cfgGeneric["EnableIP6Tables"].(bool); enabled {
|
||||
if c.cfg.BridgeConfig.EnableIP6Tables {
|
||||
versions = append(versions, iptables.IPv6)
|
||||
}
|
||||
return versions
|
||||
|
||||
@@ -188,7 +188,7 @@ func newDriver(store *datastore.Store, pms *drvregistry.PortMappers) *driver {
|
||||
}
|
||||
|
||||
// Register registers a new instance of bridge driver.
|
||||
func Register(r driverapi.Registerer, store *datastore.Store, pms *drvregistry.PortMappers, config map[string]any) error {
|
||||
func Register(r driverapi.Registerer, store *datastore.Store, pms *drvregistry.PortMappers, config Configuration) error {
|
||||
d := newDriver(store, pms)
|
||||
if err := d.configure(config); err != nil {
|
||||
return err
|
||||
@@ -496,23 +496,7 @@ func (n *bridgeNetwork) getEndpoint(eid string) (*bridgeEndpoint, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (d *driver) configure(option map[string]any) error {
|
||||
var config Configuration
|
||||
switch opt := option[netlabel.GenericData].(type) {
|
||||
case options.Generic:
|
||||
opaqueConfig, err := options.GenerateFromModel(opt, &Configuration{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
config = *opaqueConfig.(*Configuration)
|
||||
case *Configuration:
|
||||
config = *opt
|
||||
case nil:
|
||||
// No GenericData option set. Use defaults.
|
||||
default:
|
||||
return errdefs.InvalidParameter(fmt.Errorf("invalid configuration type (%T) passed", opt))
|
||||
}
|
||||
|
||||
func (d *driver) configure(config Configuration) error {
|
||||
var err error
|
||||
d.firewaller, err = newFirewaller(context.Background(), firewaller.Config{
|
||||
IPv4: config.EnableIPTables,
|
||||
|
||||
@@ -277,11 +277,6 @@ func TestCreateFullOptions(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
d := newDriver(storeutils.NewTempStore(t), &drvregistry.PortMappers{})
|
||||
|
||||
config := &Configuration{
|
||||
EnableIPForwarding: true,
|
||||
EnableIPTables: true,
|
||||
}
|
||||
|
||||
// Test this scenario: Default gw address does not belong to
|
||||
// container network and it's greater than bridge address
|
||||
cnw, _ := types.ParseCIDR("172.16.122.0/24")
|
||||
@@ -289,10 +284,10 @@ func TestCreateFullOptions(t *testing.T) {
|
||||
br, _ := types.ParseCIDR("172.16.0.1/16")
|
||||
defgw, _ := types.ParseCIDR("172.16.0.100/16")
|
||||
|
||||
genericOption := make(map[string]any)
|
||||
genericOption[netlabel.GenericData] = config
|
||||
|
||||
if err := d.configure(genericOption); err != nil {
|
||||
if err := d.configure(Configuration{
|
||||
EnableIPForwarding: true,
|
||||
EnableIPTables: true,
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
}
|
||||
|
||||
@@ -331,7 +326,7 @@ func TestCreateFullOptions(t *testing.T) {
|
||||
func TestCreateNoConfig(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
d := newDriver(storeutils.NewTempStore(t), &drvregistry.PortMappers{})
|
||||
err := d.configure(nil)
|
||||
err := d.configure(Configuration{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
netconfig := &networkConfiguration{BridgeName: DefaultBridgeName, EnableIPv4: true}
|
||||
@@ -347,13 +342,9 @@ func TestCreateFullOptionsLabels(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
d := newDriver(storeutils.NewTempStore(t), &drvregistry.PortMappers{})
|
||||
|
||||
config := &Configuration{
|
||||
if err := d.configure(Configuration{
|
||||
EnableIPForwarding: true,
|
||||
}
|
||||
genericOption := make(map[string]any)
|
||||
genericOption[netlabel.GenericData] = config
|
||||
|
||||
if err := d.configure(genericOption); err != nil {
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
}
|
||||
|
||||
@@ -534,7 +525,7 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
d := newDriver(storeutils.NewTempStore(t), &drvregistry.PortMappers{})
|
||||
|
||||
if err := d.configure(nil); err != nil {
|
||||
if err := d.configure(Configuration{}); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
}
|
||||
|
||||
@@ -560,7 +551,7 @@ func TestCreateFail(t *testing.T) {
|
||||
|
||||
d := newDriver(storeutils.NewTempStore(t), &drvregistry.PortMappers{})
|
||||
|
||||
if err := d.configure(nil); err != nil {
|
||||
if err := d.configure(Configuration{}); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
}
|
||||
|
||||
@@ -591,18 +582,14 @@ func TestCreateMultipleNetworks(t *testing.T) {
|
||||
assert.Check(t, is.Len(slices.Collect(maps.Keys(got)), 0), "Rules for bridges have not been deleted")
|
||||
}
|
||||
|
||||
config := &Configuration{
|
||||
if err := d.configure(Configuration{
|
||||
EnableIPTables: true,
|
||||
}
|
||||
genericOption := make(map[string]any)
|
||||
genericOption[netlabel.GenericData] = config
|
||||
|
||||
if err := d.configure(genericOption); err != nil {
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
}
|
||||
|
||||
config1 := &networkConfiguration{BridgeName: "net_test_1", EnableIPv4: true}
|
||||
genericOption = make(map[string]any)
|
||||
genericOption := make(map[string]any)
|
||||
genericOption[netlabel.GenericData] = config1
|
||||
if err := d.CreateNetwork(context.Background(), "1", genericOption, nil, getIPv4Data(t), nil); err != nil {
|
||||
t.Fatalf("Failed to create bridge: %v", err)
|
||||
@@ -798,13 +785,9 @@ func testQueryEndpointInfo(t *testing.T, ulPxyEnabled bool) {
|
||||
d := newDriver(storeutils.NewTempStore(t), &pms)
|
||||
portallocator.Get().ReleaseAll()
|
||||
|
||||
config := &Configuration{
|
||||
if err := d.configure(Configuration{
|
||||
EnableIPTables: true,
|
||||
}
|
||||
genericOption := make(map[string]any)
|
||||
genericOption[netlabel.GenericData] = config
|
||||
|
||||
if err := d.configure(genericOption); err != nil {
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
}
|
||||
|
||||
@@ -813,7 +796,7 @@ func testQueryEndpointInfo(t *testing.T, ulPxyEnabled bool) {
|
||||
EnableIPv4: true,
|
||||
EnableICC: false,
|
||||
}
|
||||
genericOption = make(map[string]any)
|
||||
genericOption := make(map[string]any)
|
||||
genericOption[netlabel.GenericData] = netconfig
|
||||
|
||||
ipdList := getIPv4Data(t)
|
||||
@@ -901,13 +884,9 @@ func TestLinkContainers(t *testing.T) {
|
||||
|
||||
d := newDriver(storeutils.NewTempStore(t), &drvregistry.PortMappers{})
|
||||
|
||||
config := &Configuration{
|
||||
if err := d.configure(Configuration{
|
||||
EnableIPTables: true,
|
||||
}
|
||||
genericOption := make(map[string]any)
|
||||
genericOption[netlabel.GenericData] = config
|
||||
|
||||
if err := d.configure(genericOption); err != nil {
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
}
|
||||
|
||||
@@ -916,7 +895,7 @@ func TestLinkContainers(t *testing.T) {
|
||||
EnableIPv4: true,
|
||||
EnableICC: false,
|
||||
}
|
||||
genericOption = make(map[string]any)
|
||||
genericOption := make(map[string]any)
|
||||
genericOption[netlabel.GenericData] = netconfig
|
||||
|
||||
ipdList := getIPv4Data(t)
|
||||
@@ -1170,7 +1149,7 @@ func TestSetDefaultGw(t *testing.T) {
|
||||
|
||||
d := newDriver(storeutils.NewTempStore(t), &drvregistry.PortMappers{})
|
||||
|
||||
if err := d.configure(nil); err != nil {
|
||||
if err := d.configure(Configuration{}); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
}
|
||||
|
||||
@@ -1220,7 +1199,7 @@ func TestCreateWithExistingBridge(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
d := newDriver(storeutils.NewTempStore(t), &drvregistry.PortMappers{})
|
||||
|
||||
if err := d.configure(nil); err != nil {
|
||||
if err := d.configure(Configuration{}); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
}
|
||||
|
||||
@@ -1293,7 +1272,7 @@ func TestCreateParallel(t *testing.T) {
|
||||
d := newDriver(storeutils.NewTempStore(t), &drvregistry.PortMappers{})
|
||||
portallocator.Get().ReleaseAll()
|
||||
|
||||
if err := d.configure(nil); err != nil {
|
||||
if err := d.configure(Configuration{}); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
}
|
||||
|
||||
@@ -1342,11 +1321,10 @@ func useStubFirewaller(t *testing.T) {
|
||||
func TestSetupIP6TablesWithHostIPv4(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
d := newDriver(storeutils.NewTempStore(t), &drvregistry.PortMappers{})
|
||||
dc := &Configuration{
|
||||
if err := d.configure(Configuration{
|
||||
EnableIPTables: true,
|
||||
EnableIP6Tables: true,
|
||||
}
|
||||
if err := d.configure(map[string]any{netlabel.GenericData: dc}); err != nil {
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
nc := &networkConfiguration{
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
func TestLinkCreate(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
d := newDriver(storeutils.NewTempStore(t), &drvregistry.PortMappers{})
|
||||
err := d.configure(nil)
|
||||
err := d.configure(Configuration{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
mtu := 1490
|
||||
@@ -80,7 +80,7 @@ func TestLinkCreate(t *testing.T) {
|
||||
func TestLinkCreateTwo(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
d := newDriver(storeutils.NewTempStore(t), &drvregistry.PortMappers{})
|
||||
err := d.configure(nil)
|
||||
err := d.configure(Configuration{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
option := map[string]any{
|
||||
@@ -108,7 +108,7 @@ func TestLinkCreateTwo(t *testing.T) {
|
||||
func TestLinkCreateNoEnableIPv6(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
d := newDriver(storeutils.NewTempStore(t), &drvregistry.PortMappers{})
|
||||
err := d.configure(nil)
|
||||
err := d.configure(Configuration{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
option := map[string]any{
|
||||
@@ -133,7 +133,7 @@ func TestLinkCreateNoEnableIPv6(t *testing.T) {
|
||||
func TestLinkDelete(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
d := newDriver(storeutils.NewTempStore(t), &drvregistry.PortMappers{})
|
||||
err := d.configure(nil)
|
||||
err := d.configure(Configuration{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
option := map[string]any{
|
||||
|
||||
@@ -43,13 +43,9 @@ func TestPortMappingConfig(t *testing.T) {
|
||||
|
||||
d := newDriver(storeutils.NewTempStore(t), &pms)
|
||||
|
||||
config := &Configuration{
|
||||
if err := d.configure(Configuration{
|
||||
EnableIPTables: true,
|
||||
}
|
||||
genericOption := make(map[string]any)
|
||||
genericOption[netlabel.GenericData] = config
|
||||
|
||||
if err := d.configure(genericOption); err != nil {
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
}
|
||||
|
||||
@@ -132,14 +128,10 @@ func TestPortMappingV6Config(t *testing.T) {
|
||||
|
||||
d := newDriver(storeutils.NewTempStore(t), &pms)
|
||||
|
||||
config := &Configuration{
|
||||
if err := d.configure(Configuration{
|
||||
EnableIPTables: true,
|
||||
EnableIP6Tables: true,
|
||||
}
|
||||
genericOption := make(map[string]any)
|
||||
genericOption[netlabel.GenericData] = config
|
||||
|
||||
if err := d.configure(genericOption); err != nil {
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed to setup driver config: %v", err)
|
||||
}
|
||||
|
||||
@@ -782,14 +774,11 @@ func TestAddPortMappings(t *testing.T) {
|
||||
bridge: &bridgeInterface{},
|
||||
driver: newDriver(storeutils.NewTempStore(t), pms),
|
||||
}
|
||||
genericOption := map[string]any{
|
||||
netlabel.GenericData: &Configuration{
|
||||
EnableIPTables: true,
|
||||
EnableIP6Tables: true,
|
||||
EnableProxy: tc.enableProxy,
|
||||
},
|
||||
}
|
||||
err = n.driver.configure(genericOption)
|
||||
err = n.driver.configure(Configuration{
|
||||
EnableIPTables: true,
|
||||
EnableIP6Tables: true,
|
||||
EnableProxy: tc.enableProxy,
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
fwn, err := n.newFirewallerNetwork(context.Background())
|
||||
assert.NilError(t, err)
|
||||
|
||||
@@ -19,31 +19,24 @@ import (
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/portmappers/routed"
|
||||
)
|
||||
|
||||
func registerNetworkDrivers(r driverapi.Registerer, store *datastore.Store, pms *drvregistry.PortMappers, driverConfig func(string) map[string]any) error {
|
||||
func registerNetworkDrivers(r driverapi.Registerer, cfg *config.Config, store *datastore.Store, pms *drvregistry.PortMappers) error {
|
||||
for _, nr := range []struct {
|
||||
ntype string
|
||||
register func(driverapi.Registerer, *datastore.Store, map[string]any) error
|
||||
register func() error
|
||||
}{
|
||||
{ntype: bridge.NetworkType, register: func(r driverapi.Registerer, store *datastore.Store, cfg map[string]any) error {
|
||||
return bridge.Register(r, store, pms, cfg)
|
||||
}},
|
||||
{ntype: host.NetworkType, register: func(r driverapi.Registerer, _ *datastore.Store, _ map[string]any) error {
|
||||
return host.Register(r)
|
||||
}},
|
||||
{ntype: ipvlan.NetworkType, register: func(r driverapi.Registerer, store *datastore.Store, _ map[string]any) error {
|
||||
return ipvlan.Register(r, store)
|
||||
}},
|
||||
{ntype: macvlan.NetworkType, register: func(r driverapi.Registerer, store *datastore.Store, _ map[string]any) error {
|
||||
return macvlan.Register(r, store)
|
||||
}},
|
||||
{ntype: null.NetworkType, register: func(r driverapi.Registerer, _ *datastore.Store, _ map[string]any) error {
|
||||
return null.Register(r)
|
||||
}},
|
||||
{ntype: overlay.NetworkType, register: func(r driverapi.Registerer, _ *datastore.Store, _ map[string]any) error {
|
||||
return overlay.Register(r)
|
||||
}},
|
||||
{
|
||||
ntype: bridge.NetworkType,
|
||||
register: func() error {
|
||||
return bridge.Register(r, store, pms, cfg.BridgeConfig)
|
||||
},
|
||||
},
|
||||
{ntype: host.NetworkType, register: func() error { return host.Register(r) }},
|
||||
{ntype: ipvlan.NetworkType, register: func() error { return ipvlan.Register(r, store) }},
|
||||
{ntype: macvlan.NetworkType, register: func() error { return macvlan.Register(r, store) }},
|
||||
{ntype: null.NetworkType, register: func() error { return null.Register(r) }},
|
||||
{ntype: overlay.NetworkType, register: func() error { return overlay.Register(r) }},
|
||||
} {
|
||||
if err := nr.register(r, store, driverConfig(nr.ntype)); err != nil {
|
||||
if err := nr.register(); err != nil {
|
||||
return fmt.Errorf("failed to register %q driver: %w", nr.ntype, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
package libnetwork
|
||||
|
||||
import "github.com/moby/moby/v2/daemon/libnetwork/driverapi"
|
||||
|
||||
func registerNetworkDrivers(r driverapi.Registerer, driverConfig func(string) map[string]any) error {
|
||||
func registerNetworkDrivers(cfg *config.Config, r driverapi.Registerer, store *datastore.Store, pms *drvregistry.PortMappers) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/drvregistry"
|
||||
)
|
||||
|
||||
func registerNetworkDrivers(r driverapi.Registerer, store *datastore.Store, _ *drvregistry.PortMappers, _ func(string) map[string]any) error {
|
||||
func registerNetworkDrivers(r driverapi.Registerer, _ *config.Config, store *datastore.Store, _ *drvregistry.PortMappers) error {
|
||||
for _, nr := range []struct {
|
||||
ntype string
|
||||
register func(driverapi.Registerer) error
|
||||
|
||||
@@ -12,8 +12,6 @@ import (
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/drivers/bridge"
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/internal/nftables"
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/iptables"
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/netlabel"
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/options"
|
||||
"github.com/moby/moby/v2/internal/testutils/netnsutils"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
@@ -70,11 +68,9 @@ func TestUserChain(t *testing.T) {
|
||||
c, err := New(
|
||||
context.Background(),
|
||||
config.OptionDataDir(t.TempDir()),
|
||||
config.OptionDriverConfig("bridge", map[string]any{
|
||||
netlabel.GenericData: options.Generic{
|
||||
"EnableIPTables": tc.iptables,
|
||||
"EnableIP6Tables": tc.iptables,
|
||||
},
|
||||
config.OptionBridgeConfig(bridge.Configuration{
|
||||
EnableIPTables: tc.iptables,
|
||||
EnableIP6Tables: tc.iptables,
|
||||
}))
|
||||
assert.NilError(t, err)
|
||||
defer c.Stop()
|
||||
|
||||
@@ -48,10 +48,8 @@ func newController(t *testing.T) *libnetwork.Controller {
|
||||
c, err := libnetwork.New(
|
||||
context.Background(),
|
||||
config.OptionDataDir(t.TempDir()),
|
||||
config.OptionDriverConfig(bridgeNetType, map[string]any{
|
||||
netlabel.GenericData: options.Generic{
|
||||
"EnableIPForwarding": true,
|
||||
},
|
||||
config.OptionBridgeConfig(bridge.Configuration{
|
||||
EnableIPForwarding: true,
|
||||
}),
|
||||
config.OptionDefaultAddressPoolConfig(ipamutils.GetLocalScopeDefaultNetworks()),
|
||||
)
|
||||
|
||||
@@ -20,12 +20,11 @@ import (
|
||||
)
|
||||
|
||||
func getTestEnv(t *testing.T, opts ...[]NetworkOption) (*Controller, []*Network) {
|
||||
const netType = "bridge"
|
||||
c, err := New(
|
||||
context.Background(),
|
||||
config.OptionDataDir(t.TempDir()),
|
||||
config.OptionDriverConfig(netType, map[string]any{
|
||||
netlabel.GenericData: options.Generic{"EnableIPForwarding": true},
|
||||
config.OptionBridgeConfig(bridge.Configuration{
|
||||
EnableIPForwarding: true,
|
||||
}),
|
||||
config.OptionDefaultAddressPoolConfig(ipamutils.GetLocalScopeDefaultNetworks()),
|
||||
)
|
||||
@@ -49,7 +48,7 @@ func getTestEnv(t *testing.T, opts ...[]NetworkOption) (*Controller, []*Network)
|
||||
}),
|
||||
}
|
||||
newOptions = append(newOptions, opt...)
|
||||
n, err := c.NewNetwork(context.Background(), netType, name, "", newOptions...)
|
||||
n, err := c.NewNetwork(context.Background(), bridge.NetworkType, name, "", newOptions...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -5,17 +5,12 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/config"
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/netlabel"
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/options"
|
||||
)
|
||||
|
||||
func testLocalBackend(t *testing.T, path, bucket string) {
|
||||
cfgOptions := []config.Option{
|
||||
config.OptionDataDir(path),
|
||||
func(c *config.Config) { c.DatastoreBucket = bucket },
|
||||
config.OptionDriverConfig("host", map[string]any{
|
||||
netlabel.GenericData: options.Generic{},
|
||||
}),
|
||||
}
|
||||
|
||||
testController, err := New(context.Background(), cfgOptions...)
|
||||
|
||||
Reference in New Issue
Block a user