diff options
author | Yuyang Huang <yuyanghuang@google.com> | 2023-12-07 16:57:01 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-12-07 16:57:01 +0000 |
commit | 494abd4a5528aef5c2a616fc167e194c1f9d69f7 (patch) | |
tree | 33fd03870ab16a31c7f20251ec1183c746c1f6fe | |
parent | 392fdc64b3b62090d61ee55f365b3bf23dc1163e (diff) | |
parent | e9477d69a1d44d3b618775141ff6c68685547181 (diff) | |
download | apf-494abd4a5528aef5c2a616fc167e194c1f9d69f7.tar.gz |
Update the APFv6 API to support pass in the ctx parameter am: e9477d69a1
Original change: https://android-review.googlesource.com/c/platform/hardware/google/apf/+/2864570
Change-Id: I967f649209566aca3292807bd98aa782e6aaa560
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | apf_run.c | 4 | ||||
-rw-r--r-- | v5/apf_interpreter.c | 9 | ||||
-rw-r--r-- | v5/apf_interpreter.h | 12 | ||||
-rw-r--r-- | v5/test_buf_allocator.c | 5 |
4 files changed, 20 insertions, 10 deletions
@@ -176,7 +176,7 @@ void packet_handler(int use_apf_v6_interpreter, uint8_t* program, int ret; if (use_apf_v6_interpreter) { - ret = apf_run(program, program_len, ram_len, packet, packet_len, + ret = apf_run(NULL, program, program_len, ram_len, packet, packet_len, filter_age); } else { ret = accept_packet(program, program_len, ram_len, packet, packet_len, @@ -234,7 +234,7 @@ void file_handler(int use_apf_v6_interpreter, uint8_t* program, int result; if (use_apf_v6_interpreter) { - result = apf_run(program, program_len, ram_len, apf_packet, + result = apf_run(NULL, program, program_len, ram_len, apf_packet, apf_header.len, filter_age); } else { result = accept_packet(program, program_len, ram_len, apf_packet, diff --git a/v5/apf_interpreter.c b/v5/apf_interpreter.c index 9c6175d..a10fd5c 100644 --- a/v5/apf_interpreter.c +++ b/v5/apf_interpreter.c @@ -44,10 +44,10 @@ extern void APF_TRACE_HOOK(uint32_t pc, const uint32_t* regs, const uint8_t* pro #define ENFORCE_UNSIGNED(c) ((c)==(uint32_t)(c)) uint32_t apf_version() { - return 20231122; + return 20231207; } -int apf_run(uint8_t* const program, const uint32_t program_len, +int apf_run(void* ctx, uint8_t* const program, const uint32_t program_len, const uint32_t ram_len, const uint8_t* const packet, const uint32_t packet_len, const uint32_t filter_age_16384ths) { // Is offset within program bounds? @@ -299,7 +299,8 @@ int apf_run(uint8_t* const program, const uint32_t program_len, case ALLOC_EXT_OPCODE: ASSERT_RETURN(allocated_buffer == NULL); allocate_buffer_len = REG; - allocated_buffer = apf_allocate_buffer(allocate_buffer_len); + allocated_buffer = + apf_allocate_buffer(ctx, allocate_buffer_len); ASSERT_RETURN(allocated_buffer != NULL); memory[MEMORY_OFFSET_OUTPUT_BUFFER_OFFSET] = 0; break; @@ -311,6 +312,7 @@ int apf_run(uint8_t* const program, const uint32_t program_len, // happened and the allocated_buffer should be deallocated. if (pkt_len > allocate_buffer_len) { apf_transmit_buffer( + ctx, allocated_buffer, 0 /* len */, 0 /* dscp */); @@ -318,6 +320,7 @@ int apf_run(uint8_t* const program, const uint32_t program_len, } // TODO: calculate packet checksum and get dscp apf_transmit_buffer( + ctx, allocated_buffer, pkt_len, 0 /* dscp */); diff --git a/v5/apf_interpreter.h b/v5/apf_interpreter.h index 914e356..a64a68e 100644 --- a/v5/apf_interpreter.h +++ b/v5/apf_interpreter.h @@ -45,13 +45,14 @@ uint32_t apf_version(); * allow firmware to later (during or after apf_transmit_buffer call) populate * any required headers, trailers, etc. * + * @param ctx - unmodified ctx pointer passed into apf_run(). * @param size - the minimum size of buffer to allocate * @return the pointer to the allocated region. The function can return NULL to * indicate allocation failure, for example if too many buffers are * pending transmit. Returning NULL will most likely result in the * apf_run() returning PASS. */ -uint8_t* apf_allocate_buffer(int size); +uint8_t* apf_allocate_buffer(void* ctx, int size); /** * Transmits the allocated buffer and deallocates it. @@ -71,6 +72,7 @@ uint8_t* apf_allocate_buffer(int size); * apf_transmit_buffer() should be asynchronous, which means the actual packet * transmission can happen sometime after the function returns. * + * @param ctx - unmodified ctx pointer passed into apf_run(). * @param ptr - pointer to the transmit buffer, must have been previously * returned by apf_allocate_buffer and not deallocated. * @param len - the number of bytes to be transmitted (possibly less than @@ -82,7 +84,7 @@ uint8_t* apf_allocate_buffer(int size); * the firmware thinks the transmit will succeed. Returning an error * will likely result in apf_run() returning PASS. */ -int apf_transmit_buffer(uint8_t* ptr, int len, uint8_t dscp); +int apf_transmit_buffer(void* ctx, uint8_t* ptr, int len, uint8_t dscp); /** * Runs an APF program over a packet. @@ -101,6 +103,10 @@ int apf_transmit_buffer(uint8_t* ptr, int len, uint8_t dscp); * | text section | data section | * +--------------------+------------------------+ * + * @param ctx - pointer to any additional context required for allocation and transmit. + may be null if no such context is required. this is opaque to + the interpreter and will be passed through unmodified + to apf_allocate_buffer() and apf_transmit_buffer() calls. * @param program - the program bytecode, followed by the writable data region. * @param program_len - the length in bytes of the read-only portion of the APF * buffer pointed to by {@code program}. @@ -116,7 +122,7 @@ int apf_transmit_buffer(uint8_t* ptr, int len, uint8_t dscp); * @return non-zero if packet should be passed, zero if packet should * be dropped. */ -int apf_run(uint8_t* const program, const uint32_t program_len, +int apf_run(void* ctx, uint8_t* const program, const uint32_t program_len, const uint32_t ram_len, const uint8_t* const packet, const uint32_t packet_len, const uint32_t filter_age_16384ths); diff --git a/v5/test_buf_allocator.c b/v5/test_buf_allocator.c index 867dba1..013754e 100644 --- a/v5/test_buf_allocator.c +++ b/v5/test_buf_allocator.c @@ -29,7 +29,7 @@ uint8_t apf_test_tx_dscp; * * Clean up the apf_test_buffer and return the pointer to beginning of the buffer region. */ -uint8_t* apf_allocate_buffer(int size) { +uint8_t* apf_allocate_buffer(__attribute__ ((unused)) void* ctx, int size) { if (size > APF_TX_BUFFER_SIZE) { return NULL; } @@ -42,7 +42,8 @@ uint8_t* apf_allocate_buffer(int size) { * * Copy the content of allocated buffer to the apf_test_tx_packet region. */ -int apf_transmit_buffer(uint8_t* ptr, int len, uint8_t dscp) { +int apf_transmit_buffer(__attribute__((unused)) void* ctx, uint8_t* ptr, + int len, uint8_t dscp) { apf_test_tx_packet_len = len; apf_test_tx_dscp = dscp; memcpy(apf_test_tx_packet, ptr, len); |