|
12 | 12 | #include "test_sockmap_progs_query.skel.h"
|
13 | 13 | #include "test_sockmap_pass_prog.skel.h"
|
14 | 14 | #include "test_sockmap_drop_prog.skel.h"
|
| 15 | +#include "test_sockmap_change_tail.skel.h" |
15 | 16 | #include "bpf_iter_sockmap.skel.h"
|
16 | 17 |
|
17 | 18 | #include "sockmap_helpers.h"
|
@@ -643,6 +644,54 @@ static void test_sockmap_skb_verdict_fionread(bool pass_prog)
|
643 | 644 | test_sockmap_drop_prog__destroy(drop);
|
644 | 645 | }
|
645 | 646 |
|
| 647 | +static void test_sockmap_skb_verdict_change_tail(void) |
| 648 | +{ |
| 649 | + struct test_sockmap_change_tail *skel; |
| 650 | + int err, map, verdict; |
| 651 | + int c1, p1, sent, recvd; |
| 652 | + int zero = 0; |
| 653 | + char buf[2]; |
| 654 | + |
| 655 | + skel = test_sockmap_change_tail__open_and_load(); |
| 656 | + if (!ASSERT_OK_PTR(skel, "open_and_load")) |
| 657 | + return; |
| 658 | + verdict = bpf_program__fd(skel->progs.prog_skb_verdict); |
| 659 | + map = bpf_map__fd(skel->maps.sock_map_rx); |
| 660 | + |
| 661 | + err = bpf_prog_attach(verdict, map, BPF_SK_SKB_STREAM_VERDICT, 0); |
| 662 | + if (!ASSERT_OK(err, "bpf_prog_attach")) |
| 663 | + goto out; |
| 664 | + err = create_pair(AF_INET, SOCK_STREAM, &c1, &p1); |
| 665 | + if (!ASSERT_OK(err, "create_pair()")) |
| 666 | + goto out; |
| 667 | + err = bpf_map_update_elem(map, &zero, &c1, BPF_NOEXIST); |
| 668 | + if (!ASSERT_OK(err, "bpf_map_update_elem(c1)")) |
| 669 | + goto out_close; |
| 670 | + sent = xsend(p1, "Tr", 2, 0); |
| 671 | + ASSERT_EQ(sent, 2, "xsend(p1)"); |
| 672 | + recvd = recv(c1, buf, 2, 0); |
| 673 | + ASSERT_EQ(recvd, 1, "recv(c1)"); |
| 674 | + ASSERT_EQ(skel->data->change_tail_ret, 0, "change_tail_ret"); |
| 675 | + |
| 676 | + sent = xsend(p1, "G", 1, 0); |
| 677 | + ASSERT_EQ(sent, 1, "xsend(p1)"); |
| 678 | + recvd = recv(c1, buf, 2, 0); |
| 679 | + ASSERT_EQ(recvd, 2, "recv(c1)"); |
| 680 | + ASSERT_EQ(skel->data->change_tail_ret, 0, "change_tail_ret"); |
| 681 | + |
| 682 | + sent = xsend(p1, "E", 1, 0); |
| 683 | + ASSERT_EQ(sent, 1, "xsend(p1)"); |
| 684 | + recvd = recv(c1, buf, 1, 0); |
| 685 | + ASSERT_EQ(recvd, 1, "recv(c1)"); |
| 686 | + ASSERT_EQ(skel->data->change_tail_ret, -EINVAL, "change_tail_ret"); |
| 687 | + |
| 688 | +out_close: |
| 689 | + close(c1); |
| 690 | + close(p1); |
| 691 | +out: |
| 692 | + test_sockmap_change_tail__destroy(skel); |
| 693 | +} |
| 694 | + |
646 | 695 | static void test_sockmap_skb_verdict_peek_helper(int map)
|
647 | 696 | {
|
648 | 697 | int err, c1, p1, zero = 0, sent, recvd, avail;
|
@@ -1058,6 +1107,8 @@ void test_sockmap_basic(void)
|
1058 | 1107 | test_sockmap_skb_verdict_fionread(true);
|
1059 | 1108 | if (test__start_subtest("sockmap skb_verdict fionread on drop"))
|
1060 | 1109 | test_sockmap_skb_verdict_fionread(false);
|
| 1110 | + if (test__start_subtest("sockmap skb_verdict change tail")) |
| 1111 | + test_sockmap_skb_verdict_change_tail(); |
1061 | 1112 | if (test__start_subtest("sockmap skb_verdict msg_f_peek"))
|
1062 | 1113 | test_sockmap_skb_verdict_peek();
|
1063 | 1114 | if (test__start_subtest("sockmap skb_verdict msg_f_peek with link"))
|
|
0 commit comments