Skip to content

Commit fcb0837

Browse files
jrifeKernel Patches Daemon
authored andcommitted
selftests/bpf: Make ehash buckets configurable in socket iterator tests
Prepare for bucket resume tests for established TCP sockets by making the number of ehash buckets configurable. Subsequent patches force all established sockets into the same bucket by setting ehash_buckets to one. Signed-off-by: Jordan Rife <[email protected]>
1 parent e50ab9e commit fcb0837

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "sock_iter_batch.skel.h"
77

88
#define TEST_NS "sock_iter_batch_netns"
9+
#define TEST_CHILD_NS "sock_iter_batch_child_netns"
910

1011
static const int init_batch_size = 16;
1112
static const int nr_soreuse = 4;
@@ -304,6 +305,7 @@ struct test_case {
304305
int *socks, int socks_len, struct sock_count *counts,
305306
int counts_len, struct bpf_link *link, int iter_fd);
306307
const char *description;
308+
int ehash_buckets;
307309
int init_socks;
308310
int max_socks;
309311
int sock_type;
@@ -410,13 +412,25 @@ static struct test_case resume_tests[] = {
410412
static void do_resume_test(struct test_case *tc)
411413
{
412414
struct sock_iter_batch *skel = NULL;
415+
struct sock_count *counts = NULL;
413416
static const __u16 port = 10001;
417+
struct nstoken *nstoken = NULL;
414418
struct bpf_link *link = NULL;
415-
struct sock_count *counts;
416419
int err, iter_fd = -1;
417420
const char *addr;
418421
int *fds = NULL;
419422

423+
if (tc->ehash_buckets) {
424+
SYS_NOFAIL("ip netns del " TEST_CHILD_NS);
425+
SYS(done, "sysctl -w net.ipv4.tcp_child_ehash_entries=%d",
426+
tc->ehash_buckets);
427+
SYS(done, "ip netns add %s", TEST_CHILD_NS);
428+
SYS(done, "ip -net %s link set dev lo up", TEST_CHILD_NS);
429+
nstoken = open_netns(TEST_CHILD_NS);
430+
if (!ASSERT_OK_PTR(nstoken, "open_child_netns"))
431+
goto done;
432+
}
433+
420434
counts = calloc(tc->max_socks, sizeof(*counts));
421435
if (!ASSERT_OK_PTR(counts, "counts"))
422436
goto done;
@@ -453,6 +467,9 @@ static void do_resume_test(struct test_case *tc)
453467
tc->test(tc->family, tc->sock_type, addr, port, fds, tc->init_socks,
454468
counts, tc->max_socks, link, iter_fd);
455469
done:
470+
close_netns(nstoken);
471+
SYS_NOFAIL("ip netns del " TEST_CHILD_NS);
472+
SYS_NOFAIL("sysctl -w net.ipv4.tcp_child_ehash_entries=0");
456473
free(counts);
457474
free_fds(fds, tc->init_socks);
458475
if (iter_fd >= 0)

0 commit comments

Comments
 (0)