Search in sources :

Example 1 with IllegalInstructionException

use of android.net.apf.ApfGenerator.IllegalInstructionException in project android_frameworks_base by crdroidandroid.

the class ApfFilter method installNewProgramLocked.

/**
     * Generate and install a new filter program.
     */
@GuardedBy("this")
@VisibleForTesting
void installNewProgramLocked() {
    purgeExpiredRasLocked();
    ArrayList<Ra> rasToFilter = new ArrayList<>();
    final byte[] program;
    long programMinLifetime = Long.MAX_VALUE;
    try {
        // Step 1: Determine how many RA filters we can fit in the program.
        ApfGenerator gen = beginProgramLocked();
        for (Ra ra : mRas) {
            ra.generateFilterLocked(gen);
            // Stop if we get too big.
            if (gen.programLengthOverEstimate() > mApfCapabilities.maximumApfProgramSize)
                break;
            rasToFilter.add(ra);
        }
        // Step 2: Actually generate the program
        gen = beginProgramLocked();
        for (Ra ra : rasToFilter) {
            programMinLifetime = Math.min(programMinLifetime, ra.generateFilterLocked(gen));
        }
        // Execution will reach the end of the program if no filters match, which will pass the
        // packet to the AP.
        program = gen.generate();
    } catch (IllegalInstructionException e) {
        Log.e(TAG, "Program failed to generate: ", e);
        return;
    }
    mLastTimeInstalledProgram = curTime();
    mLastInstalledProgramMinLifetime = programMinLifetime;
    mLastInstalledProgram = program;
    mNumProgramUpdates++;
    if (VDBG) {
        hexDump("Installing filter: ", program, program.length);
    }
    mIpManagerCallback.installPacketFilter(program);
    int flags = ApfProgramEvent.flagsFor(mIPv4Address != null, mMulticastFilter);
    mMetricsLog.log(new ApfProgramEvent(programMinLifetime, rasToFilter.size(), mRas.size(), program.length, flags));
}
Also used : IllegalInstructionException(android.net.apf.ApfGenerator.IllegalInstructionException) ApfGenerator(android.net.apf.ApfGenerator) ArrayList(java.util.ArrayList) ApfProgramEvent(android.net.metrics.ApfProgramEvent) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) GuardedBy(com.android.internal.annotations.GuardedBy)

Example 2 with IllegalInstructionException

use of android.net.apf.ApfGenerator.IllegalInstructionException in project platform_frameworks_base by android.

the class ApfFilter method installNewProgramLocked.

/**
     * Generate and install a new filter program.
     */
@GuardedBy("this")
@VisibleForTesting
void installNewProgramLocked() {
    purgeExpiredRasLocked();
    ArrayList<Ra> rasToFilter = new ArrayList<>();
    final byte[] program;
    long programMinLifetime = Long.MAX_VALUE;
    try {
        // Step 1: Determine how many RA filters we can fit in the program.
        ApfGenerator gen = beginProgramLocked();
        for (Ra ra : mRas) {
            ra.generateFilterLocked(gen);
            // Stop if we get too big.
            if (gen.programLengthOverEstimate() > mApfCapabilities.maximumApfProgramSize)
                break;
            rasToFilter.add(ra);
        }
        // Step 2: Actually generate the program
        gen = beginProgramLocked();
        for (Ra ra : rasToFilter) {
            programMinLifetime = Math.min(programMinLifetime, ra.generateFilterLocked(gen));
        }
        // Execution will reach the end of the program if no filters match, which will pass the
        // packet to the AP.
        program = gen.generate();
    } catch (IllegalInstructionException | IllegalStateException e) {
        Log.e(TAG, "Failed to generate APF program.", e);
        return;
    }
    mLastTimeInstalledProgram = currentTimeSeconds();
    mLastInstalledProgramMinLifetime = programMinLifetime;
    mLastInstalledProgram = program;
    mNumProgramUpdates++;
    if (VDBG) {
        hexDump("Installing filter: ", program, program.length);
    }
    mIpManagerCallback.installPacketFilter(program);
    int flags = ApfProgramEvent.flagsFor(mIPv4Address != null, mMulticastFilter);
    mMetricsLog.log(new ApfProgramEvent(programMinLifetime, rasToFilter.size(), mRas.size(), program.length, flags));
}
Also used : IllegalInstructionException(android.net.apf.ApfGenerator.IllegalInstructionException) ApfGenerator(android.net.apf.ApfGenerator) ArrayList(java.util.ArrayList) ApfProgramEvent(android.net.metrics.ApfProgramEvent) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) GuardedBy(com.android.internal.annotations.GuardedBy)

Example 3 with IllegalInstructionException

use of android.net.apf.ApfGenerator.IllegalInstructionException in project android_frameworks_base by DirtyUnicorns.

