diff options
author | Geliang Tang <tanggeliang@kylinos.cn> | 2024-05-23 14:50:00 +0800 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2024-06-03 19:32:54 +0200 |
commit | 24bb90a42633ea47256d4f13289dd3181236e028 (patch) | |
tree | 263232ab2aa7cc0047a7d6a4b14d764facfb1918 | |
parent | 3f32a115f61d31049e3e91d469bca849f712a979 (diff) | |
download | linux-24bb90a42633ea47256d4f13289dd3181236e028.tar.gz linux-24bb90a42633ea47256d4f13289dd3181236e028.tar.bz2 linux-24bb90a42633ea47256d4f13289dd3181236e028.zip |
selftests/bpf: Replace tx_prog_fd with tx_prog in test_sockmap
bpf_program__attach_sockmap() needs to take a parameter of type bpf_program
instead of an fd, so tx_prog_fd becomes useless. This patch uses a pointer
tx_prog to point to an item in progs[] array.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Tested-by: Jakub Sitnicki <jakub@cloudflare.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/23b37f932c547dd1ebfe154bbc0b0e957be21ee6.1716446893.git.tanggeliang@kylinos.cn
-rw-r--r-- | tools/testing/selftests/bpf/test_sockmap.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c index 81e7a57c727c..c185c4242abb 100644 --- a/tools/testing/selftests/bpf/test_sockmap.c +++ b/tools/testing/selftests/bpf/test_sockmap.c @@ -954,7 +954,8 @@ enum { static int run_options(struct sockmap_options *options, int cg_fd, int test) { - int i, key, next_key, err, tx_prog_fd = -1, zero = 0; + int i, key, next_key, err, zero = 0; + struct bpf_program *tx_prog; /* If base test skip BPF setup */ if (test == BASE || test == BASE_SENDPAGE) @@ -1015,27 +1016,27 @@ run: /* Attach txmsg program to sockmap */ if (txmsg_pass) - tx_prog_fd = prog_fd[4]; + tx_prog = progs[4]; else if (txmsg_redir) - tx_prog_fd = prog_fd[5]; + tx_prog = progs[5]; else if (txmsg_apply) - tx_prog_fd = prog_fd[6]; + tx_prog = progs[6]; else if (txmsg_cork) - tx_prog_fd = prog_fd[7]; + tx_prog = progs[7]; else if (txmsg_drop) - tx_prog_fd = prog_fd[8]; + tx_prog = progs[8]; else - tx_prog_fd = -1; + tx_prog = NULL; - if (tx_prog_fd > 0) { + if (tx_prog) { int redir_fd; - err = bpf_prog_attach(tx_prog_fd, - map_fd[1], BPF_SK_MSG_VERDICT, 0); - if (err) { + links[4] = bpf_program__attach_sockmap(tx_prog, map_fd[1]); + if (!links[4]) { fprintf(stderr, - "ERROR: bpf_prog_attach (txmsg): %d (%s)\n", - err, strerror(errno)); + "ERROR: bpf_program__attach_sockmap (txmsg): (%s)\n", + strerror(errno)); + err = -1; goto out; } @@ -1285,9 +1286,6 @@ out: bpf_link__detach(links[i]); } - if (tx_prog_fd > 0) - bpf_prog_detach2(tx_prog_fd, map_fd[1], BPF_SK_MSG_VERDICT); - for (i = 0; i < 8; i++) { key = next_key = 0; bpf_map_update_elem(map_fd[i], &key, &zero, BPF_ANY); |