Commit 78368781 authored by Prashant Bhole's avatar Prashant Bhole Committed by Daniel Borkmann

bpf: test_maps: cleanup sockmaps when test ends

Bug: BPF programs and maps related to sockmaps test exist
in memory even after test_maps ends.

This patch fixes it as a short term workaround (sockmap
kernel side needs real fixing) by empyting sockmaps when
test ends.

Fixes: 6f6d33f3 ("bpf: selftests add sockmap tests")
Signed-off-by: default avatarPrashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
[ daniel: Note on workaround. ]
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent 8e687525
...@@ -463,7 +463,7 @@ static void test_devmap(int task, void *data) ...@@ -463,7 +463,7 @@ static void test_devmap(int task, void *data)
#define SOCKMAP_VERDICT_PROG "./sockmap_verdict_prog.o" #define SOCKMAP_VERDICT_PROG "./sockmap_verdict_prog.o"
static void test_sockmap(int tasks, void *data) static void test_sockmap(int tasks, void *data)
{ {
int one = 1, map_fd_rx, map_fd_tx, map_fd_break, s, sc, rc; int one = 1, map_fd_rx = 0, map_fd_tx = 0, map_fd_break, s, sc, rc;
struct bpf_map *bpf_map_rx, *bpf_map_tx, *bpf_map_break; struct bpf_map *bpf_map_rx, *bpf_map_tx, *bpf_map_break;
int ports[] = {50200, 50201, 50202, 50204}; int ports[] = {50200, 50201, 50202, 50204};
int err, i, fd, udp, sfd[6] = {0xdeadbeef}; int err, i, fd, udp, sfd[6] = {0xdeadbeef};
...@@ -868,9 +868,12 @@ static void test_sockmap(int tasks, void *data) ...@@ -868,9 +868,12 @@ static void test_sockmap(int tasks, void *data)
goto out_sockmap; goto out_sockmap;
} }
/* Test map close sockets */ /* Test map close sockets and empty maps */
for (i = 0; i < 6; i++) for (i = 0; i < 6; i++) {
bpf_map_delete_elem(map_fd_tx, &i);
bpf_map_delete_elem(map_fd_rx, &i);
close(sfd[i]); close(sfd[i]);
}
close(fd); close(fd);
close(map_fd_rx); close(map_fd_rx);
bpf_object__close(obj); bpf_object__close(obj);
...@@ -881,8 +884,13 @@ static void test_sockmap(int tasks, void *data) ...@@ -881,8 +884,13 @@ static void test_sockmap(int tasks, void *data)
printf("Failed to create sockmap '%i:%s'!\n", i, strerror(errno)); printf("Failed to create sockmap '%i:%s'!\n", i, strerror(errno));
exit(1); exit(1);
out_sockmap: out_sockmap:
for (i = 0; i < 6; i++) for (i = 0; i < 6; i++) {
if (map_fd_tx)
bpf_map_delete_elem(map_fd_tx, &i);
if (map_fd_rx)
bpf_map_delete_elem(map_fd_rx, &i);
close(sfd[i]); close(sfd[i]);
}
close(fd); close(fd);
exit(1); exit(1);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment