Co-authored-by: Dave Thaler <dthaler@microsoft.com>
This commit is contained in:
saxena-anurag 2021-11-23 12:38:29 -08:00 коммит произвёл GitHub
Родитель b771bac9bd
Коммит 5328bf3f14
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 7 добавлений и 9 удалений

Просмотреть файл

@ -400,9 +400,6 @@ _update_array_map_entry_with_handle(
if (index >= map->ebpf_map_definition.max_entries)
return EBPF_INVALID_ARGUMENT;
// The following addition is safe since it was checked during map creation.
size_t actual_value_size = ((size_t)map->ebpf_map_definition.value_size) + sizeof(struct _ebpf_object*);
ebpf_result_t result = EBPF_SUCCESS;
ebpf_lock_state_t lock_state = ebpf_lock_lock(&map->lock);
@ -414,7 +411,7 @@ _update_array_map_entry_with_handle(
}
// Release the reference on the old ID stored here, if any.
uint8_t* entry = &map->data[*key * actual_value_size];
uint8_t* entry = &map->data[*key * map->ebpf_map_definition.value_size];
ebpf_id_t old_id = *(ebpf_id_t*)entry;
if (old_id) {
ebpf_object_dereference_by_id(old_id, value_type);

Просмотреть файл

@ -4,7 +4,7 @@
#include "bpf_helpers.h"
SEC("maps")
struct bpf_map map = {sizeof(struct bpf_map), BPF_MAP_TYPE_PROG_ARRAY, sizeof(uint32_t), sizeof(uint32_t), 1};
struct bpf_map map = {sizeof(struct bpf_map), BPF_MAP_TYPE_PROG_ARRAY, sizeof(uint32_t), sizeof(uint32_t), 10};
SEC("maps") struct bpf_map canary = {sizeof(struct bpf_map), BPF_MAP_TYPE_ARRAY, sizeof(uint32_t), sizeof(uint32_t), 1};
@ -13,7 +13,7 @@ SEC("xdp_prog") int caller(struct xdp_md* ctx)
uint32_t key = 0;
uint32_t* value;
bpf_tail_call(ctx, &map, 0);
bpf_tail_call(ctx, &map, 9);
// If we get to here it means bpf_tail_call failed.
value = bpf_map_lookup_elem(&canary, &key);

Просмотреть файл

@ -4,7 +4,7 @@
#include "bpf_helpers.h"
SEC("maps")
struct bpf_map map = {sizeof(struct bpf_map), BPF_MAP_TYPE_PROG_ARRAY, sizeof(uint32_t), sizeof(uint32_t), 1};
struct bpf_map map = {sizeof(struct bpf_map), BPF_MAP_TYPE_PROG_ARRAY, sizeof(uint32_t), sizeof(uint32_t), 10};
SEC("maps") struct bpf_map canary = {sizeof(struct bpf_map), BPF_MAP_TYPE_ARRAY, sizeof(uint32_t), sizeof(uint32_t), 1};
@ -14,7 +14,7 @@ SEC("xdp_prog") int caller(struct xdp_md* ctx)
uint32_t* value;
// This should fail since the index is past the end of the array.
long error = bpf_tail_call(ctx, &map, 1);
long error = bpf_tail_call(ctx, &map, 10);
value = bpf_map_lookup_elem(&canary, &key);
if (value) {

Просмотреть файл

@ -410,7 +410,7 @@ _ebpf_test_tail_call(_In_z_ const char* filename, int expected_result)
REQUIRE(canary_map_fd >= 0);
// First do some negative tests.
int index = 1;
int index = 10;
error = bpf_map_update_elem(map_fd, (uint8_t*)&index, (uint8_t*)&callee_fd, 0);
REQUIRE(error < 0);
REQUIRE(errno == -error);
@ -421,6 +421,7 @@ _ebpf_test_tail_call(_In_z_ const char* filename, int expected_result)
REQUIRE(errno == -error);
// Finally store the correct program fd.
index = 9;
error = bpf_map_update_elem(map_fd, (uint8_t*)&index, (uint8_t*)&callee_fd, 0);
REQUIRE(error == 0);