summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiao Ma <xiaom@google.com>2020-05-07 12:26:30 +0000
committerXiao Ma <xiaom@google.com>2020-05-07 13:22:51 +0000
commit32bee5e753cfc9902fe72d49b96011018824e2fa (patch)
tree8c4e184fca33b7b2b6ce320ef822ca86cf3cfbf3
parentb12790b92269c9810122c414d77a592f9f17cc35 (diff)
Set clientId when parsing an explicit DHCP_CLIENT_IDENTIFIER option.
Bug: 130741856 Test: atest NetworkStackTests TetheringTests Test: manually turn on the hotspot and verify the downstream device can attach to the upstream hotspot, then turn it off, repeat multiple times. Merged-In: I9da5fec47a74de36869e795fa9b1d7170d2f91c9 Change-Id: I9da5fec47a74de36869e795fa9b1d7170d2f91c9
-rw-r--r--src/android/net/dhcp/DhcpPacket.java4
-rw-r--r--tests/unit/src/android/net/dhcp/DhcpPacketTest.java35
2 files changed, 37 insertions, 2 deletions
diff --git a/src/android/net/dhcp/DhcpPacket.java b/src/android/net/dhcp/DhcpPacket.java
index 852719e..a4dbda1 100644
--- a/src/android/net/dhcp/DhcpPacket.java
+++ b/src/android/net/dhcp/DhcpPacket.java
@@ -1182,8 +1182,8 @@ public abstract class DhcpPacket {
vendorId = readAsciiString(packet, optionLen, true);
break;
case DHCP_CLIENT_IDENTIFIER: { // Client identifier
- byte[] id = new byte[optionLen];
- packet.get(id);
+ clientId = new byte[optionLen];
+ packet.get(clientId);
expectedLen = optionLen;
} break;
case DHCP_VENDOR_INFO:
diff --git a/tests/unit/src/android/net/dhcp/DhcpPacketTest.java b/tests/unit/src/android/net/dhcp/DhcpPacketTest.java
index 6ce1fdf..c565238 100644
--- a/tests/unit/src/android/net/dhcp/DhcpPacketTest.java
+++ b/tests/unit/src/android/net/dhcp/DhcpPacketTest.java
@@ -728,6 +728,41 @@ public class DhcpPacketTest {
}
@Test
+ public void testExplicitClientId() throws Exception {
+ final byte[] clientId = new byte[] {
+ 0x01 /* CLIENT_ID_ETH */, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+
+ // CHECKSTYLE:OFF Generated code
+ final byte[] packet = HexDump.hexStringToByteArray(
+ // IP header.
+ "450001518d0600004011144dc0a82b01c0a82bf7" +
+ // UDP header
+ "00430044013d9ac7" +
+ // BOOTP header
+ "02010600dfc23d1f0002000000000000c0a82bf7c0a82b0100000000" +
+ // MAC address.
+ "30766ff2a90c00000000000000000000" +
+ // Server name ("dhcp.android.com" plus invalid "AAAA" after null terminator).
+ "646863702e616e64726f69642e636f6d00000000000000000000000000000000" +
+ "0000000000004141414100000000000000000000000000000000000000000000" +
+ // File.
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ // Options
+ "638253633501013d0701010203040506390205dc3c0e616e64726f69642d6468" +
+ "63702d52370a0103060f1a1c333a3b2bff00");
+ // CHECKSTYLE:ON Generated code
+
+ final DhcpPacket discoverPacket = DhcpPacket.decodeFullPacket(packet,
+ packet.length, ENCAP_L3);
+ assertTrue(discoverPacket instanceof DhcpDiscoverPacket);
+ assertTrue(discoverPacket.hasExplicitClientId());
+ assertTrue(Arrays.equals(discoverPacket.mClientId, clientId));
+ }
+
+ @Test
public void testBadHwaddrLength() throws Exception {
// CHECKSTYLE:OFF Generated code
final ByteBuffer packet = ByteBuffer.wrap(HexDump.hexStringToByteArray(