Search in sources :

Example 21 with IpPrefix

use of android.net.IpPrefix in project android_frameworks_base by AOSPA.

the class RouteInfoTest method testMatches.

public void testMatches() {
    class PatchedRouteInfo {

        private final RouteInfo mRouteInfo;

        public PatchedRouteInfo(IpPrefix destination, InetAddress gateway, String iface) {
            mRouteInfo = new RouteInfo(destination, gateway, iface);
        }

        public boolean matches(InetAddress destination) {
            return mRouteInfo.matches(destination);
        }
    }
    PatchedRouteInfo r;
    r = new PatchedRouteInfo(Prefix("2001:db8:f00::ace:d00d/127"), null, "rmnet0");
    assertTrue(r.matches(Address("2001:db8:f00::ace:d00c")));
    assertTrue(r.matches(Address("2001:db8:f00::ace:d00d")));
    assertFalse(r.matches(Address("2001:db8:f00::ace:d00e")));
    assertFalse(r.matches(Address("2001:db8:f00::bad:d00d")));
    assertFalse(r.matches(Address("2001:4868:4860::8888")));
    assertFalse(r.matches(Address("8.8.8.8")));
    r = new PatchedRouteInfo(Prefix("192.0.2.0/23"), null, "wlan0");
    assertTrue(r.matches(Address("192.0.2.43")));
    assertTrue(r.matches(Address("192.0.3.21")));
    assertFalse(r.matches(Address("192.0.0.21")));
    assertFalse(r.matches(Address("8.8.8.8")));
    PatchedRouteInfo ipv6Default = new PatchedRouteInfo(Prefix("::/0"), null, "rmnet0");
    assertTrue(ipv6Default.matches(Address("2001:db8::f00")));
    assertFalse(ipv6Default.matches(Address("192.0.2.1")));
    PatchedRouteInfo ipv4Default = new PatchedRouteInfo(Prefix("0.0.0.0/0"), null, "rmnet0");
    assertTrue(ipv4Default.matches(Address("255.255.255.255")));
    assertTrue(ipv4Default.matches(Address("192.0.2.1")));
    assertFalse(ipv4Default.matches(Address("2001:db8::f00")));
}
Also used : IpPrefix(android.net.IpPrefix) RouteInfo(android.net.RouteInfo) InetAddress(java.net.InetAddress)

Example 22 with IpPrefix

use of android.net.IpPrefix in project android_frameworks_base by AOSPA.

the class StaticIpConfigurationTest method testToLinkProperties.

@SmallTest
public void testToLinkProperties() {
    LinkProperties expected = new LinkProperties();
    expected.setInterfaceName(IFACE);
    StaticIpConfiguration s = new StaticIpConfiguration();
    assertEquals(expected, s.toLinkProperties(IFACE));
    final RouteInfo connectedRoute = new RouteInfo(new IpPrefix(ADDRSTR), null, IFACE);
    s.ipAddress = ADDR;
    expected.addLinkAddress(ADDR);
    expected.addRoute(connectedRoute);
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.gateway = GATEWAY;
    RouteInfo defaultRoute = new RouteInfo(new IpPrefix("0.0.0.0/0"), GATEWAY, IFACE);
    expected.addRoute(defaultRoute);
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.gateway = OFFLINKGATEWAY;
    expected.removeRoute(defaultRoute);
    defaultRoute = new RouteInfo(new IpPrefix("0.0.0.0/0"), OFFLINKGATEWAY, IFACE);
    expected.addRoute(defaultRoute);
    RouteInfo gatewayRoute = new RouteInfo(new IpPrefix("192.0.2.129/32"), null, IFACE);
    expected.addRoute(gatewayRoute);
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.dnsServers.add(DNS1);
    expected.addDnsServer(DNS1);
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.dnsServers.add(DNS2);
    s.dnsServers.add(DNS3);
    expected.addDnsServer(DNS2);
    expected.addDnsServer(DNS3);
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.domains = "google.com";
    expected.setDomains("google.com");
    assertEquals(expected, s.toLinkProperties(IFACE));
    s.gateway = null;
    expected.removeRoute(defaultRoute);
    expected.removeRoute(gatewayRoute);
    assertEquals(expected, s.toLinkProperties(IFACE));
    // Without knowing the IP address, we don't have a directly-connected route, so we can't
    // tell if the gateway is off-link or not and we don't add a host route. This isn't a real
    // configuration, but we should at least not crash.
    s.gateway = OFFLINKGATEWAY;
    s.ipAddress = null;
    expected.removeLinkAddress(ADDR);
    expected.removeRoute(connectedRoute);
    expected.addRoute(defaultRoute);
    assertEquals(expected, s.toLinkProperties(IFACE));
}
Also used : IpPrefix(android.net.IpPrefix) StaticIpConfiguration(android.net.StaticIpConfiguration) RouteInfo(android.net.RouteInfo) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 23 with IpPrefix

