Search in sources :

Example 56 with IpPrefix

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

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_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 57 with IpPrefix

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

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)

Example 58 with IpPrefix

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

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

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

the class RouterAdvertisementDaemon method assembleRaLocked.

private void assembleRaLocked() {
    final ByteBuffer ra = ByteBuffer.wrap(mRA);
    ra.order(ByteOrder.BIG_ENDIAN);
    boolean shouldSendRA = false;
    try {
        putHeader(ra, mRaParams != null && mRaParams.hasDefaultRoute);
        putSlla(ra, mHwAddr);
        mRaLength = ra.position();
        if (mRaParams != null) {
            putMtu(ra, mRaParams.mtu);
            mRaLength = ra.position();
            for (IpPrefix ipp : mRaParams.prefixes) {
                putPio(ra, ipp, DEFAULT_LIFETIME, DEFAULT_LIFETIME);
                mRaLength = ra.position();
                shouldSendRA = true;
            }
            if (mRaParams.dnses.size() > 0) {
                putRdnss(ra, mRaParams.dnses, DEFAULT_LIFETIME);
                mRaLength = ra.position();
                shouldSendRA = true;
            }
        }
        for (IpPrefix ipp : mDeprecatedInfoTracker.getPrefixes()) {
            putPio(ra, ipp, 0, 0);
            mRaLength = ra.position();
            shouldSendRA = true;
        }
        final Set<Inet6Address> deprecatedDnses = mDeprecatedInfoTracker.getDnses();
        if (!deprecatedDnses.isEmpty()) {
            putRdnss(ra, deprecatedDnses, 0);
            mRaLength = ra.position();
            shouldSendRA = true;
        }
    } catch (BufferOverflowException e) {
        // The packet up to mRaLength  is valid, since it has been updated
        // progressively as the RA was built. Log an error, and continue
        // on as best as possible.
        Log.e(TAG, "Could not construct new RA: " + e);
    }
    // We have nothing worth announcing; indicate as much to maybeSendRA().
    if (!shouldSendRA) {
        mRaLength = 0;
    }
}
Also used : IpPrefix(android.net.IpPrefix) Inet6Address(java.net.Inet6Address) BufferOverflowException(java.nio.BufferOverflowException) ByteBuffer(java.nio.ByteBuffer)

Example 60 with IpPrefix

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

the class IpPrefixTest method assertParcelingIsLossless.

public void assertParcelingIsLossless(IpPrefix p) {
    IpPrefix p2 = passThroughParcel(p);
    assertEquals(p, p2);
}
Also used : IpPrefix(android.net.IpPrefix)

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