Update LinkProperties treatment of gateways
A link can have multiple gateways (think ipv4/ipv6 for a trivial example). . bug:3438810 Change-Id: I28c90a6947cd50b82e5ca9a0113148f98b3f4dd8
This commit is contained in:
@@ -31,7 +31,24 @@ import java.util.Collections;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes the properties of a network link.
|
* Describes the properties of a network link.
|
||||||
* TODO - consider adding optional fields like Apn and ApnType
|
*
|
||||||
|
* A link represents a connection to a network.
|
||||||
|
* It may have multiple addresses and multiple gateways,
|
||||||
|
* multiple dns servers but only one http proxy.
|
||||||
|
*
|
||||||
|
* Because it's a single network, the dns's
|
||||||
|
* are interchangeable and don't need associating with
|
||||||
|
* particular addresses. The gateways similarly don't
|
||||||
|
* need associating with particular addresses.
|
||||||
|
*
|
||||||
|
* A dual stack interface works fine in this model:
|
||||||
|
* each address has it's own prefix length to describe
|
||||||
|
* the local network. The dns servers all return
|
||||||
|
* both v4 addresses and v6 addresses regardless of the
|
||||||
|
* address family of the server itself (rfc4213) and we
|
||||||
|
* don't care which is used. The gateways will be
|
||||||
|
* selected based on the destination address and the
|
||||||
|
* source address has no relavence.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public class LinkProperties implements Parcelable {
|
public class LinkProperties implements Parcelable {
|
||||||
@@ -39,7 +56,7 @@ public class LinkProperties implements Parcelable {
|
|||||||
String mIfaceName;
|
String mIfaceName;
|
||||||
private Collection<LinkAddress> mLinkAddresses;
|
private Collection<LinkAddress> mLinkAddresses;
|
||||||
private Collection<InetAddress> mDnses;
|
private Collection<InetAddress> mDnses;
|
||||||
private InetAddress mGateway;
|
private Collection<InetAddress> mGateways;
|
||||||
private ProxyProperties mHttpProxy;
|
private ProxyProperties mHttpProxy;
|
||||||
|
|
||||||
public LinkProperties() {
|
public LinkProperties() {
|
||||||
@@ -52,7 +69,7 @@ public class LinkProperties implements Parcelable {
|
|||||||
mIfaceName = source.getInterfaceName();
|
mIfaceName = source.getInterfaceName();
|
||||||
mLinkAddresses = source.getLinkAddresses();
|
mLinkAddresses = source.getLinkAddresses();
|
||||||
mDnses = source.getDnses();
|
mDnses = source.getDnses();
|
||||||
mGateway = source.getGateway();
|
mGateways = source.getGateways();
|
||||||
mHttpProxy = new ProxyProperties(source.getHttpProxy());
|
mHttpProxy = new ProxyProperties(source.getHttpProxy());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,11 +106,11 @@ public class LinkProperties implements Parcelable {
|
|||||||
return Collections.unmodifiableCollection(mDnses);
|
return Collections.unmodifiableCollection(mDnses);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGateway(InetAddress gateway) {
|
public void addGateway(InetAddress gateway) {
|
||||||
mGateway = gateway;
|
mGateways.add(gateway);
|
||||||
}
|
}
|
||||||
public InetAddress getGateway() {
|
public Collection<InetAddress> getGateways() {
|
||||||
return mGateway;
|
return Collections.unmodifiableCollection(mGateways);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHttpProxy(ProxyProperties proxy) {
|
public void setHttpProxy(ProxyProperties proxy) {
|
||||||
@@ -107,7 +124,7 @@ public class LinkProperties implements Parcelable {
|
|||||||
mIfaceName = null;
|
mIfaceName = null;
|
||||||
mLinkAddresses = new ArrayList<LinkAddress>();
|
mLinkAddresses = new ArrayList<LinkAddress>();
|
||||||
mDnses = new ArrayList<InetAddress>();
|
mDnses = new ArrayList<InetAddress>();
|
||||||
mGateway = null;
|
mGateways = new ArrayList<InetAddress>();
|
||||||
mHttpProxy = null;
|
mHttpProxy = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,10 +148,12 @@ public class LinkProperties implements Parcelable {
|
|||||||
for (InetAddress addr : mDnses) dns += addr.getHostAddress() + ",";
|
for (InetAddress addr : mDnses) dns += addr.getHostAddress() + ",";
|
||||||
dns += "] ";
|
dns += "] ";
|
||||||
|
|
||||||
|
String gateways = "Gateways: [";
|
||||||
|
for (InetAddress gw : mGateways) gateways += gw.getHostAddress() + ",";
|
||||||
|
gateways += "] ";
|
||||||
String proxy = (mHttpProxy == null ? "" : "HttpProxy: " + mHttpProxy.toString() + " ");
|
String proxy = (mHttpProxy == null ? "" : "HttpProxy: " + mHttpProxy.toString() + " ");
|
||||||
String gateway = (mGateway == null ? "" : "Gateway: " + mGateway.getHostAddress() + " ");
|
|
||||||
|
|
||||||
return ifaceName + linkAddresses + gateway + dns + proxy;
|
return ifaceName + linkAddresses + gateways + dns + proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -152,12 +171,12 @@ public class LinkProperties implements Parcelable {
|
|||||||
for(InetAddress d : mDnses) {
|
for(InetAddress d : mDnses) {
|
||||||
dest.writeByteArray(d.getAddress());
|
dest.writeByteArray(d.getAddress());
|
||||||
}
|
}
|
||||||
if (mGateway != null) {
|
|
||||||
dest.writeByte((byte)1);
|
dest.writeInt(mGateways.size());
|
||||||
dest.writeByteArray(mGateway.getAddress());
|
for(InetAddress gw : mGateways) {
|
||||||
} else {
|
dest.writeByteArray(gw.getAddress());
|
||||||
dest.writeByte((byte)0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mHttpProxy != null) {
|
if (mHttpProxy != null) {
|
||||||
dest.writeByte((byte)1);
|
dest.writeByte((byte)1);
|
||||||
dest.writeParcelable(mHttpProxy, flags);
|
dest.writeParcelable(mHttpProxy, flags);
|
||||||
@@ -192,10 +211,11 @@ public class LinkProperties implements Parcelable {
|
|||||||
netProp.addDns(InetAddress.getByAddress(in.createByteArray()));
|
netProp.addDns(InetAddress.getByAddress(in.createByteArray()));
|
||||||
} catch (UnknownHostException e) { }
|
} catch (UnknownHostException e) { }
|
||||||
}
|
}
|
||||||
if (in.readByte() == 1) {
|
addressCount = in.readInt();
|
||||||
|
for (int i=0; i<addressCount; i++) {
|
||||||
try {
|
try {
|
||||||
netProp.setGateway(InetAddress.getByAddress(in.createByteArray()));
|
netProp.addGateway(InetAddress.getByAddress(in.createByteArray()));
|
||||||
} catch (UnknownHostException e) {}
|
} catch (UnknownHostException e) { }
|
||||||
}
|
}
|
||||||
if (in.readByte() == 1) {
|
if (in.readByte() == 1) {
|
||||||
netProp.setHttpProxy((ProxyProperties)in.readParcelable(null));
|
netProp.setHttpProxy((ProxyProperties)in.readParcelable(null));
|
||||||
|
|||||||
@@ -1414,13 +1414,13 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
LinkProperties p = nt.getLinkProperties();
|
LinkProperties p = nt.getLinkProperties();
|
||||||
if (p == null) return;
|
if (p == null) return;
|
||||||
String interfaceName = p.getInterfaceName();
|
String interfaceName = p.getInterfaceName();
|
||||||
InetAddress defaultGatewayAddr = p.getGateway();
|
if (TextUtils.isEmpty(interfaceName)) return;
|
||||||
|
for (InetAddress gateway : p.getGateways()) {
|
||||||
|
|
||||||
if ((interfaceName != null) && (defaultGatewayAddr != null )) {
|
if (!NetworkUtils.addDefaultRoute(interfaceName, gateway) && DBG) {
|
||||||
if (!NetworkUtils.addDefaultRoute(interfaceName, defaultGatewayAddr) && DBG) {
|
|
||||||
NetworkInfo networkInfo = nt.getNetworkInfo();
|
NetworkInfo networkInfo = nt.getNetworkInfo();
|
||||||
log("addDefaultRoute for " + networkInfo.getTypeName() +
|
log("addDefaultRoute for " + networkInfo.getTypeName() +
|
||||||
" (" + interfaceName + "), GatewayAddr=" + defaultGatewayAddr);
|
" (" + interfaceName + "), GatewayAddr=" + gateway.getHostAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user