Always try to set/remove default routes

Must clean up default route if a default 3g connection is replaced
by a non-default (ie, mms) connection on the same interface.

Also stop mucking with all connections dns and routes - do it only
for the connection that has changed.

bug:2865974
Change-Id: I589a0b2768b5e67b608fde181e7ddbd7fce4f491
This commit is contained in:
Robert Greenwalt
2010-07-23 15:46:26 -07:00
parent 653e2a2f64
commit 3afbead19f

View File

@@ -605,7 +605,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
!network.isTeardownRequested()) { !network.isTeardownRequested()) {
if (ni.isConnected() == true) { if (ni.isConnected() == true) {
// add the pid-specific dns // add the pid-specific dns
handleDnsConfigurationChange(); handleDnsConfigurationChange(networkType);
if (DBG) Slog.d(TAG, "special network already active"); if (DBG) Slog.d(TAG, "special network already active");
return Phone.APN_ALREADY_ACTIVE; return Phone.APN_ALREADY_ACTIVE;
} }
@@ -967,7 +967,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
} }
// do this before we broadcast the change // do this before we broadcast the change
handleConnectivityChange(); handleConnectivityChange(prevNetType);
sendStickyBroadcast(intent); sendStickyBroadcast(intent);
/* /*
@@ -1123,9 +1123,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
} }
// do this before we broadcast the change
handleConnectivityChange();
sendStickyBroadcast(intent); sendStickyBroadcast(intent);
/* /*
* If the failover network is already connected, then immediately send * If the failover network is already connected, then immediately send
@@ -1204,7 +1201,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
thisNet.setTeardownRequested(false); thisNet.setTeardownRequested(false);
updateNetworkSettings(thisNet); updateNetworkSettings(thisNet);
handleConnectivityChange(); handleConnectivityChange(type);
sendConnectedBroadcast(info); sendConnectedBroadcast(info);
} }
@@ -1231,26 +1228,18 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
/** /**
* After any kind of change in the connectivity state of any network, * After a change in the connectivity state of a network. We're mainly
* make sure that anything that depends on the connectivity state of * concerned with making sure that the list of DNS servers is set up
* more than one network is set up correctly. We're mainly concerned * according to which networks are connected, and ensuring that the
* with making sure that the list of DNS servers is set up according * right routing table entries exist.
* to which networks are connected, and ensuring that the right routing
* table entries exist.
*/ */
private void handleConnectivityChange() { private void handleConnectivityChange(int netType) {
/* /*
* If a non-default network is enabled, add the host routes that * If a non-default network is enabled, add the host routes that
* will allow it's DNS servers to be accessed. Only * will allow it's DNS servers to be accessed.
* If both mobile and wifi are enabled, add the host routes that
* will allow MMS traffic to pass on the mobile network. But
* remove the default route for the mobile network, so that there
* will be only one default route, to ensure that all traffic
* except MMS will travel via Wi-Fi.
*/ */
handleDnsConfigurationChange(); handleDnsConfigurationChange(netType);
for (int netType : mPriorityList) {
if (mNetTrackers[netType].getNetworkInfo().isConnected()) { if (mNetTrackers[netType].getNetworkInfo().isConnected()) {
if (mNetAttributes[netType].isDefault()) { if (mNetAttributes[netType].isDefault()) {
addDefaultRoute(mNetTrackers[netType]); addDefaultRoute(mNetTrackers[netType]);
@@ -1265,7 +1254,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
} }
} }
}
private void addPrivateDnsRoutes(NetworkStateTracker nt) { private void addPrivateDnsRoutes(NetworkStateTracker nt) {
boolean privateDnsRouteSet = nt.isPrivateDnsRouteSet(); boolean privateDnsRouteSet = nt.isPrivateDnsRouteSet();
@@ -1310,18 +1298,13 @@ public class ConnectivityService extends IConnectivityManager.Stub {
if (p == null) return; if (p == null) return;
String interfaceName = p.getInterfaceName(); String interfaceName = p.getInterfaceName();
InetAddress defaultGatewayAddr = p.getGateway(); InetAddress defaultGatewayAddr = p.getGateway();
boolean defaultRouteSet = nt.isDefaultRouteSet();
if ((interfaceName != null) && (defaultGatewayAddr != null ) && if ((interfaceName != null) && (defaultGatewayAddr != null )) {
(defaultRouteSet == false)) { if ((NetworkUtils.setDefaultRoute(interfaceName, defaultGatewayAddr) >= 0) && DBG) {
boolean error = (NetworkUtils.setDefaultRoute(interfaceName, defaultGatewayAddr) < 0);
if (DBG && !error) {
NetworkInfo networkInfo = nt.getNetworkInfo(); NetworkInfo networkInfo = nt.getNetworkInfo();
Slog.d(TAG, "addDefaultRoute for " + networkInfo.getTypeName() + Slog.d(TAG, "addDefaultRoute for " + networkInfo.getTypeName() +
" (" + interfaceName + "), GatewayAddr=" + defaultGatewayAddr); " (" + interfaceName + "), GatewayAddr=" + defaultGatewayAddr);
} }
nt.defaultRouteSet(!error);
} }
} }
@@ -1330,16 +1313,13 @@ public class ConnectivityService extends IConnectivityManager.Stub {
NetworkProperties p = nt.getNetworkProperties(); NetworkProperties p = nt.getNetworkProperties();
if (p == null) return; if (p == null) return;
String interfaceName = p.getInterfaceName(); String interfaceName = p.getInterfaceName();
boolean defaultRouteSet = nt.isDefaultRouteSet();
if (interfaceName != null && defaultRouteSet == true) { if (interfaceName != null) {
boolean error = (NetworkUtils.removeDefaultRoute(interfaceName) < 0); if ((NetworkUtils.removeDefaultRoute(interfaceName) >= 0) && DBG) {
if (DBG && !error) {
NetworkInfo networkInfo = nt.getNetworkInfo(); NetworkInfo networkInfo = nt.getNetworkInfo();
Slog.d(TAG, "removeDefaultRoute for " + networkInfo.getTypeName() + " (" + Slog.d(TAG, "removeDefaultRoute for " + networkInfo.getTypeName() + " (" +
interfaceName + ")"); interfaceName + ")");
} }
nt.defaultRouteSet(error);
} }
} }
@@ -1480,15 +1460,12 @@ public class ConnectivityService extends IConnectivityManager.Stub {
SystemProperties.set("net.dnschange", "" + (n+1)); SystemProperties.set("net.dnschange", "" + (n+1));
} }
private void handleDnsConfigurationChange() { private void handleDnsConfigurationChange(int netType) {
// add default net's dns entries // add default net's dns entries
for (int x = mPriorityList.length-1; x>= 0; x--) {
int netType = mPriorityList[x];
NetworkStateTracker nt = mNetTrackers[netType]; NetworkStateTracker nt = mNetTrackers[netType];
if (nt != null && nt.getNetworkInfo().isConnected() && if (nt != null && nt.getNetworkInfo().isConnected() && !nt.isTeardownRequested()) {
!nt.isTeardownRequested()) {
NetworkProperties p = nt.getNetworkProperties(); NetworkProperties p = nt.getNetworkProperties();
if (p == null) continue; if (p == null) return;
Collection<InetAddress> dnses = p.getDnses(); Collection<InetAddress> dnses = p.getDnses();
if (mNetAttributes[netType].isDefault()) { if (mNetAttributes[netType].isDefault()) {
int j = 1; int j = 1;
@@ -1512,11 +1489,9 @@ public class ConnectivityService extends IConnectivityManager.Stub {
writePidDns(dnses, pid.intValue()); writePidDns(dnses, pid.intValue());
} }
} }
}
}
bumpDns(); bumpDns();
} }
}
private int getRestoreDefaultNetworkDelay() { private int getRestoreDefaultNetworkDelay() {
String restoreDefaultNetworkDelayStr = SystemProperties.get( String restoreDefaultNetworkDelayStr = SystemProperties.get(
@@ -1654,9 +1629,11 @@ public class ConnectivityService extends IConnectivityManager.Stub {
(Notification) msg.obj); (Notification) msg.obj);
case NetworkStateTracker.EVENT_CONFIGURATION_CHANGED: case NetworkStateTracker.EVENT_CONFIGURATION_CHANGED:
handleDnsConfigurationChange(); // TODO - make this handle ip/proxy/gateway/dns changes
info = (NetworkInfo) msg.obj;
type = info.getType();
handleDnsConfigurationChange(type);
break; break;
case NetworkStateTracker.EVENT_ROAMING_CHANGED: case NetworkStateTracker.EVENT_ROAMING_CHANGED:
// fill me in // fill me in
break; break;