Java Code Examples for android.net.LinkAddress#isGlobalPreferred()

The following examples show how to use android.net.LinkAddress#isGlobalPreferred() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetworkDiagnostics.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void prepareExplicitSourceIcmpMeasurements(InetAddress target) {
    for (LinkAddress l : mLinkProperties.getLinkAddresses()) {
        InetAddress source = l.getAddress();
        if (source instanceof Inet6Address && l.isGlobalPreferred()) {
            Pair<InetAddress, InetAddress> srcTarget = new Pair<>(source, target);
            if (!mExplicitSourceIcmpChecks.containsKey(srcTarget)) {
                Measurement measurement = new Measurement();
                measurement.thread = new Thread(new IcmpCheck(source, target, measurement));
                mExplicitSourceIcmpChecks.put(srcTarget, measurement);
            }
        }
    }
}
 
Example 2
Source File: OffloadController.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static Set<String> computeLocalPrefixStrings(
        Set<IpPrefix> localPrefixes, LinkProperties upstreamLinkProperties) {
    // Create an editable copy.
    final Set<IpPrefix> prefixSet = new HashSet<>(localPrefixes);

    // TODO: If a downstream interface (not currently passed in) is reusing
    // the /64 of the upstream (64share) then:
    //
    //     [a] remove that /64 from the local prefixes
    //     [b] add in /128s for IP addresses on the downstream interface
    //     [c] add in /128s for IP addresses on the upstream interface
    //
    // Until downstream information is available here, simply add /128s from
    // the upstream network; they'll just be redundant with their /64.
    if (upstreamLinkProperties != null) {
        for (LinkAddress linkAddr : upstreamLinkProperties.getLinkAddresses()) {
            if (!linkAddr.isGlobalPreferred()) continue;
            final InetAddress ip = linkAddr.getAddress();
            if (!(ip instanceof Inet6Address)) continue;
            prefixSet.add(new IpPrefix(ip, 128));
        }
    }

    final HashSet<String> localPrefixStrs = new HashSet<>();
    for (IpPrefix pfx : prefixSet) localPrefixStrs.add(pfx.toString());
    return localPrefixStrs;
}
 
Example 3
Source File: IPv6TetheringCoordinator.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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;
}