summaryrefslogtreecommitdiff
path: root/src/android/net/dhcp/DhcpPacket.java
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2019-04-26 19:10:20 +0900
committerLorenzo Colitti <lorenzo@google.com>2019-04-27 16:36:10 +0900
commitef1ac51adacb2751f6357e6afc8ce36af8c46ea4 (patch)
treeae8aa3be162c3b730b6ec25cd69b765cd1cba0cb /src/android/net/dhcp/DhcpPacket.java
parentb945b7982b2dc83dd63ada4e4947b2a41e7c1f53 (diff)
Additional code for server name in DHCP packets.
- Add the hostname to DhcpResultsParcelable. - Don't store the server hostname if option overload is in use, as this is not valid. - Add unit tests. Bug: 120584519 Bug: 127423755 Test: atest NetworkStackTests Test: atest FrameworksNetTests Change-Id: I47d9d53d1fb58968322cc8b071a44fbc8f7156e1
Diffstat (limited to 'src/android/net/dhcp/DhcpPacket.java')
-rw-r--r--src/android/net/dhcp/DhcpPacket.java26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/android/net/dhcp/DhcpPacket.java b/src/android/net/dhcp/DhcpPacket.java
index c5b75f8..a15d423 100644
--- a/src/android/net/dhcp/DhcpPacket.java
+++ b/src/android/net/dhcp/DhcpPacket.java
@@ -195,6 +195,18 @@ public abstract class DhcpPacket {
public static final String VENDOR_INFO_ANDROID_METERED = "ANDROID_METERED";
/**
+ * DHCP Optional Type: Option overload option
+ */
+ protected static final byte DHCP_OPTION_OVERLOAD = 52;
+
+ /**
+ * Possible values of the option overload option.
+ */
+ private static final byte OPTION_OVERLOAD_FILE = 1;
+ private static final byte OPTION_OVERLOAD_SNAME = 2;
+ private static final byte OPTION_OVERLOAD_BOTH = 3;
+
+ /**
* DHCP Optional Type: DHCP Requested IP Address
*/
protected static final byte DHCP_REQUESTED_IP = 50;
@@ -853,7 +865,8 @@ public abstract class DhcpPacket {
Inet4Address ipDst = null;
Inet4Address bcAddr = null;
Inet4Address requestedIp = null;
- String serverHostName = null;
+ String serverHostName;
+ byte optionOverload = 0;
// The following are all unsigned integers. Internally we store them as signed integers of
// the same length because that way we're guaranteed that they can't be out of the range of
@@ -1108,6 +1121,11 @@ public abstract class DhcpPacket {
// Embedded nulls are safe as this does not get passed to netd.
vendorInfo = readAsciiString(packet, optionLen, true);
break;
+ case DHCP_OPTION_OVERLOAD:
+ expectedLen = 1;
+ optionOverload = packet.get();
+ optionOverload &= OPTION_OVERLOAD_BOTH;
+ break;
default:
// ignore any other parameters
for (int i = 0; i < optionLen; i++) {
@@ -1198,7 +1216,11 @@ public abstract class DhcpPacket {
newPacket.mT2 = T2;
newPacket.mVendorId = vendorId;
newPacket.mVendorInfo = vendorInfo;
- newPacket.mServerHostName = serverHostName;
+ if ((optionOverload & OPTION_OVERLOAD_SNAME) == 0) {
+ newPacket.mServerHostName = serverHostName;
+ } else {
+ newPacket.mServerHostName = "";
+ }
return newPacket;
}