Search in sources :

Example 81 with LinkProperties

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

the class ApfTest method testApfFilterArp.

@LargeTest
public void testApfFilterArp() throws Exception {
    MockIpManagerCallback ipManagerCallback = new MockIpManagerCallback();
    ApfFilter apfFilter = new TestApfFilter(ipManagerCallback, ALLOW_MULTICAST, mLog);
    // Verify initially ARP request filter is off, and GARP filter is on.
    verifyArpFilter(ipManagerCallback.getApfProgram(), PASS);
    // Inform ApfFilter of our address and verify ARP filtering is on
    LinkAddress linkAddress = new LinkAddress(InetAddress.getByAddress(MOCK_IPV4_ADDR), 24);
    LinkProperties lp = new LinkProperties();
    assertTrue(lp.addLinkAddress(linkAddress));
    verifyArpFilter(getProgram(ipManagerCallback, apfFilter, lp), DROP);
    // Inform ApfFilter of loss of IP and verify ARP filtering is off
    verifyArpFilter(getProgram(ipManagerCallback, apfFilter, new LinkProperties()), PASS);
    apfFilter.shutdown();
}
Also used : LinkAddress(android.net.LinkAddress) ApfFilter(android.net.apf.ApfFilter) LinkProperties(android.net.LinkProperties) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 82 with LinkProperties

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

the class ApfTest method testApfFilterMulticast.

@LargeTest
public void testApfFilterMulticast() throws Exception {
    final byte[] unicastIpv4Addr = { (byte) 192, 0, 2, 63 };
    final byte[] broadcastIpv4Addr = { (byte) 192, 0, 2, (byte) 255 };
    final byte[] multicastIpv4Addr = { (byte) 224, 0, 0, 1 };
    final byte[] multicastIpv6Addr = { (byte) 0xff, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) 0xfb };
    MockIpManagerCallback ipManagerCallback = new MockIpManagerCallback();
    LinkAddress link = new LinkAddress(InetAddress.getByAddress(unicastIpv4Addr), 24);
    LinkProperties lp = new LinkProperties();
    lp.addLinkAddress(link);
    ApfFilter apfFilter = new TestApfFilter(ipManagerCallback, ALLOW_MULTICAST, mLog);
    apfFilter.setLinkProperties(lp);
    byte[] program = ipManagerCallback.getApfProgram();
    // Construct IPv4 and IPv6 multicast packets.
    ByteBuffer mcastv4packet = ByteBuffer.wrap(new byte[100]);
    mcastv4packet.putShort(ETH_ETHERTYPE_OFFSET, (short) ETH_P_IP);
    put(mcastv4packet, IPV4_DEST_ADDR_OFFSET, multicastIpv4Addr);
    ByteBuffer mcastv6packet = ByteBuffer.wrap(new byte[100]);
    mcastv6packet.putShort(ETH_ETHERTYPE_OFFSET, (short) ETH_P_IPV6);
    mcastv6packet.put(IPV6_NEXT_HEADER_OFFSET, (byte) IPPROTO_UDP);
    put(mcastv6packet, IPV6_DEST_ADDR_OFFSET, multicastIpv6Addr);
    // Construct IPv4 broadcast packet.
    ByteBuffer bcastv4packet1 = ByteBuffer.wrap(new byte[100]);
    bcastv4packet1.put(ETH_BROADCAST_MAC_ADDRESS);
    bcastv4packet1.putShort(ETH_ETHERTYPE_OFFSET, (short) ETH_P_IP);
    put(bcastv4packet1, IPV4_DEST_ADDR_OFFSET, multicastIpv4Addr);
    ByteBuffer bcastv4packet2 = ByteBuffer.wrap(new byte[100]);
    bcastv4packet2.put(ETH_BROADCAST_MAC_ADDRESS);
    bcastv4packet2.putShort(ETH_ETHERTYPE_OFFSET, (short) ETH_P_IP);
    put(bcastv4packet2, IPV4_DEST_ADDR_OFFSET, IPV4_BROADCAST_ADDRESS);
    // Construct IPv4 broadcast with L2 unicast address packet (b/30231088).
    ByteBuffer bcastv4unicastl2packet = ByteBuffer.wrap(new byte[100]);
    bcastv4unicastl2packet.put(TestApfFilter.MOCK_MAC_ADDR);
    bcastv4unicastl2packet.putShort(ETH_ETHERTYPE_OFFSET, (short) ETH_P_IP);
    put(bcastv4unicastl2packet, IPV4_DEST_ADDR_OFFSET, broadcastIpv4Addr);
    // Verify initially disabled multicast filter is off
    assertPass(program, mcastv4packet.array());
    assertPass(program, mcastv6packet.array());
    assertPass(program, bcastv4packet1.array());
    assertPass(program, bcastv4packet2.array());
    assertPass(program, bcastv4unicastl2packet.array());
    // Turn on multicast filter and verify it works
    ipManagerCallback.resetApfProgramWait();
    apfFilter.setMulticastFilter(true);
    program = ipManagerCallback.getApfProgram();
    assertDrop(program, mcastv4packet.array());
    assertDrop(program, mcastv6packet.array());
    assertDrop(program, bcastv4packet1.array());
    assertDrop(program, bcastv4packet2.array());
    assertDrop(program, bcastv4unicastl2packet.array());
    // Turn off multicast filter and verify it's off
    ipManagerCallback.resetApfProgramWait();
    apfFilter.setMulticastFilter(false);
    program = ipManagerCallback.getApfProgram();
    assertPass(program, mcastv4packet.array());
    assertPass(program, mcastv6packet.array());
    assertPass(program, bcastv4packet1.array());
    assertPass(program, bcastv4packet2.array());
    assertPass(program, bcastv4unicastl2packet.array());
    // Verify it can be initialized to on
    ipManagerCallback.resetApfProgramWait();
    apfFilter.shutdown();
    apfFilter = new TestApfFilter(ipManagerCallback, DROP_MULTICAST, mLog);
    apfFilter.setLinkProperties(lp);
    program = ipManagerCallback.getApfProgram();
    assertDrop(program, mcastv4packet.array());
    assertDrop(program, mcastv6packet.array());
    assertDrop(program, bcastv4packet1.array());
    assertDrop(program, bcastv4unicastl2packet.array());
    // Verify that ICMPv6 multicast is not dropped.
    mcastv6packet.put(IPV6_NEXT_HEADER_OFFSET, (byte) IPPROTO_ICMPV6);
    assertPass(program, mcastv6packet.array());
    apfFilter.shutdown();
}
Also used : LinkAddress(android.net.LinkAddress) ApfFilter(android.net.apf.ApfFilter) LinkProperties(android.net.LinkProperties) ByteBuffer(java.nio.ByteBuffer) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 83 with LinkProperties

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

