Skip to content

Commit d696721

Browse files
liujian56borkmann
authored andcommitted
selftests, bpf: Add one test for sockmap with strparser
Add the test to check sockmap with strparser is working well. Signed-off-by: Liu Jian <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: John Fastabend <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent b556c3f commit d696721

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

tools/testing/selftests/bpf/test_sockmap.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ struct sockmap_options {
139139
bool sendpage;
140140
bool data_test;
141141
bool drop_expected;
142+
bool check_recved_len;
142143
int iov_count;
143144
int iov_length;
144145
int rate;
@@ -556,8 +557,12 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
556557
int err, i, flags = MSG_NOSIGNAL;
557558
bool drop = opt->drop_expected;
558559
bool data = opt->data_test;
560+
int iov_alloc_length = iov_length;
559561

560-
err = msg_alloc_iov(&msg, iov_count, iov_length, data, tx);
562+
if (!tx && opt->check_recved_len)
563+
iov_alloc_length *= 2;
564+
565+
err = msg_alloc_iov(&msg, iov_count, iov_alloc_length, data, tx);
561566
if (err)
562567
goto out_errno;
563568
if (peek_flag) {
@@ -665,6 +670,13 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
665670

666671
s->bytes_recvd += recv;
667672

673+
if (opt->check_recved_len && s->bytes_recvd > total_bytes) {
674+
errno = EMSGSIZE;
675+
fprintf(stderr, "recv failed(), bytes_recvd:%zd, total_bytes:%f\n",
676+
s->bytes_recvd, total_bytes);
677+
goto out_errno;
678+
}
679+
668680
if (data) {
669681
int chunk_sz = opt->sendpage ?
670682
iov_length * cnt :
@@ -744,7 +756,8 @@ static int sendmsg_test(struct sockmap_options *opt)
744756

745757
rxpid = fork();
746758
if (rxpid == 0) {
747-
iov_buf -= (txmsg_pop - txmsg_start_pop + 1);
759+
if (txmsg_pop || txmsg_start_pop)
760+
iov_buf -= (txmsg_pop - txmsg_start_pop + 1);
748761
if (opt->drop_expected || txmsg_ktls_skb_drop)
749762
_exit(0);
750763

@@ -1688,6 +1701,19 @@ static void test_txmsg_ingress_parser(int cgrp, struct sockmap_options *opt)
16881701
test_exec(cgrp, opt);
16891702
}
16901703

1704+
static void test_txmsg_ingress_parser2(int cgrp, struct sockmap_options *opt)
1705+
{
1706+
if (ktls == 1)
1707+
return;
1708+
skb_use_parser = 10;
1709+
opt->iov_length = 20;
1710+
opt->iov_count = 1;
1711+
opt->rate = 1;
1712+
opt->check_recved_len = true;
1713+
test_exec(cgrp, opt);
1714+
opt->check_recved_len = false;
1715+
}
1716+
16911717
char *map_names[] = {
16921718
"sock_map",
16931719
"sock_map_txmsg",
@@ -1786,7 +1812,8 @@ struct _test test[] = {
17861812
{"txmsg test pull-data", test_txmsg_pull},
17871813
{"txmsg test pop-data", test_txmsg_pop},
17881814
{"txmsg test push/pop data", test_txmsg_push_pop},
1789-
{"txmsg text ingress parser", test_txmsg_ingress_parser},
1815+
{"txmsg test ingress parser", test_txmsg_ingress_parser},
1816+
{"txmsg test ingress parser2", test_txmsg_ingress_parser2},
17901817
};
17911818

17921819
static int check_whitelist(struct _test *t, struct sockmap_options *opt)

0 commit comments

Comments
 (0)