Skip to content

Commit

Permalink
Update _single_instance_hook to set link type (#4139)
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Jowett <[email protected]>
  • Loading branch information
Alan-Jowett authored Jan 18, 2025
1 parent 5f890b1 commit a4d8799
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
6 changes: 5 additions & 1 deletion tests/end_to_end/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ typedef class _hook_helper
typedef class _single_instance_hook : public _hook_helper
{
public:
_single_instance_hook(ebpf_program_type_t program_type, ebpf_attach_type_t attach_type)
_single_instance_hook(
ebpf_program_type_t program_type,
ebpf_attach_type_t attach_type,
bpf_link_type link_type = BPF_LINK_TYPE_UNSPEC)
: _hook_helper{attach_type}, client_binding_context(nullptr), client_data(nullptr),
client_dispatch_table(nullptr), link_object(nullptr), client_registration_instance(nullptr),
nmr_binding_handle(nullptr), nmr_provider_handle(nullptr)
Expand All @@ -141,6 +144,7 @@ typedef class _single_instance_hook : public _hook_helper
attach_provider_data.supported_program_type = program_type;
attach_provider_data.bpf_attach_type = get_bpf_attach_type(&attach_type);
this->attach_type = attach_type;
attach_provider_data.link_type = link_type;
module_id.Guid = attach_type;
}
ebpf_result_t
Expand Down
13 changes: 7 additions & 6 deletions tests/end_to_end/test_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,28 +807,29 @@ _test_helper_libbpf::initialize()

xdp_program_info = new program_info_provider_t();
REQUIRE(xdp_program_info->initialize(EBPF_PROGRAM_TYPE_XDP) == EBPF_SUCCESS);
xdp_hook = new single_instance_hook_t(EBPF_PROGRAM_TYPE_XDP, EBPF_ATTACH_TYPE_XDP);
xdp_hook = new single_instance_hook_t(EBPF_PROGRAM_TYPE_XDP, EBPF_ATTACH_TYPE_XDP, BPF_LINK_TYPE_XDP);
REQUIRE(xdp_hook->initialize() == EBPF_SUCCESS);

bind_program_info = new program_info_provider_t();
REQUIRE(bind_program_info->initialize(EBPF_PROGRAM_TYPE_BIND) == EBPF_SUCCESS);
bind_hook = new single_instance_hook_t(EBPF_PROGRAM_TYPE_BIND, EBPF_ATTACH_TYPE_BIND);
bind_hook = new single_instance_hook_t(EBPF_PROGRAM_TYPE_BIND, EBPF_ATTACH_TYPE_BIND, BPF_LINK_TYPE_PLAIN);
REQUIRE(bind_hook->initialize() == EBPF_SUCCESS);

cgroup_sock_addr_program_info = new program_info_provider_t();
REQUIRE(cgroup_sock_addr_program_info->initialize(EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR) == EBPF_SUCCESS);
cgroup_inet4_connect_hook =
new single_instance_hook_t(EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR, EBPF_ATTACH_TYPE_CGROUP_INET4_CONNECT);
cgroup_inet4_connect_hook = new single_instance_hook_t(
EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR, EBPF_ATTACH_TYPE_CGROUP_INET4_CONNECT, BPF_LINK_TYPE_CGROUP);
REQUIRE(cgroup_inet4_connect_hook->initialize() == EBPF_SUCCESS);

sample_program_info = new program_info_provider_t();
REQUIRE(sample_program_info->initialize(EBPF_PROGRAM_TYPE_SAMPLE) == EBPF_SUCCESS);
sample_hook = new single_instance_hook_t(EBPF_PROGRAM_TYPE_SAMPLE, EBPF_ATTACH_TYPE_SAMPLE);
sample_hook = new single_instance_hook_t(EBPF_PROGRAM_TYPE_SAMPLE, EBPF_ATTACH_TYPE_SAMPLE, BPF_LINK_TYPE_PLAIN);
REQUIRE(sample_hook->initialize() == EBPF_SUCCESS);

xdp_test_program_info = new program_info_provider_t();
REQUIRE(xdp_test_program_info->initialize(EBPF_PROGRAM_TYPE_XDP_TEST) == EBPF_SUCCESS);
xdp_test_hook = new single_instance_hook_t(EBPF_PROGRAM_TYPE_XDP_TEST, EBPF_ATTACH_TYPE_XDP_TEST);
xdp_test_hook =
new single_instance_hook_t(EBPF_PROGRAM_TYPE_XDP_TEST, EBPF_ATTACH_TYPE_XDP_TEST, BPF_LINK_TYPE_XDP);
REQUIRE(xdp_test_hook->initialize() == EBPF_SUCCESS);
}

Expand Down
8 changes: 3 additions & 5 deletions tests/unit/libbpf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2173,9 +2173,9 @@ TEST_CASE("enumerate link IDs with bpf", "[libbpf][bpf]")
REQUIRE(sample_program_info.initialize(EBPF_PROGRAM_TYPE_SAMPLE) == EBPF_SUCCESS);
program_info_provider_t bind_program_info;
REQUIRE(bind_program_info.initialize(EBPF_PROGRAM_TYPE_BIND) == EBPF_SUCCESS);
single_instance_hook_t sample_hook(EBPF_PROGRAM_TYPE_SAMPLE, EBPF_ATTACH_TYPE_SAMPLE);
single_instance_hook_t sample_hook(EBPF_PROGRAM_TYPE_SAMPLE, EBPF_ATTACH_TYPE_SAMPLE, BPF_LINK_TYPE_UNSPEC);
REQUIRE(sample_hook.initialize() == EBPF_SUCCESS);
single_instance_hook_t bind_hook(EBPF_PROGRAM_TYPE_BIND, EBPF_ATTACH_TYPE_BIND);
single_instance_hook_t bind_hook(EBPF_PROGRAM_TYPE_BIND, EBPF_ATTACH_TYPE_BIND, BPF_LINK_TYPE_PLAIN);
REQUIRE(bind_hook.initialize() == EBPF_SUCCESS);

// Verify the enumeration is empty.
Expand Down Expand Up @@ -2270,9 +2270,7 @@ TEST_CASE("enumerate link IDs with bpf", "[libbpf][bpf]")
attr.info.info = (uintptr_t)&info;
attr.info.info_len = sizeof(info);
REQUIRE(bpf(BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr)) == 0);
// TODO: Should this be BPF_LINK_TYPE_PLAIN?
// See https://github.com/microsoft/ebpf-for-windows/issues/4096
REQUIRE(info.type == BPF_LINK_TYPE_UNSPEC);
REQUIRE(info.type == BPF_LINK_TYPE_PLAIN);
REQUIRE(info.id == id2);
REQUIRE(info.prog_id != 0);

Expand Down

0 comments on commit a4d8799

Please sign in to comment.