the class ApfTest method testApfFilterIPv4.

@LargeTest
public void testApfFilterIPv4() throws Exception {
    MockIpManagerCallback ipManagerCallback = new MockIpManagerCallback();
    LinkAddress link = new LinkAddress(InetAddress.getByAddress(MOCK_IPV4_ADDR), 19);
    LinkProperties lp = new LinkProperties();
    lp.addLinkAddress(link);
    ApfFilter apfFilter = new TestApfFilter(ipManagerCallback, DROP_MULTICAST, mLog);
    apfFilter.setLinkProperties(lp);
    byte[] program = ipManagerCallback.getApfProgram();
    // Verify empty packet of 100 zero bytes is passed
    ByteBuffer packet = ByteBuffer.wrap(new byte[100]);
    assertPass(program, packet.array());
    // Verify unicast IPv4 packet is passed
    put(packet, ETH_DEST_ADDR_OFFSET, TestApfFilter.MOCK_MAC_ADDR);
    packet.putShort(ETH_ETHERTYPE_OFFSET, (short) ETH_P_IP);
    put(packet, IPV4_DEST_ADDR_OFFSET, MOCK_IPV4_ADDR);
    assertPass(program, packet.array());
    // Verify L2 unicast to IPv4 broadcast addresses is dropped (b/30231088)
    put(packet, IPV4_DEST_ADDR_OFFSET, IPV4_BROADCAST_ADDRESS);
    assertDrop(program, packet.array());
    put(packet, IPV4_DEST_ADDR_OFFSET, MOCK_BROADCAST_IPV4_ADDR);
    assertDrop(program, packet.array());
    // Verify multicast/broadcast IPv4, not DHCP to us, is dropped
    put(packet, ETH_DEST_ADDR_OFFSET, ETH_BROADCAST_MAC_ADDRESS);
    assertDrop(program, packet.array());
    packet.put(IPV4_VERSION_IHL_OFFSET, (byte) 0x45);
    assertDrop(program, packet.array());
    packet.put(IPV4_PROTOCOL_OFFSET, (byte) IPPROTO_UDP);
    assertDrop(program, packet.array());
    packet.putShort(UDP_DESTINATION_PORT_OFFSET, (short) DHCP_CLIENT_PORT);
    assertDrop(program, packet.array());
    put(packet, IPV4_DEST_ADDR_OFFSET, MOCK_MULTICAST_IPV4_ADDR);
    assertDrop(program, packet.array());
    put(packet, IPV4_DEST_ADDR_OFFSET, MOCK_BROADCAST_IPV4_ADDR);
    assertDrop(program, packet.array());
    put(packet, IPV4_DEST_ADDR_OFFSET, IPV4_BROADCAST_ADDRESS);
    assertDrop(program, packet.array());
    // Verify broadcast IPv4 DHCP to us is passed
    put(packet, DHCP_CLIENT_MAC_OFFSET, TestApfFilter.MOCK_MAC_ADDR);
    assertPass(program, packet.array());
    // Verify unicast IPv4 DHCP to us is passed
    put(packet, ETH_DEST_ADDR_OFFSET, TestApfFilter.MOCK_MAC_ADDR);
    assertPass(program, packet.array());
    apfFilter.shutdown();
}
Also used : LinkAddress(android.net.LinkAddress) ApfFilter(android.net.apf.ApfFilter) LinkProperties(android.net.LinkProperties) ByteBuffer(java.nio.ByteBuffer) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 84 with LinkProperties

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

