Search in sources :

Example 16 with RouteInfo

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

the class IpReachabilityMonitor method updateLinkProperties.

public void updateLinkProperties(LinkProperties lp) {
    if (!mInterfaceName.equals(lp.getInterfaceName())) {
        // TODO: figure out whether / how to cope with interface changes.
        Log.wtf(TAG, "requested LinkProperties interface '" + lp.getInterfaceName() + "' does not match: " + mInterfaceName);
        return;
    }
    synchronized (mLock) {
        mLinkProperties = new LinkProperties(lp);
        Map<InetAddress, Short> newIpWatchList = new HashMap<>();
        final List<RouteInfo> routes = mLinkProperties.getRoutes();
        for (RouteInfo route : routes) {
            if (route.hasGateway()) {
                InetAddress gw = route.getGateway();
                if (isOnLink(routes, gw)) {
                    newIpWatchList.put(gw, getNeighborStateLocked(gw));
                }
            }
        }
        for (InetAddress nameserver : lp.getDnsServers()) {
            if (isOnLink(routes, nameserver)) {
                newIpWatchList.put(nameserver, getNeighborStateLocked(nameserver));
            }
        }
        mIpWatchList = newIpWatchList;
        mIpWatchListVersion++;
    }
    if (DBG) {
        Log.d(TAG, "watch: " + describeWatchList());
    }
}
Also used : HashMap(java.util.HashMap) RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress)

Example 17 with RouteInfo

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

the class IpReachabilityMonitor method handleNeighborLost.

private void handleNeighborLost(String msg) {
    InetAddress ip = null;
    final ProvisioningChange delta;
    synchronized (mLock) {
        LinkProperties whatIfLp = new LinkProperties(mLinkProperties);
        for (Map.Entry<InetAddress, Short> entry : mIpWatchList.entrySet()) {
            if (entry.getValue() != StructNdMsg.NUD_FAILED) {
                continue;
            }
            ip = entry.getKey();
            for (RouteInfo route : mLinkProperties.getRoutes()) {
                if (ip.equals(route.getGateway())) {
                    whatIfLp.removeRoute(route);
                }
            }
            if (avoidingBadLinks() || !(ip instanceof Inet6Address)) {
                // We should do this unconditionally, but alas we cannot: b/31827713.
                whatIfLp.removeDnsServer(ip);
            }
        }
        delta = LinkProperties.compareProvisioning(mLinkProperties, whatIfLp);
    }
    if (delta == ProvisioningChange.LOST_PROVISIONING) {
        final String logMsg = "FAILURE: LOST_PROVISIONING, " + msg;
        Log.w(TAG, logMsg);
        if (mCallback != null) {
            // TODO: remove |ip| when the callback signature no longer has
            // an InetAddress argument.
            mCallback.notifyLost(ip, logMsg);
        }
    }
    logNudFailed(delta);
}
Also used : Inet6Address(java.net.Inet6Address) ProvisioningChange(android.net.LinkProperties.ProvisioningChange) RouteInfo(android.net.RouteInfo) InetAddress(java.net.InetAddress) LinkProperties(android.net.LinkProperties) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with RouteInfo

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

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));
}
Also used : IpPrefix(android.net.IpPrefix) LinkAddress(android.net.LinkAddress) RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress) SmallTest(android.test.suitebuilder.annotation.SmallTest) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 19 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 20 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)

Aggregations

RouteInfo (android.net.RouteInfo)168 LinkProperties (android.net.LinkProperties)73 LinkAddress (android.net.LinkAddress)60 InetAddress (java.net.InetAddress)57 SmallTest (android.test.suitebuilder.annotation.SmallTest)45 IpPrefix (android.net.IpPrefix)35 Inet6Address (java.net.Inet6Address)21 Inet4Address (java.net.Inet4Address)20 IOException (java.io.IOException)11 StaticIpConfiguration (android.net.StaticIpConfiguration)10 EOFException (java.io.EOFException)8 DataInputStream (java.io.DataInputStream)7 UnknownHostException (java.net.UnknownHostException)7 HashMap (java.util.HashMap)7 StringJoiner (java.util.StringJoiner)7 Parcel (android.os.Parcel)6 BufferedInputStream (java.io.BufferedInputStream)6 FileInputStream (java.io.FileInputStream)6 ArrayList (java.util.ArrayList)6 UserInfo (android.content.pm.UserInfo)5