s/HostIP/HostIPv4/ for com.docker.network.host_ipv4
setting
Rename all variables/fields/map keys associated with the `com.docker.network.host_ipv4` option from `HostIP` to `HostIPv4`. Rationale: * This makes the variable/field name consistent with the option name. * This makes the code more readable because it is clear that the variable/field does not hold an IPv6 address. This will hopefully avoid bugs like <https://github.com/moby/moby/issues/46445> in the future. * If IPv6 SNAT support is ever added, the names will be symmetric. Signed-off-by: Richard Hansen <rhansen@rhansen.org>
This commit is contained in:
parent
2a14b6cf60
commit
96f85def5b
6 changed files with 19 additions and 17 deletions
|
@ -73,7 +73,7 @@ type networkConfiguration struct {
|
|||
Mtu int
|
||||
DefaultBindingIP net.IP
|
||||
DefaultBridge bool
|
||||
HostIP net.IP
|
||||
HostIPv4 net.IP
|
||||
ContainerIfacePrefix string
|
||||
// Internal fields set after ipam data parsing
|
||||
AddressIPv4 *net.IPNet
|
||||
|
@ -266,8 +266,8 @@ func (c *networkConfiguration) fromLabels(labels map[string]string) error {
|
|||
}
|
||||
case netlabel.ContainerIfacePrefix:
|
||||
c.ContainerIfacePrefix = value
|
||||
case netlabel.HostIP:
|
||||
if c.HostIP = net.ParseIP(value); c.HostIP == nil {
|
||||
case netlabel.HostIPv4:
|
||||
if c.HostIPv4 = net.ParseIP(value); c.HostIPv4 == nil {
|
||||
return parseErr(label, value, "nil ip")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -298,7 +298,7 @@ func TestCreateFullOptionsLabels(t *testing.T) {
|
|||
}
|
||||
|
||||
bndIPs := "127.0.0.1"
|
||||
testHostIP := "1.2.3.4"
|
||||
testHostIPv4 := "1.2.3.4"
|
||||
nwV6s := "2001:db8:2600:2700:2800::/80"
|
||||
gwV6s := "2001:db8:2600:2700:2800::25/80"
|
||||
nwV6, _ := types.ParseCIDR(nwV6s)
|
||||
|
@ -310,7 +310,7 @@ func TestCreateFullOptionsLabels(t *testing.T) {
|
|||
EnableICC: "true",
|
||||
EnableIPMasquerade: "true",
|
||||
DefaultBindingIP: bndIPs,
|
||||
netlabel.HostIP: testHostIP,
|
||||
netlabel.HostIPv4: testHostIPv4,
|
||||
}
|
||||
|
||||
netOption := make(map[string]interface{})
|
||||
|
@ -358,9 +358,9 @@ func TestCreateFullOptionsLabels(t *testing.T) {
|
|||
t.Fatalf("Unexpected: %v", nw.config.DefaultBindingIP)
|
||||
}
|
||||
|
||||
hostIP := net.ParseIP(testHostIP)
|
||||
if !hostIP.Equal(nw.config.HostIP) {
|
||||
t.Fatalf("Unexpected: %v", nw.config.HostIP)
|
||||
hostIP := net.ParseIP(testHostIPv4)
|
||||
if !hostIP.Equal(nw.config.HostIPv4) {
|
||||
t.Fatalf("Unexpected: %v", nw.config.HostIPv4)
|
||||
}
|
||||
|
||||
if !types.CompareIPNet(nw.config.AddressIPv6, nwV6) {
|
||||
|
|
|
@ -146,7 +146,8 @@ func (ncfg *networkConfiguration) MarshalJSON() ([]byte, error) {
|
|||
nMap["Internal"] = ncfg.Internal
|
||||
nMap["DefaultBridge"] = ncfg.DefaultBridge
|
||||
nMap["DefaultBindingIP"] = ncfg.DefaultBindingIP.String()
|
||||
nMap["HostIP"] = ncfg.HostIP.String()
|
||||
// This key is "HostIP" instead of "HostIPv4" to preserve compatibility with the on-disk format.
|
||||
nMap["HostIP"] = ncfg.HostIPv4.String()
|
||||
nMap["DefaultGatewayIPv4"] = ncfg.DefaultGatewayIPv4.String()
|
||||
nMap["DefaultGatewayIPv6"] = ncfg.DefaultGatewayIPv6.String()
|
||||
nMap["ContainerIfacePrefix"] = ncfg.ContainerIfacePrefix
|
||||
|
@ -189,8 +190,9 @@ func (ncfg *networkConfiguration) UnmarshalJSON(b []byte) error {
|
|||
ncfg.ContainerIfacePrefix = v.(string)
|
||||
}
|
||||
|
||||
// This key is "HostIP" instead of "HostIPv4" to preserve compatibility with the on-disk format.
|
||||
if v, ok := nMap["HostIP"]; ok {
|
||||
ncfg.HostIP = net.ParseIP(v.(string))
|
||||
ncfg.HostIPv4 = net.ParseIP(v.(string))
|
||||
}
|
||||
|
||||
ncfg.DefaultBridge = nMap["DefaultBridge"].(bool)
|
||||
|
|
|
@ -249,9 +249,9 @@ func setupIPTablesInternal(ipVer iptables.IPVersion, config *networkConfiguratio
|
|||
natArgs []string
|
||||
hpNatArgs []string
|
||||
)
|
||||
// If config.HostIP is set, the user wants IPv4 SNAT with the given address.
|
||||
if config.HostIP != nil && ipVer == iptables.IPv4 {
|
||||
hostAddr := config.HostIP.String()
|
||||
// If config.HostIPv4 is set, the user wants IPv4 SNAT with the given address.
|
||||
if config.HostIPv4 != nil && ipVer == iptables.IPv4 {
|
||||
hostAddr := config.HostIPv4.String()
|
||||
natArgs = []string{"-s", address, "!", "-o", config.BridgeName, "-j", "SNAT", "--to-source", hostAddr}
|
||||
hpNatArgs = []string{"-m", "addrtype", "--src-type", "LOCAL", "-o", config.BridgeName, "-j", "SNAT", "--to-source", hostAddr}
|
||||
// Else use MASQUERADE which picks the src-ip based on NH from the route table
|
||||
|
|
|
@ -158,7 +158,7 @@ func assertBridgeConfig(config *networkConfiguration, br *bridgeInterface, d *dr
|
|||
}
|
||||
|
||||
// Regression test for https://github.com/moby/moby/issues/46445
|
||||
func TestSetupIP6TablesWithHostIP(t *testing.T) {
|
||||
func TestSetupIP6TablesWithHostIPv4(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
d := newDriver()
|
||||
dc := &configuration{
|
||||
|
@ -174,7 +174,7 @@ func TestSetupIP6TablesWithHostIP(t *testing.T) {
|
|||
EnableIPMasquerade: true,
|
||||
EnableIPv6: true,
|
||||
AddressIPv6: &net.IPNet{IP: net.ParseIP("2001:db8::1"), Mask: net.CIDRMask(64, 128)},
|
||||
HostIP: net.ParseIP("192.0.2.2"),
|
||||
HostIPv4: net.ParseIP("192.0.2.2"),
|
||||
}
|
||||
nh, err := netlink.NewHandle()
|
||||
if err != nil {
|
||||
|
|
|
@ -44,8 +44,8 @@ const (
|
|||
// ContainerIfacePrefix can be used to override the interface prefix used inside the container
|
||||
ContainerIfacePrefix = Prefix + ".container_iface_prefix"
|
||||
|
||||
// HostIP is the Source-IP Address used to SNAT container traffic
|
||||
HostIP = Prefix + ".host_ipv4"
|
||||
// HostIPv4 is the Source-IPv4 Address used to SNAT IPv4 container traffic
|
||||
HostIPv4 = Prefix + ".host_ipv4"
|
||||
|
||||
// LocalKVClient constants represents the local kv store client
|
||||
LocalKVClient = DriverPrivatePrefix + "localkv_client"
|
||||
|
|
Loading…
Add table
Reference in a new issue