Search in sources :

Example 11 with LinkAddress

use of android.net.LinkAddress in project platform_frameworks_base by android.

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());
    }
}
Also used : LinkAddress(android.net.LinkAddress)

Example 12 with LinkAddress

use of android.net.LinkAddress in project platform_frameworks_base by android.

the class LinkPropertiesTest method testEqualsSameOrder.

@SmallTest
public void testEqualsSameOrder() {
    try {
        LinkProperties source = new LinkProperties();
        source.setInterfaceName(NAME);
        // set 2 link addresses
        source.addLinkAddress(LINKADDRV4);
        source.addLinkAddress(LINKADDRV6);
        // set 2 dnses
        source.addDnsServer(DNS1);
        source.addDnsServer(DNS2);
        // set 2 gateways
        source.addRoute(new RouteInfo(GATEWAY1));
        source.addRoute(new RouteInfo(GATEWAY2));
        source.setMtu(MTU);
        LinkProperties target = new LinkProperties();
        // All fields are same
        target.setInterfaceName(NAME);
        target.addLinkAddress(LINKADDRV4);
        target.addLinkAddress(LINKADDRV6);
        target.addDnsServer(DNS1);
        target.addDnsServer(DNS2);
        target.addRoute(new RouteInfo(GATEWAY1));
        target.addRoute(new RouteInfo(GATEWAY2));
        target.setMtu(MTU);
        assertLinkPropertiesEqual(source, target);
        target.clear();
        // change Interface Name
        target.setInterfaceName("qmi1");
        target.addLinkAddress(LINKADDRV4);
        target.addLinkAddress(LINKADDRV6);
        target.addDnsServer(DNS1);
        target.addDnsServer(DNS2);
        target.addRoute(new RouteInfo(GATEWAY1));
        target.addRoute(new RouteInfo(GATEWAY2));
        target.setMtu(MTU);
        assertFalse(source.equals(target));
        target.clear();
        target.setInterfaceName(NAME);
        // change link addresses
        target.addLinkAddress(new LinkAddress(NetworkUtils.numericToInetAddress("75.208.6.2"), 32));
        target.addLinkAddress(LINKADDRV6);
        target.addDnsServer(DNS1);
        target.addDnsServer(DNS2);
        target.addRoute(new RouteInfo(GATEWAY1));
        target.addRoute(new RouteInfo(GATEWAY2));
        target.setMtu(MTU);
        assertFalse(source.equals(target));
        target.clear();
        target.setInterfaceName(NAME);
        target.addLinkAddress(LINKADDRV4);
        target.addLinkAddress(LINKADDRV6);
        // change dnses
        target.addDnsServer(NetworkUtils.numericToInetAddress("75.208.7.2"));
        target.addDnsServer(DNS2);
        target.addRoute(new RouteInfo(GATEWAY1));
        target.addRoute(new RouteInfo(GATEWAY2));
        target.setMtu(MTU);
        assertFalse(source.equals(target));
        target.clear();
        target.setInterfaceName(NAME);
        target.addLinkAddress(LINKADDRV4);
        target.addLinkAddress(LINKADDRV6);
        target.addDnsServer(DNS1);
        target.addDnsServer(DNS2);
        // change gateway
        target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress("75.208.8.2")));
        target.addRoute(new RouteInfo(GATEWAY2));
        target.setMtu(MTU);
        assertFalse(source.equals(target));
        target.clear();
        target.setInterfaceName(NAME);
        target.addLinkAddress(LINKADDRV4);
        target.addLinkAddress(LINKADDRV6);
        target.addDnsServer(DNS1);
        target.addDnsServer(DNS2);
        target.addRoute(new RouteInfo(GATEWAY1));
        target.addRoute(new RouteInfo(GATEWAY2));
        // change mtu
        target.setMtu(1440);
        assertFalse(source.equals(target));
    } catch (Exception e) {
        throw new RuntimeException(e.toString());
    //fail();
    }
}
Also used : LinkAddress(android.net.LinkAddress) RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 13 with LinkAddress

use of android.net.LinkAddress in project platform_frameworks_base by android.

the class LinkPropertiesTest method testAddressMethods.

