File Index
Files and directories
Sign in
FILE

tc_helpers.h

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/bpf/prog_tests/tc_helpers.h C
 1/* SPDX-License-Identifier: GPL-2.0 */
 2/* Copyright (c) 2023 Isovalent */
 3#ifndef TC_HELPERS
 4#define TC_HELPERS
 5#include <test_progs.h>
 6
 7#ifndef loopback
 8# define loopback 1
 9#endif
10
11static inline __u32 ifindex_from_link_fd(int fd)
12{
13	struct bpf_link_info link_info = {};
14	__u32 link_info_len = sizeof(link_info);
15	int err;
16
17	err = bpf_link_get_info_by_fd(fd, &link_info, &link_info_len);
18	if (!ASSERT_OK(err, "id_from_link_fd"))
19		return 0;
20
21	return link_info.tcx.ifindex;
22}
23
24static inline void __assert_mprog_count(int target, int expected, int ifindex)
25{
26	__u32 count = 0, attach_flags = 0;
27	int err;
28
29	err = bpf_prog_query(ifindex, target, 0, &attach_flags,
30			     NULL, &count);
31	ASSERT_EQ(count, expected, "count");
32	ASSERT_EQ(err, 0, "prog_query");
33}
34
35static inline void assert_mprog_count(int target, int expected)
36{
37	__assert_mprog_count(target, expected, loopback);
38}
39
40static inline void assert_mprog_count_ifindex(int ifindex, int target, int expected)
41{
42	__assert_mprog_count(target, expected, ifindex);
43}
44
45static inline void tc_skel_reset_all_seen(struct test_tc_link *skel)
46{
47	memset(skel->bss, 0, sizeof(*skel->bss));
48}
49
50#endif /* TC_HELPERS */
~/ Read-only file preview.