Stop using LinkProperties for static configuration.
Also make static IP configuration more robust (e.g., tear down our NetworkAgent when we switch between static and DHCP). Bug: 16114392 Bug: 16893413 Change-Id: Ib33f35c004e30b6067bb20235ffa43c247d174df
This commit is contained in:
@@ -19,7 +19,6 @@ package com.android.server.ethernet;
|
|||||||
import android.net.IpConfiguration;
|
import android.net.IpConfiguration;
|
||||||
import android.net.IpConfiguration.IpAssignment;
|
import android.net.IpConfiguration.IpAssignment;
|
||||||
import android.net.IpConfiguration.ProxySettings;
|
import android.net.IpConfiguration.ProxySettings;
|
||||||
import android.net.LinkProperties;
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
@@ -44,7 +43,7 @@ public class EthernetConfigStore extends IpConfigStore {
|
|||||||
|
|
||||||
if (networks.size() == 0) {
|
if (networks.size() == 0) {
|
||||||
Log.w(TAG, "No Ethernet configuration found. Using default.");
|
Log.w(TAG, "No Ethernet configuration found. Using default.");
|
||||||
return new IpConfiguration(IpAssignment.DHCP, ProxySettings.NONE, new LinkProperties());
|
return new IpConfiguration(IpAssignment.DHCP, ProxySettings.NONE, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (networks.size() > 1) {
|
if (networks.size() > 1) {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import android.net.NetworkInfo;
|
|||||||
import android.net.NetworkInfo.DetailedState;
|
import android.net.NetworkInfo.DetailedState;
|
||||||
import android.net.NetworkRequest;
|
import android.net.NetworkRequest;
|
||||||
import android.net.EthernetManager;
|
import android.net.EthernetManager;
|
||||||
|
import android.net.StaticIpConfiguration;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.INetworkManagementService;
|
import android.os.INetworkManagementService;
|
||||||
@@ -211,24 +212,23 @@ class EthernetNetworkFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setStaticIpAddress(LinkProperties linkProperties) {
|
private boolean setStaticIpAddress(StaticIpConfiguration staticConfig) {
|
||||||
Log.i(TAG, "Applying static IPv4 configuration to " + mIface + ": " + mLinkProperties);
|
if (staticConfig.ipAddress != null &&
|
||||||
try {
|
staticConfig.gateway != null &&
|
||||||
InterfaceConfiguration config = mNMService.getInterfaceConfig(mIface);
|
staticConfig.dnsServers.size() > 0) {
|
||||||
for (LinkAddress address: linkProperties.getLinkAddresses()) {
|
try {
|
||||||
// IPv6 uses autoconfiguration.
|
Log.i(TAG, "Applying static IPv4 configuration to " + mIface + ": " + staticConfig);
|
||||||
if (address.getAddress() instanceof Inet4Address) {
|
InterfaceConfiguration config = mNMService.getInterfaceConfig(mIface);
|
||||||
config.setLinkAddress(address);
|
config.setLinkAddress(staticConfig.ipAddress);
|
||||||
// This API only supports one IPv4 address.
|
mNMService.setInterfaceConfig(mIface, config);
|
||||||
mNMService.setInterfaceConfig(mIface, config);
|
return true;
|
||||||
break;
|
} catch(RemoteException|IllegalStateException e) {
|
||||||
}
|
Log.e(TAG, "Setting static IP address failed: " + e.getMessage());
|
||||||
}
|
}
|
||||||
} catch(RemoteException e) {
|
} else {
|
||||||
Log.e(TAG, "Setting static IP address failed: " + e.getMessage());
|
Log.e(TAG, "Invalid static IP configuration.");
|
||||||
} catch(IllegalStateException e) {
|
|
||||||
Log.e(TAG, "Setting static IP address failed: " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAgent() {
|
public void updateAgent() {
|
||||||
@@ -260,9 +260,12 @@ class EthernetNetworkFactory {
|
|||||||
|
|
||||||
IpConfiguration config = mEthernetManager.getConfiguration();
|
IpConfiguration config = mEthernetManager.getConfiguration();
|
||||||
|
|
||||||
if (config.ipAssignment == IpAssignment.STATIC) {
|
if (config.getIpAssignment() == IpAssignment.STATIC) {
|
||||||
linkProperties = config.linkProperties;
|
if (!setStaticIpAddress(config.getStaticIpConfiguration())) {
|
||||||
setStaticIpAddress(linkProperties);
|
// We've already logged an error.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
linkProperties = config.getStaticIpConfiguration().toLinkProperties(mIface);
|
||||||
} else {
|
} else {
|
||||||
mNetworkInfo.setDetailedState(DetailedState.OBTAINING_IPADDR, null, mHwAddr);
|
mNetworkInfo.setDetailedState(DetailedState.OBTAINING_IPADDR, null, mHwAddr);
|
||||||
|
|
||||||
@@ -277,11 +280,11 @@ class EthernetNetworkFactory {
|
|||||||
mFactory.setScoreFilter(-1);
|
mFactory.setScoreFilter(-1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
linkProperties = dhcpResults.linkProperties;
|
linkProperties = dhcpResults.toLinkProperties(mIface);
|
||||||
linkProperties.setInterfaceName(mIface);
|
|
||||||
}
|
}
|
||||||
if (config.proxySettings == ProxySettings.STATIC) {
|
if (config.getProxySettings() == ProxySettings.STATIC ||
|
||||||
linkProperties.setHttpProxy(config.linkProperties.getHttpProxy());
|
config.getProxySettings() == ProxySettings.PAC) {
|
||||||
|
linkProperties.setHttpProxy(config.getHttpProxy());
|
||||||
}
|
}
|
||||||
|
|
||||||
linkProperties.setTcpBufferSizes(TCP_BUFFER_SIZES_ETHERNET);
|
linkProperties.setTcpBufferSizes(TCP_BUFFER_SIZES_ETHERNET);
|
||||||
@@ -383,12 +386,21 @@ class EthernetNetworkFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void stop() {
|
public synchronized void stop() {
|
||||||
|
NetworkUtils.stopDhcp(mIface);
|
||||||
|
// ConnectivityService will only forget our NetworkAgent if we send it a NetworkInfo object
|
||||||
|
// with a state of DISCONNECTED or SUSPENDED. So we can't simply clear our NetworkInfo here:
|
||||||
|
// that sets the state to IDLE, and ConnectivityService will still think we're connected.
|
||||||
|
//
|
||||||
|
// TODO: stop using explicit comparisons to DISCONNECTED / SUSPENDED in ConnectivityService,
|
||||||
|
// and instead use isConnectedOrConnecting().
|
||||||
|
mNetworkInfo.setDetailedState(DetailedState.DISCONNECTED, null, mHwAddr);
|
||||||
|
mLinkUp = false;
|
||||||
|
updateAgent();
|
||||||
|
mLinkProperties = new LinkProperties();
|
||||||
|
mNetworkAgent = null;
|
||||||
mIface = "";
|
mIface = "";
|
||||||
mHwAddr = null;
|
mHwAddr = null;
|
||||||
mLinkUp = false;
|
|
||||||
mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_ETHERNET, 0, NETWORK_TYPE, "");
|
mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_ETHERNET, 0, NETWORK_TYPE, "");
|
||||||
mLinkProperties = new LinkProperties();
|
|
||||||
updateAgent();
|
|
||||||
mFactory.unregister();
|
mFactory.unregister();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ import android.net.IpConfiguration;
|
|||||||
import android.net.IpConfiguration.IpAssignment;
|
import android.net.IpConfiguration.IpAssignment;
|
||||||
import android.net.IpConfiguration.ProxySettings;
|
import android.net.IpConfiguration.ProxySettings;
|
||||||
import android.net.LinkAddress;
|
import android.net.LinkAddress;
|
||||||
import android.net.LinkProperties;
|
|
||||||
import android.net.NetworkAgent;
|
import android.net.NetworkAgent;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.NetworkRequest;
|
import android.net.NetworkRequest;
|
||||||
import android.net.RouteInfo;
|
import android.net.RouteInfo;
|
||||||
|
import android.net.StaticIpConfiguration;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -143,10 +143,7 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
|
|||||||
// TODO: this does not check proxy settings, gateways, etc.
|
// TODO: this does not check proxy settings, gateways, etc.
|
||||||
// Fix this by making IpConfiguration a complete representation of static configuration.
|
// Fix this by making IpConfiguration a complete representation of static configuration.
|
||||||
if (!config.equals(mIpConfiguration)) {
|
if (!config.equals(mIpConfiguration)) {
|
||||||
mIpConfiguration.ipAssignment = config.ipAssignment;
|
mIpConfiguration = new IpConfiguration(config);
|
||||||
mIpConfiguration.proxySettings = config.proxySettings;
|
|
||||||
mIpConfiguration.linkProperties = new LinkProperties(config.linkProperties);
|
|
||||||
|
|
||||||
mTracker.stop();
|
mTracker.stop();
|
||||||
mTracker.start(mContext, mHandler);
|
mTracker.start(mContext, mHandler);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user