@SmallTest
public void testAddressMethods() {
    LinkProperties lp = new LinkProperties();
    // No addresses.
    assertFalse(lp.hasIPv4Address());
    assertFalse(lp.hasGlobalIPv6Address());
    // Addresses on stacked links don't count.
    LinkProperties stacked = new LinkProperties();
    stacked.setInterfaceName("stacked");
    lp.addStackedLink(stacked);
    stacked.addLinkAddress(LINKADDRV4);
    stacked.addLinkAddress(LINKADDRV6);
    assertTrue(stacked.hasIPv4Address());
    assertTrue(stacked.hasGlobalIPv6Address());
    assertFalse(lp.hasIPv4Address());
    assertFalse(lp.hasGlobalIPv6Address());
    lp.removeStackedLink("stacked");
    assertFalse(lp.hasIPv4Address());
    assertFalse(lp.hasGlobalIPv6Address());
    // Addresses on the base link.
    // Check the return values of hasIPvXAddress and ensure the add/remove methods return true
    // iff something changes.
    assertEquals(0, lp.getLinkAddresses().size());
    assertTrue(lp.addLinkAddress(LINKADDRV6));
    assertEquals(1, lp.getLinkAddresses().size());
    assertFalse(lp.hasIPv4Address());
    assertTrue(lp.hasGlobalIPv6Address());
    assertTrue(lp.removeLinkAddress(LINKADDRV6));
    assertEquals(0, lp.getLinkAddresses().size());
    assertTrue(lp.addLinkAddress(LINKADDRV6LINKLOCAL));
    assertEquals(1, lp.getLinkAddresses().size());
    assertFalse(lp.hasGlobalIPv6Address());
    assertTrue(lp.addLinkAddress(LINKADDRV4));
    assertEquals(2, lp.getLinkAddresses().size());
    assertTrue(lp.hasIPv4Address());
    assertFalse(lp.hasGlobalIPv6Address());
    assertTrue(lp.addLinkAddress(LINKADDRV6));
    assertEquals(3, lp.getLinkAddresses().size());
    assertTrue(lp.hasIPv4Address());
    assertTrue(lp.hasGlobalIPv6Address());
    assertTrue(lp.removeLinkAddress(LINKADDRV6LINKLOCAL));
    assertEquals(2, lp.getLinkAddresses().size());
    assertTrue(lp.hasIPv4Address());
    assertTrue(lp.hasGlobalIPv6Address());
    // Adding an address twice has no effect.
    // Removing an address that's not present has no effect.
    assertFalse(lp.addLinkAddress(LINKADDRV4));
    assertEquals(2, lp.getLinkAddresses().size());
    assertTrue(lp.hasIPv4Address());
    assertTrue(lp.removeLinkAddress(LINKADDRV4));
    assertEquals(1, lp.getLinkAddresses().size());
    assertFalse(lp.hasIPv4Address());
    assertFalse(lp.removeLinkAddress(LINKADDRV4));
    assertEquals(1, lp.getLinkAddresses().size());
    // Adding an address that's already present but with different properties causes the
    // existing address to be updated and returns true.
    // Start with only LINKADDRV6.
    assertEquals(1, lp.getLinkAddresses().size());
    assertEquals(LINKADDRV6, getFirstLinkAddress(lp));
    // Create a LinkAddress object for the same address, but with different flags.
    LinkAddress deprecated = new LinkAddress(ADDRV6, 128, OsConstants.IFA_F_DEPRECATED, OsConstants.RT_SCOPE_UNIVERSE);
    assertTrue(deprecated.isSameAddressAs(LINKADDRV6));
    assertFalse(deprecated.equals(LINKADDRV6));
    // Check that adding it updates the existing address instead of adding a new one.
    assertTrue(lp.addLinkAddress(deprecated));
    assertEquals(1, lp.getLinkAddresses().size());
    assertEquals(deprecated, getFirstLinkAddress(lp));
    assertFalse(LINKADDRV6.equals(getFirstLinkAddress(lp)));
    // Removing LINKADDRV6 removes deprecated, because removing addresses ignores properties.
    assertTrue(lp.removeLinkAddress(LINKADDRV6));
    assertEquals(0, lp.getLinkAddresses().size());
}
Also used : LinkAddress(android.net.LinkAddress) LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 14 with LinkAddress

use of android.net.LinkAddress in project platform_frameworks_base by android.

the class LinkAddressTest method testIsGlobalPreferred.

