android, ios: ignore link-local addresses in network changes

This commit is contained in:
Narasimha-sc committed 2026-10-20 12:30:31 +00:00
1 parent bf422c879f
commit 97c18b18fd
2 files changed
+9 -5

No files matched your search

+4 -2
View File
@@ -69,7 +69,8 @@ class NetworkObserver {
}
// NWPath has no addresses, and a changed address with the same interface and gateway
// (e.g. the lease was renewed after internet loss) also means the connections via it are dead
// (e.g. a new lease after internet loss) also means the connections via it are dead;
// link-local addresses are not used for the connections to the servers
private func localAddresses(_ interface: String?) -> Set<String> {
var ifap: UnsafeMutablePointer<ifaddrs>?
guard let interface = interface, getifaddrs(&ifap) == 0, let first = ifap else { return [] }
@@ -80,7 +81,8 @@ class NetworkObserver {
String(cString: ifa.pointee.ifa_name) == interface else { return nil }
var host = [CChar](repeating: 0, count: Int(NI_MAXHOST))
guard getnameinfo(sa, socklen_t(sa.pointee.sa_len), &host, socklen_t(host.count), nil, 0, NI_NUMERICHOST) == 0 else { return nil }
return String(cString: host)
let address = String(cString: host)
return address.hasPrefix("fe80:") || address.hasPrefix("169.254.") ? nil : address
})
}
@@ -134,7 +134,7 @@ class NetworkObserver {
sendMutex.withLock {
val removals = addressRemovals
// the core has the same network info for the network its connections were made via, e.g. the network
// was reported offline less than 3 seconds ago and it was not sent - the connections are not affected
// was reported offline less than 3 seconds ago and it was not sent - the connections are assumed not affected
if ((removals != sentAddressRemovals || sentInfo != info || network != sentNetwork) &&
sendNetworkInfo(info, network, removals, ctrlGen)) sent.set(true)
}
@@ -188,8 +188,10 @@ class NetworkObserver {
private fun lost(prev: Set<InetAddress>?, addresses: Set<InetAddress>?): Boolean =
prev != null && (addresses == null || !addresses.containsAll(prev) || (prev.isEmpty() && addresses.isNotEmpty()))
// LinkAddress equality includes address lifetimes that change with every router advertisement
private fun addresses(linkProperties: LinkProperties): Set<InetAddress> = linkProperties.linkAddresses.map { it.address }.toSet()
// LinkAddress equality includes address lifetimes that change with every router advertisement;
// link-local addresses are not used for the connections to the servers
private fun addresses(linkProperties: LinkProperties): Set<InetAddress> =
linkProperties.linkAddresses.map { it.address }.filterNot { it.isLinkLocalAddress }.toSet()
private fun networkInfo(capabilities: NetworkCapabilities) = UserNetworkInfo(
networkType = networkTypeFromCapabilities(capabilities),