From 9cd977f9f469bba280e7875d0fac0b1565da4f17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bram=20Bonn=C3=A9?= Date: Wed, 15 Apr 2020 18:19:34 +0200 Subject: Use EUI64 IPv6 link-local address generation when randomizing MAC When connected MAC address randomization is used, generate IPv6 link-local addresses using EUI64 with the per-network defined MAC address. Networks that do not use MAC address randomization keep using RFC7217 stable privacy address generation instead. Bug: 154114734 Test: atest ClientModeImplTest Test: atest WifiManagerTest Test: Connect to network Test: Set up hotspot Test: Cast from device Test: Observe that IPv6 link-local address differs for two networks using randomization Test: Observe that stable-privacy link-local address is used for network when not using randomization Change-Id: Iefb027b17657031116e068bbccdb7b2231a65238 (cherry picked from commit d870eee583e9300fbdaa1620325fe3c13d30817d) --- .../com/android/server/wifi/ClientModeImpl.java | 30 ++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index 5b616dd0a..b5bd479db 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -6447,12 +6447,17 @@ public class ClientModeImpl extends StateMachine { final boolean isUsingStaticIp = (config.getIpAssignment() == IpConfiguration.IpAssignment.STATIC); + final boolean isUsingMacRandomization = + config.macRandomizationSetting + == WifiConfiguration.RANDOMIZATION_PERSISTENT + && isConnectedMacRandomizationEnabled(); if (mVerboseLoggingEnabled) { final String key = config.getKey(); log("startIpClient netId=" + Integer.toString(mLastNetworkId) + " " + key + " " + " roam=" + mIsAutoRoaming + " static=" + isUsingStaticIp + + " randomMac=" + isUsingMacRandomization + " isFilsConnection=" + isFilsConnection); } @@ -6471,15 +6476,18 @@ public class ClientModeImpl extends StateMachine { return false; } setConfigurationsPriorToIpClientProvisioning(config); - final ProvisioningConfiguration prov = + final ProvisioningConfiguration.Builder prov = new ProvisioningConfiguration.Builder() .withPreDhcpAction() .withPreconnection() .withApfCapabilities( mWifiNative.getApfCapabilities(mInterfaceName)) - .withLayer2Information(layer2Info) - .build(); - mIpClient.startProvisioning(prov); + .withLayer2Information(layer2Info); + if (isUsingMacRandomization) { + // Use EUI64 address generation for link-local IPv6 addresses. + prov.withRandomMacAddress(); + } + mIpClient.startProvisioning(prov.build()); } else { sendNetworkChangeBroadcast(DetailedState.OBTAINING_IPADDR); // We must clear the config BSSID, as the wifi chipset may decide to roam @@ -6521,7 +6529,7 @@ public class ClientModeImpl extends StateMachine { } } - final ProvisioningConfiguration prov; + final ProvisioningConfiguration.Builder prov; ProvisioningConfiguration.ScanResultInfo scanResultInfo = null; if (scanResult != null) { final List ies = @@ -6542,8 +6550,7 @@ public class ClientModeImpl extends StateMachine { .withNetwork(getCurrentNetwork()) .withDisplayName(config.SSID) .withScanResultInfo(scanResultInfo) - .withLayer2Information(layer2Info) - .build(); + .withLayer2Information(layer2Info); } else { StaticIpConfiguration staticIpConfig = config.getStaticIpConfiguration(); prov = new ProvisioningConfiguration.Builder() @@ -6551,10 +6558,13 @@ public class ClientModeImpl extends StateMachine { .withApfCapabilities(mWifiNative.getApfCapabilities(mInterfaceName)) .withNetwork(getCurrentNetwork()) .withDisplayName(config.SSID) - .withLayer2Information(layer2Info) - .build(); + .withLayer2Information(layer2Info); + } + if (isUsingMacRandomization) { + // Use EUI64 address generation for link-local IPv6 addresses. + prov.withRandomMacAddress(); } - mIpClient.startProvisioning(prov); + mIpClient.startProvisioning(prov.build()); } return true; -- cgit v1.2.3