the class IpManager method resetLinkProperties.

// This needs to be called with care to ensure that our LinkProperties
// are in sync with the actual LinkProperties of the interface. For example,
// we should only call this if we know for sure that there are no IP addresses
// assigned to the interface, etc.
private void resetLinkProperties() {
    mNetlinkTracker.clearLinkProperties();
    mConfiguration = null;
    mDhcpResults = null;
    mTcpBufferSizes = "";
    mHttpProxy = null;
    mLinkProperties = new LinkProperties();
    mLinkProperties.setInterfaceName(mInterfaceName);
}
Also used : LinkProperties(android.net.LinkProperties)

Example 85 with LinkProperties

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

the class IpManager method assembleLinkProperties.

private LinkProperties assembleLinkProperties() {
    // [1] Create a new LinkProperties object to populate.
    LinkProperties newLp = new LinkProperties();
    newLp.setInterfaceName(mInterfaceName);
    // [2] Pull in data from netlink:
    //         - IPv4 addresses
    //         - IPv6 addresses
    //         - IPv6 routes
    //         - IPv6 DNS servers
    //
    // N.B.: this is fundamentally race-prone and should be fixed by
    // changing NetlinkTracker from a hybrid edge/level model to an
    // edge-only model, or by giving IpManager its own netlink socket(s)
    // so as to track all required information directly.
    LinkProperties netlinkLinkProperties = mNetlinkTracker.getLinkProperties();
    newLp.setLinkAddresses(netlinkLinkProperties.getLinkAddresses());
    for (RouteInfo route : netlinkLinkProperties.getRoutes()) {
        newLp.addRoute(route);
    }
    addAllReachableDnsServers(newLp, netlinkLinkProperties.getDnsServers());
    // to worry about concurrent modification.
    if (mDhcpResults != null) {
        for (RouteInfo route : mDhcpResults.getRoutes(mInterfaceName)) {
            newLp.addRoute(route);
        }
        addAllReachableDnsServers(newLp, mDhcpResults.dnsServers);
        newLp.setDomains(mDhcpResults.domains);
        if (mDhcpResults.mtu != 0) {
            newLp.setMtu(mDhcpResults.mtu);
        }
    }
    // [4] Add in TCP buffer sizes and HTTP Proxy config, if available.
    if (!TextUtils.isEmpty(mTcpBufferSizes)) {
        newLp.setTcpBufferSizes(mTcpBufferSizes);
    }
    if (mHttpProxy != null) {
        newLp.setHttpProxy(mHttpProxy);
    }
    if (VDBG) {
        Log.d(mTag, "newLp{" + newLp + "}");
    }
    return newLp;
}
Also used : RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties)

Aggregations

LinkProperties (android.net.LinkProperties)283 RouteInfo (android.net.RouteInfo)72 LinkAddress (android.net.LinkAddress)70 SmallTest (android.test.suitebuilder.annotation.SmallTest)66 InetAddress (java.net.InetAddress)52 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)40 NetworkInfo (android.net.NetworkInfo)38 NetworkState (android.net.NetworkState)36 RemoteException (android.os.RemoteException)36 NetworkCapabilities (android.net.NetworkCapabilities)23 Network (android.net.Network)21 ProvisioningChange (android.net.LinkProperties.ProvisioningChange)20 ArrayList (java.util.ArrayList)17 IpPrefix (android.net.IpPrefix)15 Inet6Address (java.net.Inet6Address)15 NetworkRequest (android.net.NetworkRequest)14 ApfFilter (android.net.apf.ApfFilter)12 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 UnknownHostException (java.net.UnknownHostException)12 NetworkMisc (android.net.NetworkMisc)10