Search in sources :

Example 16 with Inet6Address

use of java.net.Inet6Address in project platform_frameworks_base by android.

the class NetworkDiagnostics method prepareExplicitSourceIcmpMeasurements.

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);
            }
        }
    }
}
Also used : LinkAddress(android.net.LinkAddress) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress) Pair(android.util.Pair)

Example 17 with Inet6Address

use of java.net.Inet6Address in project platform_frameworks_base by android.

the class IpReachabilityMonitor method handleNeighborLost.

private void handleNeighborLost(String msg) {
    InetAddress ip = null;
    final ProvisioningChange delta;
    synchronized (mLock) {
        LinkProperties whatIfLp = new LinkProperties(mLinkProperties);
        for (Map.Entry<InetAddress, Short> entry : mIpWatchList.entrySet()) {
            if (entry.getValue() != StructNdMsg.NUD_FAILED) {
                continue;
            }
            ip = entry.getKey();
            for (RouteInfo route : mLinkProperties.getRoutes()) {
                if (ip.equals(route.getGateway())) {
                    whatIfLp.removeRoute(route);
                }
            }
            if (avoidingBadLinks() || !(ip instanceof Inet6Address)) {
                // We should do this unconditionally, but alas we cannot: b/31827713.
                whatIfLp.removeDnsServer(ip);
            }
        }
        delta = LinkProperties.compareProvisioning(mLinkProperties, whatIfLp);
    }
    if (delta == ProvisioningChange.LOST_PROVISIONING) {
        final String logMsg = "FAILURE: LOST_PROVISIONING, " + msg;
        Log.w(TAG, logMsg);
        if (mCallback != null) {
            // TODO: remove |ip| when the callback signature no longer has
            // an InetAddress argument.
            mCallback.notifyLost(ip, logMsg);
        }
    }
    logNudFailed(delta);
}
Also used : Inet6Address(java.net.Inet6Address) ProvisioningChange(android.net.LinkProperties.ProvisioningChange) RouteInfo(android.net.RouteInfo) InetAddress(java.net.InetAddress) LinkProperties(android.net.LinkProperties) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with Inet6Address

use of java.net.Inet6Address in project platform_frameworks_base by android.

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 19 with Inet6Address

use of java.net.Inet6Address in project platform_frameworks_base by android.

the class RtNetlinkNeighborMessage method newNewNeighborMessage.

/**
     * A convenience method to create an RTM_NEWNEIGH message, to modify
     * the kernel's state information for a specific neighbor.
     */
public static byte[] newNewNeighborMessage(int seqNo, InetAddress ip, short nudState, int ifIndex, byte[] llAddr) {
    final StructNlMsgHdr nlmsghdr = new StructNlMsgHdr();
    nlmsghdr.nlmsg_type = NetlinkConstants.RTM_NEWNEIGH;
    nlmsghdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_REPLACE;
    nlmsghdr.nlmsg_seq = seqNo;
    final RtNetlinkNeighborMessage msg = new RtNetlinkNeighborMessage(nlmsghdr);
    msg.mNdmsg = new StructNdMsg();
    msg.mNdmsg.ndm_family = (byte) ((ip instanceof Inet6Address) ? OsConstants.AF_INET6 : OsConstants.AF_INET);
    msg.mNdmsg.ndm_ifindex = ifIndex;
    msg.mNdmsg.ndm_state = nudState;
    msg.mDestination = ip;
    // might be null
    msg.mLinkLayerAddr = llAddr;
    final byte[] bytes = new byte[msg.getRequiredSpace()];
    nlmsghdr.nlmsg_len = bytes.length;
    final ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
    byteBuffer.order(ByteOrder.nativeOrder());
    msg.pack(byteBuffer);
    return bytes;
}
Also used : StructNlMsgHdr(android.net.netlink.StructNlMsgHdr) StructNdMsg(android.net.netlink.StructNdMsg) Inet6Address(java.net.Inet6Address) ByteBuffer(java.nio.ByteBuffer)

Example 20 with Inet6Address

use of java.net.Inet6Address in project platform_frameworks_base by android.

the class CommonTimeUtils method transactSetSockaddr.

public int transactSetSockaddr(int method_code, InetSocketAddress addr) {
    android.os.Parcel data = android.os.Parcel.obtain();
    android.os.Parcel reply = android.os.Parcel.obtain();
    int ret_val = ERROR;
    try {
        data.writeInterfaceToken(mInterfaceDesc);
        if (null == addr) {
            data.writeInt(0);
        } else {
            data.writeInt(1);
            final InetAddress a = addr.getAddress();
            final byte[] b = a.getAddress();
            final int p = addr.getPort();
            if (a instanceof Inet4Address) {
                int v4addr = (((int) b[0] & 0xFF) << 24) | (((int) b[1] & 0xFF) << 16) | (((int) b[2] & 0xFF) << 8) | ((int) b[3] & 0xFF);
                data.writeInt(AF_INET);
                data.writeInt(v4addr);
                data.writeInt(p);
            } else if (a instanceof Inet6Address) {
                int i;
                Inet6Address v6 = (Inet6Address) a;
                data.writeInt(AF_INET6);
                for (i = 0; i < 4; ++i) {
                    int aword = (((int) b[(i * 4) + 0] & 0xFF) << 24) | (((int) b[(i * 4) + 1] & 0xFF) << 16) | (((int) b[(i * 4) + 2] & 0xFF) << 8) | ((int) b[(i * 4) + 3] & 0xFF);
                    data.writeInt(aword);
                }
                data.writeInt(p);
                // flow info
                data.writeInt(0);
                data.writeInt(v6.getScopeId());
            } else {
                return ERROR_BAD_VALUE;
            }
        }
        mRemote.transact(method_code, data, reply, 0);
        ret_val = reply.readInt();
    } catch (RemoteException e) {
        ret_val = ERROR_DEAD_OBJECT;
    } finally {
        reply.recycle();
        data.recycle();
    }
    return ret_val;
}
Also used : Inet4Address(java.net.Inet4Address) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress)

Aggregations

Inet6Address (java.net.Inet6Address)137 InetAddress (java.net.InetAddress)92 Inet4Address (java.net.Inet4Address)45 NetworkInterface (java.net.NetworkInterface)28 LinkAddress (android.net.LinkAddress)21 IpPrefix (android.net.IpPrefix)19 IOException (java.io.IOException)18 UnknownHostException (java.net.UnknownHostException)17 LinkProperties (android.net.LinkProperties)15 SocketException (java.net.SocketException)15 RouteInfo (android.net.RouteInfo)14 InetSocketAddress (java.net.InetSocketAddress)12 ByteBuffer (java.nio.ByteBuffer)9 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 RaParams (android.net.ip.RouterAdvertisementDaemon.RaParams)5 Pair (android.util.Pair)5 ProvisioningChange (android.net.LinkProperties.ProvisioningChange)4 StructNdMsg (android.net.netlink.StructNdMsg)4