Skip to content

Commit

Permalink
PR Feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
shankarseal committed Apr 3, 2024
1 parent dc0163e commit 5ac466e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
9 changes: 6 additions & 3 deletions docs/eBpfExtensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,19 @@ in the context descriptor.
#### `ebpf_helper_function_prototype_t` Struct
This structure is used to describe the prototypes of the various helper functions implemented by the extension.
```c
typedef struct _ebpf_helper_function_prototype_flags
{
bool reallocate_packet : 1;
} ebpf_helper_function_prototype_flags_t;
typedef struct _ebpf_helper_function_prototype
{
ebpf_extension_header_t header;
uint32_t helper_id;
const char* name;
ebpf_return_type_t return_type;
ebpf_argument_type_t arguments[5];
struct {
bool reallocate_packet : 1;
} flags;
ebpf_helper_function_prototype_flags_t flags;
} ebpf_helper_function_prototype_t;
```
* `header`: Version and size.
Expand Down
10 changes: 6 additions & 4 deletions include/ebpf_program_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ typedef struct _ebpf_program_type_descriptor
char is_privileged;
} ebpf_program_type_descriptor_t;

typedef struct _ebpf_helper_function_prototype_flags
{
bool reallocate_packet : 1;
} ebpf_helper_function_prototype_flags_t;

// This is the type definition for the eBPF helper function prototype
// when version is EBPF_HELPER_FUNCTION_PROTOTYPE_CURRENT_VERSION.
typedef struct _ebpf_helper_function_prototype
Expand All @@ -30,10 +35,7 @@ typedef struct _ebpf_helper_function_prototype
const char* name;
ebpf_return_type_t return_type;
ebpf_argument_type_t arguments[5];
struct
{
bool reallocate_packet : 1;
} flags;
ebpf_helper_function_prototype_flags_t flags;
} ebpf_helper_function_prototype_t;

// This is the type definition for the eBPF program information
Expand Down
8 changes: 3 additions & 5 deletions libs/execution_context/ebpf_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -2157,11 +2157,9 @@ _IRQL_requires_max_(PASSIVE_LEVEL) static ebpf_result_t _ebpf_program_compute_pr
}
}

if (helper_function_prototype->flags.reallocate_packet) {
result = EBPF_CRYPTOGRAPHIC_HASH_APPEND_STR(cryptographic_hash, "reallocate_packet");
if (result != EBPF_SUCCESS) {
goto Exit;
}
result = EBPF_CRYPTOGRAPHIC_HASH_APPEND_VALUE(cryptographic_hash, helper_function_prototype->flags);
if (result != EBPF_SUCCESS) {
goto Exit;
}
}
*hash_length = 0;
Expand Down
9 changes: 3 additions & 6 deletions libs/shared/ebpf_serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ typedef struct _ebpf_serialized_helper_function_prototype
uint32_t helper_id;
ebpf_return_type_t return_type;
ebpf_argument_type_t arguments[5];
struct
{
bool reallocate_packet : 1;
} flags;
ebpf_helper_function_prototype_flags_t flags;
size_t name_length;
uint8_t name[1];
} ebpf_serialized_helper_function_prototype_t;
Expand Down Expand Up @@ -481,7 +478,7 @@ ebpf_serialize_program_info(
for (uint16_t index = 0; index < EBPF_COUNT_OF(helper_prototype->arguments); index++) {
serialized_helper_prototype->arguments[index] = helper_prototype->arguments[index];
}
serialized_helper_prototype->flags.reallocate_packet = helper_prototype->flags.reallocate_packet;
serialized_helper_prototype->flags = helper_prototype->flags;
serialized_helper_prototype->name_length = helper_function_name_length;
// Copy the program type descriptor name buffer.
memcpy(serialized_helper_prototype->name, helper_prototype->name, helper_function_name_length);
Expand Down Expand Up @@ -662,7 +659,7 @@ ebpf_deserialize_program_info(
for (int i = 0; i < EBPF_COUNT_OF(helper_prototype->arguments); i++) {
helper_prototype->arguments[i] = serialized_helper_prototype->arguments[i];
}
helper_prototype->flags.reallocate_packet = serialized_helper_prototype->flags.reallocate_packet;
helper_prototype->flags = serialized_helper_prototype->flags;

// Adjust remaining buffer length.
result = ebpf_safe_size_t_subtract(
Expand Down
4 changes: 1 addition & 3 deletions tools/bpf2c/bpf2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ get_program_info_type_hash(const std::vector<int32_t>& actual_helper_ids, const
hash_t::append_byte_range(
byte_range, program_info->program_type_specific_helper_prototype[index].arguments[argument]);
}
if (program_info->program_type_specific_helper_prototype[index].flags.reallocate_packet) {
hash_t::append_byte_range(byte_range, reinterpret_cast<const char*>("reallocate_packet"));
}
hash_t::append_byte_range(byte_range, program_info->program_type_specific_helper_prototype[index].flags);
}
}
hash_t hash(algorithm);
Expand Down

0 comments on commit 5ac466e

Please sign in to comment.