Merge "Avoid APF JNEBS instruction with R1 as it doesn't work" into nyc-dev

This commit is contained in:
Paul Jensen
2016-04-18 10:56:13 +00:00
committed by Android (Google) Code Review
2 changed files with 8 additions and 5 deletions

View File

@@ -107,6 +107,7 @@ public class ApfFilter {
private static final boolean VDBG = false; private static final boolean VDBG = false;
private static final int ETH_HEADER_LEN = 14; private static final int ETH_HEADER_LEN = 14;
private static final int ETH_DEST_ADDR_OFFSET = 0;
private static final int ETH_ETHERTYPE_OFFSET = 12; private static final int ETH_ETHERTYPE_OFFSET = 12;
private static final byte[] ETH_BROADCAST_MAC_ADDRESS = new byte[]{ private static final byte[] ETH_BROADCAST_MAC_ADDRESS = new byte[]{
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff }; (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff };
@@ -582,7 +583,6 @@ public class ApfFilter {
* DROP_LABEL or PASS_LABEL and does not fall off the end. * DROP_LABEL or PASS_LABEL and does not fall off the end.
* Preconditions: * Preconditions:
* - Packet being filtered is IPv4 * - Packet being filtered is IPv4
* - R1 is initialized to 0
*/ */
@GuardedBy("this") @GuardedBy("this")
private void generateIPv4FilterLocked(ApfGenerator gen) throws IllegalInstructionException { private void generateIPv4FilterLocked(ApfGenerator gen) throws IllegalInstructionException {
@@ -605,9 +605,8 @@ public class ApfFilter {
// Drop all broadcasts besides DHCP addressed to us // Drop all broadcasts besides DHCP addressed to us
// If not a broadcast packet, pass // If not a broadcast packet, pass
// NOTE: Relies on R1 being initialized to 0 which is the offset of the ethernet gen.addLoadImmediate(Register.R0, ETH_DEST_ADDR_OFFSET);
// destination MAC address gen.addJumpIfBytesNotEqual(Register.R0, ETH_BROADCAST_MAC_ADDRESS, gen.PASS_LABEL);
gen.addJumpIfBytesNotEqual(Register.R1, ETH_BROADCAST_MAC_ADDRESS, gen.PASS_LABEL);
// If not UDP, drop // If not UDP, drop
gen.addLoad8(Register.R0, IPV4_PROTOCOL_OFFSET); gen.addLoad8(Register.R0, IPV4_PROTOCOL_OFFSET);
gen.addJumpIfR0NotEquals(IPPROTO_UDP, gen.DROP_LABEL); gen.addJumpIfR0NotEquals(IPPROTO_UDP, gen.DROP_LABEL);

View File

@@ -734,7 +734,11 @@ 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 {
if (register == Register.R1) {
throw new IllegalInstructionException("JNEBS fails with R1");
}
Instruction instruction = new Instruction(Opcodes.JNEBS, register); Instruction instruction = new Instruction(Opcodes.JNEBS, register);
instruction.setUnsignedImm(bytes.length); instruction.setUnsignedImm(bytes.length);
instruction.setTargetLabel(target); instruction.setTargetLabel(target);