the class ApfFilter method installNewProgramLocked.

/**
     * Generate and install a new filter program.
     */
@GuardedBy("this")
@VisibleForTesting
void installNewProgramLocked() {
    purgeExpiredRasLocked();
    ArrayList<Ra> rasToFilter = new ArrayList<>();
    final byte[] program;
    long programMinLifetime = Long.MAX_VALUE;
    try {
        // Step 1: Determine how many RA filters we can fit in the program.
        ApfGenerator gen = beginProgramLocked();
        for (Ra ra : mRas) {
            ra.generateFilterLocked(gen);
            // Stop if we get too big.
            if (gen.programLengthOverEstimate() > mApfCapabilities.maximumApfProgramSize)
                break;
            rasToFilter.add(ra);
        }
        // Step 2: Actually generate the program
        gen = beginProgramLocked();
        for (Ra ra : rasToFilter) {
            programMinLifetime = Math.min(programMinLifetime, ra.generateFilterLocked(gen));
        }
        // Execution will reach the end of the program if no filters match, which will pass the
        // packet to the AP.
        program = gen.generate();
    } catch (IllegalInstructionException e) {
        Log.e(TAG, "Program failed to generate: ", e);
        return;
    }
    mLastTimeInstalledProgram = curTime();
    mLastInstalledProgramMinLifetime = programMinLifetime;
    mLastInstalledProgram = program;
    mNumProgramUpdates++;
    if (VDBG) {
        hexDump("Installing filter: ", program, program.length);
    }
    mIpManagerCallback.installPacketFilter(program);
    int flags = ApfProgramEvent.flagsFor(mIPv4Address != null, mMulticastFilter);
    mMetricsLog.log(new ApfProgramEvent(programMinLifetime, rasToFilter.size(), mRas.size(), program.length, flags));
}
Also used : IllegalInstructionException(android.net.apf.ApfGenerator.IllegalInstructionException) ApfGenerator(android.net.apf.ApfGenerator) ArrayList(java.util.ArrayList) ApfProgramEvent(android.net.metrics.ApfProgramEvent) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) GuardedBy(com.android.internal.annotations.GuardedBy)

Example 4 with IllegalInstructionException

use of android.net.apf.ApfGenerator.IllegalInstructionException in project android_frameworks_base by ResurrectionRemix.

the class ApfFilter method installNewProgramLocked.

/**
     * Generate and install a new filter program.
     */
@GuardedBy("this")
@VisibleForTesting
void installNewProgramLocked() {
    purgeExpiredRasLocked();
    ArrayList<Ra> rasToFilter = new ArrayList<>();
    final byte[] program;
    long programMinLifetime = Long.MAX_VALUE;
    try {
        // Step 1: Determine how many RA filters we can fit in the program.
        ApfGenerator gen = beginProgramLocked();
        for (Ra ra : mRas) {
            ra.generateFilterLocked(gen);
            // Stop if we get too big.
            if (gen.programLengthOverEstimate() > mApfCapabilities.maximumApfProgramSize)
                break;
            rasToFilter.add(ra);
        }
        // Step 2: Actually generate the program
        gen = beginProgramLocked();
        for (Ra ra : rasToFilter) {
            programMinLifetime = Math.min(programMinLifetime, ra.generateFilterLocked(gen));
        }
        // Execution will reach the end of the program if no filters match, which will pass the
        // packet to the AP.
        program = gen.generate();
    } catch (IllegalInstructionException e) {
        Log.e(TAG, "Program failed to generate: ", e);
        return;
    }
    mLastTimeInstalledProgram = curTime();
    mLastInstalledProgramMinLifetime = programMinLifetime;
    mLastInstalledProgram = program;
    mNumProgramUpdates++;
    if (VDBG) {
        hexDump("Installing filter: ", program, program.length);
    }
    mIpManagerCallback.installPacketFilter(program);
    int flags = ApfProgramEvent.flagsFor(mIPv4Address != null, mMulticastFilter);
    mMetricsLog.log(new ApfProgramEvent(programMinLifetime, rasToFilter.size(), mRas.size(), program.length, flags));
}
Also used : IllegalInstructionException(android.net.apf.ApfGenerator.IllegalInstructionException) ApfGenerator(android.net.apf.ApfGenerator) ArrayList(java.util.ArrayList) ApfProgramEvent(android.net.metrics.ApfProgramEvent) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) GuardedBy(com.android.internal.annotations.GuardedBy)

Aggregations

ApfGenerator (android.net.apf.ApfGenerator)4 IllegalInstructionException (android.net.apf.ApfGenerator.IllegalInstructionException)4 ApfProgramEvent (android.net.metrics.ApfProgramEvent)4 GuardedBy (com.android.internal.annotations.GuardedBy)4 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)4 ArrayList (java.util.ArrayList)4