Search in sources :

Example 1 with ApfFilter

use of android.net.apf.ApfFilter in project platform_frameworks_base by android.

the class ApfTest method testApfFilterIPv6.

@SmallTest
public void testApfFilterIPv6() throws Exception {
    MockIpManagerCallback ipManagerCallback = new MockIpManagerCallback();
    ApfFilter apfFilter = new TestApfFilter(ipManagerCallback, ALLOW_MULTICAST, mLog);
    byte[] program = ipManagerCallback.getApfProgram();
    // Verify empty IPv6 packet is passed
    ByteBuffer packet = ByteBuffer.wrap(new byte[100]);
    packet.putShort(ETH_ETHERTYPE_OFFSET, (short) ETH_P_IPV6);
    assertPass(program, packet.array());
    // Verify empty ICMPv6 packet is passed
    packet.put(IPV6_NEXT_HEADER_OFFSET, (byte) IPPROTO_ICMPV6);
    assertPass(program, packet.array());
    // Verify empty ICMPv6 NA packet is passed
    packet.put(ICMP6_TYPE_OFFSET, (byte) ICMP6_NEIGHBOR_ANNOUNCEMENT);
    assertPass(program, packet.array());
    // Verify ICMPv6 NA to ff02::1 is dropped
    put(packet, IPV6_DEST_ADDR_OFFSET, IPV6_ALL_NODES_ADDRESS);
    assertDrop(program, packet.array());
    // Verify ICMPv6 RS to any is dropped
    packet.put(ICMP6_TYPE_OFFSET, (byte) ICMP6_ROUTER_SOLICITATION);
    assertDrop(program, packet.array());
    put(packet, IPV6_DEST_ADDR_OFFSET, IPV6_ALL_ROUTERS_ADDRESS);
    assertDrop(program, packet.array());
    apfFilter.shutdown();
}
Also used : ApfFilter(android.net.apf.ApfFilter) ByteBuffer(java.nio.ByteBuffer) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 2 with ApfFilter

use of android.net.apf.ApfFilter in project platform_frameworks_base by android.

the class ApfTest method testRaParsing.

@SmallTest
public void testRaParsing() throws Exception {
    final int maxRandomPacketSize = 512;
    final Random r = new Random();
    MockIpManagerCallback cb = new MockIpManagerCallback();
    TestApfFilter apfFilter = new TestApfFilter(cb, DROP_MULTICAST, mLog);
    for (int i = 0; i < 1000; i++) {
        byte[] packet = new byte[r.nextInt(maxRandomPacketSize + 1)];
        r.nextBytes(packet);
        try {
            apfFilter.new Ra(packet, packet.length);
        } catch (ApfFilter.InvalidRaException e) {
        } catch (Exception e) {
            throw new Exception("bad packet: " + HexDump.toHexString(packet), e);
        }
    }
}
Also used : ApfFilter(android.net.apf.ApfFilter) Random(java.util.Random) ErrnoException(android.system.ErrnoException) IllegalInstructionException(android.net.apf.ApfGenerator.IllegalInstructionException) IOException(java.io.IOException) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 3 with ApfFilter

use of android.net.apf.ApfFilter in project platform_frameworks_base by android.

the class ApfTest method testApfFilterMulticast.

@SmallTest
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) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 4 with ApfFilter

use of android.net.apf.ApfFilter in project platform_frameworks_base by android.

the class IpManager method dump.

public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
    if (args.length > 0 && DUMP_ARG_CONFIRM.equals(args[0])) {
        // Execute confirmConfiguration() and take no further action.
        confirmConfiguration();
        return;
    }
    IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
    pw.println(mTag + " APF dump:");
    pw.increaseIndent();
    // Thread-unsafe access to mApfFilter but just used for debugging.
    ApfFilter apfFilter = mApfFilter;
    if (apfFilter != null) {
        apfFilter.dump(pw);
    } else {
        pw.println("No apf support");
    }
    pw.decreaseIndent();
    pw.println();
    pw.println(mTag + " StateMachine dump:");
    pw.increaseIndent();
    mLocalLog.readOnlyLocalLog().dump(fd, pw, args);
    pw.decreaseIndent();
    pw.println();
    pw.println(mTag + " connectivity packet log:");
    pw.println();
    pw.println("Debug with python and scapy via:");
    pw.println("shell$ python");
    pw.println(">>> from scapy import all as scapy");
    pw.println(">>> scapy.Ether(\"<paste_hex_string>\".decode(\"hex\")).show2()");
    pw.println();
    pw.increaseIndent();
    mConnectivityPacketLog.readOnlyLocalLog().dump(fd, pw, args);
    pw.decreaseIndent();
}
Also used : ApfFilter(android.net.apf.ApfFilter) IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter)

Example 5 with ApfFilter

use of android.net.apf.ApfFilter 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)

Aggregations

ApfFilter (android.net.apf.ApfFilter)21 LinkAddress (android.net.LinkAddress)12 LinkProperties (android.net.LinkProperties)12 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 ByteBuffer (java.nio.ByteBuffer)12 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 IndentingPrintWriter (com.android.internal.util.IndentingPrintWriter)4 IllegalInstructionException (android.net.apf.ApfGenerator.IllegalInstructionException)1 ErrnoException (android.system.ErrnoException)1 IOException (java.io.IOException)1 Random (java.util.Random)1