mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
filter non usabel IPs from state changes
This commit is contained in:
@@ -1419,14 +1419,39 @@ func interfaceIPsEqual(a, b []netip.Prefix) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Create maps for easier comparison
|
||||
aMap := make(map[netip.Prefix]bool)
|
||||
for _, ip := range a {
|
||||
aMap[ip] = true
|
||||
isUsableIP := func(ip netip.Prefix) bool {
|
||||
addr := ip.Addr()
|
||||
return !addr.IsLinkLocalUnicast() && // fe80::/10
|
||||
!addr.IsLoopback() && // 127.0.0.1/8, ::1
|
||||
!addr.IsMulticast() && // 224.0.0.0/4, ff00::/8
|
||||
!addr.IsUnspecified() && // 0.0.0.0, ::
|
||||
!addr.IsLinkLocalMulticast() && // 224.0.0.0/24
|
||||
!(addr.Is4() && addr.String() == "255.255.255.255") && // broadcast
|
||||
!tsaddr.CGNATRange().Contains(addr) // 100.64.0.0/10 CGNAT
|
||||
}
|
||||
|
||||
// Filter and create maps for comparison
|
||||
aMap := make(map[netip.Prefix]bool)
|
||||
for _, ip := range a {
|
||||
if isUsableIP(ip) {
|
||||
aMap[ip] = true
|
||||
}
|
||||
}
|
||||
|
||||
bMap := make(map[netip.Prefix]bool)
|
||||
for _, ip := range b {
|
||||
if !aMap[ip] {
|
||||
if isUsableIP(ip) {
|
||||
bMap[ip] = true
|
||||
}
|
||||
}
|
||||
|
||||
// Compare the filtered IP sets
|
||||
if len(aMap) != len(bMap) {
|
||||
return false
|
||||
}
|
||||
|
||||
for ip := range aMap {
|
||||
if !bMap[ip] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user