Skip to content

Commit 86289e9

Browse files
mmhalKernel Patches Daemon
authored andcommitted
selftests/bpf: sockmap_redir: Let test specify skel's redirect_type
Preparatory patch before adding SK_PASS/SK_DROP support: allow to dynamically switch BPF program's redirect_type. This way, after setting up for a redirection, test can make the BPF program skip the actual bpf_{sk,msg}_redirect_{map,hash} part and return a specified verdict. Signed-off-by: Michal Luczaj <[email protected]>
1 parent 3b71eb0 commit 86289e9

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

tools/testing/selftests/bpf/prog_tests/sockmap_redir.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static void test_redir(enum bpf_map_type type, struct redir_spec *redir,
371371
}
372372

373373
static void test_sockets(enum bpf_map_type type, struct redir_spec *redir,
374-
struct maps *maps)
374+
struct maps *maps, int *skel_redir_type)
375375
{
376376
struct socket_spec *s, sockets[] = {
377377
{ AF_INET, SOCK_STREAM },
@@ -392,6 +392,8 @@ static void test_sockets(enum bpf_map_type type, struct redir_spec *redir,
392392
if (socket_spec_pairs(s))
393393
goto out;
394394

395+
*skel_redir_type = type;
396+
395397
/* Intra-proto */
396398
for (s = sockets; s < sockets + ARRAY_SIZE(sockets); s++)
397399
test_redir(type, redir, maps, s, s);
@@ -451,15 +453,14 @@ static void test_map(enum bpf_map_type type)
451453
return;
452454
}
453455

454-
skel->bss->redirect_type = type;
455456
maps.verd = bpf_map__fd(skel->maps.verdict_map);
456457
get_redir_params(r, skel, &prog_fd, &attach_type,
457458
&skel->bss->redirect_flags);
458459

459460
if (xbpf_prog_attach(prog_fd, maps.in, attach_type, 0))
460461
return;
461462

462-
test_sockets(type, r, &maps);
463+
test_sockets(type, r, &maps, &skel->bss->redirect_type);
463464

464465
if (xbpf_prog_detach2(prog_fd, maps.in, attach_type))
465466
return;

0 commit comments

Comments
 (0)