Skip to content

Commit f6dcc1c

Browse files
committed
Minor tweak to IPv6 service IP allocation
The service allocator skips the "broadcast address" in the service CIDR, but that concept only applies to IPv4 addressing.
1 parent 4a7c86c commit f6dcc1c

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

pkg/registry/core/service/ipallocator/allocator.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,19 @@ func NewAllocatorCIDRRange(cidr *net.IPNet, allocatorFactory allocator.Allocator
9191
if max > 65536 {
9292
max = 65536
9393
}
94+
} else {
95+
// Don't use the IPv4 network's broadcast address.
96+
max--
9497
}
9598

99+
// Don't use the network's ".0" address.
100+
base.Add(base, big.NewInt(1))
101+
max--
102+
96103
r := Range{
97104
net: cidr,
98-
base: base.Add(base, big.NewInt(1)), // don't use the network base
99-
max: maximum(0, int(max-2)), // don't use the network broadcast,
105+
base: base,
106+
max: maximum(0, int(max)),
100107
}
101108
var err error
102109
r.alloc, err = allocatorFactory(r.max, rangeSpec)

pkg/registry/core/service/ipallocator/allocator_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,13 @@ func TestAllocate(t *testing.T) {
4949
{
5050
name: "IPv6",
5151
cidr: "2001:db8:1::/48",
52-
free: 65534,
52+
free: 65535,
5353
released: "2001:db8:1::5",
5454
outOfRange: []string{
55-
"2001:db8::1", // not in 2001:db8:1::/48
56-
"2001:db8:1::", // reserved (base address)
57-
"2001:db8:1::ffff", // reserved (broadcast address)
58-
"2001:db8:1::1:0", // not in the low 16 bits of 2001:db8:1::/48
59-
"2001:db8:2::2", // not in 2001:db8:1::/48
55+
"2001:db8::1", // not in 2001:db8:1::/48
56+
"2001:db8:1::", // reserved (base address)
57+
"2001:db8:1::1:0", // not in the low 16 bits of 2001:db8:1::/48
58+
"2001:db8:2::2", // not in 2001:db8:1::/48
6059
},
6160
alreadyAllocated: "2001:db8:1::1",
6261
},

pkg/registry/core/service/ipallocator/controller/repair_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ func TestRepairWithExistingDualStack(t *testing.T) {
529529
if !secondaryAfter.Has(net.ParseIP("2000::1")) || !secondaryAfter.Has(net.ParseIP("2000::2")) {
530530
t.Errorf("unexpected ipallocator state: %#v", secondaryAfter)
531531
}
532-
if free := secondaryAfter.Free(); free != 65532 {
532+
if free := secondaryAfter.Free(); free != 65533 {
533533
t.Errorf("unexpected ipallocator state: %d free (number of free ips is not 65532)", free)
534534
}
535535

0 commit comments

Comments
 (0)