diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-05-14 23:15:01 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-05-14 23:15:01 +0000 |
commit | 5fb94da1aca5cab83055af2cfa0f475e8ffd3f7b (patch) | |
tree | 9e29962fb99b6599591b2de19a3abef0df4cf4a6 | |
parent | 4041dd6ec6ac5b21d93eee3fe40b1d67525f0d0e (diff) | |
parent | e0ffcb902ce7153e7d43397cd041c7a2a1ff5dc4 (diff) | |
download | apf-sdk-release.tar.gz |
Snap for 11841552 from e0ffcb902ce7153e7d43397cd041c7a2a1ff5dc4 to sdk-releasesdk-release
Change-Id: I90cca411e4befa36eed37d02e4c977c8d1239cfc
-rw-r--r-- | Android.bp | 4 | ||||
-rw-r--r-- | apf_run.c | 4 | ||||
l--------- | devtools/apf_interpreter.c | 2 | ||||
l--------- | devtools/apf_interpreter.h | 2 | ||||
-rw-r--r-- | disassembler.c | 8 | ||||
-rw-r--r-- | v4/apf_interpreter.h | 6 | ||||
-rw-r--r-- | v6/apf_interpreter.c | 2 | ||||
-rw-r--r-- | v6/apf_interpreter.h | 6 | ||||
-rw-r--r-- | v7/Android.bp (renamed from v5/Android.bp) | 6 | ||||
-rw-r--r-- | v7/apf.h (renamed from v5/apf.h) | 2 | ||||
-rw-r--r-- | v7/apf_assemble_test.xml (renamed from v5/apf_assemble_test.xml) | 0 | ||||
l--------- | v7/apf_checksum.h (renamed from v5/apf_checksum.h) | 0 | ||||
l--------- | v7/apf_defs.h (renamed from v5/apf_defs.h) | 0 | ||||
l--------- | v7/apf_dns.h (renamed from v5/apf_dns.h) | 0 | ||||
-rw-r--r-- | v7/apf_interpreter.c (renamed from v5/apf_interpreter.c) | 48 | ||||
-rw-r--r-- | v7/apf_interpreter.h (renamed from v5/apf_interpreter.h) | 6 | ||||
-rwxr-xr-x | v7/apf_interpreter_assemble.sh (renamed from v5/apf_interpreter_assemble.sh) | 0 | ||||
-rw-r--r-- | v7/apf_interpreter_source.c (renamed from v5/apf_interpreter_source.c) | 46 | ||||
l--------- | v7/apf_utils.h (renamed from v5/apf_utils.h) | 0 | ||||
-rw-r--r-- | v7/test_buf_allocator.c (renamed from v5/test_buf_allocator.c) | 0 | ||||
-rw-r--r-- | v7/test_buf_allocator.h (renamed from v5/test_buf_allocator.h) | 0 |
21 files changed, 82 insertions, 60 deletions
@@ -69,8 +69,8 @@ cc_binary_host { "apf_run.c", "apf_interpreter.c", "disassembler.c", - "v5/apf_interpreter.c", - "v5/test_buf_allocator.c", + "v7/apf_interpreter.c", + "v7/test_buf_allocator.c", ], cflags: [ "-DAPF_TRACE_HOOK=apf_trace_hook", @@ -29,8 +29,8 @@ #include "disassembler.h" #include "apf_interpreter.h" -#include "v5/apf_interpreter.h" -#include "v5/test_buf_allocator.h" +#include "v7/apf_interpreter.h" +#include "v7/test_buf_allocator.h" #define __unused __attribute__((unused)) diff --git a/devtools/apf_interpreter.c b/devtools/apf_interpreter.c index de07dc7..a44bd13 120000 --- a/devtools/apf_interpreter.c +++ b/devtools/apf_interpreter.c @@ -1 +1 @@ -../v5/apf_interpreter.c
\ No newline at end of file +../v7/apf_interpreter.c
\ No newline at end of file diff --git a/devtools/apf_interpreter.h b/devtools/apf_interpreter.h index 9a19beb..1aef88e 120000 --- a/devtools/apf_interpreter.h +++ b/devtools/apf_interpreter.h @@ -1 +1 @@ -../v5/apf_interpreter.h
\ No newline at end of file +../v7/apf_interpreter.h
\ No newline at end of file diff --git a/disassembler.c b/disassembler.c index 5f343e1..2e93c3c 100644 --- a/disassembler.c +++ b/disassembler.c @@ -20,8 +20,8 @@ typedef enum { false, true } bool; -#include "v5/apf_defs.h" -#include "v5/apf.h" +#include "v7/apf_defs.h" +#include "v7/apf.h" #include "disassembler.h" // If "c" is of a signed type, generate a compile warning that gets promoted to an error. @@ -75,6 +75,7 @@ static const char* opcode_names [] = { [LDDW_OPCODE] = "lddw", [STDW_OPCODE] = "stdw", [WRITE_OPCODE] = "write", + [JNSET_OPCODE] = "jnset", }; static void print_jump_target(uint32_t target, uint32_t program_len) { @@ -174,7 +175,8 @@ const char* apf_disassemble(const uint8_t* program, uint32_t program_len, uint32 case JNE_OPCODE: case JGT_OPCODE: case JLT_OPCODE: - case JSET_OPCODE: { + case JSET_OPCODE: + case JNSET_OPCODE: { PRINT_OPCODE(); bprintf("r0, "); // Load second immediate field. diff --git a/v4/apf_interpreter.h b/v4/apf_interpreter.h index 1c8e7c9..8c9e85f 100644 --- a/v4/apf_interpreter.h +++ b/v4/apf_interpreter.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef APF_INTERPRETER_H_ -#define APF_INTERPRETER_H_ +#ifndef APF_V4_INTERPRETER_H_ +#define APF_V4_INTERPRETER_H_ #include <stdint.h> @@ -63,4 +63,4 @@ int accept_packet(uint8_t* program, uint32_t program_len, uint32_t ram_len, } #endif -#endif // APF_INTERPRETER_H_ +#endif // APF_V4_INTERPRETER_H_ diff --git a/v6/apf_interpreter.c b/v6/apf_interpreter.c index 001aad9..6721ffe 100644 --- a/v6/apf_interpreter.c +++ b/v6/apf_interpreter.c @@ -607,7 +607,7 @@ extern void APF_TRACE_HOOK(u32 pc, const u32* regs, const u8* program, #define ENFORCE_UNSIGNED(c) ((c)==(u32)(c)) u32 apf_version(void) { - return 20240401; + return 6000; } typedef struct { diff --git a/v6/apf_interpreter.h b/v6/apf_interpreter.h index 10821bf..71a7603 100644 --- a/v6/apf_interpreter.h +++ b/v6/apf_interpreter.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef APF_INTERPRETER_V5_H_ -#define APF_INTERPRETER_V5_H_ +#ifndef APF_INTERPRETER_V6_H_ +#define APF_INTERPRETER_V6_H_ #include <stdint.h> @@ -172,4 +172,4 @@ int apf_run(void* ctx, uint32_t* const program, const uint32_t program_len, } #endif -#endif /* APF_INTERPRETER_V5_H_ */ +#endif /* APF_INTERPRETER_V6_H_ */ diff --git a/v5/Android.bp b/v7/Android.bp index 19faf78..1277aaf 100644 --- a/v5/Android.bp +++ b/v7/Android.bp @@ -19,7 +19,7 @@ package { } cc_defaults { - name: "apfv5_defaults", + name: "apfv7_defaults", cflags: [ "-Wall", @@ -37,8 +37,8 @@ cc_defaults { } cc_library_static { - name: "libapf_v5", - defaults: ["apfv5_defaults"], + name: "libapf_v7", + defaults: ["apfv7_defaults"], srcs: [ "apf_interpreter.c", "test_buf_allocator.c", @@ -210,6 +210,8 @@ typedef union { */ #define PKTDATACOPY_OPCODE 25 +#define JNSET_OPCODE 26 // JSET with reverse condition (jump if no bits set) + /* ---------------------------------------------------------------------------------------------- */ // Extended opcodes. diff --git a/v5/apf_assemble_test.xml b/v7/apf_assemble_test.xml index 5e3c00b..5e3c00b 100644 --- a/v5/apf_assemble_test.xml +++ b/v7/apf_assemble_test.xml diff --git a/v5/apf_checksum.h b/v7/apf_checksum.h index 71ae895..71ae895 120000 --- a/v5/apf_checksum.h +++ b/v7/apf_checksum.h diff --git a/v5/apf_defs.h b/v7/apf_defs.h index 7e1dfa0..7e1dfa0 120000 --- a/v5/apf_defs.h +++ b/v7/apf_defs.h diff --git a/v5/apf_dns.h b/v7/apf_dns.h index 504778f..504778f 120000 --- a/v5/apf_dns.h +++ b/v7/apf_dns.h diff --git a/v5/apf_interpreter.c b/v7/apf_interpreter.c index 001aad9..c4ef59e 100644 --- a/v5/apf_interpreter.c +++ b/v7/apf_interpreter.c @@ -266,6 +266,8 @@ typedef union { */ #define PKTDATACOPY_OPCODE 25 +#define JNSET_OPCODE 26 /* JSET with reverse condition (jump if no bits set) */ + /* ---------------------------------------------------------------------------------------------- */ /* Extended opcodes. */ @@ -607,7 +609,7 @@ extern void APF_TRACE_HOOK(u32 pc, const u32* regs, const u8* program, #define ENFORCE_UNSIGNED(c) ((c)==(u32)(c)) u32 apf_version(void) { - return 20240401; + return 20240510; } typedef struct { @@ -643,22 +645,27 @@ static int do_discard_buffer(apf_context* ctx) { return apf_internal_do_transmit_buffer(ctx, 0 /* pkt_len */, 0 /* dscp */); } +#define DECODE_U8() (ctx->program[ctx->pc++]) + +static u16 decode_be16(apf_context* ctx) { + u16 v = DECODE_U8(); + v <<= 8; + v |= DECODE_U8(); + return v; +} + /* Decode an immediate, lengths [0..4] all work, does not do range checking. */ /* But note that program is at least 20 bytes shorter than ram, so first few */ /* immediates can always be safely decoded without exceeding ram buffer. */ static u32 decode_imm(apf_context* ctx, u32 length) { u32 i, v = 0; - for (i = 0; i < length; ++i) v = (v << 8) | ctx->program[ctx->pc++]; + for (i = 0; i < length; ++i) v = (v << 8) | DECODE_U8(); return v; } -#define DECODE_U8() (ctx->program[ctx->pc++]) - -static u16 decode_be16(apf_context* ctx) { - u16 v = ctx->program[ctx->pc++]; - v <<= 8; - v |= ctx->program[ctx->pc++]; - return v; +/* Warning: 'ofs' should be validated by caller! */ +static u8 read_packet_u8(apf_context* ctx, u32 ofs) { + return ctx->packet[ofs]; } static int do_apf_run(apf_context* ctx) { @@ -693,8 +700,9 @@ static int do_apf_run(apf_context* ctx) { /* Only populate if packet long enough, and IP version is IPv4. */ /* Note: this doesn't actually check the ethertype... */ - if ((ctx->packet_len >= ETH_HLEN + IPV4_HLEN) && ((ctx->packet[ETH_HLEN] & 0xf0) == 0x40)) { - ctx->mem.named.ipv4_header_size = (ctx->packet[ETH_HLEN] & 15) * 4; + if ((ctx->packet_len >= ETH_HLEN + IPV4_HLEN) + && ((read_packet_u8(ctx, ETH_HLEN) & 0xf0) == 0x40)) { + ctx->mem.named.ipv4_header_size = (read_packet_u8(ctx, ETH_HLEN) & 15) * 4; } /* Is access to offset |p| length |size| within output buffer bounds? */ @@ -714,7 +722,7 @@ static int do_apf_run(apf_context* ctx) { { /* half indent to avoid needless line length... */ - const u8 bytecode = ctx->program[ctx->pc++]; + const u8 bytecode = DECODE_U8(); const u8 opcode = EXTRACT_OPCODE(bytecode); const u8 reg_num = EXTRACT_REGISTER(bytecode); #define REG (ctx->R[reg_num]) @@ -781,7 +789,7 @@ static int do_apf_run(apf_context* ctx) { /* Catch overflow/wrap-around. */ ASSERT_RETURN(end_offs >= offs); ASSERT_IN_PACKET_BOUNDS(end_offs); - while (load_size--) val = (val << 8) | ctx->packet[offs++]; + while (load_size--) val = (val << 8) | read_packet_u8(ctx, offs++); REG = val; } break; @@ -800,7 +808,8 @@ static int do_apf_run(apf_context* ctx) { case JNE_OPCODE: case JGT_OPCODE: case JLT_OPCODE: - case JSET_OPCODE: { + case JSET_OPCODE: + case JNSET_OPCODE: { u32 cmp_imm = 0; /* Load second immediate field. */ if (reg_num == 1) { @@ -809,11 +818,12 @@ static int do_apf_run(apf_context* ctx) { cmp_imm = decode_imm(ctx, imm_len); /* 2nd imm, at worst 8 bytes past prog_len */ } switch (opcode) { - case JEQ_OPCODE: if (ctx->R[0] == cmp_imm) ctx->pc += imm; break; - case JNE_OPCODE: if (ctx->R[0] != cmp_imm) ctx->pc += imm; break; - case JGT_OPCODE: if (ctx->R[0] > cmp_imm) ctx->pc += imm; break; - case JLT_OPCODE: if (ctx->R[0] < cmp_imm) ctx->pc += imm; break; - case JSET_OPCODE: if (ctx->R[0] & cmp_imm) ctx->pc += imm; break; + case JEQ_OPCODE: if ( ctx->R[0] == cmp_imm ) ctx->pc += imm; break; + case JNE_OPCODE: if ( ctx->R[0] != cmp_imm ) ctx->pc += imm; break; + case JGT_OPCODE: if ( ctx->R[0] > cmp_imm ) ctx->pc += imm; break; + case JLT_OPCODE: if ( ctx->R[0] < cmp_imm ) ctx->pc += imm; break; + case JSET_OPCODE: if ( ctx->R[0] & cmp_imm ) ctx->pc += imm; break; + case JNSET_OPCODE: if (!(ctx->R[0] & cmp_imm)) ctx->pc += imm; break; } break; } diff --git a/v5/apf_interpreter.h b/v7/apf_interpreter.h index 10821bf..f290355 100644 --- a/v5/apf_interpreter.h +++ b/v7/apf_interpreter.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef APF_INTERPRETER_V5_H_ -#define APF_INTERPRETER_V5_H_ +#ifndef APF_INTERPRETER_H_ +#define APF_INTERPRETER_H_ #include <stdint.h> @@ -172,4 +172,4 @@ int apf_run(void* ctx, uint32_t* const program, const uint32_t program_len, } #endif -#endif /* APF_INTERPRETER_V5_H_ */ +#endif /* APF_INTERPRETER_H_ */ diff --git a/v5/apf_interpreter_assemble.sh b/v7/apf_interpreter_assemble.sh index 6650bf0..6650bf0 100755 --- a/v5/apf_interpreter_assemble.sh +++ b/v7/apf_interpreter_assemble.sh diff --git a/v5/apf_interpreter_source.c b/v7/apf_interpreter_source.c index 68af15b..a36a4ee 100644 --- a/v5/apf_interpreter_source.c +++ b/v7/apf_interpreter_source.c @@ -63,7 +63,7 @@ extern void APF_TRACE_HOOK(u32 pc, const u32* regs, const u8* program, #define ENFORCE_UNSIGNED(c) ((c)==(u32)(c)) u32 apf_version(void) { - return 20240401; + return 20240510; } typedef struct { @@ -99,22 +99,27 @@ static int do_discard_buffer(apf_context* ctx) { return do_transmit_buffer(ctx, 0 /* pkt_len */, 0 /* dscp */); } +#define DECODE_U8() (ctx->program[ctx->pc++]) + +static u16 decode_be16(apf_context* ctx) { + u16 v = DECODE_U8(); + v <<= 8; + v |= DECODE_U8(); + return v; +} + // Decode an immediate, lengths [0..4] all work, does not do range checking. // But note that program is at least 20 bytes shorter than ram, so first few // immediates can always be safely decoded without exceeding ram buffer. static u32 decode_imm(apf_context* ctx, u32 length) { u32 i, v = 0; - for (i = 0; i < length; ++i) v = (v << 8) | ctx->program[ctx->pc++]; + for (i = 0; i < length; ++i) v = (v << 8) | DECODE_U8(); return v; } -#define DECODE_U8() (ctx->program[ctx->pc++]) - -static u16 decode_be16(apf_context* ctx) { - u16 v = ctx->program[ctx->pc++]; - v <<= 8; - v |= ctx->program[ctx->pc++]; - return v; +// Warning: 'ofs' should be validated by caller! +static u8 read_packet_u8(apf_context* ctx, u32 ofs) { + return ctx->packet[ofs]; } static int do_apf_run(apf_context* ctx) { @@ -149,8 +154,9 @@ static int do_apf_run(apf_context* ctx) { // Only populate if packet long enough, and IP version is IPv4. // Note: this doesn't actually check the ethertype... - if ((ctx->packet_len >= ETH_HLEN + IPV4_HLEN) && ((ctx->packet[ETH_HLEN] & 0xf0) == 0x40)) { - ctx->mem.named.ipv4_header_size = (ctx->packet[ETH_HLEN] & 15) * 4; + if ((ctx->packet_len >= ETH_HLEN + IPV4_HLEN) + && ((read_packet_u8(ctx, ETH_HLEN) & 0xf0) == 0x40)) { + ctx->mem.named.ipv4_header_size = (read_packet_u8(ctx, ETH_HLEN) & 15) * 4; } // Is access to offset |p| length |size| within output buffer bounds? @@ -170,7 +176,7 @@ static int do_apf_run(apf_context* ctx) { { // half indent to avoid needless line length... - const u8 bytecode = ctx->program[ctx->pc++]; + const u8 bytecode = DECODE_U8(); const u8 opcode = EXTRACT_OPCODE(bytecode); const u8 reg_num = EXTRACT_REGISTER(bytecode); #define REG (ctx->R[reg_num]) @@ -237,7 +243,7 @@ static int do_apf_run(apf_context* ctx) { // Catch overflow/wrap-around. ASSERT_RETURN(end_offs >= offs); ASSERT_IN_PACKET_BOUNDS(end_offs); - while (load_size--) val = (val << 8) | ctx->packet[offs++]; + while (load_size--) val = (val << 8) | read_packet_u8(ctx, offs++); REG = val; } break; @@ -256,7 +262,8 @@ static int do_apf_run(apf_context* ctx) { case JNE_OPCODE: case JGT_OPCODE: case JLT_OPCODE: - case JSET_OPCODE: { + case JSET_OPCODE: + case JNSET_OPCODE: { u32 cmp_imm = 0; // Load second immediate field. if (reg_num == 1) { @@ -265,11 +272,12 @@ static int do_apf_run(apf_context* ctx) { cmp_imm = decode_imm(ctx, imm_len); // 2nd imm, at worst 8 bytes past prog_len } switch (opcode) { - case JEQ_OPCODE: if (ctx->R[0] == cmp_imm) ctx->pc += imm; break; - case JNE_OPCODE: if (ctx->R[0] != cmp_imm) ctx->pc += imm; break; - case JGT_OPCODE: if (ctx->R[0] > cmp_imm) ctx->pc += imm; break; - case JLT_OPCODE: if (ctx->R[0] < cmp_imm) ctx->pc += imm; break; - case JSET_OPCODE: if (ctx->R[0] & cmp_imm) ctx->pc += imm; break; + case JEQ_OPCODE: if ( ctx->R[0] == cmp_imm ) ctx->pc += imm; break; + case JNE_OPCODE: if ( ctx->R[0] != cmp_imm ) ctx->pc += imm; break; + case JGT_OPCODE: if ( ctx->R[0] > cmp_imm ) ctx->pc += imm; break; + case JLT_OPCODE: if ( ctx->R[0] < cmp_imm ) ctx->pc += imm; break; + case JSET_OPCODE: if ( ctx->R[0] & cmp_imm ) ctx->pc += imm; break; + case JNSET_OPCODE: if (!(ctx->R[0] & cmp_imm)) ctx->pc += imm; break; } break; } diff --git a/v5/apf_utils.h b/v7/apf_utils.h index 1ac8063..1ac8063 120000 --- a/v5/apf_utils.h +++ b/v7/apf_utils.h diff --git a/v5/test_buf_allocator.c b/v7/test_buf_allocator.c index e30815e..e30815e 100644 --- a/v5/test_buf_allocator.c +++ b/v7/test_buf_allocator.c diff --git a/v5/test_buf_allocator.h b/v7/test_buf_allocator.h index c5fa5c4..c5fa5c4 100644 --- a/v5/test_buf_allocator.h +++ b/v7/test_buf_allocator.h |