Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <liujian56@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20211029141216.211899-3-liujian56@huawei.com

authored by

Liu Jian and committed by
Daniel Borkmann
d6967214 b556c3fd

+30 -3
+30 -3
tools/testing/selftests/bpf/test_sockmap.c
··· 139 139 bool sendpage; 140 140 bool data_test; 141 141 bool drop_expected; 142 + bool check_recved_len; 142 143 int iov_count; 143 144 int iov_length; 144 145 int rate; ··· 557 556 int err, i, flags = MSG_NOSIGNAL; 558 557 bool drop = opt->drop_expected; 559 558 bool data = opt->data_test; 559 + int iov_alloc_length = iov_length; 560 560 561 - err = msg_alloc_iov(&msg, iov_count, iov_length, data, tx); 561 + if (!tx && opt->check_recved_len) 562 + iov_alloc_length *= 2; 563 + 564 + err = msg_alloc_iov(&msg, iov_count, iov_alloc_length, data, tx); 562 565 if (err) 563 566 goto out_errno; 564 567 if (peek_flag) { ··· 670 665 671 666 s->bytes_recvd += recv; 672 667 668 + if (opt->check_recved_len && s->bytes_recvd > total_bytes) { 669 + errno = EMSGSIZE; 670 + fprintf(stderr, "recv failed(), bytes_recvd:%zd, total_bytes:%f\n", 671 + s->bytes_recvd, total_bytes); 672 + goto out_errno; 673 + } 674 + 673 675 if (data) { 674 676 int chunk_sz = opt->sendpage ? 675 677 iov_length * cnt : ··· 756 744 757 745 rxpid = fork(); 758 746 if (rxpid == 0) { 759 - iov_buf -= (txmsg_pop - txmsg_start_pop + 1); 747 + if (txmsg_pop || txmsg_start_pop) 748 + iov_buf -= (txmsg_pop - txmsg_start_pop + 1); 760 749 if (opt->drop_expected || txmsg_ktls_skb_drop) 761 750 _exit(0); 762 751 ··· 1701 1688 test_exec(cgrp, opt); 1702 1689 } 1703 1690 1691 + static void test_txmsg_ingress_parser2(int cgrp, struct sockmap_options *opt) 1692 + { 1693 + if (ktls == 1) 1694 + return; 1695 + skb_use_parser = 10; 1696 + opt->iov_length = 20; 1697 + opt->iov_count = 1; 1698 + opt->rate = 1; 1699 + opt->check_recved_len = true; 1700 + test_exec(cgrp, opt); 1701 + opt->check_recved_len = false; 1702 + } 1703 + 1704 1704 char *map_names[] = { 1705 1705 "sock_map", 1706 1706 "sock_map_txmsg", ··· 1812 1786 {"txmsg test pull-data", test_txmsg_pull}, 1813 1787 {"txmsg test pop-data", test_txmsg_pop}, 1814 1788 {"txmsg test push/pop data", test_txmsg_push_pop}, 1815 - {"txmsg text ingress parser", test_txmsg_ingress_parser}, 1789 + {"txmsg test ingress parser", test_txmsg_ingress_parser}, 1790 + {"txmsg test ingress parser2", test_txmsg_ingress_parser2}, 1816 1791 }; 1817 1792 1818 1793 static int check_whitelist(struct _test *t, struct sockmap_options *opt)