Skip to content

Commit

Permalink
restored the exact behaviour for IPv4
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Finneran <daniel.finneran@gmail.com>
  • Loading branch information
thebsdbox committed Sep 5, 2024
1 parent f438367 commit 5512a08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/manager/service_egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (sm *Manager) iptablesCheck() error {
return nil
}

func getSameFamilyCidr(sourceCidrs, ip string) string {
func getSameFamilyCidr(sourceCidrs, ip string) string { //Todo: not sure how this ever worked
cidrs := strings.Split(sourceCidrs, ",")
for _, cidr := range cidrs {
// Is the ip an IPv6 address
Expand All @@ -56,7 +56,9 @@ func getSameFamilyCidr(sourceCidrs, ip string) string {
}
} else {
if vip.IsIPv4CIDR(cidr) {
return cidr
if vip.IsIPv4(cidr) == vip.IsIPv4(ip) {
return cidr
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/vip/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,18 @@ func IsIPv6(address string) bool {

func IsIPv4CIDR(cidr string) bool {
_, n, _ := net.ParseCIDR(cidr)
if n == nil {
return false
}
_, bits := n.Mask.Size()
return bits/8 == net.IPv4len
}

func IsIPv6CIDR(cidr string) bool {
_, n, _ := net.ParseCIDR(cidr)
if n == nil {
return false
}
_, bits := n.Mask.Size()
return bits/8 == net.IPv6len
}
Expand Down

0 comments on commit 5512a08

Please sign in to comment.