Search in sources :

Example 71 with IpPrefix

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

the class IpPrefixTest method testEquals.

@SmallTest
public void testEquals() {
    IpPrefix p1, p2;
    p1 = new IpPrefix("192.0.2.251/23");
    p2 = new IpPrefix(new byte[] { (byte) 192, (byte) 0, (byte) 2, (byte) 251 }, 23);
    assertAreEqual(p1, p2);
    p1 = new IpPrefix("192.0.2.5/23");
    assertAreEqual(p1, p2);
    p1 = new IpPrefix("192.0.2.5/24");
    assertAreNotEqual(p1, p2);
    p1 = new IpPrefix("192.0.4.5/23");
    assertAreNotEqual(p1, p2);
    p1 = new IpPrefix("2001:db8:dead:beef:f00::80/122");
    p2 = new IpPrefix(IPV6_BYTES, 122);
    assertEquals("2001:db8:dead:beef:f00::80/122", p2.toString());
    assertAreEqual(p1, p2);
    p1 = new IpPrefix("2001:db8:dead:beef:f00::bf/122");
    assertAreEqual(p1, p2);
    p1 = new IpPrefix("2001:db8:dead:beef:f00::8:0/123");
    assertAreNotEqual(p1, p2);
    p1 = new IpPrefix("2001:db8:dead:beef::/122");
    assertAreNotEqual(p1, p2);
    // 192.0.2.4/32 != c000:0204::/32.
    byte[] ipv6bytes = new byte[16];
    System.arraycopy(IPV4_BYTES, 0, ipv6bytes, 0, IPV4_BYTES.length);
    p1 = new IpPrefix(ipv6bytes, 32);
    assertAreEqual(p1, new IpPrefix("c000:0204::/32"));
    p2 = new IpPrefix(IPV4_BYTES, 32);
    assertAreNotEqual(p1, p2);
}
Also used : IpPrefix(android.net.IpPrefix) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 72 with IpPrefix

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

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)

Example 73 with IpPrefix

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

the class RouteInfoTest method testConstructor.

@SmallTest
public void testConstructor() {
    RouteInfo r;
    // Invalid input.
    try {
        r = new RouteInfo((IpPrefix) null, null, "rmnet0");
        fail("Expected RuntimeException:  destination and gateway null");
    } catch (RuntimeException e) {
    }
    // Null destination is default route.
    r = new RouteInfo((IpPrefix) null, Address("2001:db8::1"), null);
    assertEquals(Prefix("::/0"), r.getDestination());
    assertEquals(Address("2001:db8::1"), r.getGateway());
    assertNull(r.getInterface());
    r = new RouteInfo((IpPrefix) null, Address("192.0.2.1"), "wlan0");
    assertEquals(Prefix("0.0.0.0/0"), r.getDestination());
    assertEquals(Address("192.0.2.1"), r.getGateway());
    assertEquals("wlan0", r.getInterface());
    // Null gateway sets gateway to unspecified address (why?).
    r = new RouteInfo(Prefix("2001:db8:beef:cafe::/48"), null, "lo");
    assertEquals(Prefix("2001:db8:beef::/48"), r.getDestination());
    assertEquals(Address("::"), r.getGateway());
    assertEquals("lo", r.getInterface());
    r = new RouteInfo(Prefix("192.0.2.5/24"), null);
    assertEquals(Prefix("192.0.2.0/24"), r.getDestination());
    assertEquals(Address("0.0.0.0"), r.getGateway());
    assertNull(r.getInterface());
}
Also used : IpPrefix(android.net.IpPrefix) RouteInfo(android.net.RouteInfo) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 74 with IpPrefix

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

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

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

the class Vpn method makeLinkProperties.

private LinkProperties makeLinkProperties() {
    boolean allowIPv4 = mConfig.allowIPv4;
    boolean allowIPv6 = mConfig.allowIPv6;
    LinkProperties lp = new LinkProperties();
    lp.setInterfaceName(mInterface);
    if (mConfig.addresses != null) {
        for (LinkAddress address : mConfig.addresses) {
            lp.addLinkAddress(address);
            allowIPv4 |= address.getAddress() instanceof Inet4Address;
            allowIPv6 |= address.getAddress() instanceof Inet6Address;
        }
    }
    if (mConfig.routes != null) {
        for (RouteInfo route : mConfig.routes) {
            lp.addRoute(route);
            InetAddress address = route.getDestination().getAddress();
            allowIPv4 |= address instanceof Inet4Address;
            allowIPv6 |= address instanceof Inet6Address;
        }
    }
    if (mConfig.dnsServers != null) {
        for (String dnsServer : mConfig.dnsServers) {
            InetAddress address = InetAddress.parseNumericAddress(dnsServer);
            lp.addDnsServer(address);
            allowIPv4 |= address instanceof Inet4Address;
            allowIPv6 |= address instanceof Inet6Address;
        }
    }
    if (!allowIPv4) {
        lp.addRoute(new RouteInfo(new IpPrefix(Inet4Address.ANY, 0), RTN_UNREACHABLE));
    }
    if (!allowIPv6) {
        lp.addRoute(new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), RTN_UNREACHABLE));
    }
    // Concatenate search domains into a string.
    StringBuilder buffer = new StringBuilder();
    if (mConfig.searchDomains != null) {
        for (String domain : mConfig.searchDomains) {
            buffer.append(domain).append(' ');
        }
    }
    lp.setDomains(buffer.toString().trim());
    return lp;
}
Also used : LinkAddress(android.net.LinkAddress) IpPrefix(android.net.IpPrefix) Inet4Address(java.net.Inet4Address) Inet6Address(java.net.Inet6Address) RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress)

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