]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: Add apply_bytes test to test_txmsg_redir_wait_sndmem in test_sockmap
authorZijian Zhang <zijianzhang@bytedance.com>
Wed, 16 Oct 2024 23:48:37 +0000 (23:48 +0000)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 26 Nov 2024 19:42:03 +0000 (20:42 +0100)
Add this to more comprehensively test the socket memory accounting logic
in the __SK_REDIRECT and __SK_DROP cases of tcp_bpf_sendmsg. We don't have
test when apply_bytes are not zero in test_txmsg_redir_wait_sndmem.
test_send_large has opt->rate=2, it will invoke sendmsg two times.

Specifically, the first sendmsg will trigger the case where the ret value
of tcp_bpf_sendmsg_redir is less than 0; while the second sendmsg happens
after the 3 seconds timeout, and it will trigger __SK_DROP because socket
c2 has been removed from the sockmap/hash.

Signed-off-by: Zijian Zhang <zijianzhang@bytedance.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20241016234838.3167769-2-zijianzhang@bytedance.com
tools/testing/selftests/bpf/test_sockmap.c

index e5c7ecbe57e38b56c565b8a8dda7e56169a65051..fd2da2234cc9b44342352bc7b0417be1cbecc747 100644 (file)
@@ -1579,8 +1579,12 @@ static void test_txmsg_redir(int cgrp, struct sockmap_options *opt)
 
 static void test_txmsg_redir_wait_sndmem(int cgrp, struct sockmap_options *opt)
 {
-       txmsg_redir = 1;
        opt->tx_wait_mem = true;
+       txmsg_redir = 1;
+       test_send_large(opt, cgrp);
+
+       txmsg_redir = 1;
+       txmsg_apply = 4097;
        test_send_large(opt, cgrp);
        opt->tx_wait_mem = false;
 }