mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-05-24 10:39:52 +00:00

Introduce selftests for the following kfunc helpers: - bpf_xdp_ct_alloc - bpf_skb_ct_alloc - bpf_ct_insert_entry - bpf_ct_set_timeout - bpf_ct_change_timeout - bpf_ct_set_status - bpf_ct_change_status Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/r/20220721134245.2450-12-memxor@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
60 lines
2.2 KiB
C
60 lines
2.2 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <test_progs.h>
|
|
#include <network_helpers.h>
|
|
#include "test_bpf_nf.skel.h"
|
|
|
|
enum {
|
|
TEST_XDP,
|
|
TEST_TC_BPF,
|
|
};
|
|
|
|
void test_bpf_nf_ct(int mode)
|
|
{
|
|
struct test_bpf_nf *skel;
|
|
int prog_fd, err;
|
|
LIBBPF_OPTS(bpf_test_run_opts, topts,
|
|
.data_in = &pkt_v4,
|
|
.data_size_in = sizeof(pkt_v4),
|
|
.repeat = 1,
|
|
);
|
|
|
|
skel = test_bpf_nf__open_and_load();
|
|
if (!ASSERT_OK_PTR(skel, "test_bpf_nf__open_and_load"))
|
|
return;
|
|
|
|
if (mode == TEST_XDP)
|
|
prog_fd = bpf_program__fd(skel->progs.nf_xdp_ct_test);
|
|
else
|
|
prog_fd = bpf_program__fd(skel->progs.nf_skb_ct_test);
|
|
|
|
err = bpf_prog_test_run_opts(prog_fd, &topts);
|
|
if (!ASSERT_OK(err, "bpf_prog_test_run"))
|
|
goto end;
|
|
|
|
ASSERT_EQ(skel->bss->test_einval_bpf_tuple, -EINVAL, "Test EINVAL for NULL bpf_tuple");
|
|
ASSERT_EQ(skel->bss->test_einval_reserved, -EINVAL, "Test EINVAL for reserved not set to 0");
|
|
ASSERT_EQ(skel->bss->test_einval_netns_id, -EINVAL, "Test EINVAL for netns_id < -1");
|
|
ASSERT_EQ(skel->bss->test_einval_len_opts, -EINVAL, "Test EINVAL for len__opts != NF_BPF_CT_OPTS_SZ");
|
|
ASSERT_EQ(skel->bss->test_eproto_l4proto, -EPROTO, "Test EPROTO for l4proto != TCP or UDP");
|
|
ASSERT_EQ(skel->bss->test_enonet_netns_id, -ENONET, "Test ENONET for bad but valid netns_id");
|
|
ASSERT_EQ(skel->bss->test_enoent_lookup, -ENOENT, "Test ENOENT for failed lookup");
|
|
ASSERT_EQ(skel->bss->test_eafnosupport, -EAFNOSUPPORT, "Test EAFNOSUPPORT for invalid len__tuple");
|
|
ASSERT_EQ(skel->data->test_alloc_entry, 0, "Test for alloc new entry");
|
|
ASSERT_EQ(skel->data->test_insert_entry, 0, "Test for insert new entry");
|
|
ASSERT_EQ(skel->data->test_succ_lookup, 0, "Test for successful lookup");
|
|
/* allow some tolerance for test_delta_timeout value to avoid races. */
|
|
ASSERT_GT(skel->bss->test_delta_timeout, 8, "Test for min ct timeout update");
|
|
ASSERT_LE(skel->bss->test_delta_timeout, 10, "Test for max ct timeout update");
|
|
/* expected status is IPS_SEEN_REPLY */
|
|
ASSERT_EQ(skel->bss->test_status, 2, "Test for ct status update ");
|
|
end:
|
|
test_bpf_nf__destroy(skel);
|
|
}
|
|
|
|
void test_bpf_nf(void)
|
|
{
|
|
if (test__start_subtest("xdp-ct"))
|
|
test_bpf_nf_ct(TEST_XDP);
|
|
if (test__start_subtest("tc-bpf-ct"))
|
|
test_bpf_nf_ct(TEST_TC_BPF);
|
|
}
|