From: Larysa Zaremba <larysa.zaremba@intel.com>
To: bpf@vger.kernel.org
Cc: Larysa Zaremba <larysa.zaremba@intel.com>,
ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
martin.lau@linux.dev, song@kernel.org, yhs@fb.com,
john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com,
haoluo@google.com, jolsa@kernel.org,
David Ahern <dsahern@gmail.com>, Jakub Kicinski <kuba@kernel.org>,
Willem de Bruijn <willemb@google.com>,
Jesper Dangaard Brouer <brouer@redhat.com>,
Anatoly Burakov <anatoly.burakov@intel.com>,
Alexander Lobakin <alexandr.lobakin@intel.com>,
Magnus Karlsson <magnus.karlsson@gmail.com>,
Maryam Tahhan <mtahhan@redhat.com>,
xdp-hints@xdp-project.net, netdev@vger.kernel.org,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Simon Horman <simon.horman@corigine.com>,
Tariq Toukan <tariqt@mellanox.com>,
Saeed Mahameed <saeedm@mellanox.com>,
Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Subject: [xdp-hints] [RFC bpf-next v2 20/24] selftests/bpf: Use AF_INET for TX in xdp_metadata
Date: Wed, 27 Sep 2023 09:51:20 +0200 [thread overview]
Message-ID: <20230927075124.23941-21-larysa.zaremba@intel.com> (raw)
In-Reply-To: <20230927075124.23941-1-larysa.zaremba@intel.com>
The easiest way to simulate stripped VLAN tag in veth is to send a packet
from VLAN interface, attached to veth. Unfortunately, this approach is
incompatible with AF_XDP on TX side, because VLAN interfaces do not have
such feature.
Replace AF_XDP packet generation with sending the same datagram via
AF_INET socket.
This does not change the packet contents or hints values with one notable
exception: rx_hash_type, which previously was expected to be 0, now is
expected be at least XDP_RSS_TYPE_L4.
Acked-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
---
.../selftests/bpf/prog_tests/xdp_metadata.c | 167 +++++++-----------
1 file changed, 59 insertions(+), 108 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
index 626c461fa34d..1877e5c6d6c7 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
@@ -20,7 +20,7 @@
#define UDP_PAYLOAD_BYTES 4
-#define AF_XDP_SOURCE_PORT 1234
+#define UDP_SOURCE_PORT 1234
#define AF_XDP_CONSUMER_PORT 8080
#define UMEM_NUM 16
@@ -33,6 +33,12 @@
#define RX_ADDR "10.0.0.2"
#define PREFIX_LEN "8"
#define FAMILY AF_INET
+#define TX_NETNS_NAME "xdp_metadata_tx"
+#define RX_NETNS_NAME "xdp_metadata_rx"
+#define TX_MAC "00:00:00:00:00:01"
+#define RX_MAC "00:00:00:00:00:02"
+
+#define XDP_RSS_TYPE_L4 BIT(3)
struct xsk {
void *umem_area;
@@ -119,90 +125,28 @@ static void close_xsk(struct xsk *xsk)
munmap(xsk->umem_area, UMEM_SIZE);
}
-static void ip_csum(struct iphdr *iph)
+static int generate_packet_udp(void)
{
- __u32 sum = 0;
- __u16 *p;
- int i;
-
- iph->check = 0;
- p = (void *)iph;
- for (i = 0; i < sizeof(*iph) / sizeof(*p); i++)
- sum += p[i];
-
- while (sum >> 16)
- sum = (sum & 0xffff) + (sum >> 16);
-
- iph->check = ~sum;
-}
-
-static int generate_packet(struct xsk *xsk, __u16 dst_port)
-{
- struct xdp_desc *tx_desc;
- struct udphdr *udph;
- struct ethhdr *eth;
- struct iphdr *iph;
- void *data;
- __u32 idx;
- int ret;
-
- ret = xsk_ring_prod__reserve(&xsk->tx, 1, &idx);
- if (!ASSERT_EQ(ret, 1, "xsk_ring_prod__reserve"))
- return -1;
-
- tx_desc = xsk_ring_prod__tx_desc(&xsk->tx, idx);
- tx_desc->addr = idx % (UMEM_NUM / 2) * UMEM_FRAME_SIZE;
- printf("%p: tx_desc[%u]->addr=%llx\n", xsk, idx, tx_desc->addr);
- data = xsk_umem__get_data(xsk->umem_area, tx_desc->addr);
-
- eth = data;
- iph = (void *)(eth + 1);
- udph = (void *)(iph + 1);
-
- memcpy(eth->h_dest, "\x00\x00\x00\x00\x00\x02", ETH_ALEN);
- memcpy(eth->h_source, "\x00\x00\x00\x00\x00\x01", ETH_ALEN);
- eth->h_proto = htons(ETH_P_IP);
-
- iph->version = 0x4;
- iph->ihl = 0x5;
- iph->tos = 0x9;
- iph->tot_len = htons(sizeof(*iph) + sizeof(*udph) + UDP_PAYLOAD_BYTES);
- iph->id = 0;
- iph->frag_off = 0;
- iph->ttl = 0;
- iph->protocol = IPPROTO_UDP;
- ASSERT_EQ(inet_pton(FAMILY, TX_ADDR, &iph->saddr), 1, "inet_pton(TX_ADDR)");
- ASSERT_EQ(inet_pton(FAMILY, RX_ADDR, &iph->daddr), 1, "inet_pton(RX_ADDR)");
- ip_csum(iph);
-
- udph->source = htons(AF_XDP_SOURCE_PORT);
- udph->dest = htons(dst_port);
- udph->len = htons(sizeof(*udph) + UDP_PAYLOAD_BYTES);
- udph->check = 0;
-
- memset(udph + 1, 0xAA, UDP_PAYLOAD_BYTES);
-
- tx_desc->len = sizeof(*eth) + sizeof(*iph) + sizeof(*udph) + UDP_PAYLOAD_BYTES;
- xsk_ring_prod__submit(&xsk->tx, 1);
-
- ret = sendto(xsk_socket__fd(xsk->socket), NULL, 0, MSG_DONTWAIT, NULL, 0);
- if (!ASSERT_GE(ret, 0, "sendto"))
- return ret;
-
- return 0;
-}
-
-static void complete_tx(struct xsk *xsk)
-{
- __u32 idx;
- __u64 addr;
-
- if (ASSERT_EQ(xsk_ring_cons__peek(&xsk->comp, 1, &idx), 1, "xsk_ring_cons__peek")) {
- addr = *xsk_ring_cons__comp_addr(&xsk->comp, idx);
-
- printf("%p: complete tx idx=%u addr=%llx\n", xsk, idx, addr);
- xsk_ring_cons__release(&xsk->comp, 1);
- }
+ char udp_payload[UDP_PAYLOAD_BYTES];
+ struct sockaddr_in rx_addr;
+ int sock_fd, err = 0;
+
+ /* Build a packet */
+ memset(udp_payload, 0xAA, UDP_PAYLOAD_BYTES);
+ rx_addr.sin_addr.s_addr = inet_addr(RX_ADDR);
+ rx_addr.sin_family = AF_INET;
+ rx_addr.sin_port = htons(UDP_SOURCE_PORT);
+
+ sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (!ASSERT_GE(sock_fd, 0, "socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)"))
+ return sock_fd;
+
+ err = sendto(sock_fd, udp_payload, UDP_PAYLOAD_BYTES, MSG_DONTWAIT,
+ (void *)&rx_addr, sizeof(rx_addr));
+ ASSERT_GE(err, 0, "sendto");
+
+ close(sock_fd);
+ return err;
}
static void refill_rx(struct xsk *xsk, __u64 addr)
@@ -268,7 +212,8 @@ static int verify_xsk_metadata(struct xsk *xsk)
if (!ASSERT_NEQ(meta->rx_hash, 0, "rx_hash"))
return -1;
- ASSERT_EQ(meta->rx_hash_type, 0, "rx_hash_type");
+ if (!ASSERT_NEQ(meta->rx_hash_type & XDP_RSS_TYPE_L4, 0, "rx_hash_type"))
+ return -1;
xsk_ring_cons__release(&xsk->rx, 1);
refill_rx(xsk, comp_addr);
@@ -284,36 +229,38 @@ void test_xdp_metadata(void)
struct nstoken *tok = NULL;
__u32 queue_id = QUEUE_ID;
struct bpf_map *prog_arr;
- struct xsk tx_xsk = {};
struct xsk rx_xsk = {};
__u32 val, key = 0;
int retries = 10;
int rx_ifindex;
- int tx_ifindex;
int sock_fd;
int ret;
- /* Setup new networking namespace, with a veth pair. */
+ /* Setup new networking namespaces, with a veth pair. */
- SYS(out, "ip netns add xdp_metadata");
- tok = open_netns("xdp_metadata");
+ SYS(out, "ip netns add " TX_NETNS_NAME);
+ SYS(out, "ip netns add " RX_NETNS_NAME);
+
+ tok = open_netns(TX_NETNS_NAME);
SYS(out, "ip link add numtxqueues 1 numrxqueues 1 " TX_NAME
" type veth peer " RX_NAME " numtxqueues 1 numrxqueues 1");
- SYS(out, "ip link set dev " TX_NAME " address 00:00:00:00:00:01");
- SYS(out, "ip link set dev " RX_NAME " address 00:00:00:00:00:02");
+ SYS(out, "ip link set " RX_NAME " netns " RX_NETNS_NAME);
+
+ SYS(out, "ip link set dev " TX_NAME " address " TX_MAC);
SYS(out, "ip link set dev " TX_NAME " up");
- SYS(out, "ip link set dev " RX_NAME " up");
SYS(out, "ip addr add " TX_ADDR "/" PREFIX_LEN " dev " TX_NAME);
- SYS(out, "ip addr add " RX_ADDR "/" PREFIX_LEN " dev " RX_NAME);
- rx_ifindex = if_nametoindex(RX_NAME);
- tx_ifindex = if_nametoindex(TX_NAME);
+ /* Avoid ARP calls */
+ SYS(out, "ip -4 neigh add " RX_ADDR " lladdr " RX_MAC " dev " TX_NAME);
+ close_netns(tok);
- /* Setup separate AF_XDP for TX and RX interfaces. */
+ tok = open_netns(RX_NETNS_NAME);
+ SYS(out, "ip link set dev " RX_NAME " address " RX_MAC);
+ SYS(out, "ip link set dev " RX_NAME " up");
+ SYS(out, "ip addr add " RX_ADDR "/" PREFIX_LEN " dev " RX_NAME);
+ rx_ifindex = if_nametoindex(RX_NAME);
- ret = open_xsk(tx_ifindex, &tx_xsk);
- if (!ASSERT_OK(ret, "open_xsk(TX_NAME)"))
- goto out;
+ /* Setup AF_XDP for RX interface. */
ret = open_xsk(rx_ifindex, &rx_xsk);
if (!ASSERT_OK(ret, "open_xsk(RX_NAME)"))
@@ -353,19 +300,20 @@ void test_xdp_metadata(void)
ret = bpf_map_update_elem(bpf_map__fd(bpf_obj->maps.xsk), &queue_id, &sock_fd, 0);
if (!ASSERT_GE(ret, 0, "bpf_map_update_elem"))
goto out;
+ close_netns(tok);
/* Send packet destined to RX AF_XDP socket. */
- if (!ASSERT_GE(generate_packet(&tx_xsk, AF_XDP_CONSUMER_PORT), 0,
- "generate AF_XDP_CONSUMER_PORT"))
+ tok = open_netns(TX_NETNS_NAME);
+ if (!ASSERT_GE(generate_packet_udp(), 0, "generate UDP packet"))
goto out;
+ close_netns(tok);
/* Verify AF_XDP RX packet has proper metadata. */
+ tok = open_netns(RX_NETNS_NAME);
if (!ASSERT_GE(verify_xsk_metadata(&rx_xsk), 0,
"verify_xsk_metadata"))
goto out;
- complete_tx(&tx_xsk);
-
/* Make sure freplace correctly picks up original bound device
* and doesn't crash.
*/
@@ -382,12 +330,15 @@ void test_xdp_metadata(void)
if (!ASSERT_OK(xdp_metadata2__attach(bpf_obj2), "attach freplace"))
goto out;
+ close_netns(tok);
/* Send packet to trigger . */
- if (!ASSERT_GE(generate_packet(&tx_xsk, AF_XDP_CONSUMER_PORT), 0,
- "generate freplace packet"))
+ tok = open_netns(TX_NETNS_NAME);
+ if (!ASSERT_GE(generate_packet_udp(), 0, "generate freplace packet"))
goto out;
+ close_netns(tok);
+ tok = open_netns(RX_NETNS_NAME);
while (!retries--) {
if (bpf_obj2->bss->called)
break;
@@ -397,10 +348,10 @@ void test_xdp_metadata(void)
out:
close_xsk(&rx_xsk);
- close_xsk(&tx_xsk);
xdp_metadata2__destroy(bpf_obj2);
xdp_metadata__destroy(bpf_obj);
if (tok)
close_netns(tok);
- SYS_NOFAIL("ip netns del xdp_metadata");
+ SYS_NOFAIL("ip netns del " RX_NETNS_NAME);
+ SYS_NOFAIL("ip netns del " TX_NETNS_NAME);
}
--
2.41.0
next prev parent reply other threads:[~2023-09-27 7:58 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-27 7:51 [xdp-hints] [RFC bpf-next v2 00/24] XDP metadata via kfuncs for ice + mlx5 Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 01/24] ice: make RX hash reading code more reusable Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 02/24] ice: make RX HW timestamp " Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 03/24] ice: make RX checksum checking " Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 04/24] ice: Make ptype internal to descriptor info processing Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 05/24] ice: Introduce ice_xdp_buff Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 06/24] ice: Support HW timestamp hint Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 07/24] ice: Support RX hash XDP hint Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 08/24] ice: Support XDP hints in AF_XDP ZC mode Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 09/24] xdp: Add VLAN tag hint Larysa Zaremba
2023-10-03 12:35 ` [xdp-hints] " Jakub Kicinski
2023-10-03 13:09 ` Alexander Lobakin
2023-10-04 18:08 ` Jakub Kicinski
2023-10-05 16:58 ` Alexander Lobakin
2023-10-05 17:16 ` Jakub Kicinski
2023-10-05 17:20 ` David Ahern
2023-10-05 18:06 ` Jakub Kicinski
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 10/24] ice: Implement " Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 11/24] ice: use VLAN proto from ring packet context in skb path Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 12/24] xdp: Add checksum hint Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 13/24] ice: Implement " Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 14/24] ice: put XDP meta sources assignment under a static key condition Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 15/24] selftests/bpf: Allow VLAN packets in xdp_hw_metadata Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 16/24] net, xdp: allow metadata > 32 Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 17/24] selftests/bpf: Add flags and new hints to xdp_hw_metadata Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 18/24] veth: Implement VLAN tag and checksum XDP hint Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 19/24] net: make vlan_get_tag() return -ENODATA instead of -EINVAL Larysa Zaremba
2023-09-27 7:51 ` Larysa Zaremba [this message]
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 21/24] selftests/bpf: Check VLAN tag and proto in xdp_metadata Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 22/24] selftests/bpf: check checksum state " Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 23/24] mlx5: implement VLAN tag XDP hint Larysa Zaremba
2023-09-27 7:51 ` [xdp-hints] [RFC bpf-next v2 24/24] mlx5: implement RX checksum " Larysa Zaremba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.xdp-project.net/postorius/lists/xdp-hints.xdp-project.net/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230927075124.23941-21-larysa.zaremba@intel.com \
--to=larysa.zaremba@intel.com \
--cc=alexandr.lobakin@intel.com \
--cc=alexei.starovoitov@gmail.com \
--cc=anatoly.burakov@intel.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brouer@redhat.com \
--cc=daniel@iogearbox.net \
--cc=dsahern@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@gmail.com \
--cc=martin.lau@linux.dev \
--cc=mtahhan@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=saeedm@mellanox.com \
--cc=sdf@google.com \
--cc=simon.horman@corigine.com \
--cc=song@kernel.org \
--cc=tariqt@mellanox.com \
--cc=willemb@google.com \
--cc=willemdebruijn.kernel@gmail.com \
--cc=xdp-hints@xdp-project.net \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox