diff options
author | Etan Cohen <etancohen@google.com> | 2015-04-24 14:03:28 -0700 |
---|---|---|
committer | Etan Cohen <etancohen@google.com> | 2015-04-24 14:03:28 -0700 |
commit | 644f41368f9eddd475fa9c5dddc7ceac5722a3a8 (patch) | |
tree | 7debb618bbe004bd6e710e758a7302715e96a3f2 /services/net | |
parent | a6e5ff899a7cc300985c09e57a2e3b4f5aa170d3 (diff) | |
parent | 4cb5d80abeb88918534e90c2a7b58cdcba22ac77 (diff) | |
download | frameworks_base-644f41368f9eddd475fa9c5dddc7ceac5722a3a8.zip frameworks_base-644f41368f9eddd475fa9c5dddc7ceac5722a3a8.tar.gz frameworks_base-644f41368f9eddd475fa9c5dddc7ceac5722a3a8.tar.bz2 |
Merge commit '4cb5d80' into merge2
Diffstat (limited to 'services/net')
9 files changed, 50 insertions, 36 deletions
diff --git a/services/net/java/android/net/dhcp/DhcpAckPacket.java b/services/net/java/android/net/dhcp/DhcpAckPacket.java index 25b8093..c0e1d19 100644 --- a/services/net/java/android/net/dhcp/DhcpAckPacket.java +++ b/services/net/java/android/net/dhcp/DhcpAckPacket.java @@ -29,9 +29,9 @@ class DhcpAckPacket extends DhcpPacket { */ private final Inet4Address mSrcIp; - DhcpAckPacket(int transId, boolean broadcast, Inet4Address serverAddress, + DhcpAckPacket(int transId, short secs, boolean broadcast, Inet4Address serverAddress, Inet4Address clientIp, byte[] clientMac) { - super(transId, INADDR_ANY, clientIp, serverAddress, INADDR_ANY, clientMac, broadcast); + super(transId, secs, INADDR_ANY, clientIp, serverAddress, INADDR_ANY, clientMac, broadcast); mBroadcast = broadcast; mSrcIp = serverAddress; } diff --git a/services/net/java/android/net/dhcp/DhcpClient.java b/services/net/java/android/net/dhcp/DhcpClient.java index ab56493..e1d1787 100644 --- a/services/net/java/android/net/dhcp/DhcpClient.java +++ b/services/net/java/android/net/dhcp/DhcpClient.java @@ -154,6 +154,7 @@ public class DhcpClient extends BaseDhcpStateMachine { private byte[] mHwAddr; private PacketSocketAddress mInterfaceBroadcastAddr; private int mTransactionId; + private long mTransactionStartMillis; private DhcpResults mDhcpLease; private long mDhcpLeaseExpiry; private DhcpResults mOffer; @@ -264,8 +265,9 @@ public class DhcpClient extends BaseDhcpStateMachine { } } - private void initTransactionId() { + private void startNewTransaction() { mTransactionId = mRandom.nextInt(); + mTransactionStartMillis = SystemClock.elapsedRealtime(); } private boolean initSockets() { @@ -344,6 +346,10 @@ public class DhcpClient extends BaseDhcpStateMachine { } } + private short getSecs() { + return (short) ((SystemClock.elapsedRealtime() - mTransactionStartMillis) / 1000); + } + private boolean transmitPacket(ByteBuffer buf, String description, Inet4Address to) { try { if (to.equals(INADDR_BROADCAST)) { @@ -362,7 +368,8 @@ public class DhcpClient extends BaseDhcpStateMachine { private boolean sendDiscoverPacket() { ByteBuffer packet = DhcpPacket.buildDiscoverPacket( - DhcpPacket.ENCAP_L2, mTransactionId, mHwAddr, DO_UNICAST, REQUESTED_PARAMS); + DhcpPacket.ENCAP_L2, mTransactionId, getSecs(), mHwAddr, + DO_UNICAST, REQUESTED_PARAMS); return transmitPacket(packet, "DHCPDISCOVER", INADDR_BROADCAST); } @@ -373,7 +380,7 @@ public class DhcpClient extends BaseDhcpStateMachine { int encap = to.equals(INADDR_BROADCAST) ? DhcpPacket.ENCAP_L2 : DhcpPacket.ENCAP_BOOTP; ByteBuffer packet = DhcpPacket.buildRequestPacket( - encap, mTransactionId, clientAddress, + encap, mTransactionId, getSecs(), clientAddress, DO_UNICAST, mHwAddr, requestedAddress, serverAddress, REQUESTED_PARAMS, null); String description = "DHCPREQUEST ciaddr=" + clientAddress.getHostAddress() + @@ -669,7 +676,7 @@ public class DhcpClient extends BaseDhcpStateMachine { @Override public void enter() { super.enter(); - initTransactionId(); + startNewTransaction(); } protected boolean sendPacket() { @@ -776,7 +783,7 @@ public class DhcpClient extends BaseDhcpStateMachine { @Override public void enter() { super.enter(); - initTransactionId(); + startNewTransaction(); } protected boolean sendPacket() { diff --git a/services/net/java/android/net/dhcp/DhcpDeclinePacket.java b/services/net/java/android/net/dhcp/DhcpDeclinePacket.java index 4a22b65..7ecdea7 100644 --- a/services/net/java/android/net/dhcp/DhcpDeclinePacket.java +++ b/services/net/java/android/net/dhcp/DhcpDeclinePacket.java @@ -26,10 +26,10 @@ class DhcpDeclinePacket extends DhcpPacket { /** * Generates a DECLINE packet with the specified parameters. */ - DhcpDeclinePacket(int transId, Inet4Address clientIp, Inet4Address yourIp, + DhcpDeclinePacket(int transId, short secs, Inet4Address clientIp, Inet4Address yourIp, Inet4Address nextIp, Inet4Address relayIp, byte[] clientMac) { - super(transId, clientIp, yourIp, nextIp, relayIp, clientMac, false); + super(transId, secs, clientIp, yourIp, nextIp, relayIp, clientMac, false); } public String toString() { diff --git a/services/net/java/android/net/dhcp/DhcpDiscoverPacket.java b/services/net/java/android/net/dhcp/DhcpDiscoverPacket.java index ed0fdc6..91e6bd6 100644 --- a/services/net/java/android/net/dhcp/DhcpDiscoverPacket.java +++ b/services/net/java/android/net/dhcp/DhcpDiscoverPacket.java @@ -26,8 +26,8 @@ class DhcpDiscoverPacket extends DhcpPacket { /** * Generates a DISCOVER packet with the specified parameters. */ - DhcpDiscoverPacket(int transId, byte[] clientMac, boolean broadcast) { - super(transId, INADDR_ANY, INADDR_ANY, INADDR_ANY, INADDR_ANY, clientMac, broadcast); + DhcpDiscoverPacket(int transId, short secs, byte[] clientMac, boolean broadcast) { + super(transId, secs, INADDR_ANY, INADDR_ANY, INADDR_ANY, INADDR_ANY, clientMac, broadcast); } public String toString() { diff --git a/services/net/java/android/net/dhcp/DhcpInformPacket.java b/services/net/java/android/net/dhcp/DhcpInformPacket.java index 2434fc9..7a83466 100644 --- a/services/net/java/android/net/dhcp/DhcpInformPacket.java +++ b/services/net/java/android/net/dhcp/DhcpInformPacket.java @@ -26,10 +26,10 @@ class DhcpInformPacket extends DhcpPacket { /** * Generates an INFORM packet with the specified parameters. */ - DhcpInformPacket(int transId, Inet4Address clientIp, Inet4Address yourIp, + DhcpInformPacket(int transId, short secs, Inet4Address clientIp, Inet4Address yourIp, Inet4Address nextIp, Inet4Address relayIp, byte[] clientMac) { - super(transId, clientIp, yourIp, nextIp, relayIp, clientMac, false); + super(transId, secs, clientIp, yourIp, nextIp, relayIp, clientMac, false); } public String toString() { diff --git a/services/net/java/android/net/dhcp/DhcpNakPacket.java b/services/net/java/android/net/dhcp/DhcpNakPacket.java index 1390ea7..6458232 100644 --- a/services/net/java/android/net/dhcp/DhcpNakPacket.java +++ b/services/net/java/android/net/dhcp/DhcpNakPacket.java @@ -26,10 +26,10 @@ class DhcpNakPacket extends DhcpPacket { /** * Generates a NAK packet with the specified parameters. */ - DhcpNakPacket(int transId, Inet4Address clientIp, Inet4Address yourIp, + DhcpNakPacket(int transId, short secs, Inet4Address clientIp, Inet4Address yourIp, Inet4Address nextIp, Inet4Address relayIp, byte[] clientMac) { - super(transId, INADDR_ANY, INADDR_ANY, nextIp, relayIp, + super(transId, secs, INADDR_ANY, INADDR_ANY, nextIp, relayIp, clientMac, false); } diff --git a/services/net/java/android/net/dhcp/DhcpOfferPacket.java b/services/net/java/android/net/dhcp/DhcpOfferPacket.java index b1f3bbd..af41708 100644 --- a/services/net/java/android/net/dhcp/DhcpOfferPacket.java +++ b/services/net/java/android/net/dhcp/DhcpOfferPacket.java @@ -31,9 +31,9 @@ class DhcpOfferPacket extends DhcpPacket { /** * Generates a OFFER packet with the specified parameters. */ - DhcpOfferPacket(int transId, boolean broadcast, Inet4Address serverAddress, + DhcpOfferPacket(int transId, short secs, boolean broadcast, Inet4Address serverAddress, Inet4Address clientIp, byte[] clientMac) { - super(transId, INADDR_ANY, clientIp, INADDR_ANY, INADDR_ANY, clientMac, broadcast); + super(transId, secs, INADDR_ANY, clientIp, INADDR_ANY, INADDR_ANY, clientMac, broadcast); mSrcIp = serverAddress; } diff --git a/services/net/java/android/net/dhcp/DhcpPacket.java b/services/net/java/android/net/dhcp/DhcpPacket.java index a64ee6f..b923b1b 100644 --- a/services/net/java/android/net/dhcp/DhcpPacket.java +++ b/services/net/java/android/net/dhcp/DhcpPacket.java @@ -226,6 +226,11 @@ abstract class DhcpPacket { protected final int mTransId; /** + * The seconds field in the BOOTP header. Per RFC, should be nonzero in client requests only. + */ + protected final short mSecs; + + /** * The IP address of the client host. This address is typically * proposed by the client (from an earlier DHCP negotiation) or * supplied by the server. @@ -258,10 +263,11 @@ abstract class DhcpPacket { */ abstract void finishPacket(ByteBuffer buffer); - protected DhcpPacket(int transId, Inet4Address clientIp, Inet4Address yourIp, + protected DhcpPacket(int transId, short secs, Inet4Address clientIp, Inet4Address yourIp, Inet4Address nextIp, Inet4Address relayIp, byte[] clientMac, boolean broadcast) { mTransId = transId; + mSecs = secs; mClientIp = clientIp; mYourIp = yourIp; mNextIp = nextIp; @@ -357,7 +363,7 @@ abstract class DhcpPacket { buf.put((byte) mClientMac.length); // Hardware Address Length buf.put((byte) 0); // Hop Count buf.putInt(mTransId); // Transaction ID - buf.putShort((short) 0); // Elapsed Seconds + buf.putShort(mSecs); // Elapsed Seconds if (broadcast) { buf.putShort((short) 0x8000); // Flags @@ -652,6 +658,7 @@ abstract class DhcpPacket { { // bootp parameters int transactionId; + short secs; Inet4Address clientIp; Inet4Address yourIp; Inet4Address nextIp; @@ -759,7 +766,7 @@ abstract class DhcpPacket { byte addrLen = packet.get(); byte hops = packet.get(); transactionId = packet.getInt(); - short elapsed = packet.getShort(); + secs = packet.getShort(); short bootpFlags = packet.getShort(); boolean broadcast = (bootpFlags & 0x8000) != 0; byte[] ipv4addr = new byte[4]; @@ -902,33 +909,33 @@ abstract class DhcpPacket { case -1: return null; case DHCP_MESSAGE_TYPE_DISCOVER: newPacket = new DhcpDiscoverPacket( - transactionId, clientMac, broadcast); + transactionId, secs, clientMac, broadcast); break; case DHCP_MESSAGE_TYPE_OFFER: newPacket = new DhcpOfferPacket( - transactionId, broadcast, ipSrc, yourIp, clientMac); + transactionId, secs, broadcast, ipSrc, yourIp, clientMac); break; case DHCP_MESSAGE_TYPE_REQUEST: newPacket = new DhcpRequestPacket( - transactionId, clientIp, clientMac, broadcast); + transactionId, secs, clientIp, clientMac, broadcast); break; case DHCP_MESSAGE_TYPE_DECLINE: newPacket = new DhcpDeclinePacket( - transactionId, clientIp, yourIp, nextIp, relayIp, + transactionId, secs, clientIp, yourIp, nextIp, relayIp, clientMac); break; case DHCP_MESSAGE_TYPE_ACK: newPacket = new DhcpAckPacket( - transactionId, broadcast, ipSrc, yourIp, clientMac); + transactionId, secs, broadcast, ipSrc, yourIp, clientMac); break; case DHCP_MESSAGE_TYPE_NAK: newPacket = new DhcpNakPacket( - transactionId, clientIp, yourIp, nextIp, relayIp, + transactionId, secs, clientIp, yourIp, nextIp, relayIp, clientMac); break; case DHCP_MESSAGE_TYPE_INFORM: newPacket = new DhcpInformPacket( - transactionId, clientIp, yourIp, nextIp, relayIp, + transactionId, secs, clientIp, yourIp, nextIp, relayIp, clientMac); break; default: @@ -1008,9 +1015,9 @@ abstract class DhcpPacket { * parameters. */ public static ByteBuffer buildDiscoverPacket(int encap, int transactionId, - byte[] clientMac, boolean broadcast, byte[] expectedParams) { + short secs, byte[] clientMac, boolean broadcast, byte[] expectedParams) { DhcpPacket pkt = new DhcpDiscoverPacket( - transactionId, clientMac, broadcast); + transactionId, secs, clientMac, broadcast); pkt.mRequestedParams = expectedParams; return pkt.buildPacket(encap, DHCP_SERVER, DHCP_CLIENT); } @@ -1025,7 +1032,7 @@ abstract class DhcpPacket { Inet4Address gateway, List<Inet4Address> dnsServers, Inet4Address dhcpServerIdentifier, String domainName) { DhcpPacket pkt = new DhcpOfferPacket( - transactionId, broadcast, serverIpAddr, clientIpAddr, mac); + transactionId, (short) 0, broadcast, serverIpAddr, clientIpAddr, mac); pkt.mGateway = gateway; pkt.mDnsServers = dnsServers; pkt.mLeaseTime = timeout; @@ -1045,7 +1052,7 @@ abstract class DhcpPacket { Inet4Address gateway, List<Inet4Address> dnsServers, Inet4Address dhcpServerIdentifier, String domainName) { DhcpPacket pkt = new DhcpAckPacket( - transactionId, broadcast, serverIpAddr, clientIpAddr, mac); + transactionId, (short) 0, broadcast, serverIpAddr, clientIpAddr, mac); pkt.mGateway = gateway; pkt.mDnsServers = dnsServers; pkt.mLeaseTime = timeout; @@ -1061,7 +1068,7 @@ abstract class DhcpPacket { */ public static ByteBuffer buildNakPacket(int encap, int transactionId, Inet4Address serverIpAddr, Inet4Address clientIpAddr, byte[] mac) { - DhcpPacket pkt = new DhcpNakPacket(transactionId, clientIpAddr, + DhcpPacket pkt = new DhcpNakPacket(transactionId, (short) 0, clientIpAddr, serverIpAddr, serverIpAddr, serverIpAddr, mac); pkt.mMessage = "requested address not available"; pkt.mRequestedIp = clientIpAddr; @@ -1072,10 +1079,10 @@ abstract class DhcpPacket { * Builds a DHCP-REQUEST packet from the required specified parameters. */ public static ByteBuffer buildRequestPacket(int encap, - int transactionId, Inet4Address clientIp, boolean broadcast, + int transactionId, short secs, Inet4Address clientIp, boolean broadcast, byte[] clientMac, Inet4Address requestedIpAddress, Inet4Address serverIdentifier, byte[] requestedParams, String hostName) { - DhcpPacket pkt = new DhcpRequestPacket(transactionId, clientIp, + DhcpPacket pkt = new DhcpRequestPacket(transactionId, secs, clientIp, clientMac, broadcast); pkt.mRequestedIp = requestedIpAddress; pkt.mServerIdentifier = serverIdentifier; diff --git a/services/net/java/android/net/dhcp/DhcpRequestPacket.java b/services/net/java/android/net/dhcp/DhcpRequestPacket.java index 5d378b8..4f9aa01 100644 --- a/services/net/java/android/net/dhcp/DhcpRequestPacket.java +++ b/services/net/java/android/net/dhcp/DhcpRequestPacket.java @@ -28,9 +28,9 @@ class DhcpRequestPacket extends DhcpPacket { /** * Generates a REQUEST packet with the specified parameters. */ - DhcpRequestPacket(int transId, Inet4Address clientIp, byte[] clientMac, + DhcpRequestPacket(int transId, short secs, Inet4Address clientIp, byte[] clientMac, boolean broadcast) { - super(transId, clientIp, INADDR_ANY, INADDR_ANY, INADDR_ANY, clientMac, broadcast); + super(transId, secs, clientIp, INADDR_ANY, INADDR_ANY, INADDR_ANY, clientMac, broadcast); } public String toString() { |