diff --git a/include/ebpf_program_types.h b/include/ebpf_program_types.h index ffefc41092..b89513fcec 100644 --- a/include/ebpf_program_types.h +++ b/include/ebpf_program_types.h @@ -29,6 +29,8 @@ typedef struct _ebpf_program_type_descriptor char is_privileged; } ebpf_program_type_descriptor_t; +#define HELPER_FUNCTION_REALLOCATE_PACKET 0x1 + typedef struct _ebpf_helper_function_prototype { uint32_t helper_id; diff --git a/libs/api_common/store_helper_internal.cpp b/libs/api_common/store_helper_internal.cpp index 9bbad554f3..3af41ffc01 100644 --- a/libs/api_common/store_helper_internal.cpp +++ b/libs/api_common/store_helper_internal.cpp @@ -50,8 +50,9 @@ _load_helper_prototype( // Read serialized helper prototype information. char serialized_data[sizeof(ebpf_helper_function_prototype_t)] = {0}; + bool reallocate_packet = false; size_t expected_size = sizeof(helper_prototype->helper_id) + sizeof(helper_prototype->return_type) + - sizeof(helper_prototype->arguments); + sizeof(helper_prototype->arguments) + sizeof(reallocate_packet); status = ebpf_read_registry_value_binary( helper_info_key, EBPF_HELPER_DATA_PROTOTYPE, (uint8_t*)serialized_data, expected_size); @@ -71,6 +72,10 @@ _load_helper_prototype( memcpy(&helper_prototype->arguments, serialized_data + offset, sizeof(helper_prototype->arguments)); offset += sizeof(helper_prototype->arguments); + memcpy(&reallocate_packet, serialized_data + offset, sizeof(reallocate_packet)); + helper_prototype->reallocate_packet = reallocate_packet ? HELPER_FUNCTION_REALLOCATE_PACKET : 0; + offset += sizeof(reallocate_packet); + helper_prototype->name = cxplat_duplicate_string(ebpf_down_cast_from_wstring(std::wstring(helper_name)).c_str()); if (helper_prototype->name == nullptr) { diff --git a/libs/store_helper/ebpf_store_helper.c b/libs/store_helper/ebpf_store_helper.c index 0e54da6b56..dfa22a6915 100644 --- a/libs/store_helper/ebpf_store_helper.c +++ b/libs/store_helper/ebpf_store_helper.c @@ -40,6 +40,7 @@ _ebpf_store_update_helper_prototype( uint32_t offset; ebpf_store_key_t helper_function_key = NULL; char serialized_data[sizeof(ebpf_helper_function_prototype_t)] = {0}; + const bool reallocate_packet = helper_info->reallocate_packet; wchar_t* wide_helper_name = ebpf_get_wstring_from_string(helper_info->name); if (wide_helper_name == NULL) { @@ -62,6 +63,9 @@ _ebpf_store_update_helper_prototype( memcpy(serialized_data + offset, helper_info->arguments, sizeof(helper_info->arguments)); offset += sizeof(helper_info->arguments); + memcpy(serialized_data + offset, &reallocate_packet, sizeof(reallocate_packet)); + offset += sizeof(reallocate_packet); + // Save the helper prototype data. result = ebpf_write_registry_value_binary( helper_function_key, EBPF_HELPER_DATA_PROTOTYPE, (uint8_t*)&serialized_data[0], offset); diff --git a/netebpfext/net_ebpf_ext_program_info.h b/netebpfext/net_ebpf_ext_program_info.h index e13f47bbe2..9ac05e23f3 100644 --- a/netebpfext/net_ebpf_ext_program_info.h +++ b/netebpfext/net_ebpf_ext_program_info.h @@ -9,8 +9,6 @@ #define XDP_EXT_HELPER_FUNCTION_START EBPF_MAX_GENERAL_HELPER_FUNCTION -#define HELPER_FUNCTION_REALLOCATE_PACKET 1 - // XDP_TEST helper function prototype descriptors. static const ebpf_helper_function_prototype_t _xdp_test_ebpf_extension_helper_function_prototype[] = { {XDP_EXT_HELPER_FUNCTION_START + 1, diff --git a/tests/end_to_end/netsh_test.cpp b/tests/end_to_end/netsh_test.cpp index 2de826c5a0..47afa24a78 100644 --- a/tests/end_to_end/netsh_test.cpp +++ b/tests/end_to_end/netsh_test.cpp @@ -373,7 +373,7 @@ TEST_CASE("show verification xdp_adjust_head_unsafe.o", "[netsh][verification]") "\n" "; ./tests/sample/unsafe/xdp_adjust_head_unsafe.c:38\n" "; ethernet_header->Type = 0x0800;\n" - "16: Upper bound must be at most packet_size (valid_access(r1.offset+26, width=2) for write)\n" + "17: Upper bound must be at most packet_size (valid_access(r1.offset+26, width=2) for write)\n" "\n" "1 errors\n" "\n"); diff --git a/tests/sample/unsafe/xdp_adjust_head_unsafe.c b/tests/sample/unsafe/xdp_adjust_head_unsafe.c index a07016fdfa..1f4b21b040 100644 --- a/tests/sample/unsafe/xdp_adjust_head_unsafe.c +++ b/tests/sample/unsafe/xdp_adjust_head_unsafe.c @@ -25,7 +25,7 @@ xdp_adjust_head_unsafe(xdp_md_t* ctx) } // Adjust the head of the packet - if (bpf_xdp_adjust_head(ctx, sizeof(ETHERNET_HEADER) < 0)) { + if (bpf_xdp_adjust_head(ctx, sizeof(ETHERNET_HEADER)) < 0) { rc = XDP_DROP; goto Done; } diff --git a/tools/bpf2c/bpf2c.cpp b/tools/bpf2c/bpf2c.cpp index d410b19a2c..3cf39848b4 100644 --- a/tools/bpf2c/bpf2c.cpp +++ b/tools/bpf2c/bpf2c.cpp @@ -117,7 +117,7 @@ get_program_info_type_hash(const std::vector& actual_helper_ids, const byte_range, program_info->program_type_specific_helper_prototype[index].arguments[argument]); } if (program_info->program_type_specific_helper_prototype[index].reallocate_packet) { - hash_t::append_byte_range(byte_range, "reallocate_packet"); + hash_t::append_byte_range(byte_range, reinterpret_cast("reallocate_packet")); } } } diff --git a/tools/bpf2c/bpf2c.vcxproj b/tools/bpf2c/bpf2c.vcxproj index 09ecfb5e5a..d13295fa2b 100644 --- a/tools/bpf2c/bpf2c.vcxproj +++ b/tools/bpf2c/bpf2c.vcxproj @@ -86,13 +86,13 @@ - true + false - true + false - true + false false @@ -108,7 +108,7 @@ Console - true + DebugFull $(FuzzerLibs);%(AdditionalDependencies) @@ -126,7 +126,7 @@ Console - true + DebugFull $(FuzzerLibs);%(AdditionalDependencies) @@ -141,7 +141,7 @@ Console - true + DebugFull $(FuzzerLibs);%(AdditionalDependencies) @@ -159,7 +159,7 @@ Console true true - true + DebugFull $(FuzzerLibs);%(AdditionalDependencies) @@ -177,7 +177,7 @@ Console true true - true + DebugFull $(FuzzerLibs);%(AdditionalDependencies)