use of android.net.IpPrefix in project android_frameworks_base by AOSPA.

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 24 with IpPrefix

use of android.net.IpPrefix in project android_frameworks_base by AOSPA.

the class IPv6TetheringInterfaceServices method updateUpstreamIPv6LinkProperties.

// IPv6TetheringCoordinator sends updates with carefully curated IPv6-only
// LinkProperties. These have extraneous data filtered out and only the
// necessary prefixes included (per its prefix distribution policy).
//
// TODO: Evaluate using a data structure than is more directly suited to
// communicating only the relevant information.
public void updateUpstreamIPv6LinkProperties(LinkProperties v6only) {
    if (mRaDaemon == null)
        return;
    // Avoid unnecessary work on spurious updates.
    if (Objects.equals(mLastIPv6LinkProperties, v6only)) {
        return;
    }
    RaParams params = null;
    if (v6only != null) {
        params = new RaParams();
        params.mtu = v6only.getMtu();
        params.hasDefaultRoute = v6only.hasIPv6DefaultRoute();
        for (LinkAddress linkAddr : v6only.getLinkAddresses()) {
            if (linkAddr.getPrefixLength() != RFC7421_IP_PREFIX_LENGTH)
                continue;
            final IpPrefix prefix = new IpPrefix(linkAddr.getAddress(), linkAddr.getPrefixLength());
            params.prefixes.add(prefix);
            final Inet6Address dnsServer = getLocalDnsIpFor(prefix);
            if (dnsServer != null) {
                params.dnses.add(dnsServer);
            }
        }
    }
    // If v6only is null, we pass in null to setRaParams(), which handles
    // deprecation of any existing RA data.
    setRaParams(params);
    mLastIPv6LinkProperties = v6only;
}
Also used : LinkAddress(android.net.LinkAddress) IpPrefix(android.net.IpPrefix) RaParams(android.net.ip.RouterAdvertisementDaemon.RaParams) Inet6Address(java.net.Inet6Address)

Example 25 with IpPrefix

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

the class IpPrefixTest method testMappedAddressesAreBroken.

@SmallTest
public void testMappedAddressesAreBroken() {
    // 192.0.2.0/24 != ::ffff:c000:0204/120, but because we use InetAddress,
    // we are unable to comprehend that.
    byte[] ipv6bytes = { (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0xff, (byte) 0xff, (byte) 192, (byte) 0, (byte) 2, (byte) 0 };
    IpPrefix p = new IpPrefix(ipv6bytes, 120);
    // Fine.
    assertEquals(16, p.getRawAddress().length);
    // Fine.
    assertArrayEquals(ipv6bytes, p.getRawAddress());
    // Broken.
    assertEquals("192.0.2.0/120", p.toString());
    assertEquals(InetAddress.parseNumericAddress("192.0.2.0"), p.getAddress());
}
Also used : IpPrefix(android.net.IpPrefix) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

IpPrefix (android.net.IpPrefix)89 SmallTest (android.test.suitebuilder.annotation.SmallTest)40 RouteInfo (android.net.RouteInfo)35 InetAddress (java.net.InetAddress)25 LinkAddress (android.net.LinkAddress)20 Inet6Address (java.net.Inet6Address)19 LinkProperties (android.net.LinkProperties)15 StaticIpConfiguration (android.net.StaticIpConfiguration)5 RaParams (android.net.ip.RouterAdvertisementDaemon.RaParams)5 Parcel (android.os.Parcel)5 Suppress (android.test.suitebuilder.annotation.Suppress)5 Inet4Address (java.net.Inet4Address)5 Random (java.util.Random)5 BufferOverflowException (java.nio.BufferOverflowException)4 ByteBuffer (java.nio.ByteBuffer)4