From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by mail.toke.dk (Postfix) with ESMTPS id D085DA43DF2 for ; Wed, 6 Dec 2023 00:00:11 +0100 (CET) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=vTZA8cUU Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1d092b42fb4so1785235ad.0 for ; Tue, 05 Dec 2023 15:00:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701817150; x=1702421950; darn=xdp-project.net; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=DiDmnpUUNncrnI6aYqSgsfPSW6+CjhtdUetE6abrmhM=; b=vTZA8cUUOT4afynS5uFPdipPYKS0pyzgL5DEkt+z9zecV+wkKS/7E6Qe3e9p2rfWlT jCu07JDpsUSG8/VdZFpIvOFWBF5KsNXPXpvBdu9828NOZjB8nVy5JxXeWsVP0te+JtES 8y1p+OHSKCzMUf5XvHskGUpJnZFD3IvZVEC9spmLBEh+umi8p7QyqYjumxTj6wcsZdoL w0vhIsaivF+m7DrDVPbOFuR8bT5A57hI/nGbYXj13Bft3wXKZKCGk+oD2diu3N87MOmN pINzGEkJGpkbbpHvMvWrDG9BsmyL60bfp3tx8bb4b42vqo4cFjZFTHJgBX2/UPpLX7sM 3b8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701817150; x=1702421950; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DiDmnpUUNncrnI6aYqSgsfPSW6+CjhtdUetE6abrmhM=; b=OvTbrOQKZLjnQIUpp1zzZDmTBfxvA9jlGtKXfwP5VsHh34A0f/KIA4l3FGswkF3KTn nNgiRp+LEeGXq0jBloJ07tdmHgUBQewrBXCAC04NvdUjMj2nTDOT6fJa5FwgevzKXbTz KEm5DyhjSSxfO8A9m2lt1ahWUZKEHuczwza+/SOh5Y5faF7f6WBxmVMIGWmck1SgUpRm toWM0w/ENPRtQl5HCATkOFTU3CGcleA1WQ73BdRqR9OmZMkWWubMUNF7HsRZUrDEwC/2 qd/WGoPXUAyA9ypkKZvSh1WIDclJSoriZjktIdn9Ext5xTlOQakmcYmAtwlIRLoBh8ri vLNA== X-Gm-Message-State: AOJu0Yxpbf7LgwKusjnCteec+tl28PdlHOo61+x3tsEUbB7vqE+oKToS DFj8PWPfNSHpwUAPttdRkKKpATc= X-Google-Smtp-Source: AGHT+IHnWRQw3sBkw9X9W/vevsDl7PUkpFSopPucOm6JGnj51cT1SO2wA03RbmH1O1pGJhycl+koljM= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a17:902:ce91:b0:1d0:4246:90b1 with SMTP id f17-20020a170902ce9100b001d0424690b1mr50333plg.0.1701817149511; Tue, 05 Dec 2023 14:59:09 -0800 (PST) Date: Tue, 5 Dec 2023 14:59:07 -0800 In-Reply-To: <20231205210847.28460-18-larysa.zaremba@intel.com> Mime-Version: 1.0 References: <20231205210847.28460-1-larysa.zaremba@intel.com> <20231205210847.28460-18-larysa.zaremba@intel.com> Message-ID: From: Stanislav Fomichev To: Larysa Zaremba Content-Type: text/plain; charset="utf-8" Message-ID-Hash: G7ZBASZSPZ6QQXR4TJCLEMQSCOKKEQIR X-Message-ID-Hash: G7ZBASZSPZ6QQXR4TJCLEMQSCOKKEQIR X-MailFrom: 3PatvZQMKCYQ0lnowwotm.kwu5lx-pqv105lx-xzwrmk1.vm1@flex--sdf.bounces.google.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: bpf@vger.kernel.org, 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, haoluo@google.com, jolsa@kernel.org, David Ahern , Jakub Kicinski , Willem de Bruijn , Jesper Dangaard Brouer , Anatoly Burakov , Alexander Lobakin , Magnus Karlsson , Maryam Tahhan , xdp-hints@xdp-project.net, netdev@vger.kernel.org, Willem de Bruijn , Alexei Starovoitov , Tariq Toukan , Saeed Mahameed , Maciej Fijalkowski X-Mailman-Version: 3.3.8 Precedence: list Subject: [xdp-hints] Re: [PATCH bpf-next v8 17/18] selftests/bpf: Add AF_INET packet generation to xdp_metadata List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 12/05, Larysa Zaremba wrote: > 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. > > Check both packets sent via AF_XDP TX and regular socket. > > AF_INET packet will also have a filled-in hash type (XDP_RSS_TYPE_L4), > unlike AF_XDP packet, so more values can be checked. > > Signed-off-by: Larysa Zaremba > --- > .../selftests/bpf/prog_tests/xdp_metadata.c | 116 +++++++++++++++--- > 1 file changed, 97 insertions(+), 19 deletions(-) > > diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c > index 33cdf88efa6b..e7f06cbdd845 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; > @@ -181,7 +187,7 @@ static int generate_packet(struct xsk *xsk, __u16 dst_port) > 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->source = htons(UDP_SOURCE_PORT); > udph->dest = htons(dst_port); > udph->len = htons(sizeof(*udph) + UDP_PAYLOAD_BYTES); > udph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, > @@ -204,6 +210,30 @@ static int generate_packet(struct xsk *xsk, __u16 dst_port) > return 0; > } > > +static int generate_packet_inet(void) > +{ > + 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(AF_XDP_CONSUMER_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 complete_tx(struct xsk *xsk) > { > struct xsk_tx_metadata *meta; > @@ -236,7 +266,7 @@ static void refill_rx(struct xsk *xsk, __u64 addr) > } > } > > -static int verify_xsk_metadata(struct xsk *xsk) > +static int verify_xsk_metadata(struct xsk *xsk, bool sent_from_af_xdp) > { > const struct xdp_desc *rx_desc; > struct pollfd fds = {}; > @@ -290,17 +320,36 @@ static int verify_xsk_metadata(struct xsk *xsk) > if (!ASSERT_NEQ(meta->rx_hash, 0, "rx_hash")) > return -1; > > + if (!sent_from_af_xdp) { > + if (!ASSERT_NEQ(meta->rx_hash_type & XDP_RSS_TYPE_L4, 0, "rx_hash_type")) > + return -1; > + goto done; > + } > + > ASSERT_EQ(meta->rx_hash_type, 0, "rx_hash_type"); > > /* checksum offload */ > ASSERT_EQ(udph->check, htons(0x721c), "csum"); > > +done: > xsk_ring_cons__release(&xsk->rx, 1); > refill_rx(xsk, comp_addr); > > return 0; > } > > +static void switch_ns_to_rx(struct nstoken **tok) > +{ > + close_netns(*tok); > + *tok = open_netns(RX_NETNS_NAME); > +} > + > +static void switch_ns_to_tx(struct nstoken **tok) > +{ > + close_netns(*tok); > + *tok = open_netns(TX_NETNS_NAME); > +} > + > void test_xdp_metadata(void) > { > struct xdp_metadata2 *bpf_obj2 = NULL; > @@ -318,27 +367,31 @@ void test_xdp_metadata(void) > 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 " TX_NETNS_NAME); > + SYS(out, "ip netns add " RX_NETNS_NAME); > > - SYS(out, "ip netns add xdp_metadata"); > - tok = open_netns("xdp_metadata"); > + 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); > + > + /* Avoid ARP calls */ > + SYS(out, "ip -4 neigh add " RX_ADDR " lladdr " RX_MAC " dev " TX_NAME); > + > + switch_ns_to_rx(&tok); > + > + 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); > - tx_ifindex = if_nametoindex(TX_NAME); > > - /* Setup separate AF_XDP for TX and RX interfaces. */ > - > - ret = open_xsk(tx_ifindex, &tx_xsk); > - if (!ASSERT_OK(ret, "open_xsk(TX_NAME)")) > - goto out; > + /* Setup separate AF_XDP for RX interface. */ > > ret = open_xsk(rx_ifindex, &rx_xsk); > if (!ASSERT_OK(ret, "open_xsk(RX_NAME)")) > @@ -379,18 +432,38 @@ void test_xdp_metadata(void) > if (!ASSERT_GE(ret, 0, "bpf_map_update_elem")) > goto out; > > - /* Send packet destined to RX AF_XDP socket. */ > + switch_ns_to_tx(&tok); > + > + /* Setup separate AF_XDP for TX interface nad send packet to the RX socket. */ Not sure we care, but s/nad/and/ if you happen to do another respin.. Acked-by: Stanislav Fomichev