public void testIsGlobalPreferred() {
    LinkAddress l;
    l = new LinkAddress(V4_ADDRESS, 32, 0, RT_SCOPE_UNIVERSE);
    assertGlobalPreferred(l, "v4,global,noflags");
    l = new LinkAddress("10.10.1.7/23", 0, RT_SCOPE_UNIVERSE);
    assertGlobalPreferred(l, "v4-rfc1918,global,noflags");
    l = new LinkAddress("10.10.1.7/23", 0, RT_SCOPE_SITE);
    assertNotGlobalPreferred(l, "v4-rfc1918,site-local,noflags");
    l = new LinkAddress("127.0.0.7/8", 0, RT_SCOPE_HOST);
    assertNotGlobalPreferred(l, "v4-localhost,node-local,noflags");
    l = new LinkAddress(V6_ADDRESS, 64, 0, RT_SCOPE_UNIVERSE);
    assertGlobalPreferred(l, "v6,global,noflags");
    l = new LinkAddress(V6_ADDRESS, 64, IFA_F_PERMANENT, RT_SCOPE_UNIVERSE);
    assertGlobalPreferred(l, "v6,global,permanent");
    // IPv6 ULAs are not acceptable "global preferred" addresses.
    l = new LinkAddress("fc12::1/64", 0, RT_SCOPE_UNIVERSE);
    assertNotGlobalPreferred(l, "v6,ula1,noflags");
    l = new LinkAddress("fd34::1/64", 0, RT_SCOPE_UNIVERSE);
    assertNotGlobalPreferred(l, "v6,ula2,noflags");
    l = new LinkAddress(V6_ADDRESS, 64, IFA_F_TEMPORARY, RT_SCOPE_UNIVERSE);
    assertGlobalPreferred(l, "v6,global,tempaddr");
    l = new LinkAddress(V6_ADDRESS, 64, (IFA_F_TEMPORARY | IFA_F_DADFAILED), RT_SCOPE_UNIVERSE);
    assertNotGlobalPreferred(l, "v6,global,tempaddr+dadfailed");
    l = new LinkAddress(V6_ADDRESS, 64, (IFA_F_TEMPORARY | IFA_F_DEPRECATED), RT_SCOPE_UNIVERSE);
    assertNotGlobalPreferred(l, "v6,global,tempaddr+deprecated");
    l = new LinkAddress(V6_ADDRESS, 64, IFA_F_TEMPORARY, RT_SCOPE_SITE);
    assertNotGlobalPreferred(l, "v6,site-local,tempaddr");
    l = new LinkAddress(V6_ADDRESS, 64, IFA_F_TEMPORARY, RT_SCOPE_LINK);
    assertNotGlobalPreferred(l, "v6,link-local,tempaddr");
    l = new LinkAddress(V6_ADDRESS, 64, IFA_F_TEMPORARY, RT_SCOPE_HOST);
    assertNotGlobalPreferred(l, "v6,node-local,tempaddr");
    l = new LinkAddress("::1/128", IFA_F_PERMANENT, RT_SCOPE_HOST);
    assertNotGlobalPreferred(l, "v6-localhost,node-local,permanent");
    l = new LinkAddress(V6_ADDRESS, 64, (IFA_F_TEMPORARY | IFA_F_TENTATIVE), RT_SCOPE_UNIVERSE);
    assertNotGlobalPreferred(l, "v6,global,tempaddr+tentative");
    l = new LinkAddress(V6_ADDRESS, 64, (IFA_F_TEMPORARY | IFA_F_TENTATIVE | IFA_F_OPTIMISTIC), RT_SCOPE_UNIVERSE);
    assertGlobalPreferred(l, "v6,global,tempaddr+optimistic");
}
Also used : LinkAddress(android.net.LinkAddress)

Example 15 with LinkAddress

use of android.net.LinkAddress in project platform_frameworks_base by android.

the class LinkAddressTest method passThroughParcel.

private LinkAddress passThroughParcel(LinkAddress l) {
    Parcel p = Parcel.obtain();
    LinkAddress l2 = null;
    try {
        l.writeToParcel(p, 0);
        p.setDataPosition(0);
        l2 = LinkAddress.CREATOR.createFromParcel(p);
    } finally {
        p.recycle();
    }
    assertNotNull(l2);
    return l2;
}
Also used : LinkAddress(android.net.LinkAddress) Parcel(android.os.Parcel)

Aggregations

LinkAddress (android.net.LinkAddress)210 LinkProperties (android.net.LinkProperties)70 InetAddress (java.net.InetAddress)70 RouteInfo (android.net.RouteInfo)52 SmallTest (android.test.suitebuilder.annotation.SmallTest)29 RemoteException (android.os.RemoteException)27 Inet4Address (java.net.Inet4Address)24 InterfaceConfiguration (android.net.InterfaceConfiguration)22 Inet6Address (java.net.Inet6Address)21 IpPrefix (android.net.IpPrefix)20 StaticIpConfiguration (android.net.StaticIpConfiguration)20 IOException (java.io.IOException)15 ApfFilter (android.net.apf.ApfFilter)12 ByteBuffer (java.nio.ByteBuffer)12 ProxyInfo (android.net.ProxyInfo)10 VpnConfig (com.android.internal.net.VpnConfig)10 DhcpResults (android.net.DhcpResults)9 LargeTest (android.test.suitebuilder.annotation.LargeTest)9 Command (com.android.server.NativeDaemonConnector.Command)9 EOFException (java.io.EOFException)6