mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
Cleanups of ipv6 changes.
I was late re-reviewing and some comments did not get resolved.
This commit is contained in:
parent
931cd3a2df
commit
9c218f0a19
@ -46,11 +46,12 @@ func (s *ipAddrSet) Init() {
|
|||||||
s.ips = map[string]bool{}
|
s.ips = map[string]bool{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds to the ipAddrSet; returns true iff it was added (was not already in set)
|
// Gets the number of IPs in the set
|
||||||
func (s *ipAddrSet) Size() int {
|
func (s *ipAddrSet) Size() int {
|
||||||
return len(s.ips)
|
return len(s.ips)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tests whether the set holds a given IP
|
||||||
func (s *ipAddrSet) Contains(ip net.IP) bool {
|
func (s *ipAddrSet) Contains(ip net.IP) bool {
|
||||||
key := ip.String()
|
key := ip.String()
|
||||||
exists := s.ips[key]
|
exists := s.ips[key]
|
||||||
@ -112,13 +113,11 @@ func newIPAllocator(subnet *net.IPNet) *ipAllocator {
|
|||||||
}
|
}
|
||||||
ipa.used.Init()
|
ipa.used.Init()
|
||||||
|
|
||||||
zero := make(net.IP, len(subnet.IP), len(subnet.IP))
|
network := make(net.IP, len(subnet.IP), len(subnet.IP))
|
||||||
for i := 0; i < len(subnet.IP); i++ {
|
for i := 0; i < len(subnet.IP); i++ {
|
||||||
zero[i] = subnet.IP[i] & subnet.Mask[i]
|
network[i] = subnet.IP[i] & subnet.Mask[i]
|
||||||
}
|
}
|
||||||
ipa.used.Add(zero) // block the zero addr
|
ipa.used.Add(network) // block the network addr
|
||||||
|
|
||||||
ipa.used.Add(subnet.IP) // block the network addr
|
|
||||||
|
|
||||||
broadcast := make(net.IP, len(subnet.IP), len(subnet.IP))
|
broadcast := make(net.IP, len(subnet.IP), len(subnet.IP))
|
||||||
for i := 0; i < len(subnet.IP); i++ {
|
for i := 0; i < len(subnet.IP); i++ {
|
||||||
|
@ -54,6 +54,14 @@ func TestAllocate(t *testing.T) {
|
|||||||
_, ipnet, _ := net.ParseCIDR("93.76.0.0/22")
|
_, ipnet, _ := net.ParseCIDR("93.76.0.0/22")
|
||||||
ipa := newIPAllocator(ipnet)
|
ipa := newIPAllocator(ipnet)
|
||||||
|
|
||||||
|
if err := ipa.Allocate(net.ParseIP("93.76.0.0")); err == nil {
|
||||||
|
t.Errorf("expected failure")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ipa.Allocate(net.ParseIP("93.76.3.255")); err == nil {
|
||||||
|
t.Errorf("expected failure")
|
||||||
|
}
|
||||||
|
|
||||||
if err := ipa.Allocate(net.ParseIP("93.76.0.1")); err != nil {
|
if err := ipa.Allocate(net.ParseIP("93.76.0.1")); err != nil {
|
||||||
t.Errorf("expected success, got %s", err)
|
t.Errorf("expected success, got %s", err)
|
||||||
}
|
}
|
||||||
|
@ -38,11 +38,11 @@ type Interface interface {
|
|||||||
IsIpv6() bool
|
IsIpv6() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Protocol bool
|
type Protocol byte
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ProtocolIpv4 Protocol = false
|
ProtocolIpv4 Protocol = iota + 1
|
||||||
ProtocolIpv6 Protocol = true
|
ProtocolIpv6
|
||||||
)
|
)
|
||||||
|
|
||||||
type Table string
|
type Table string
|
||||||
|
Loading…
Reference in New Issue
Block a user