mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
BPF object files are, in a way, the final artifact produced as part of the ahead-of-time compilation process. That makes them somewhat special compared to "regular" object files, which are a intermediate build artifacts that can typically be removed safely. As such, it can make sense to name them differently to make it easier to spot this difference at a glance. Among others, libbpf-bootstrap [0] has established the extension .bpf.o for BPF object files. It seems reasonable to follow this example and establish the same denomination for selftest build artifacts. To that end, this change adjusts the corresponding part of the build system and the test programs loading BPF object files to work with .bpf.o files. [0] https://github.com/libbpf/libbpf-bootstrap Suggested-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Daniel Müller <deso@posteo.net> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20220901222253.1199242-1-deso@posteo.net
87 lines
2.5 KiB
C
87 lines
2.5 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <test_progs.h>
|
|
|
|
/* TODO: corrupts other tests uses connect() */
|
|
void serial_test_probe_user(void)
|
|
{
|
|
static const char *const prog_names[] = {
|
|
"handle_sys_connect",
|
|
#if defined(__s390x__)
|
|
"handle_sys_socketcall",
|
|
#endif
|
|
};
|
|
enum { prog_count = ARRAY_SIZE(prog_names) };
|
|
const char *obj_file = "./test_probe_user.bpf.o";
|
|
DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts, );
|
|
int err, results_map_fd, sock_fd, duration = 0;
|
|
struct sockaddr curr, orig, tmp;
|
|
struct sockaddr_in *in = (struct sockaddr_in *)&curr;
|
|
struct bpf_link *kprobe_links[prog_count] = {};
|
|
struct bpf_program *kprobe_progs[prog_count];
|
|
struct bpf_object *obj;
|
|
static const int zero = 0;
|
|
size_t i;
|
|
|
|
obj = bpf_object__open_file(obj_file, &opts);
|
|
if (!ASSERT_OK_PTR(obj, "obj_open_file"))
|
|
return;
|
|
|
|
for (i = 0; i < prog_count; i++) {
|
|
kprobe_progs[i] =
|
|
bpf_object__find_program_by_name(obj, prog_names[i]);
|
|
if (CHECK(!kprobe_progs[i], "find_probe",
|
|
"prog '%s' not found\n", prog_names[i]))
|
|
goto cleanup;
|
|
}
|
|
|
|
err = bpf_object__load(obj);
|
|
if (CHECK(err, "obj_load", "err %d\n", err))
|
|
goto cleanup;
|
|
|
|
results_map_fd = bpf_find_map(__func__, obj, "test_pro.bss");
|
|
if (CHECK(results_map_fd < 0, "find_bss_map",
|
|
"err %d\n", results_map_fd))
|
|
goto cleanup;
|
|
|
|
for (i = 0; i < prog_count; i++) {
|
|
kprobe_links[i] = bpf_program__attach(kprobe_progs[i]);
|
|
if (!ASSERT_OK_PTR(kprobe_links[i], "attach_kprobe"))
|
|
goto cleanup;
|
|
}
|
|
|
|
memset(&curr, 0, sizeof(curr));
|
|
in->sin_family = AF_INET;
|
|
in->sin_port = htons(5555);
|
|
in->sin_addr.s_addr = inet_addr("255.255.255.255");
|
|
memcpy(&orig, &curr, sizeof(curr));
|
|
|
|
sock_fd = socket(AF_INET, SOCK_STREAM, 0);
|
|
if (CHECK(sock_fd < 0, "create_sock_fd", "err %d\n", sock_fd))
|
|
goto cleanup;
|
|
|
|
connect(sock_fd, &curr, sizeof(curr));
|
|
close(sock_fd);
|
|
|
|
err = bpf_map_lookup_elem(results_map_fd, &zero, &tmp);
|
|
if (CHECK(err, "get_kprobe_res",
|
|
"failed to get kprobe res: %d\n", err))
|
|
goto cleanup;
|
|
|
|
in = (struct sockaddr_in *)&tmp;
|
|
if (CHECK(memcmp(&tmp, &orig, sizeof(orig)), "check_kprobe_res",
|
|
"wrong kprobe res from probe read: %s:%u\n",
|
|
inet_ntoa(in->sin_addr), ntohs(in->sin_port)))
|
|
goto cleanup;
|
|
|
|
memset(&tmp, 0xab, sizeof(tmp));
|
|
|
|
in = (struct sockaddr_in *)&curr;
|
|
if (CHECK(memcmp(&curr, &tmp, sizeof(tmp)), "check_kprobe_res",
|
|
"wrong kprobe res from probe write: %s:%u\n",
|
|
inet_ntoa(in->sin_addr), ntohs(in->sin_port)))
|
|
goto cleanup;
|
|
cleanup:
|
|
for (i = 0; i < prog_count; i++)
|
|
bpf_link__destroy(kprobe_links[i]);
|
|
bpf_object__close(obj);
|
|
}
|