Repository: moby/moby
File: daemon/daemon_unix.go (Go)

Code before:
		if len(v4Info) > 0 {
			addr, _ := netip.AddrFromSlice(v4Info[0].Gateway.IP)
			config.HostGatewayIPs = append(config.HostGatewayIPs, addr)
		}
		if len(v6Info) > 0 {
			addr, _ := netip.AddrFromSlice(v6Info[0].Gateway.IP)
			config.HostGatewayIPs = append(config.HostGatewayIPs, addr)
		}
	}
}

// networkPlatformOptions returns a slice of platform-specific libnetwork
// options.
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,
				"Hairpin":                  !conf.EnableUserlandProxy || conf.UserlandProxyPath == "",
				"AllowDirectRouting":       conf.BridgeConfig.AllowDirectRouting,
				"AcceptFwMark":             conf.BridgeConfig.BridgeAcceptFwMark,
			},
		}),
	}
}

type defBrOptsV4 struct {
	cfg config.BridgeConfig
}

func (o defBrOptsV4) nlFamily() int {
	return netlink.FAMILY_V4
}

func (o defBrOptsV4) fixedCIDR() (fCIDR, optName string) {
	return o.cfg.FixedCIDR, "fixed-cidr"
}

func (o defBrOptsV4) bip() (bip, optName string) {
	return o.cfg.IP, "bip"
}

func (o defBrOptsV4) defGw() (gw net.IP, optName, auxAddrLabel string) {
	return o.cfg.DefaultGatewayIPv4, "default-gateway", bridge.DefaultGatewayV4AuxKey

Review comment (bug):
`Hairpin` is `!EnableProxy` ... it'd be better to only have one of the fields?

It's already confusing in `TestAddPortMappings`, which does this (rather than `EnableProxy: tc.enableProxy`)
on line 793:
```
					Hairpin:         tc.hairpin,
					EnableProxy:     true,
```

In the modified code, `EnableProxy` is used to decide whether set up the proxy. On line 893 the test itself looks at `tc.enableProxy` to decide whether to check that - I think the test would fail if it checked that no proxies were started if `!tc.enableProxy`?

Code after:
		if len(v4Info) > 0 {
			addr, _ := netip.AddrFromSlice(v4Info[0].Gateway.IP)
			config.HostGatewayIPs = append(config.HostGatewayIPs, addr)
		}
		if len(v6Info) > 0 {
			addr, _ := netip.AddrFromSlice(v6Info[0].Gateway.IP)
			config.HostGatewayIPs = append(config.HostGatewayIPs, addr)
		}
	}
}

// networkPlatformOptions returns a slice of platform-specific libnetwork
// options.
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,
			},
		}),
	}
}

type defBrOptsV4 struct {
	cfg config.BridgeConfig
}

func (o defBrOptsV4) nlFamily() int {
	return netlink.FAMILY_V4
}

func (o defBrOptsV4) fixedCIDR() (fCIDR, optName string) {
	return o.cfg.FixedCIDR, "fixed-cidr"
}

func (o defBrOptsV4) bip() (bip, optName string) {
	return o.cfg.IP, "bip"
}

func (o defBrOptsV4) defGw() (gw net.IP, optName, auxAddrLabel string) {
	return o.cfg.DefaultGatewayIPv4, "default-gateway", bridge.DefaultGatewayV4AuxKey
}