summaryrefslogtreecommitdiff
path: root/apf_interpreter.c
diff options
context:
space:
mode:
authorBernie Innocenti <codewiz@google.com>2018-03-30 08:29:11 +0000
committerBernie Innocenti <codewiz@google.com>2018-03-30 08:29:11 +0000
commitdee75a7f2e6f3e687055df1abc509287a2694e48 (patch)
treec02a065d615b3a5d716339357f9dc622b71fdd87 /apf_interpreter.c
parent6921f7406faceee05fe74bfd90b972c05017e850 (diff)
downloadapf-dee75a7f2e6f3e687055df1abc509287a2694e48.tar.gz
Revert "Add APF opcodes to read and write data memory."
This reverts commit 6921f7406faceee05fe74bfd90b972c05017e850. Reason for revert: broke JNI bindings used by framework tests Change-Id: Ibbd38276da1cbabdd2229d93a1b212072cdc3cb9
Diffstat (limited to 'apf_interpreter.c')
-rw-r--r--apf_interpreter.c43
1 files changed, 13 insertions, 30 deletions
diff --git a/apf_interpreter.c b/apf_interpreter.c
index f5e0072..924b23e 100644
--- a/apf_interpreter.c
+++ b/apf_interpreter.c
@@ -31,26 +31,30 @@
// superfluous ">= 0" with unsigned expressions generates compile warnings.
#define ENFORCE_UNSIGNED(c) ((c)==(uint32_t)(c))
+/**
+ * Runs a packet filtering program over a packet.
+ *
+ * @param program the program bytecode.
+ * @param program_len the length of {@code apf_program} in bytes.
+ * @param packet the packet bytes, starting from the 802.3 header and not
+ * including any CRC bytes at the end.
+ * @param packet_len the length of {@code packet} in bytes.
+ * @param filter_age the number of seconds since the filter was programmed.
+ *
+ * @return non-zero if packet should be passed to AP, zero if
+ * packet should be dropped.
+ */
int accept_packet(const uint8_t* program, uint32_t program_len,
const uint8_t* packet, uint32_t packet_len,
- uint8_t* data, uint32_t data_len,
uint32_t filter_age) {
// Is offset within program bounds?
#define IN_PROGRAM_BOUNDS(p) (ENFORCE_UNSIGNED(p) && (p) < program_len)
// Is offset within packet bounds?
#define IN_PACKET_BOUNDS(p) (ENFORCE_UNSIGNED(p) && (p) < packet_len)
-// Is access to offset |p| length |size| within data bounds?
-#define IN_DATA_BOUNDS(p, size) (ENFORCE_UNSIGNED(p) && \
- ENFORCE_UNSIGNED(size) && \
- (p) + (size) < data_len && \
- (p) + (size) >= (p)) // catch wraparounds
// Accept packet if not within program bounds
#define ASSERT_IN_PROGRAM_BOUNDS(p) ASSERT_RETURN(IN_PROGRAM_BOUNDS(p))
// Accept packet if not within packet bounds
#define ASSERT_IN_PACKET_BOUNDS(p) ASSERT_RETURN(IN_PACKET_BOUNDS(p))
-// Accept packet if not within data bounds
-#define ASSERT_IN_DATA_BOUNDS(p, size) ASSERT_RETURN(IN_DATA_BOUNDS(p, size))
-
// Program counter.
uint32_t pc = 0;
// Accept packet if not within program or not ahead of program counter
@@ -264,27 +268,6 @@ int accept_packet(const uint8_t* program, uint32_t program_len,
return PASS_PACKET;
}
break;
- case LDDW_OPCODE: {
- uint32_t offs = imm + OTHER_REG;
- uint32_t size = 4;
- uint32_t val = 0;
- ASSERT_IN_DATA_BOUNDS(offs, size);
- while (size--)
- val = (val << 8) | data[offs++];
- REG = val;
- break;
- }
- case STDW_OPCODE: {
- uint32_t offs = imm + OTHER_REG;
- uint32_t size = 4;
- uint32_t val = REG;
- ASSERT_IN_DATA_BOUNDS(offs, size);
- while (size--) {
- data[offs++] = (val >> 24);
- val <<= 8;
- }
- break;
- }
// Unknown opcode
default:
// Bail out