diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2015-06-02 13:15:50 +0900 |
---|---|---|
committer | Lorenzo Colitti <lorenzo@google.com> | 2015-06-02 16:21:17 +0900 |
commit | d973537ee1bd013b4233d3369d66821e124a2e65 (patch) | |
tree | 57f67609e47e2964b1726b700042425bffe5134c /services/net/java/android/net/dhcp/DhcpPacket.java | |
parent | 99fbb56a0ab81ead404480f0c2df529332a93a32 (diff) | |
download | frameworks_base-d973537ee1bd013b4233d3369d66821e124a2e65.zip frameworks_base-d973537ee1bd013b4233d3369d66821e124a2e65.tar.gz frameworks_base-d973537ee1bd013b4233d3369d66821e124a2e65.tar.bz2 |
Fix DHCP lease time parsing.
Currently we treat a lease time larger than 2**31-1 as a negative
value, which causes DhcpClient to attempt to renew its IP address
constantly. Fix this by properly handling large and infinite
lifetimes, and while we're at it, impose a minimum lease time of
60 seconds.
Bug: 21352084
Change-Id: If62c9efeffad6222e2fe0c110f77d0e4c70de96d
Diffstat (limited to 'services/net/java/android/net/dhcp/DhcpPacket.java')
-rw-r--r-- | services/net/java/android/net/dhcp/DhcpPacket.java | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/services/net/java/android/net/dhcp/DhcpPacket.java b/services/net/java/android/net/dhcp/DhcpPacket.java index b923b1b..2a25d30 100644 --- a/services/net/java/android/net/dhcp/DhcpPacket.java +++ b/services/net/java/android/net/dhcp/DhcpPacket.java @@ -28,6 +28,12 @@ import java.util.List; abstract class DhcpPacket { protected static final String TAG = "DhcpPacket"; + // dhcpcd has a minimum lease of 20 seconds, but DhcpStateMachine would refuse to wake up the + // CPU for anything shorter than 5 minutes. For sanity's sake, this must be higher than the + // DHCP client timeout. + public static final int MINIMUM_LEASE = 60; + public static final int INFINITE_LEASE = (int) 0xffffffff; + public static final Inet4Address INADDR_ANY = (Inet4Address) Inet4Address.ANY; public static final Inet4Address INADDR_BROADCAST = (Inet4Address) Inet4Address.ALL; public static final byte[] ETHER_BROADCAST = new byte[] { @@ -1006,11 +1012,25 @@ abstract class DhcpPacket { results.domains = mDomainName; results.serverAddress = mServerIdentifier; results.vendorInfo = mVendorId; - results.leaseDuration = mLeaseTime; + results.leaseDuration = (mLeaseTime != null) ? mLeaseTime : INFINITE_LEASE; return results; } /** + * Returns the parsed lease time, in milliseconds, or 0 for infinite. + */ + public long getLeaseTimeMillis() { + // dhcpcd treats the lack of a lease time option as an infinite lease. + if (mLeaseTime == null || mLeaseTime == INFINITE_LEASE) { + return 0; + } else if (0 <= mLeaseTime && mLeaseTime < MINIMUM_LEASE) { + return MINIMUM_LEASE * 1000; + } else { + return (mLeaseTime & 0xffffffffL) * 1000; + } + } + + /** * Builds a DHCP-DISCOVER packet from the required specified * parameters. */ |