diff options
author | Maciej Żenczykowski <maze@google.com> | 2024-05-10 05:40:43 -0700 |
---|---|---|
committer | Maciej Żenczykowski <maze@google.com> | 2024-05-10 13:36:33 +0000 |
commit | 73e3f4825383eec688d752910d7409d0e58a45be (patch) | |
tree | 43f3c330b0bc840a7085ab4f1b9365e037f3be3a | |
parent | f8ce289a958f7a05d30792e05d3ecf54dfce29c3 (diff) | |
download | apf-main.tar.gz |
Both before and after:
text data bss dec hex filename
4296 0 0 4296 10c8 apf_interpreter.arm.o
text data bss dec hex filename
5581 0 0 5581 15cd apf_interpreter.x86.o
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I383e33eb174c45f8965395e4a0d251fd50305755
-rw-r--r-- | v7/apf_interpreter.c | 12 | ||||
-rw-r--r-- | v7/apf_interpreter_source.c | 12 |
2 files changed, 18 insertions, 6 deletions
diff --git a/v7/apf_interpreter.c b/v7/apf_interpreter.c index 56659e1..6fcbf93 100644 --- a/v7/apf_interpreter.c +++ b/v7/apf_interpreter.c @@ -661,6 +661,11 @@ static u32 decode_imm(apf_context* ctx, u32 length) { 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) { /* Is offset within ram bounds? */ #define IN_RAM_BOUNDS(p) (ENFORCE_UNSIGNED(p) && (p) < ctx->ram_len) @@ -693,8 +698,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? */ @@ -781,7 +787,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; diff --git a/v7/apf_interpreter_source.c b/v7/apf_interpreter_source.c index eb09d90..7259d5e 100644 --- a/v7/apf_interpreter_source.c +++ b/v7/apf_interpreter_source.c @@ -117,6 +117,11 @@ static u32 decode_imm(apf_context* ctx, u32 length) { 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) { // Is offset within ram bounds? #define IN_RAM_BOUNDS(p) (ENFORCE_UNSIGNED(p) && (p) < ctx->ram_len) @@ -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? @@ -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; |