Commit 043a7356 authored by Liu Jian's avatar Liu Jian Committed by Daniel Borkmann

selftests/bpf: Add wait send memory test for sockmap redirect

Add one test for wait redirect sock's send memory test for sockmap.
Signed-off-by: default avatarLiu Jian <liujian56@huawei.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20220823133755.314697-3-liujian56@huawei.com
parent 3f8ef65a
...@@ -138,6 +138,7 @@ struct sockmap_options { ...@@ -138,6 +138,7 @@ struct sockmap_options {
bool data_test; bool data_test;
bool drop_expected; bool drop_expected;
bool check_recved_len; bool check_recved_len;
bool tx_wait_mem;
int iov_count; int iov_count;
int iov_length; int iov_length;
int rate; int rate;
...@@ -578,6 +579,10 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, ...@@ -578,6 +579,10 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
sent = sendmsg(fd, &msg, flags); sent = sendmsg(fd, &msg, flags);
if (!drop && sent < 0) { if (!drop && sent < 0) {
if (opt->tx_wait_mem && errno == EACCES) {
errno = 0;
goto out_errno;
}
perror("sendmsg loop error"); perror("sendmsg loop error");
goto out_errno; goto out_errno;
} else if (drop && sent >= 0) { } else if (drop && sent >= 0) {
...@@ -644,6 +649,15 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, ...@@ -644,6 +649,15 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
goto out_errno; goto out_errno;
} }
if (opt->tx_wait_mem) {
FD_ZERO(&w);
FD_SET(fd, &w);
slct = select(max_fd + 1, NULL, NULL, &w, &timeout);
errno = 0;
close(fd);
goto out_errno;
}
errno = 0; errno = 0;
if (peek_flag) { if (peek_flag) {
flags |= MSG_PEEK; flags |= MSG_PEEK;
...@@ -752,6 +766,22 @@ static int sendmsg_test(struct sockmap_options *opt) ...@@ -752,6 +766,22 @@ static int sendmsg_test(struct sockmap_options *opt)
return err; return err;
} }
if (opt->tx_wait_mem) {
struct timeval timeout;
int rxtx_buf_len = 1024;
timeout.tv_sec = 3;
timeout.tv_usec = 0;
err = setsockopt(c2, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(struct timeval));
err |= setsockopt(c2, SOL_SOCKET, SO_SNDBUFFORCE, &rxtx_buf_len, sizeof(int));
err |= setsockopt(p2, SOL_SOCKET, SO_RCVBUFFORCE, &rxtx_buf_len, sizeof(int));
if (err) {
perror("setsockopt failed()");
return errno;
}
}
rxpid = fork(); rxpid = fork();
if (rxpid == 0) { if (rxpid == 0) {
if (txmsg_pop || txmsg_start_pop) if (txmsg_pop || txmsg_start_pop)
...@@ -788,6 +818,9 @@ static int sendmsg_test(struct sockmap_options *opt) ...@@ -788,6 +818,9 @@ static int sendmsg_test(struct sockmap_options *opt)
return errno; return errno;
} }
if (opt->tx_wait_mem)
close(c2);
txpid = fork(); txpid = fork();
if (txpid == 0) { if (txpid == 0) {
if (opt->sendpage) if (opt->sendpage)
...@@ -1452,6 +1485,14 @@ static void test_txmsg_redir(int cgrp, struct sockmap_options *opt) ...@@ -1452,6 +1485,14 @@ static void test_txmsg_redir(int cgrp, struct sockmap_options *opt)
test_send(opt, cgrp); test_send(opt, cgrp);
} }
static void test_txmsg_redir_wait_sndmem(int cgrp, struct sockmap_options *opt)
{
txmsg_redir = 1;
opt->tx_wait_mem = true;
test_send_large(opt, cgrp);
opt->tx_wait_mem = false;
}
static void test_txmsg_drop(int cgrp, struct sockmap_options *opt) static void test_txmsg_drop(int cgrp, struct sockmap_options *opt)
{ {
txmsg_drop = 1; txmsg_drop = 1;
...@@ -1800,6 +1841,7 @@ static int populate_progs(char *bpf_file) ...@@ -1800,6 +1841,7 @@ static int populate_progs(char *bpf_file)
struct _test test[] = { struct _test test[] = {
{"txmsg test passthrough", test_txmsg_pass}, {"txmsg test passthrough", test_txmsg_pass},
{"txmsg test redirect", test_txmsg_redir}, {"txmsg test redirect", test_txmsg_redir},
{"txmsg test redirect wait send mem", test_txmsg_redir_wait_sndmem},
{"txmsg test drop", test_txmsg_drop}, {"txmsg test drop", test_txmsg_drop},
{"txmsg test ingress redirect", test_txmsg_ingress_redir}, {"txmsg test ingress redirect", test_txmsg_ingress_redir},
{"txmsg test skb", test_txmsg_skb}, {"txmsg test skb", test_txmsg_skb},
......
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