Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab30db70 authored by Bernie Innocenti's avatar Bernie Innocenti
Browse files

apf: Add counters for dropped / passed packets

ApfFilter maintains separate counters for each reason why a packet was
passed or dropped by the filter logic.

There's also a total which should match the individual counters,
*unless* the APF interpreter aborted execution early due to an illegal
instruction or an out-of-bounds access.

Test: both on APFv2 and APFv4-capable device:
	runtest -x tests/net/java/android/net/ip/IpClientTest.java
	runtest -x tests/net/java/android/net/apf/ApfTest.java
	manual tests connected to an AP
Bug: 73804303
Change-Id: I54b17fcbb95dfaea5db975d282314ce73d79d6ec
Merged-In: I54b17fcbb95dfaea5db975d282314ce73d79d6ec
(cherry picked from commit 3cc40ea6)
parent 40b43542
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -49,4 +49,14 @@ public class ApfCapabilities {
        return String.format("%s{version: %d, maxSize: %d, format: %d}", getClass().getSimpleName(),
        return String.format("%s{version: %d, maxSize: %d, format: %d}", getClass().getSimpleName(),
                apfVersionSupported, maximumApfProgramSize, apfPacketFormat);
                apfVersionSupported, maximumApfProgramSize, apfPacketFormat);
    }
    }

    /**
     * Returns true if the APF interpreter advertises support for the data buffer access opcodes
     * LDDW and STDW.
     *
     * Full LDDW and STDW support is present from APFv4 on.
     */
    public boolean hasDataAccess() {
        return apfVersionSupported >= 4;
    }
}
}
+247 −29

File changed.

Preview size limit exceeded, changes collapsed.

+2 −3
Original line number Original line Diff line number Diff line
@@ -378,8 +378,7 @@ public class ApfGenerator {
    }
    }


    /**
    /**
     * Returns true if the specified {@code version} is supported by the ApfGenerator, otherwise
     * Returns true if the ApfGenerator supports the specified {@code version}, otherwise false.
     * false.
     */
     */
    public static boolean supportsVersion(int version) {
    public static boolean supportsVersion(int version) {
        return version >= MIN_APF_VERSION;
        return version >= MIN_APF_VERSION;
@@ -753,7 +752,7 @@ public class ApfGenerator {


    /**
    /**
     * Add an instruction to the end of the program to jump to {@code target} if the bytes of the
     * Add an instruction to the end of the program to jump to {@code target} if the bytes of the
     * packet at, an offset specified by {@code register}, match {@code bytes}.
     * packet at an offset specified by {@code register} match {@code bytes}.
     */
     */
    public ApfGenerator addJumpIfBytesNotEqual(Register register, byte[] bytes, String target)
    public ApfGenerator addJumpIfBytesNotEqual(Register register, byte[] bytes, String target)
            throws IllegalInstructionException {
            throws IllegalInstructionException {
+21 −12
Original line number Original line Diff line number Diff line
@@ -656,7 +656,14 @@ public class IpClient extends StateMachine {
    private ApfFilter mApfFilter;
    private ApfFilter mApfFilter;
    private boolean mMulticastFiltering;
    private boolean mMulticastFiltering;
    private long mStartTimeMillis;
    private long mStartTimeMillis;
    private byte[] mApfDataSnapshot;

    /**
     * Reading the snapshot is an asynchronous operation initiated by invoking
     * Callback.startReadPacketFilter() and completed when the WiFi Service responds with an
     * EVENT_READ_PACKET_FILTER_COMPLETE message. The mApfDataSnapshotComplete condition variable
     * signals when a new snapshot is ready.
     */
    private final ConditionVariable mApfDataSnapshotComplete = new ConditionVariable();


    public static class Dependencies {
    public static class Dependencies {
        public INetworkManagementService getNMS() {
        public INetworkManagementService getNMS() {
@@ -915,13 +922,21 @@ public class IpClient extends StateMachine {
        final ProvisioningConfiguration provisioningConfig = mConfiguration;
        final ProvisioningConfiguration provisioningConfig = mConfiguration;
        final ApfCapabilities apfCapabilities = (provisioningConfig != null)
        final ApfCapabilities apfCapabilities = (provisioningConfig != null)
                ? provisioningConfig.mApfCapabilities : null;
                ? provisioningConfig.mApfCapabilities : null;
        final byte[] apfDataSnapshot = mApfDataSnapshot;


        IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
        IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
        pw.println(mTag + " APF dump:");
        pw.println(mTag + " APF dump:");
        pw.increaseIndent();
        pw.increaseIndent();
        if (apfFilter != null) {
        if (apfFilter != null) {
            if (apfCapabilities.hasDataAccess()) {
                // Request a new snapshot, then wait for it.
                mApfDataSnapshotComplete.close();
                mCallback.startReadPacketFilter();
                if (!mApfDataSnapshotComplete.block(1000)) {
                    pw.print("TIMEOUT: DUMPING STALE APF SNAPSHOT");
                }
            }
            apfFilter.dump(pw);
            apfFilter.dump(pw);

        } else {
        } else {
            pw.print("No active ApfFilter; ");
            pw.print("No active ApfFilter; ");
            if (provisioningConfig == null) {
            if (provisioningConfig == null) {
@@ -933,15 +948,6 @@ public class IpClient extends StateMachine {
            }
            }
        }
        }
        pw.decreaseIndent();
        pw.decreaseIndent();
        pw.println(mTag + " latest APF data snapshot: ");
        pw.increaseIndent();
        if (apfDataSnapshot != null) {
            pw.println(HexDump.dumpHexString(apfDataSnapshot));
        } else {
            pw.println("No last snapshot.");
        }
        pw.decreaseIndent();

        pw.println();
        pw.println();
        pw.println(mTag + " current ProvisioningConfiguration:");
        pw.println(mTag + " current ProvisioningConfiguration:");
        pw.increaseIndent();
        pw.increaseIndent();
@@ -1738,7 +1744,10 @@ public class IpClient extends StateMachine {
                }
                }


                case EVENT_READ_PACKET_FILTER_COMPLETE: {
                case EVENT_READ_PACKET_FILTER_COMPLETE: {
                    mApfDataSnapshot = (byte[]) msg.obj;
                    if (mApfFilter != null) {
                        mApfFilter.setDataSnapshot((byte[]) msg.obj);
                    }
                    mApfDataSnapshotComplete.open();
                    break;
                    break;
                }
                }