mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-08-10 13:20:33 +02:00
filter non usabel IPs from state changes
This commit is contained in:
+30
-5
@@ -1419,14 +1419,39 @@ func interfaceIPsEqual(a, b []netip.Prefix) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create maps for easier comparison
|
isUsableIP := func(ip netip.Prefix) bool {
|
||||||
aMap := make(map[netip.Prefix]bool)
|
addr := ip.Addr()
|
||||||
for _, ip := range a {
|
return !addr.IsLinkLocalUnicast() && // fe80::/10
|
||||||
aMap[ip] = true
|
!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 {
|
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
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user