Skip to content

Commit c59e93a

Browse files
committed
Revert "daemon: automatically set network EnableIPv6 if needed"
This reverts commit 5d5eeac. Signed-off-by: Albin Kerouanton <[email protected]>
1 parent ca683c1 commit c59e93a

3 files changed

Lines changed: 13 additions & 28 deletions

File tree

api/types/network/ipam.go

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,9 @@ const (
3030
ip6 ipFamily = "IPv6"
3131
)
3232

33-
// HasIPv6Subnets checks whether there's any IPv6 subnets in the ipam parameter. It ignores any invalid Subnet and nil
34-
// ipam.
35-
func HasIPv6Subnets(ipam *IPAM) bool {
36-
if ipam == nil {
37-
return false
38-
}
39-
40-
for _, cfg := range ipam.Config {
41-
subnet, err := netip.ParsePrefix(cfg.Subnet)
42-
if err != nil {
43-
continue
44-
}
45-
46-
if subnet.Addr().Is6() {
47-
return true
48-
}
49-
}
50-
51-
return false
52-
}
53-
5433
// ValidateIPAM checks whether the network's IPAM passed as argument is valid. It returns a joinError of the list of
5534
// errors found.
56-
func ValidateIPAM(ipam *IPAM) error {
35+
func ValidateIPAM(ipam *IPAM, enableIPv6 bool) error {
5736
if ipam == nil {
5837
return nil
5938
}
@@ -74,6 +53,10 @@ func ValidateIPAM(ipam *IPAM) error {
7453
errs = append(errs, fmt.Errorf("invalid subnet %s: it should be %s", subnet, subnet.Masked()))
7554
}
7655

56+
if !enableIPv6 && subnetFamily == ip6 {
57+
errs = append(errs, fmt.Errorf("invalid subnet %s: IPv6 has not been enabled for this network", subnet))
58+
}
59+
7760
if ipRangeErrs := validateIPRange(cfg.IPRange, subnet, subnetFamily); len(ipRangeErrs) > 0 {
7861
errs = append(errs, ipRangeErrs...)
7962
}

api/types/network/ipam_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ func TestNetworkWithInvalidIPAM(t *testing.T) {
3030
"invalid auxiliary address DefaultGatewayIPv4: parent subnet is an IPv4 block",
3131
},
3232
},
33+
{
34+
name: "IPv6 subnet is discarded when IPv6 is disabled",
35+
ipam: IPAM{Config: []IPAMConfig{{Subnet: "2001:db8::/32"}}},
36+
ipv6: false,
37+
expectedErrors: []string{"invalid subnet 2001:db8::/32: IPv6 has not been enabled for this network"},
38+
},
3339
{
3440
name: "Invalid data - Subnet",
3541
ipam: IPAM{Config: []IPAMConfig{{Subnet: "foobar"}}},
@@ -122,7 +128,7 @@ func TestNetworkWithInvalidIPAM(t *testing.T) {
122128
t.Run(tc.name, func(t *testing.T) {
123129
t.Parallel()
124130

125-
errs := ValidateIPAM(&tc.ipam)
131+
errs := ValidateIPAM(&tc.ipam, tc.ipv6)
126132
if tc.expectedErrors == nil {
127133
assert.NilError(t, errs)
128134
return

daemon/network.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,6 @@ func (daemon *Daemon) createNetwork(cfg *config.Config, create types.NetworkCrea
305305
return nil, errdefs.Forbidden(errors.New(`This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.`))
306306
}
307307

308-
if network.HasIPv6Subnets(create.IPAM) {
309-
create.EnableIPv6 = true
310-
}
311-
312308
networkOptions := make(map[string]string)
313309
for k, v := range create.Options {
314310
networkOptions[k] = v
@@ -335,7 +331,7 @@ func (daemon *Daemon) createNetwork(cfg *config.Config, create types.NetworkCrea
335331
nwOptions = append(nwOptions, libnetwork.NetworkOptionConfigOnly())
336332
}
337333

338-
if err := network.ValidateIPAM(create.IPAM); err != nil {
334+
if err := network.ValidateIPAM(create.IPAM, create.EnableIPv6); err != nil {
339335
return nil, errdefs.InvalidParameter(err)
340336
}
341337

0 commit comments

Comments
 (0)