Fix return values from bpf_map_delete_elem etc helpers (#362)

Per https://github.com/iovisor/bpf-docs/blob/master/bpf_helpers.rst
negative numbers indicate failure.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
This commit is contained in:
Dave Thaler 2021-08-09 08:41:15 -07:00 коммит произвёл GitHub
Родитель be67121fda
Коммит 30246d0025
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 12 добавлений и 12 удалений

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

@ -38,7 +38,7 @@ EBPF_HELPER(void*, bpf_map_lookup_elem, (struct bpf_map * map, void* key));
* @param[in] value Value to insert into the map.
* @param[in] flags Map flags.
* @retval EBPF_SUCCESS The operation was successful.
* @retval EBPF_NO_MEMORY Unable to allocate resources for this
* @retval -EBPF_NO_MEMORY Unable to allocate resources for this
* entry.
*/
EBPF_HELPER(int64_t, bpf_map_update_elem, (struct bpf_map * map, void* key, void* value, uint64_t flags));
@ -52,7 +52,7 @@ EBPF_HELPER(int64_t, bpf_map_update_elem, (struct bpf_map * map, void* key, void
* @param[in] map Map to update.
* @param[in] key Key to use when searching and updating the map.
* @retval EBPF_SUCCESS The operation was successful.
* @retval EBPF_INVALID_ARGUMENT One or more parameters are invalid.
* @retval -EBPF_INVALID_ARGUMENT One or more parameters are invalid.
*/
EBPF_HELPER(int64_t, bpf_map_delete_elem, (struct bpf_map * map, void* key));
#ifndef __doxygen
@ -66,9 +66,9 @@ EBPF_HELPER(int64_t, bpf_map_delete_elem, (struct bpf_map * map, void* key));
* @param[in] prog_array_map Map of program fds.
* @param[in] index Index in map of program to call.
* @retval EBPF_SUCCESS The operation was successful.
* @retval EBPF_INVALID_ARGUMENT One or more parameters are invalid.
* @retval -EBPF_INVALID_ARGUMENT One or more parameters are invalid.
*/
EBPF_HELPER(int, bpf_tail_call, (void* ctx, struct bpf_map* prog_array_map, uint32_t index));
EBPF_HELPER(int64_t, bpf_tail_call, (void* ctx, struct bpf_map* prog_array_map, uint32_t index));
#ifndef __doxygen
#define bpf_tail_call ((bpf_tail_call_t)4)
#endif

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

@ -26,9 +26,9 @@ static void*
_ebpf_core_map_find_element(ebpf_map_t* map, const uint8_t* key);
static int64_t
_ebpf_core_map_update_element(ebpf_map_t* map, const uint8_t* key, const uint8_t* data, uint64_t flags);
static void
static int64_t
_ebpf_core_map_delete_element(ebpf_map_t* map, const uint8_t* key);
static long
static int64_t
_ebpf_core_tail_call(void* ctx, ebpf_map_t* map, uint32_t index);
#define EBPF_CORE_GLOBAL_HELPER_EXTENSION_VERSION 0
@ -937,22 +937,22 @@ static int64_t
_ebpf_core_map_update_element(ebpf_map_t* map, const uint8_t* key, const uint8_t* value, uint64_t flags)
{
UNREFERENCED_PARAMETER(flags);
return ebpf_map_update_entry(map, key, value) == EBPF_SUCCESS ? 0 : -1;
return -ebpf_map_update_entry(map, key, value);
}
static void
static int64_t
_ebpf_core_map_delete_element(ebpf_map_t* map, const uint8_t* key)
{
ebpf_map_delete_entry(map, key);
return -ebpf_map_delete_entry(map, key);
}
static long
static int64_t
_ebpf_core_tail_call(void* context, ebpf_map_t* map, uint32_t index)
{
// Get program from map[index].
ebpf_program_t* callee = ebpf_map_get_program_from_entry(map, (uint8_t*)&index, sizeof(index));
if (callee == NULL) {
return -1;
return -EBPF_INVALID_ARGUMENT;
}
// TODO(issue #344): Jump to (not call) the callee.

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

@ -314,4 +314,4 @@ TEST_CASE("good tail_call", "[libbpf]")
_ebpf_test_tail_call("tail_call.o", 6);
}
TEST_CASE("bad tail_call", "[libbpf]") { _ebpf_test_tail_call("tail_call_bad.o", -1); }
TEST_CASE("bad tail_call", "[libbpf]") { _ebpf_test_tail_call("tail_call_bad.o", -EBPF_INVALID_ARGUMENT); }