From 511818ffb3a21de86d02ccc29e3c1c92d75c81c4 Mon Sep 17 00:00:00 2001 From: Erik Kline Date: Tue, 13 Dec 2016 13:44:19 +0900 Subject: [PATCH] DHCPv4 anonymity profile: support skipping hostname option Per https://tools.ietf.org/html/rfc7844#section-3.7 When using the anonymity profile, DHCP clients SHOULD NOT send the Host Name option. Once the net.hostname property is removed and ensured unset via CTS this option will no longer be sent. Test: as follows - build, flashed - connected to v4-only and dualstack networks, verified v4 works - android.net.dhcp.DhcpPacketTest passes - setprop net.hostname "" and verified no hostname option Bug: 30979015 Change-Id: Ieab3f04ea38e176d9147bb788742a5397762c2e4 --- services/net/java/android/net/dhcp/DhcpPacket.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/net/java/android/net/dhcp/DhcpPacket.java b/services/net/java/android/net/dhcp/DhcpPacket.java index ef4bc024c1533..96c8e9f0f549a 100644 --- a/services/net/java/android/net/dhcp/DhcpPacket.java +++ b/services/net/java/android/net/dhcp/DhcpPacket.java @@ -7,6 +7,7 @@ import android.net.metrics.DhcpErrorEvent; import android.os.Build; import android.os.SystemProperties; import android.system.OsConstants; +import android.text.TextUtils; import com.android.internal.annotations.VisibleForTesting; import java.io.UnsupportedEncodingException; @@ -629,7 +630,8 @@ abstract class DhcpPacket { protected void addCommonClientTlvs(ByteBuffer buf) { addTlv(buf, DHCP_MAX_MESSAGE_SIZE, (short) MAX_LENGTH); addTlv(buf, DHCP_VENDOR_CLASS_ID, getVendorId()); - addTlv(buf, DHCP_HOST_NAME, getHostname()); + final String hn = getHostname(); + if (!TextUtils.isEmpty(hn)) addTlv(buf, DHCP_HOST_NAME, hn); } /**