Search in sources :

Example 66 with RouteInfo

use of android.net.RouteInfo in project android_frameworks_base by ResurrectionRemix.

the class LinkPropertiesTest method testIsProvisioned.

@SmallTest
public void testIsProvisioned() {
    LinkProperties lp4 = new LinkProperties();
    assertFalse("v4only:empty", lp4.isProvisioned());
    lp4.addLinkAddress(LINKADDRV4);
    assertFalse("v4only:addr-only", lp4.isProvisioned());
    lp4.addDnsServer(DNS1);
    assertFalse("v4only:addr+dns", lp4.isProvisioned());
    lp4.addRoute(new RouteInfo(GATEWAY1));
    assertTrue("v4only:addr+dns+route", lp4.isProvisioned());
    assertTrue("v4only:addr+dns+route", lp4.isIPv4Provisioned());
    assertFalse("v4only:addr+dns+route", lp4.isIPv6Provisioned());
    LinkProperties lp6 = new LinkProperties();
    assertFalse("v6only:empty", lp6.isProvisioned());
    lp6.addLinkAddress(LINKADDRV6LINKLOCAL);
    assertFalse("v6only:fe80-only", lp6.isProvisioned());
    lp6.addDnsServer(DNS6);
    assertFalse("v6only:fe80+dns", lp6.isProvisioned());
    lp6.addRoute(new RouteInfo(GATEWAY61));
    assertFalse("v6only:fe80+dns+route", lp6.isProvisioned());
    lp6.addLinkAddress(LINKADDRV6);
    assertTrue("v6only:fe80+global+dns+route", lp6.isIPv6Provisioned());
    assertTrue("v6only:fe80+global+dns+route", lp6.isProvisioned());
    lp6.removeLinkAddress(LINKADDRV6LINKLOCAL);
    assertFalse("v6only:global+dns+route", lp6.isIPv4Provisioned());
    assertTrue("v6only:global+dns+route", lp6.isIPv6Provisioned());
    assertTrue("v6only:global+dns+route", lp6.isProvisioned());
    LinkProperties lp46 = new LinkProperties();
    lp46.addLinkAddress(LINKADDRV4);
    lp46.addLinkAddress(LINKADDRV6);
    lp46.addDnsServer(DNS1);
    lp46.addDnsServer(DNS6);
    assertFalse("dualstack:missing-routes", lp46.isProvisioned());
    lp46.addRoute(new RouteInfo(GATEWAY1));
    assertTrue("dualstack:v4-provisioned", lp46.isIPv4Provisioned());
    assertFalse("dualstack:v4-provisioned", lp46.isIPv6Provisioned());
    assertTrue("dualstack:v4-provisioned", lp46.isProvisioned());
    lp46.addRoute(new RouteInfo(GATEWAY61));
    assertTrue("dualstack:both-provisioned", lp46.isIPv4Provisioned());
    assertTrue("dualstack:both-provisioned", lp46.isIPv6Provisioned());
    assertTrue("dualstack:both-provisioned", lp46.isProvisioned());
    // A link with an IPv6 address and default route, but IPv4 DNS server.
    LinkProperties mixed = new LinkProperties();
    mixed.addLinkAddress(LINKADDRV6);
    mixed.addDnsServer(DNS1);
    mixed.addRoute(new RouteInfo(GATEWAY61));
    assertFalse("mixed:addr6+route6+dns4", mixed.isIPv4Provisioned());
    assertFalse("mixed:addr6+route6+dns4", mixed.isIPv6Provisioned());
    assertFalse("mixed:addr6+route6+dns4", mixed.isProvisioned());
}
Also used : RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 67 with RouteInfo

use of android.net.RouteInfo in project android_frameworks_base by ResurrectionRemix.

the class VpnConfig method addLegacyRoutes.

public void addLegacyRoutes(String routesStr) {
    if (routesStr.trim().equals("")) {
        return;
    }
    String[] routes = routesStr.trim().split(" ");
    for (String route : routes) {
        //each route is ip/prefix
        RouteInfo info = new RouteInfo(new IpPrefix(route), null);
        this.routes.add(info);
        updateAllowedFamilies(info.getDestination().getAddress());
    }
}
Also used : IpPrefix(android.net.IpPrefix) RouteInfo(android.net.RouteInfo)

Example 68 with RouteInfo

use of android.net.RouteInfo in project android_frameworks_base by ResurrectionRemix.

the class IPv6TetheringCoordinator method getIPv6OnlyLinkProperties.

private static LinkProperties getIPv6OnlyLinkProperties(LinkProperties lp) {
    final LinkProperties v6only = new LinkProperties();
    if (lp == null) {
        return v6only;
    }
    // NOTE: At this time we don't copy over any information about any
    // stacked links. No current stacked link configuration has IPv6.
    v6only.setInterfaceName(lp.getInterfaceName());
    v6only.setMtu(lp.getMtu());
    for (LinkAddress linkAddr : lp.getLinkAddresses()) {
        if (linkAddr.isGlobalPreferred() && linkAddr.getPrefixLength() == 64) {
            v6only.addLinkAddress(linkAddr);
        }
    }
    for (RouteInfo routeInfo : lp.getRoutes()) {
        final IpPrefix destination = routeInfo.getDestination();
        if ((destination.getAddress() instanceof Inet6Address) && (destination.getPrefixLength() <= 64)) {
            v6only.addRoute(routeInfo);
        }
    }
    for (InetAddress dnsServer : lp.getDnsServers()) {
        if (isIPv6GlobalAddress(dnsServer)) {
            // For now we include ULAs.
            v6only.addDnsServer(dnsServer);
        }
    }
    v6only.setDomains(lp.getDomains());
    return v6only;
}
Also used : LinkAddress(android.net.LinkAddress) IpPrefix(android.net.IpPrefix) Inet6Address(java.net.Inet6Address) RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress)

