diff options
author | Yuyang Huang <yuyanghuang@google.com> | 2023-11-22 15:05:38 +0900 |
---|---|---|
committer | Yuyang Huang <yuyanghuang@google.com> | 2023-11-22 21:14:57 +0900 |
commit | b2e7296f8492af5a686b8082506f9456ac1c3d49 (patch) | |
tree | 3ceaa8917853bc0c884f992a9ff9ddde267c29c6 | |
parent | d2da8aa25991fabcefa1741b2cf8e30a3de3d475 (diff) | |
download | apf-b2e7296f8492af5a686b8082506f9456ac1c3d49.tar.gz |
Update the apf_run() to match the latest design doc
* design doc: go/apf-v6-proposal
Bug: 293811969
Test: TH
Change-Id: I56e9b7e548f55e27bf8768b42fe2323e31bfdaf9
-rw-r--r-- | v5/apf_interpreter.c | 8 | ||||
-rw-r--r-- | v5/apf_interpreter.h | 40 |
2 files changed, 24 insertions, 24 deletions
diff --git a/v5/apf_interpreter.c b/v5/apf_interpreter.c index 586287a..f3b9d36 100644 --- a/v5/apf_interpreter.c +++ b/v5/apf_interpreter.c @@ -47,9 +47,9 @@ uint32_t apf_version() { return 20231122; } -int apf_run(uint8_t* program, uint32_t program_len, uint32_t ram_len, - const uint8_t* packet, uint32_t packet_len, - uint32_t filter_age) { +int apf_run(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? #define IN_PROGRAM_BOUNDS(p) (ENFORCE_UNSIGNED(p) && (p) < program_len) // Is offset within packet bounds? @@ -78,7 +78,7 @@ int apf_run(uint8_t* program, uint32_t program_len, uint32_t ram_len, memory[MEMORY_OFFSET_PROGRAM_SIZE] = program_len; memory[MEMORY_OFFSET_DATA_SIZE] = ram_len; memory[MEMORY_OFFSET_PACKET_SIZE] = packet_len; - memory[MEMORY_OFFSET_FILTER_AGE] = filter_age; + memory[MEMORY_OFFSET_FILTER_AGE] = filter_age_16384ths >> 14; ASSERT_IN_PACKET_BOUNDS(APF_FRAME_HEADER_SIZE); // Only populate if IP version is IPv4. if ((packet[APF_FRAME_HEADER_SIZE] & 0xf0) == 0x40) { diff --git a/v5/apf_interpreter.h b/v5/apf_interpreter.h index 2d493e3..914e356 100644 --- a/v5/apf_interpreter.h +++ b/v5/apf_interpreter.h @@ -85,12 +85,12 @@ uint8_t* apf_allocate_buffer(int size); int apf_transmit_buffer(uint8_t* ptr, int len, uint8_t dscp); /** - * Runs a packet filtering program over a packet. + * Runs an APF program over a packet. * - * The return value of the apf_run indicates whether the packet should be - * passed to AP or not. As a part of apf_run execution, the packet filtering + * The return value of apf_run indicates whether the packet should + * be passed or dropped. As a part of apf_run execution, the APF * program can call apf_allocate_buffer()/apf_transmit_buffer() to construct - * an egress packet to transmit it. + * a reply packet and transmit it. * * The text section containing the program instructions starts at address * program and stops at + program_len - 1, and the writable data section @@ -101,24 +101,24 @@ int apf_transmit_buffer(uint8_t* ptr, int len, uint8_t dscp); * | text section | data section | * +--------------------+------------------------+ * - * @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 + * @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}. - * @param ram_len total length of the APF buffer pointed to by {@code program}, - * including the read-only bytecode portion and the read-write - * data portion. - * @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. Return 1 indicating the packet is accepted - * without error. Negative return values are reserved for error code. + * @param ram_len - total length of the APF buffer pointed to by + * {@code program}, including the read-only bytecode + * portion and the read-write data portion. + * @param packet - the packet bytes, starting from the ethernet header. + * @param packet_len - the length of {@code packet} in bytes, not + * including trailers/CRC. + * @param filter_age_16384ths - the number of 1/16384 seconds since the filter + * was programmed. + * + * @return non-zero if packet should be passed, zero if packet should + * be dropped. */ -int apf_run(uint8_t* program, uint32_t program_len, uint32_t ram_len, - const uint8_t* packet, uint32_t packet_len, - uint32_t filter_age); +int apf_run(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); #ifdef __cplusplus } |