Commit 5a9b8e2c authored by Dmitrii Dolgov's avatar Dmitrii Dolgov Committed by Alexei Starovoitov

selftests/bpf: Add bpf link iter test

Add a simple test for bpf link iterator
Signed-off-by: default avatarDmitrii Dolgov <9erthalion6@gmail.com>
Link: https://lore.kernel.org/r/20220510155233.9815-5-9erthalion6@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent f78625fd
......@@ -26,6 +26,7 @@
#include "bpf_iter_bpf_sk_storage_map.skel.h"
#include "bpf_iter_test_kern5.skel.h"
#include "bpf_iter_test_kern6.skel.h"
#include "bpf_iter_bpf_link.skel.h"
static int duration;
......@@ -1106,6 +1107,19 @@ static void test_buf_neg_offset(void)
bpf_iter_test_kern6__destroy(skel);
}
static void test_link_iter(void)
{
struct bpf_iter_bpf_link *skel;
skel = bpf_iter_bpf_link__open_and_load();
if (!ASSERT_OK_PTR(skel, "bpf_iter_bpf_link__open_and_load"))
return;
do_dummy_read(skel->progs.dump_bpf_link);
bpf_iter_bpf_link__destroy(skel);
}
#define CMP_BUFFER_SIZE 1024
static char task_vma_output[CMP_BUFFER_SIZE];
static char proc_maps_output[CMP_BUFFER_SIZE];
......@@ -1251,4 +1265,6 @@ void test_bpf_iter(void)
test_rdonly_buf_out_of_bound();
if (test__start_subtest("buf-neg-offset"))
test_buf_neg_offset();
if (test__start_subtest("link-iter"))
test_link_iter();
}
......@@ -16,6 +16,7 @@
#define bpf_iter__bpf_map_elem bpf_iter__bpf_map_elem___not_used
#define bpf_iter__bpf_sk_storage_map bpf_iter__bpf_sk_storage_map___not_used
#define bpf_iter__sockmap bpf_iter__sockmap___not_used
#define bpf_iter__bpf_link bpf_iter__bpf_link___not_used
#define btf_ptr btf_ptr___not_used
#define BTF_F_COMPACT BTF_F_COMPACT___not_used
#define BTF_F_NONAME BTF_F_NONAME___not_used
......@@ -37,6 +38,7 @@
#undef bpf_iter__bpf_map_elem
#undef bpf_iter__bpf_sk_storage_map
#undef bpf_iter__sockmap
#undef bpf_iter__bpf_link
#undef btf_ptr
#undef BTF_F_COMPACT
#undef BTF_F_NONAME
......@@ -132,6 +134,11 @@ struct bpf_iter__sockmap {
struct sock *sk;
};
struct bpf_iter__bpf_link {
struct bpf_iter_meta *meta;
struct bpf_link *link;
};
struct btf_ptr {
void *ptr;
__u32 type_id;
......
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2022 Red Hat, Inc. */
#include "bpf_iter.h"
#include <bpf/bpf_helpers.h>
char _license[] SEC("license") = "GPL";
SEC("iter/bpf_link")
int dump_bpf_link(struct bpf_iter__bpf_link *ctx)
{
struct seq_file *seq = ctx->meta->seq;
struct bpf_link *link = ctx->link;
int link_id;
if (!link)
return 0;
link_id = link->id;
bpf_seq_write(seq, &link_id, sizeof(link_id));
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment