use of android.net.LinkAddress in project android_frameworks_base by crdroidandroid.
the class LinkAddressTest method testParceling.
public void testParceling() {
LinkAddress l;
l = new LinkAddress(V6_ADDRESS, 64, 123, 456);
assertParcelingIsLossless(l);
l = new LinkAddress(V4 + "/28", IFA_F_PERMANENT, RT_SCOPE_LINK);
assertParcelingIsLossless(l);
}
use of android.net.LinkAddress in project android_frameworks_base by crdroidandroid.
the class LinkPropertiesTest method testRouteInterfaces.
@SmallTest
public void testRouteInterfaces() {
LinkAddress prefix = new LinkAddress(NetworkUtils.numericToInetAddress("2001:db8::"), 32);
InetAddress address = ADDRV6;
// Add a route with no interface to a LinkProperties with no interface. No errors.
LinkProperties lp = new LinkProperties();
RouteInfo r = new RouteInfo(prefix, address, null);
assertTrue(lp.addRoute(r));
assertEquals(1, lp.getRoutes().size());
assertAllRoutesHaveInterface(null, lp);
// Adding the same route twice has no effect.
assertFalse(lp.addRoute(r));
assertEquals(1, lp.getRoutes().size());
// Add a route with an interface. Expect an exception.
r = new RouteInfo(prefix, address, "wlan0");
try {
lp.addRoute(r);
fail("Adding wlan0 route to LP with no interface, expect exception");
} catch (IllegalArgumentException expected) {
}
// Change the interface name. All the routes should change their interface name too.
lp.setInterfaceName("rmnet0");
assertAllRoutesHaveInterface("rmnet0", lp);
// Now add a route with the wrong interface. This causes an exception too.
try {
lp.addRoute(r);
fail("Adding wlan0 route to rmnet0 LP, expect exception");
} catch (IllegalArgumentException expected) {
}
// If the interface name matches, the route is added.
r = new RouteInfo(prefix, null, "wlan0");
lp.setInterfaceName("wlan0");
lp.addRoute(r);
assertEquals(2, lp.getRoutes().size());
assertAllRoutesHaveInterface("wlan0", lp);
// Routes with null interfaces are converted to wlan0.
r = RouteInfo.makeHostRoute(ADDRV6, null);
lp.addRoute(r);
assertEquals(3, lp.getRoutes().size());
assertAllRoutesHaveInterface("wlan0", lp);
// Check comparisons work.
LinkProperties lp2 = new LinkProperties(lp);
assertAllRoutesHaveInterface("wlan0", lp);
assertEquals(0, lp.compareAllRoutes(lp2).added.size());
assertEquals(0, lp.compareAllRoutes(lp2).removed.size());
lp2.setInterfaceName("p2p0");
assertAllRoutesHaveInterface("p2p0", lp2);
assertEquals(3, lp.compareAllRoutes(lp2).added.size());
assertEquals(3, lp.compareAllRoutes(lp2).removed.size());
}
use of android.net.LinkAddress in project android_frameworks_base by crdroidandroid.
the class LinkPropertiesTest method testIsReachable.
@SmallTest
// Failing.
@Suppress
public void testIsReachable() {
final LinkProperties v4lp = new LinkProperties();
assertFalse(v4lp.isReachable(DNS1));
assertFalse(v4lp.isReachable(DNS2));
// Add an on-link route, making the on-link DNS server reachable,
// but there is still no IPv4 address.
assertTrue(v4lp.addRoute(new RouteInfo(new IpPrefix(NetworkUtils.numericToInetAddress("75.208.0.0"), 16))));
assertFalse(v4lp.isReachable(DNS1));
assertFalse(v4lp.isReachable(DNS2));
// Adding an IPv4 address (right now, any IPv4 address) means we use
// the routes to compute likely reachability.
assertTrue(v4lp.addLinkAddress(new LinkAddress(ADDRV4, 16)));
assertTrue(v4lp.isReachable(DNS1));
assertFalse(v4lp.isReachable(DNS2));
// Adding a default route makes the off-link DNS server reachable.
assertTrue(v4lp.addRoute(new RouteInfo(GATEWAY1)));
assertTrue(v4lp.isReachable(DNS1));
assertTrue(v4lp.isReachable(DNS2));
final LinkProperties v6lp = new LinkProperties();
final InetAddress kLinkLocalDns = NetworkUtils.numericToInetAddress("fe80::6:1");
final InetAddress kLinkLocalDnsWithScope = NetworkUtils.numericToInetAddress("fe80::6:2%43");
final InetAddress kOnLinkDns = NetworkUtils.numericToInetAddress("2001:db8:85a3::53");
assertFalse(v6lp.isReachable(kLinkLocalDns));
assertFalse(v6lp.isReachable(kLinkLocalDnsWithScope));
assertFalse(v6lp.isReachable(kOnLinkDns));
assertFalse(v6lp.isReachable(DNS6));
// Add a link-local route, making the link-local DNS servers reachable. Because
// we assume the presence of an IPv6 link-local address, link-local DNS servers
// are considered reachable, but only those with a non-zero scope identifier.
assertTrue(v6lp.addRoute(new RouteInfo(new IpPrefix(NetworkUtils.numericToInetAddress("fe80::"), 64))));
assertFalse(v6lp.isReachable(kLinkLocalDns));
assertTrue(v6lp.isReachable(kLinkLocalDnsWithScope));
assertFalse(v6lp.isReachable(kOnLinkDns));
assertFalse(v6lp.isReachable(DNS6));
// Add a link-local address--nothing changes.
assertTrue(v6lp.addLinkAddress(LINKADDRV6LINKLOCAL));
assertFalse(v6lp.isReachable(kLinkLocalDns));
assertTrue(v6lp.isReachable(kLinkLocalDnsWithScope));
assertFalse(v6lp.isReachable(kOnLinkDns));
assertFalse(v6lp.isReachable(DNS6));
// Add a global route on link, but no global address yet. DNS servers reachable
// via a route that doesn't require a gateway: give them the benefit of the
// doubt and hope the link-local source address suffices for communication.
assertTrue(v6lp.addRoute(new RouteInfo(new IpPrefix(NetworkUtils.numericToInetAddress("2001:db8:85a3::"), 64))));
assertFalse(v6lp.isReachable(kLinkLocalDns));
assertTrue(v6lp.isReachable(kLinkLocalDnsWithScope));
assertTrue(v6lp.isReachable(kOnLinkDns));
assertFalse(v6lp.isReachable(DNS6));
// Add a global address; the on-link global address DNS server is (still)
// presumed reachable.
assertTrue(v6lp.addLinkAddress(new LinkAddress(ADDRV6, 64)));
assertFalse(v6lp.isReachable(kLinkLocalDns));
assertTrue(v6lp.isReachable(kLinkLocalDnsWithScope));
assertTrue(v6lp.isReachable(kOnLinkDns));
assertFalse(v6lp.isReachable(DNS6));
// Adding a default route makes the off-link DNS server reachable.
assertTrue(v6lp.addRoute(new RouteInfo(GATEWAY62)));
assertFalse(v6lp.isReachable(kLinkLocalDns));
assertTrue(v6lp.isReachable(kLinkLocalDnsWithScope));
assertTrue(v6lp.isReachable(kOnLinkDns));
assertTrue(v6lp.isReachable(DNS6));
// Check isReachable on stacked links. This requires that the source IP address be assigned
// on the interface returned by the route lookup.
LinkProperties stacked = new LinkProperties();
// Can't add a stacked link without an interface name.
stacked.setInterfaceName("v4-test0");
v6lp.addStackedLink(stacked);
InetAddress stackedAddress = Address("192.0.0.4");
LinkAddress stackedLinkAddress = new LinkAddress(stackedAddress, 32);
assertFalse(v6lp.isReachable(stackedAddress));
stacked.addLinkAddress(stackedLinkAddress);
assertFalse(v6lp.isReachable(stackedAddress));
stacked.addRoute(new RouteInfo(stackedLinkAddress));
assertTrue(stacked.isReachable(stackedAddress));
assertTrue(v6lp.isReachable(stackedAddress));
assertFalse(v6lp.isReachable(DNS1));
stacked.addRoute(new RouteInfo((IpPrefix) null, stackedAddress));
assertTrue(v6lp.isReachable(DNS1));
}
use of android.net.LinkAddress in project android_frameworks_base by crdroidandroid.
the class VpnConfig method addLegacyAddresses.
public void addLegacyAddresses(String addressesStr) {
if (addressesStr.trim().equals("")) {
return;
}
String[] addresses = addressesStr.trim().split(" ");
for (String address : addresses) {
//each address is ip/prefix
LinkAddress addr = new LinkAddress(address);
this.addresses.add(addr);
updateAllowedFamilies(addr.getAddress());
}
}
use of android.net.LinkAddress in project android_frameworks_base by crdroidandroid.
the class IpConfigStore method writeConfig.
private boolean writeConfig(DataOutputStream out, int configKey, IpConfiguration config) throws IOException {
boolean written = false;
try {
switch(config.ipAssignment) {
case STATIC:
out.writeUTF(IP_ASSIGNMENT_KEY);
out.writeUTF(config.ipAssignment.toString());
StaticIpConfiguration staticIpConfiguration = config.staticIpConfiguration;
if (staticIpConfiguration != null) {
if (staticIpConfiguration.ipAddress != null) {
LinkAddress ipAddress = staticIpConfiguration.ipAddress;
out.writeUTF(LINK_ADDRESS_KEY);
out.writeUTF(ipAddress.getAddress().getHostAddress());
out.writeInt(ipAddress.getPrefixLength());
}
if (staticIpConfiguration.gateway != null) {
out.writeUTF(GATEWAY_KEY);
// Default route.
out.writeInt(0);
// Have a gateway.
out.writeInt(1);
out.writeUTF(staticIpConfiguration.gateway.getHostAddress());
}
for (InetAddress inetAddr : staticIpConfiguration.dnsServers) {
out.writeUTF(DNS_KEY);
out.writeUTF(inetAddr.getHostAddress());
}
}
written = true;
break;
case DHCP:
out.writeUTF(IP_ASSIGNMENT_KEY);
out.writeUTF(config.ipAssignment.toString());
written = true;
break;
case UNASSIGNED:
/* Ignore */
break;
default:
loge("Ignore invalid ip assignment while writing");
break;
}
switch(config.proxySettings) {
case STATIC:
ProxyInfo proxyProperties = config.httpProxy;
String exclusionList = proxyProperties.getExclusionListAsString();
out.writeUTF(PROXY_SETTINGS_KEY);
out.writeUTF(config.proxySettings.toString());
out.writeUTF(PROXY_HOST_KEY);
out.writeUTF(proxyProperties.getHost());
out.writeUTF(PROXY_PORT_KEY);
out.writeInt(proxyProperties.getPort());
if (exclusionList != null) {
out.writeUTF(EXCLUSION_LIST_KEY);
out.writeUTF(exclusionList);
}
written = true;
break;
case PAC:
ProxyInfo proxyPacProperties = config.httpProxy;
out.writeUTF(PROXY_SETTINGS_KEY);
out.writeUTF(config.proxySettings.toString());
out.writeUTF(PROXY_PAC_FILE);
out.writeUTF(proxyPacProperties.getPacFileUrl().toString());
written = true;
break;
case NONE:
out.writeUTF(PROXY_SETTINGS_KEY);
out.writeUTF(config.proxySettings.toString());
written = true;
break;
case UNASSIGNED:
/* Ignore */
break;
default:
loge("Ignore invalid proxy settings while writing");
break;
}
if (written) {
out.writeUTF(ID_KEY);
out.writeInt(configKey);
}
} catch (NullPointerException e) {
loge("Failure in writing " + config + e);
}
out.writeUTF(EOS);
return written;
}
Aggregations