Skip to content

Commit f996384

Browse files
authored
Merge pull request moby#50382 from akerouanton/split-nat-routed-portmappers
libnet/d/bridge: mv portmapper to libnet/pms/{nat,routed}
2 parents c9a83e3 + 4e246ef commit f996384

22 files changed

+1259
-850
lines changed

daemon/daemon.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,9 +1458,10 @@ func (daemon *Daemon) networkOptions(conf *config.Config, pg plugingetter.Plugin
14581458
nwconfig.OptionLabels(conf.Labels),
14591459
nwconfig.OptionNetworkControlPlaneMTU(conf.NetworkControlPlaneMTU),
14601460
nwconfig.OptionFirewallBackend(conf.FirewallBackend),
1461-
driverOptions(conf),
14621461
}
14631462

1463+
options = append(options, networkPlatformOptions(conf)...)
1464+
14641465
defaultAddressPools := ipamutils.GetLocalScopeDefaultNetworks()
14651466
if len(conf.NetworkConfig.DefaultAddressPools.Value()) > 0 {
14661467
defaultAddressPools = conf.NetworkConfig.DefaultAddressPools.Value()

daemon/daemon_unix.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -924,19 +924,23 @@ func setHostGatewayIP(controller *libnetwork.Controller, config *config.Config)
924924
}
925925
}
926926

927-
func driverOptions(config *config.Config) nwconfig.Option {
928-
return nwconfig.OptionDriverConfig("bridge", options.Generic{
929-
netlabel.GenericData: options.Generic{
930-
"EnableIPForwarding": config.BridgeConfig.EnableIPForward,
931-
"DisableFilterForwardDrop": config.BridgeConfig.DisableFilterForwardDrop,
932-
"EnableIPTables": config.BridgeConfig.EnableIPTables,
933-
"EnableIP6Tables": config.BridgeConfig.EnableIP6Tables,
934-
"EnableUserlandProxy": config.BridgeConfig.EnableUserlandProxy,
935-
"UserlandProxyPath": config.BridgeConfig.UserlandProxyPath,
936-
"AllowDirectRouting": config.BridgeConfig.AllowDirectRouting,
937-
"Rootless": config.Rootless,
938-
},
939-
})
927+
// networkPlatformOptions returns a slice of platform-specific libnetwork
928+
// options.
929+
func networkPlatformOptions(conf *config.Config) []nwconfig.Option {
930+
return []nwconfig.Option{
931+
nwconfig.OptionRootless(conf.Rootless),
932+
nwconfig.OptionUserlandProxy(conf.EnableUserlandProxy, conf.UserlandProxyPath),
933+
nwconfig.OptionDriverConfig("bridge", options.Generic{
934+
netlabel.GenericData: options.Generic{
935+
"EnableIPForwarding": conf.BridgeConfig.EnableIPForward,
936+
"DisableFilterForwardDrop": conf.BridgeConfig.DisableFilterForwardDrop,
937+
"EnableIPTables": conf.BridgeConfig.EnableIPTables,
938+
"EnableIP6Tables": conf.BridgeConfig.EnableIP6Tables,
939+
"Hairpin": !conf.EnableUserlandProxy || conf.UserlandProxyPath == "",
940+
"AllowDirectRouting": conf.BridgeConfig.AllowDirectRouting,
941+
},
942+
}),
943+
}
940944
}
941945

942946
type defBrOptsV4 struct {

daemon/daemon_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ func (daemon *Daemon) conditionalUnmountOnCleanup(container *container.Container
524524
return daemon.Unmount(container)
525525
}
526526

527-
func driverOptions(_ *config.Config) nwconfig.Option {
527+
func networkPlatformOptions(_ *config.Config) []nwconfig.Option {
528528
return nil
529529
}
530530

daemon/libnetwork/config/config.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ type Config struct {
4343
ActiveSandboxes map[string]any
4444
PluginGetter plugingetter.PluginGetter
4545
FirewallBackend string
46+
Rootless bool
47+
EnableUserlandProxy bool
48+
UserlandProxyPath string
4649
}
4750

4851
// New creates a new Config and initializes it with the given Options.
@@ -162,3 +165,20 @@ func OptionFirewallBackend(val string) Option {
162165
c.FirewallBackend = val
163166
}
164167
}
168+
169+
// OptionRootless returns an option setter that indicates whether the daemon is
170+
// running in rootless mode.
171+
func OptionRootless(rootless bool) Option {
172+
return func(c *Config) {
173+
c.Rootless = rootless
174+
}
175+
}
176+
177+
// OptionUserlandProxy returns an option setter that indicates whether the
178+
// userland proxy is enabled, and sets the path to the proxy binary.
179+
func OptionUserlandProxy(enabled bool, proxyPath string) Option {
180+
return func(c *Config) {
181+
c.EnableUserlandProxy = enabled
182+
c.UserlandProxyPath = proxyPath
183+
}
184+
}

daemon/libnetwork/controller.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type Controller struct {
8686
id string
8787
drvRegistry drvregistry.Networks
8888
ipamRegistry drvregistry.IPAMs
89+
pmRegistry drvregistry.PortMappers
8990
sandboxes map[string]*Sandbox
9091
cfg *config.Config
9192
store *datastore.Store
@@ -173,13 +174,20 @@ func New(ctx context.Context, cfgOptions ...config.Option) (_ *Controller, retEr
173174
}
174175
c.drvRegistry.Notify = c
175176

177+
// Register portmappers before network drivers to make sure they can
178+
// restore existing sandboxes (with port mappings) during their
179+
// initialization, if the daemon is started in live restore mode.
180+
if err := registerPortMappers(ctx, &c.pmRegistry, c.cfg); err != nil {
181+
return nil, err
182+
}
183+
176184
// External plugins don't need config passed through daemon. They can
177185
// bootstrap themselves.
178186
if err := remotedriver.Register(&c.drvRegistry, c.cfg.PluginGetter); err != nil {
179187
return nil, err
180188
}
181189

182-
if err := registerNetworkDrivers(&c.drvRegistry, c.store, c.makeDriverConfig); err != nil {
190+
if err := registerNetworkDrivers(&c.drvRegistry, c.store, &c.pmRegistry, c.makeDriverConfig); err != nil {
183191
return nil, err
184192
}
185193

0 commit comments

Comments
 (0)