mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-22 02:17:36 -04:00
selftests/bpf: Test FIONREAD on a sockmap socket without a verdict program
Add a test validating that FIONREAD on a TCP socket in a sockmap without a verdict program reports data pending in sk_receive_queue. Signed-off-by: Mattia Meleleo <mattia.meleleo@coralogix.com> Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev> Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com> Reviewed-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/bpf/20260708-fionread-no-verdict-v3-2-b4ee31b3af53@coralogix.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
This commit is contained in:
committed by
Kumar Kartikeya Dwivedi
parent
04af4efde5
commit
a42f05cc4c
@@ -1373,6 +1373,43 @@ static void test_sockmap_multi_channels(int sotype)
|
||||
test_sockmap_pass_prog__destroy(skel);
|
||||
}
|
||||
|
||||
/* A socket in a sockmap without a verdict program keeps its ingress data
|
||||
* in sk_receive_queue: FIONREAD must account for it.
|
||||
*/
|
||||
static void test_sockmap_no_verdict_fionread(void)
|
||||
{
|
||||
int err, map, zero = 0, sent, avail;
|
||||
int c0 = -1, c1 = -1, p0 = -1, p1 = -1;
|
||||
struct test_sockmap_pass_prog *skel;
|
||||
char buf[256] = "0123456789";
|
||||
|
||||
skel = test_sockmap_pass_prog__open_and_load();
|
||||
if (!ASSERT_OK_PTR(skel, "open_and_load"))
|
||||
return;
|
||||
map = bpf_map__fd(skel->maps.sock_map_rx);
|
||||
|
||||
err = create_socket_pairs(AF_INET, SOCK_STREAM, &c0, &c1, &p0, &p1);
|
||||
if (!ASSERT_OK(err, "create_socket_pairs()"))
|
||||
goto out;
|
||||
|
||||
err = bpf_map_update_elem(map, &zero, &c1, BPF_NOEXIST);
|
||||
if (!ASSERT_OK(err, "bpf_map_update_elem(c1)"))
|
||||
goto out_close;
|
||||
|
||||
sent = xsend(p1, &buf, sizeof(buf), 0);
|
||||
ASSERT_EQ(sent, sizeof(buf), "xsend(p1)");
|
||||
avail = wait_for_fionread(c1, sizeof(buf), IO_TIMEOUT_SEC);
|
||||
ASSERT_EQ(avail, sizeof(buf), "ioctl(FIONREAD)");
|
||||
|
||||
out_close:
|
||||
close(c0);
|
||||
close(p0);
|
||||
close(c1);
|
||||
close(p1);
|
||||
out:
|
||||
test_sockmap_pass_prog__destroy(skel);
|
||||
}
|
||||
|
||||
void test_sockmap_basic(void)
|
||||
{
|
||||
if (test__start_subtest("sockmap create_update_free"))
|
||||
@@ -1415,6 +1452,8 @@ void test_sockmap_basic(void)
|
||||
test_sockmap_skb_verdict_shutdown();
|
||||
if (test__start_subtest("sockmap skb_verdict fionread"))
|
||||
test_sockmap_skb_verdict_fionread(true);
|
||||
if (test__start_subtest("sockmap no_verdict fionread"))
|
||||
test_sockmap_no_verdict_fionread();
|
||||
if (test__start_subtest("sockmap skb_verdict fionread on drop"))
|
||||
test_sockmap_skb_verdict_fionread(false);
|
||||
if (test__start_subtest("sockmap skb_verdict change tail"))
|
||||
|
||||
Reference in New Issue
Block a user