mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
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.
This commit is contained in:
parent
4a7c86c105
commit
f6dcc1c07e
@ -91,12 +91,19 @@ func NewAllocatorCIDRRange(cidr *net.IPNet, allocatorFactory allocator.Allocator
|
||||
if max > 65536 {
|
||||
max = 65536
|
||||
}
|
||||
} else {
|
||||
// Don't use the IPv4 network's broadcast address.
|
||||
max--
|
||||
}
|
||||
|
||||
// Don't use the network's ".0" address.
|
||||
base.Add(base, big.NewInt(1))
|
||||
max--
|
||||
|
||||
r := Range{
|
||||
net: cidr,
|
||||
base: base.Add(base, big.NewInt(1)), // don't use the network base
|
||||
max: maximum(0, int(max-2)), // don't use the network broadcast,
|
||||
base: base,
|
||||
max: maximum(0, int(max)),
|
||||
}
|
||||
var err error
|
||||
r.alloc, err = allocatorFactory(r.max, rangeSpec)
|
||||
|
@ -49,14 +49,13 @@ func TestAllocate(t *testing.T) {
|
||||
{
|
||||
name: "IPv6",
|
||||
cidr: "2001:db8:1::/48",
|
||||
free: 65534,
|
||||
free: 65535,
|
||||
released: "2001:db8:1::5",
|
||||
outOfRange: []string{
|
||||
"2001:db8::1", // not in 2001:db8:1::/48
|
||||
"2001:db8:1::", // reserved (base address)
|
||||
"2001:db8:1::ffff", // reserved (broadcast address)
|
||||
"2001:db8:1::1:0", // not in the low 16 bits of 2001:db8:1::/48
|
||||
"2001:db8:2::2", // not in 2001:db8:1::/48
|
||||
"2001:db8::1", // not in 2001:db8:1::/48
|
||||
"2001:db8:1::", // reserved (base address)
|
||||
"2001:db8:1::1:0", // not in the low 16 bits of 2001:db8:1::/48
|
||||
"2001:db8:2::2", // not in 2001:db8:1::/48
|
||||
},
|
||||
alreadyAllocated: "2001:db8:1::1",
|
||||
},
|
||||
|
@ -529,7 +529,7 @@ func TestRepairWithExistingDualStack(t *testing.T) {
|
||||
if !secondaryAfter.Has(net.ParseIP("2000::1")) || !secondaryAfter.Has(net.ParseIP("2000::2")) {
|
||||
t.Errorf("unexpected ipallocator state: %#v", secondaryAfter)
|
||||
}
|
||||
if free := secondaryAfter.Free(); free != 65532 {
|
||||
if free := secondaryAfter.Free(); free != 65533 {
|
||||
t.Errorf("unexpected ipallocator state: %d free (number of free ips is not 65532)", free)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user