Skip to content

Commit 7b4400a

Browse files
TropicaoMartin KaFai Lau
authored and
Martin KaFai Lau
committed
selftests/bpf: add proper section name to bpf prog and rename it
test_skb_cgroup_id_kern.c is currently involved in a manual test. In its current form, it can not be used with the auto-generated skeleton APIs, because the section name is not valid to allow libbpf to deduce the program type. Update section name to allow skeleton APIs usage. Also rename the program name to make it shorter and more straighforward regarding the API it is testing. While doing so, make sure that test_skb_cgroup_id.sh passes to get a working reference before converting it to test_progs - update the obj name - fix loading issue (verifier rejecting the program when loaded through tc, because of map not found), by preloading the whole obj with bpftool Reviewed-by: Alan Maguire <[email protected]> Signed-off-by: Alexis Lothoré (eBPF Foundation) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
1 parent 37a14cf commit 7b4400a

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

tools/testing/selftests/bpf/progs/test_skb_cgroup_id_kern.c renamed to tools/testing/selftests/bpf/progs/cgroup_ancestor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static __always_inline void log_nth_level(struct __sk_buff *skb, __u32 level)
2828
bpf_map_update_elem(&cgroup_ids, &level, &id, 0);
2929
}
3030

31-
SEC("cgroup_id_logger")
31+
SEC("tc")
3232
int log_cgroup_id(struct __sk_buff *skb)
3333
{
3434
/* Loop unroll can't be used here due to [1]. Unrolling manually.

tools/testing/selftests/bpf/test_skb_cgroup_id.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ setup()
3030
wait_for_ip
3131

3232
tc qdisc add dev ${TEST_IF} clsact
33-
tc filter add dev ${TEST_IF} egress bpf obj ${BPF_PROG_OBJ} \
34-
sec ${BPF_PROG_SECTION} da
33+
mkdir -p /sys/fs/bpf/${BPF_PROG_PIN}
34+
bpftool prog loadall ${BPF_PROG_OBJ} /sys/fs/bpf/${BPF_PROG_PIN} type tc
35+
tc filter add dev ${TEST_IF} egress bpf da object-pinned \
36+
/sys/fs/bpf/${BPF_PROG_PIN}/${BPF_PROG_NAME}
3537

3638
BPF_PROG_ID=$(tc filter show dev ${TEST_IF} egress | \
3739
awk '/ id / {sub(/.* id /, "", $0); print($1)}')
@@ -41,6 +43,7 @@ cleanup()
4143
{
4244
ip link del ${TEST_IF} 2>/dev/null || :
4345
ip link del ${TEST_IF_PEER} 2>/dev/null || :
46+
rm -rf /sys/fs/bpf/${BPF_PROG_PIN}
4447
}
4548

4649
main()
@@ -54,8 +57,9 @@ DIR=$(dirname $0)
5457
TEST_IF="test_cgid_1"
5558
TEST_IF_PEER="test_cgid_2"
5659
MAX_PING_TRIES=5
57-
BPF_PROG_OBJ="${DIR}/test_skb_cgroup_id_kern.bpf.o"
58-
BPF_PROG_SECTION="cgroup_id_logger"
60+
BPF_PROG_PIN="cgroup_ancestor"
61+
BPF_PROG_OBJ="${DIR}/${BPF_PROG_PIN}.bpf.o"
62+
BPF_PROG_NAME="log_cgroup_id"
5963
BPF_PROG_ID=0
6064
PROG="${DIR}/test_skb_cgroup_id_user"
6165
type ping6 >/dev/null 2>&1 && PING6="ping6" || PING6="ping -6"

0 commit comments

Comments
 (0)