* Remove ebpf_get_next_program (bpf_prog_get_next_id should be used
  instead)
* Don't export the internal ebpf_map_pin api

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
This commit is contained in:
Dave Thaler 2022-05-16 10:02:22 -07:00 коммит произвёл GitHub
Родитель ee73ea7de4
Коммит eab141f47c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 36 добавлений и 119 удалений

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

@ -95,11 +95,9 @@ EXPORTS
ebpf_free_string
ebpf_get_attach_type_name
ebpf_get_next_pinned_program_path
ebpf_get_next_program
ebpf_get_program_type_by_name
ebpf_get_program_type_name
ebpf_link_close
ebpf_map_pin
ebpf_object_get
ebpf_object_unpin
ebpf_program_attach

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

@ -74,17 +74,6 @@ extern "C"
uint32_t map_flags,
_Out_ fd_t* map_fd);
/**
* @brief Get file descriptor to the next eBPF program.
* @param[in] previous_fd File descriptor of the previous eBPF program or ebpf_fd_invalid to
* start enumeration.
* @param[out] next_fd File descriptor of the next eBPF program or ebpf_fd_invalid if
* this is the last program.
* @retval EBPF_SUCCESS The operation was successful.
*/
ebpf_result_t
ebpf_get_next_program(fd_t previous_fd, _Out_ fd_t* next_fd);
/**
* @brief Query info about an eBPF program.
* @param[in] fd File descriptor of an eBPF program.

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

@ -851,39 +851,6 @@ ebpf_object_get(_In_z_ const char* path)
return fd;
}
ebpf_result_t
ebpf_get_next_program(fd_t previous_fd, _Out_ fd_t* next_fd)
{
ebpf_assert(next_fd);
fd_t local_fd = previous_fd;
*next_fd = ebpf_fd_invalid;
ebpf_handle_t previous_handle = _get_handle_from_file_descriptor(local_fd);
ebpf_operation_get_next_program_request_t request{
sizeof(request), ebpf_operation_id_t::EBPF_OPERATION_GET_NEXT_PROGRAM, previous_handle};
ebpf_operation_get_next_program_reply_t reply;
uint32_t retval = invoke_ioctl(request, reply);
if (retval == ERROR_SUCCESS) {
ebpf_assert(reply.header.id == ebpf_operation_id_t::EBPF_OPERATION_GET_NEXT_PROGRAM);
ebpf_handle_t next_handle = reply.next_handle;
if (next_handle != ebpf_handle_invalid) {
fd_t fd = _create_file_descriptor_for_handle(next_handle);
if (fd == ebpf_fd_invalid) {
// Some error getting fd for the handle.
Platform::CloseHandle(next_handle);
retval = ERROR_OUTOFMEMORY;
} else {
*next_fd = fd;
}
} else {
*next_fd = ebpf_fd_invalid;
}
}
return win32_error_code_to_ebpf_result(retval);
}
ebpf_result_t
ebpf_program_query_info(
fd_t fd,

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

@ -649,26 +649,23 @@ handle_ebpf_show_programs(
std::cout << "====== ==== ===== ========= ============= ====================\n";
}
uint32_t program_id = 0;
fd_t program_fd = ebpf_fd_invalid;
for (;;) {
const char* program_file_name;
const char* program_section_name;
const char* execution_type_name;
ebpf_execution_type_t program_execution_type;
fd_t next_program_fd;
status = ebpf_get_next_program(program_fd, &next_program_fd);
if (status != ERROR_SUCCESS) {
uint32_t next_program_id;
if (bpf_prog_get_next_id(program_id, &next_program_id) < 0) {
break;
}
program_id = next_program_id;
if (program_fd != ebpf_fd_invalid) {
Platform::_close(program_fd);
}
program_fd = next_program_fd;
if (program_fd == ebpf_fd_invalid) {
break;
}
program_fd = bpf_prog_get_fd_by_id(program_id);
struct bpf_prog_info info;
uint32_t info_size = (uint32_t)sizeof(info);

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

@ -848,17 +848,6 @@ _ebpf_core_protocol_get_next_map(
EBPF_RETURN_RESULT(_ebpf_core_get_next_handle(request->previous_handle, EBPF_OBJECT_MAP, &reply->next_handle));
}
static ebpf_result_t
_ebpf_core_protocol_get_next_program(
_In_ const struct _ebpf_operation_get_next_program_request* request,
_Inout_ struct _ebpf_operation_get_next_program_reply* reply,
uint16_t reply_length)
{
EBPF_LOG_ENTRY();
UNREFERENCED_PARAMETER(reply_length);
EBPF_RETURN_RESULT(_ebpf_core_get_next_handle(request->previous_handle, EBPF_OBJECT_PROGRAM, &reply->next_handle));
}
static ebpf_result_t
_ebpf_core_protocol_query_program_info(
_In_ const struct _ebpf_operation_query_program_info_request* request,
@ -1846,11 +1835,6 @@ static ebpf_protocol_handler_t _ebpf_protocol_handlers[] = {
sizeof(struct _ebpf_operation_get_next_map_request),
sizeof(struct _ebpf_operation_get_next_map_reply)},
// EBPF_OPERATION_GET_NEXT_PROGRAM
{(ebpf_result_t(__cdecl*)(const void*))_ebpf_core_protocol_get_next_program,
sizeof(struct _ebpf_operation_get_next_program_request),
sizeof(struct _ebpf_operation_get_next_program_reply)},
// EBPF_OPERATION_QUERY_PROGRAM_INFO
{(ebpf_result_t(__cdecl*)(const void*))_ebpf_core_protocol_query_program_info,
sizeof(struct _ebpf_operation_query_program_info_request),

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

@ -20,7 +20,6 @@ typedef enum _ebpf_operation_id
EBPF_OPERATION_MAP_DELETE_ELEMENT,
EBPF_OPERATION_MAP_GET_NEXT_KEY,
EBPF_OPERATION_GET_NEXT_MAP,
EBPF_OPERATION_GET_NEXT_PROGRAM,
EBPF_OPERATION_QUERY_PROGRAM_INFO,
EBPF_OPERATION_UPDATE_PINNING,
EBPF_OPERATION_GET_PINNING,
@ -177,18 +176,6 @@ typedef struct _ebpf_operation_get_next_map_reply
ebpf_handle_t next_handle;
} ebpf_operation_get_next_map_reply_t;
typedef struct _ebpf_operation_get_next_program_request
{
struct _ebpf_operation_header header;
ebpf_handle_t previous_handle;
} ebpf_operation_get_next_program_request_t;
typedef struct _ebpf_operation_get_next_program_reply
{
struct _ebpf_operation_header header;
ebpf_handle_t next_handle;
} ebpf_operation_get_next_program_reply_t;
typedef struct _ebpf_operation_get_handle_by_id_request
{
struct _ebpf_operation_header header;

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

@ -72,8 +72,6 @@ _test_program_load(
ebpf_result_t result;
struct bpf_object* object = nullptr;
fd_t program_fd;
fd_t previous_fd = ebpf_fd_invalid;
fd_t next_fd = ebpf_fd_invalid;
result = _program_load_helper(file_name, program_type, execution_type, &object, &program_fd);
REQUIRE(result == expected_load_result);
@ -84,9 +82,12 @@ _test_program_load(
return;
}
uint32_t next_id;
REQUIRE(bpf_prog_get_next_id(0, &next_id) == 0);
// Query loaded programs to verify this program is loaded.
REQUIRE(ebpf_get_next_program(previous_fd, &next_fd) == EBPF_SUCCESS);
REQUIRE(next_fd != ebpf_fd_invalid);
program_fd = bpf_prog_get_fd_by_id(next_id);
REQUIRE(program_fd > 0);
const char* program_file_name;
const char* program_section_name;
@ -94,6 +95,7 @@ _test_program_load(
REQUIRE(
ebpf_program_query_info(program_fd, &program_execution_type, &program_file_name, &program_section_name) ==
EBPF_SUCCESS);
_close(program_fd);
// Set the default execution type to JIT. This will eventually
// be decided by a system-wide policy. TODO(Issue #288): Configure
@ -106,17 +108,13 @@ _test_program_load(
REQUIRE(strcmp(program_file_name, file_name) == 0);
// Next program should not be present.
previous_fd = next_fd;
REQUIRE(ebpf_get_next_program(previous_fd, &next_fd) == EBPF_SUCCESS);
REQUIRE(next_fd == ebpf_fd_invalid);
uint32_t previous_id = next_id;
REQUIRE(bpf_prog_get_next_id(previous_id, &next_id) == -ENOENT);
_close(previous_fd);
previous_fd = ebpf_fd_invalid;
bpf_object__close(object);
// We have closed both handles to the program. Program should be unloaded now.
REQUIRE(ebpf_get_next_program(previous_fd, &next_fd) == ERROR_SUCCESS);
REQUIRE(next_fd == ebpf_fd_invalid);
REQUIRE(bpf_prog_get_next_id(0, &next_id) == -ENOENT);
}
struct _ebpf_program_load_test_parameters

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

@ -1059,8 +1059,8 @@ TEST_CASE("enumerate_and_query_programs", "[end_to_end]")
{
_test_helper_end_to_end test_helper;
fd_t program_fd;
fd_t next_program_fd;
uint32_t program_id;
uint32_t next_program_id;
const char* error_message = nullptr;
ebpf_result_t result;
const char* file_name = nullptr;
@ -1097,11 +1097,13 @@ TEST_CASE("enumerate_and_query_programs", "[end_to_end]")
REQUIRE(result == EBPF_SUCCESS);
ebpf_execution_type_t type;
program_fd = ebpf_fd_invalid;
REQUIRE(ebpf_get_next_program(program_fd, &next_program_fd) == EBPF_SUCCESS);
REQUIRE(next_program_fd != ebpf_fd_invalid);
program_fd = next_program_fd;
program_id = 0;
REQUIRE(bpf_prog_get_next_id(program_id, &next_program_id) == 0);
program_id = next_program_id;
fd_t program_fd = bpf_prog_get_fd_by_id(program_id);
REQUIRE(program_fd > 0);
REQUIRE(ebpf_program_query_info(program_fd, &type, &file_name, &section_name) == EBPF_SUCCESS);
Platform::_close(program_fd);
REQUIRE(type == EBPF_EXECUTION_JIT);
REQUIRE(strcmp(file_name, SAMPLE_PATH "droppacket.o") == 0);
ebpf_free_string(file_name);
@ -1110,11 +1112,12 @@ TEST_CASE("enumerate_and_query_programs", "[end_to_end]")
ebpf_free_string(section_name);
section_name = nullptr;
REQUIRE(ebpf_get_next_program(program_fd, &next_program_fd) == EBPF_SUCCESS);
REQUIRE(next_program_fd != ebpf_fd_invalid);
Platform::_close(program_fd);
program_fd = next_program_fd;
REQUIRE(bpf_prog_get_next_id(program_id, &next_program_id) == 0);
program_id = next_program_id;
program_fd = bpf_prog_get_fd_by_id(program_id);
REQUIRE(program_fd > 0);
REQUIRE(ebpf_program_query_info(program_fd, &type, &file_name, &section_name) == EBPF_SUCCESS);
Platform::_close(program_fd);
REQUIRE(type == EBPF_EXECUTION_INTERPRET);
REQUIRE(strcmp(file_name, SAMPLE_PATH "droppacket.o") == 0);
REQUIRE(strcmp(section_name, "xdp") == 0);
@ -1123,9 +1126,7 @@ TEST_CASE("enumerate_and_query_programs", "[end_to_end]")
file_name = nullptr;
section_name = nullptr;
REQUIRE(ebpf_get_next_program(program_fd, &next_program_fd) == EBPF_SUCCESS);
REQUIRE(next_program_fd == ebpf_fd_invalid);
Platform::_close(program_fd);
REQUIRE(bpf_prog_get_next_id(program_id, &next_program_id) == -ENOENT);
for (int i = 0; i < _countof(object); i++) {
bpf_object__close(object[i]);
@ -1175,9 +1176,8 @@ TEST_CASE("implicit_detach", "[end_to_end]")
// detach the program from the hook and unload the program.
bpf_object__close(object);
program_fd = ebpf_fd_invalid;
REQUIRE(ebpf_get_next_program(program_fd, &program_fd) == EBPF_SUCCESS);
REQUIRE(program_fd == ebpf_fd_invalid);
uint32_t program_id;
REQUIRE(bpf_prog_get_next_id(0, &program_id) == -ENOENT);
// Close link handle (without detaching). This should delete the link
// object. ebpf_object_tracking_terminate() which is called when the test
@ -1222,9 +1222,8 @@ TEST_CASE("implicit_detach_2", "[end_to_end]")
// detach the program from the hook and unload the program.
bpf_object__close(object);
program_fd = ebpf_fd_invalid;
REQUIRE(ebpf_get_next_program(program_fd, &program_fd) == EBPF_SUCCESS);
REQUIRE(program_fd == ebpf_fd_invalid);
uint32_t program_id;
REQUIRE(bpf_prog_get_next_id(0, &program_id) == -ENOENT);
// Close link handle (without detaching). This should delete the link
// object. ebpf_object_tracking_terminate() which is called when the test
@ -1272,9 +1271,8 @@ TEST_CASE("explicit_detach", "[end_to_end]")
// Close program handle.
bpf_object__close(object);
program_fd = ebpf_fd_invalid;
REQUIRE(ebpf_get_next_program(program_fd, &program_fd) == EBPF_SUCCESS);
REQUIRE(program_fd == ebpf_fd_invalid);
uint32_t program_id;
REQUIRE(bpf_prog_get_next_id(0, &program_id) == -ENOENT);
}
TEST_CASE("implicit_explicit_detach", "[end_to_end]")
@ -1311,9 +1309,8 @@ TEST_CASE("implicit_explicit_detach", "[end_to_end]")
// Close program handle. That should detach the program from the hook
// and unload the program.
bpf_object__close(object);
program_fd = ebpf_fd_invalid;
REQUIRE(ebpf_get_next_program(program_fd, &program_fd) == EBPF_SUCCESS);
REQUIRE(program_fd == ebpf_fd_invalid);
uint32_t program_id;
REQUIRE(bpf_prog_get_next_id(0, &program_id) == -ENOENT);
// Detach and close link handle.
// ebpf_object_tracking_terminate() which is called when the test