summaryrefslogtreecommitdiff
path: root/src/android/net/ip/IpClientLinkObserver.java
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2019-09-26 00:18:25 +0900
committerLorenzo Colitti <lorenzo@google.com>2019-11-06 14:42:52 +0900
commit7d5191f51514cd679c95b1586a6b9359002ccd03 (patch)
treea7c42be3e153487bdb92d8f9a653883a477f8252 /src/android/net/ip/IpClientLinkObserver.java
parentdfc4f7c2547eeb26be2e7b2f63318933eec1fb75 (diff)
Support dropping RDNSS options with a low lifetime.
Some routers have been known to use RDNSS lifetimes of 10 seconds(!). This causes APF filters to be set to very low lifetimes, which substantially impacts battery life. There are two parts to this: 1. Ignore low RDNSS option lifetimes for the purpose of calculating APF filter lifetimes. 2. Do not add DNS servers to the repository if their lifetimes are too low. If we do #1 without #2, the servers will expire because APF will drop the RAs that refresh them, potentially causing outages or disconnections. The behaviour is enabled by default starting from R and can be enabled on all builds using a flag. Bug: 66928272 Test: New unit test passes Change-Id: Ib2e2555026da3e81ea3d50767a30092413b4e4f5
Diffstat (limited to 'src/android/net/ip/IpClientLinkObserver.java')
-rw-r--r--src/android/net/ip/IpClientLinkObserver.java28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/android/net/ip/IpClientLinkObserver.java b/src/android/net/ip/IpClientLinkObserver.java
index 3f399e9..02bf5f0 100644
--- a/src/android/net/ip/IpClientLinkObserver.java
+++ b/src/android/net/ip/IpClientLinkObserver.java
@@ -71,20 +71,31 @@ public class IpClientLinkObserver implements NetworkObserver {
void update();
}
+ /** Configuration parameters for IpClientLinkObserver. */
+ public static class Configuration {
+ public final int minRdnssLifetime;
+
+ public Configuration(int minRdnssLifetime) {
+ this.minRdnssLifetime = minRdnssLifetime;
+ }
+ }
+
private final String mInterfaceName;
private final Callback mCallback;
private final LinkProperties mLinkProperties;
private DnsServerRepository mDnsServerRepository;
+ private final Configuration mConfig;
private static final boolean DBG = false;
- public IpClientLinkObserver(String iface, Callback callback) {
+ public IpClientLinkObserver(String iface, Callback callback, Configuration config) {
mTag = "NetlinkTracker/" + iface;
mInterfaceName = iface;
mCallback = callback;
mLinkProperties = new LinkProperties();
mLinkProperties.setInterfaceName(mInterfaceName);
- mDnsServerRepository = new DnsServerRepository();
+ mConfig = config;
+ mDnsServerRepository = new DnsServerRepository(config.minRdnssLifetime);
}
private void maybeLog(String operation, String iface, LinkAddress address) {
@@ -197,7 +208,7 @@ public class IpClientLinkObserver implements NetworkObserver {
// Clear the repository before clearing mLinkProperties. That way, if a clear() happens
// while interfaceDnsServerInfo() is being called, we'll end up with no DNS servers in
// mLinkProperties, as desired.
- mDnsServerRepository = new DnsServerRepository();
+ mDnsServerRepository = new DnsServerRepository(mConfig.minRdnssLifetime);
mLinkProperties.clear();
mLinkProperties.setInterfaceName(mInterfaceName);
}
@@ -260,10 +271,16 @@ public class IpClientLinkObserver implements NetworkObserver {
*/
private HashMap<InetAddress, DnsServerEntry> mIndex;
- DnsServerRepository() {
+ /**
+ * Minimum (non-zero) RDNSS lifetime to accept.
+ */
+ private final int mMinLifetime;
+
+ DnsServerRepository(int minLifetime) {
mCurrentServers = new HashSet<>();
mAllServers = new ArrayList<>(NUM_SERVERS);
mIndex = new HashMap<>(NUM_SERVERS);
+ mMinLifetime = minLifetime;
}
/** Sets the DNS servers of the provided LinkProperties object to the current servers. */
@@ -277,6 +294,9 @@ public class IpClientLinkObserver implements NetworkObserver {
* @param addresses the string representations of the IP addresses of DNS servers to use.
*/
public synchronized boolean addServers(long lifetime, String[] addresses) {
+ // If the servers are below the minimum lifetime, don't change anything.
+ if (lifetime != 0 && lifetime < mMinLifetime) return false;
+
// The lifetime is actually an unsigned 32-bit number, but Java doesn't have unsigned.
// Technically 0xffffffff (the maximum) is special and means "forever", but 2^32 seconds
// (136 years) is close enough.