Example 69 with RouteInfo

use of android.net.RouteInfo in project android_frameworks_base by crdroidandroid.

the class VpnConfig method addLegacyRoutes.

public void addLegacyRoutes(String routesStr) {
    if (routesStr.trim().equals("")) {
        return;
    }
    String[] routes = routesStr.trim().split(" ");
    for (String route : routes) {
        //each route is ip/prefix
        RouteInfo info = new RouteInfo(new IpPrefix(route), null);
        this.routes.add(info);
        updateAllowedFamilies(info.getDestination().getAddress());
    }
}
Also used : IpPrefix(android.net.IpPrefix) RouteInfo(android.net.RouteInfo)

Example 70 with RouteInfo

use of android.net.RouteInfo in project android_frameworks_base by crdroidandroid.

the class LinkPropertiesTest method testIsProvisioned.

@SmallTest
public void testIsProvisioned() {
    LinkProperties lp4 = new LinkProperties();
    assertFalse("v4only:empty", lp4.isProvisioned());
    lp4.addLinkAddress(LINKADDRV4);
    assertFalse("v4only:addr-only", lp4.isProvisioned());
    lp4.addDnsServer(DNS1);
    assertFalse("v4only:addr+dns", lp4.isProvisioned());
    lp4.addRoute(new RouteInfo(GATEWAY1));
    assertTrue("v4only:addr+dns+route", lp4.isProvisioned());
    assertTrue("v4only:addr+dns+route", lp4.isIPv4Provisioned());
    assertFalse("v4only:addr+dns+route", lp4.isIPv6Provisioned());
    LinkProperties lp6 = new LinkProperties();
    assertFalse("v6only:empty", lp6.isProvisioned());
    lp6.addLinkAddress(LINKADDRV6LINKLOCAL);
    assertFalse("v6only:fe80-only", lp6.isProvisioned());
    lp6.addDnsServer(DNS6);
    assertFalse("v6only:fe80+dns", lp6.isProvisioned());
    lp6.addRoute(new RouteInfo(GATEWAY61));
    assertFalse("v6only:fe80+dns+route", lp6.isProvisioned());
    lp6.addLinkAddress(LINKADDRV6);
    assertTrue("v6only:fe80+global+dns+route", lp6.isIPv6Provisioned());
    assertTrue("v6only:fe80+global+dns+route", lp6.isProvisioned());
    lp6.removeLinkAddress(LINKADDRV6LINKLOCAL);
    assertFalse("v6only:global+dns+route", lp6.isIPv4Provisioned());
    assertTrue("v6only:global+dns+route", lp6.isIPv6Provisioned());
    assertTrue("v6only:global+dns+route", lp6.isProvisioned());
    LinkProperties lp46 = new LinkProperties();
    lp46.addLinkAddress(LINKADDRV4);
    lp46.addLinkAddress(LINKADDRV6);
    lp46.addDnsServer(DNS1);
    lp46.addDnsServer(DNS6);
    assertFalse("dualstack:missing-routes", lp46.isProvisioned());
    lp46.addRoute(new RouteInfo(GATEWAY1));
    assertTrue("dualstack:v4-provisioned", lp46.isIPv4Provisioned());
    assertFalse("dualstack:v4-provisioned", lp46.isIPv6Provisioned());
    assertTrue("dualstack:v4-provisioned", lp46.isProvisioned());
    lp46.addRoute(new RouteInfo(GATEWAY61));
    assertTrue("dualstack:both-provisioned", lp46.isIPv4Provisioned());
    assertTrue("dualstack:both-provisioned", lp46.isIPv6Provisioned());
    assertTrue("dualstack:both-provisioned", lp46.isProvisioned());
    // A link with an IPv6 address and default route, but IPv4 DNS server.
    LinkProperties mixed = new LinkProperties();
    mixed.addLinkAddress(LINKADDRV6);
    mixed.addDnsServer(DNS1);
    mixed.addRoute(new RouteInfo(GATEWAY61));
    assertFalse("mixed:addr6+route6+dns4", mixed.isIPv4Provisioned());
    assertFalse("mixed:addr6+route6+dns4", mixed.isIPv6Provisioned());
    assertFalse("mixed:addr6+route6+dns4", mixed.isProvisioned());
}
Also used : RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

RouteInfo (android.net.RouteInfo)160 LinkProperties (android.net.LinkProperties)72 InetAddress (java.net.InetAddress)56 LinkAddress (android.net.LinkAddress)52 SmallTest (android.test.suitebuilder.annotation.SmallTest)45 IpPrefix (android.net.IpPrefix)35 Inet6Address (java.net.Inet6Address)14 Inet4Address (java.net.Inet4Address)12 IOException (java.io.IOException)11 StaticIpConfiguration (android.net.StaticIpConfiguration)10 EOFException (java.io.EOFException)8 DataInputStream (java.io.DataInputStream)7 HashMap (java.util.HashMap)7 Parcel (android.os.Parcel)6 BufferedInputStream (java.io.BufferedInputStream)6 FileInputStream (java.io.FileInputStream)6 UnknownHostException (java.net.UnknownHostException)6 ArrayList (java.util.ArrayList)6 UserInfo (android.content.pm.UserInfo)5 IpConfiguration (android.net.IpConfiguration)5