|
103 | 103 | #include <bpf/bpf.h>
|
104 | 104 | #include <linux/filter.h>
|
105 | 105 | #include "../kselftest.h"
|
| 106 | +#include "xsk_xdp_metadata.h" |
106 | 107 |
|
107 | 108 | static const char *MAC1 = "\x00\x0A\x56\x9E\xEE\x62";
|
108 | 109 | static const char *MAC2 = "\x00\x0A\x56\x9E\xEE\x61";
|
@@ -464,6 +465,7 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
|
464 | 465 | ifobj->use_fill_ring = true;
|
465 | 466 | ifobj->release_rx = true;
|
466 | 467 | ifobj->validation_func = NULL;
|
| 468 | + ifobj->use_metadata = false; |
467 | 469 |
|
468 | 470 | if (i == 0) {
|
469 | 471 | ifobj->rx_on = false;
|
@@ -798,6 +800,20 @@ static bool is_offset_correct(struct xsk_umem_info *umem, struct pkt_stream *pkt
|
798 | 800 | return false;
|
799 | 801 | }
|
800 | 802 |
|
| 803 | +static bool is_metadata_correct(struct pkt *pkt, void *buffer, u64 addr) |
| 804 | +{ |
| 805 | + void *data = xsk_umem__get_data(buffer, addr); |
| 806 | + struct xdp_info *meta = data - sizeof(struct xdp_info); |
| 807 | + |
| 808 | + if (meta->count != pkt->payload) { |
| 809 | + ksft_print_msg("[%s] expected meta_count [%d], got meta_count [%d]\n", |
| 810 | + __func__, pkt->payload, meta->count); |
| 811 | + return false; |
| 812 | + } |
| 813 | + |
| 814 | + return true; |
| 815 | +} |
| 816 | + |
801 | 817 | static bool is_pkt_valid(struct pkt *pkt, void *buffer, u64 addr, u32 len)
|
802 | 818 | {
|
803 | 819 | void *data = xsk_umem__get_data(buffer, addr);
|
@@ -959,7 +975,8 @@ static int receive_pkts(struct test_spec *test, struct pollfd *fds)
|
959 | 975 | addr = xsk_umem__add_offset_to_addr(addr);
|
960 | 976 |
|
961 | 977 | if (!is_pkt_valid(pkt, umem->buffer, addr, desc->len) ||
|
962 |
| - !is_offset_correct(umem, pkt_stream, addr, pkt->addr)) |
| 978 | + !is_offset_correct(umem, pkt_stream, addr, pkt->addr) || |
| 979 | + (ifobj->use_metadata && !is_metadata_correct(pkt, umem->buffer, addr))) |
963 | 980 | return TEST_FAILURE;
|
964 | 981 |
|
965 | 982 | if (ifobj->use_fill_ring)
|
@@ -1686,6 +1703,30 @@ static void testapp_xdp_drop(struct test_spec *test)
|
1686 | 1703 | testapp_validate_traffic(test);
|
1687 | 1704 | }
|
1688 | 1705 |
|
| 1706 | +static void testapp_xdp_metadata_count(struct test_spec *test) |
| 1707 | +{ |
| 1708 | + struct xsk_xdp_progs *skel_rx = test->ifobj_rx->xdp_progs; |
| 1709 | + struct xsk_xdp_progs *skel_tx = test->ifobj_tx->xdp_progs; |
| 1710 | + struct bpf_map *data_map; |
| 1711 | + int count = 0; |
| 1712 | + int key = 0; |
| 1713 | + |
| 1714 | + test_spec_set_name(test, "XDP_METADATA_COUNT"); |
| 1715 | + test_spec_set_xdp_prog(test, skel_rx->progs.xsk_xdp_populate_metadata, |
| 1716 | + skel_tx->progs.xsk_xdp_populate_metadata, |
| 1717 | + skel_rx->maps.xsk, skel_tx->maps.xsk); |
| 1718 | + test->ifobj_rx->use_metadata = true; |
| 1719 | + |
| 1720 | + data_map = bpf_object__find_map_by_name(skel_rx->obj, "xsk_xdp_.bss"); |
| 1721 | + if (!data_map || !bpf_map__is_internal(data_map)) |
| 1722 | + exit_with_error(ENOMEM); |
| 1723 | + |
| 1724 | + if (bpf_map_update_elem(bpf_map__fd(data_map), &key, &count, BPF_ANY)) |
| 1725 | + exit_with_error(errno); |
| 1726 | + |
| 1727 | + testapp_validate_traffic(test); |
| 1728 | +} |
| 1729 | + |
1689 | 1730 | static void testapp_poll_txq_tmout(struct test_spec *test)
|
1690 | 1731 | {
|
1691 | 1732 | test_spec_set_name(test, "POLL_TXQ_FULL");
|
@@ -1835,6 +1876,9 @@ static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_
|
1835 | 1876 | case TEST_TYPE_XDP_DROP_HALF:
|
1836 | 1877 | testapp_xdp_drop(test);
|
1837 | 1878 | break;
|
| 1879 | + case TEST_TYPE_XDP_METADATA_COUNT: |
| 1880 | + testapp_xdp_metadata_count(test); |
| 1881 | + break; |
1838 | 1882 | default:
|
1839 | 1883 | break;
|
1840 | 1884 | }
|
|
0 commit comments