Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4297656rdb; Mon, 11 Dec 2023 15:13:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHyTDLS7OsTZrIz6HeU8Bd1K36s1vjqs6sp7YXs71W1gWEn8j2vI5rYVao2BXzUeb3CwmEv X-Received: by 2002:a05:6e02:1a49:b0:35d:5420:84fe with SMTP id u9-20020a056e021a4900b0035d542084femr5421488ilv.6.1702336408193; Mon, 11 Dec 2023 15:13:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702336408; cv=none; d=google.com; s=arc-20160816; b=ItV6A5W1s/a7/nHENIAcxlxYer00Y0DByxAoW7PZeKl5nJMF04RRHsRGSFe4pHQgSW FwNnhRMgQCoR90a7L8O4yRbSFX0iQcXCe1Sw0BbcltG9ZWjDOHUS1kgLI9jp+q36zH91 Zz2p1aw1S7Az4VYaY1jEbYKKtPTwq2eHcPC5uUps7m6IaAhcbvouhQmwUDwl1BnlKd0B ANltDVLRsFNXZl7Dq3ry/qRoX07otE7nRQuyTupmmiBQ7StdaJYkCOcEK8P419TvzVVz Drtmv9Yij09rdtYoh4sclbfIG26yb7fz/Bj9ylPfCS3WTx3JP6hjogLYDK+fbxIptXav RBrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=xubElgI4Z56aixIPByeWysvBwAoYQd2kSEQW2+R/bzE=; fh=Y+mhQPahvhIMiO0uJJMbllkU/U976O8TZ0z/gw41KHA=; b=jv/InG6gpTD2dFiItMGtmCmlZ4Ad5fNcCoYwSinCJvAZDXhbs8Rz4bc+W8fXFoAEOQ wxIcCXTtqZ6dJez4L1i+7F0yyaS14/awOJ3LAk3uAfmSIWp6ODkU+H2l3O6aR5Xf0PmU lE/xUJ98gTYw1FjzAmrOByVG1mDyHcbJunMma4dFze8gpAO6orw8WD26xz6lMbeb9f5n GlfwULzClgGMtlT2Wd2M4NP2ZVJQixsQUMRcWcdRiiRnRclDDjBG6zw+jASLRy3+1j3j m8J7RT/wWFjw8h1/rDnKvD5JDAXEnxnyh6gJ02GLkcm2CEc7UMEAhxZMVYIhfXIIxmx5 vpjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=m2BaB0nX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id w69-20020a638248000000b005c6ed253558si6171439pgd.195.2023.12.11.15.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 15:13:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=m2BaB0nX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 32EAB804F639; Mon, 11 Dec 2023 15:13:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345331AbjLKXNP (ORCPT + 99 others); Mon, 11 Dec 2023 18:13:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345313AbjLKXNO (ORCPT ); Mon, 11 Dec 2023 18:13:14 -0500 Received: from mail-oo1-xc2d.google.com (mail-oo1-xc2d.google.com [IPv6:2607:f8b0:4864:20::c2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 510D6CD; Mon, 11 Dec 2023 15:13:20 -0800 (PST) Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-590bb31ccf5so1666215eaf.3; Mon, 11 Dec 2023 15:13:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702336399; x=1702941199; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xubElgI4Z56aixIPByeWysvBwAoYQd2kSEQW2+R/bzE=; b=m2BaB0nX9CcWyDNId/hrYcLMRpPGJurHtazB4F8WRzEpB6f8aXwxQSyk6gAGMik6LG VxgvZ5Lg8j0qQ3Gc5oWoozsqza67RAHkadQBBsy/Zlf6Oq5HZ/PwZU0uBGXGP2FNWuE6 wbA04uKRktB5t8w6sPp9epFKmPTXib299XDAMbBRkeO8IvBx0FdHNesPwg8zbDoQjHDV lvGzrZZxTE7VwEkXeamz6R20p0hiOibl1icPP4QhLg0CrxoZ8Up/zVDYxlGBovs7WkiA RJrDBMvkrkd+JGDHeF3VtVPPfU7FjEQvQsy4TaPC2ZuyJkrSHrKYnHpFHDYD+PQVTbll ES5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702336399; x=1702941199; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xubElgI4Z56aixIPByeWysvBwAoYQd2kSEQW2+R/bzE=; b=H8fpWQvMRsRks9i41VDq5OjqXTLlhT4s+DrXppCpagT+LzsQ2N760jL+i4jFYXnLn+ rO6KwlM+3vgXuY01qck2te3b8662fgSc7HErDSaiSc/C7NedonsJHGVQdCVvY++YY9mE OE8OcdlCN/g5Ln7cfzbWsVvjv30T0j2URQM9PPpcy0VnHmYkqhsy7ICNEbLgT4ocgVWI SnGiOez0vhkDWfFWvZk/QcXbfRQ1Wu41VRSCW9W1iXpr+utr7d911RyIqXFrohkb6c10 yZKhi7T7PjqB+kXZqcHFFOfmE0chufmpVbsStCJFIiuNH2T8tGa0AYkIoWqjjEpx3jLF ZrjA== X-Gm-Message-State: AOJu0YyL2+2nHiOzpcAcZXYa1UxFSHfFAPMIaVpcML3hnvYWILZHLCoo EUNSlj5a3lL+kdM30P+AMLYAg+lDKJlxr6lTGxA= X-Received: by 2002:a4a:5507:0:b0:591:203b:c1d6 with SMTP id e7-20020a4a5507000000b00591203bc1d6mr977454oob.15.1702336399455; Mon, 11 Dec 2023 15:13:19 -0800 (PST) MIME-Version: 1.0 References: <8ec1b885d2e13fcd20944cce9edc0340d993d044.1702325874.git.dxu@dxuuu.xyz> <7yjkfhrwdphtcljq3odv4jc6lucd32wcg277hfsf4ve2jbo7hp@vuqzwbq5nxjw> In-Reply-To: <7yjkfhrwdphtcljq3odv4jc6lucd32wcg277hfsf4ve2jbo7hp@vuqzwbq5nxjw> From: Eyal Birger Date: Mon, 11 Dec 2023 15:13:07 -0800 Message-ID: Subject: Re: [PATCH bpf-next v5 9/9] bpf: xfrm: Add selftest for bpf_xdp_get_xfrm_state() To: Daniel Xu Cc: daniel@iogearbox.net, davem@davemloft.net, shuah@kernel.org, ast@kernel.org, john.fastabend@gmail.com, kuba@kernel.org, andrii@kernel.org, hawk@kernel.org, steffen.klassert@secunet.com, antony.antony@secunet.com, alexei.starovoitov@gmail.com, yonghong.song@linux.dev, eddyz87@gmail.com, mykolal@fb.com, martin.lau@linux.dev, song@kernel.org, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, devel@linux-ipsec.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 11 Dec 2023 15:13:27 -0800 (PST) On Mon, Dec 11, 2023 at 2:31=E2=80=AFPM Daniel Xu wrote: > > On Mon, Dec 11, 2023 at 01:39:25PM -0800, Eyal Birger wrote: > > Hi Daniel, > > > > Tiny nits below in case you respin this for other reasons: > > > > On Mon, Dec 11, 2023 at 12:20=E2=80=AFPM Daniel Xu wrot= e: > > > > > > This commit extends test_tunnel selftest to test the new XDP xfrm sta= te > > > lookup kfunc. > > > > > > Co-developed-by: Antony Antony > > > Signed-off-by: Antony Antony > > > Signed-off-by: Daniel Xu > > > --- > > > .../selftests/bpf/prog_tests/test_tunnel.c | 20 ++++++-- > > > .../selftests/bpf/progs/test_tunnel_kern.c | 51 +++++++++++++++++= ++ > > > 2 files changed, 67 insertions(+), 4 deletions(-) > > > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/test_tunnel.c b/t= ools/testing/selftests/bpf/prog_tests/test_tunnel.c > > > index 2d7f8fa82ebd..fc804095d578 100644 > > > --- a/tools/testing/selftests/bpf/prog_tests/test_tunnel.c > > > +++ b/tools/testing/selftests/bpf/prog_tests/test_tunnel.c > > > @@ -278,7 +278,7 @@ static int add_xfrm_tunnel(void) > > > SYS(fail, > > > "ip netns exec at_ns0 " > > > "ip xfrm state add src %s dst %s proto esp " > > > - "spi %d reqid 1 mode tunnel " > > > + "spi %d reqid 1 mode tunnel replay-window 42 = " > > > "auth-trunc 'hmac(sha1)' %s 96 enc 'cbc(aes)'= %s", > > > IP4_ADDR_VETH0, IP4_ADDR1_VETH1, XFRM_SPI_IN_TO_OUT, XFRM= _AUTH, XFRM_ENC); > > > SYS(fail, > > > @@ -292,7 +292,7 @@ static int add_xfrm_tunnel(void) > > > SYS(fail, > > > "ip netns exec at_ns0 " > > > "ip xfrm state add src %s dst %s proto esp " > > > - "spi %d reqid 2 mode tunnel " > > > + "spi %d reqid 2 mode tunnel replay-window 42 = " > > > > nit: why do you need to set the replay-window in both directions? > > No reason - probably just careless here. > > > > > > "auth-trunc 'hmac(sha1)' %s 96 enc 'cbc(aes)'= %s", > > > IP4_ADDR1_VETH1, IP4_ADDR_VETH0, XFRM_SPI_OUT_TO_IN, XFRM= _AUTH, XFRM_ENC); > > > SYS(fail, > > > @@ -313,7 +313,7 @@ static int add_xfrm_tunnel(void) > > > */ > > > SYS(fail, > > > "ip xfrm state add src %s dst %s proto esp " > > > - "spi %d reqid 1 mode tunnel " > > > + "spi %d reqid 1 mode tunnel replay-window 42 " > > > "auth-trunc 'hmac(sha1)' %s 96 enc 'cbc(aes)' %s= ", > > > IP4_ADDR_VETH0, IP4_ADDR1_VETH1, XFRM_SPI_IN_TO_OUT, XFRM= _AUTH, XFRM_ENC); > > > SYS(fail, > > > @@ -325,7 +325,7 @@ static int add_xfrm_tunnel(void) > > > /* root -> at_ns0 */ > > > SYS(fail, > > > "ip xfrm state add src %s dst %s proto esp " > > > - "spi %d reqid 2 mode tunnel " > > > + "spi %d reqid 2 mode tunnel replay-window 42 " > > > "auth-trunc 'hmac(sha1)' %s 96 enc 'cbc(aes)' %s= ", > > > IP4_ADDR1_VETH1, IP4_ADDR_VETH0, XFRM_SPI_OUT_TO_IN, XFRM= _AUTH, XFRM_ENC); > > > SYS(fail, > > > @@ -628,8 +628,10 @@ static void test_xfrm_tunnel(void) > > > { > > > DECLARE_LIBBPF_OPTS(bpf_tc_hook, tc_hook, > > > .attach_point =3D BPF_TC_INGRESS); > > > + LIBBPF_OPTS(bpf_xdp_attach_opts, opts); > > > struct test_tunnel_kern *skel =3D NULL; > > > struct nstoken *nstoken; > > > + int xdp_prog_fd; > > > int tc_prog_fd; > > > int ifindex; > > > int err; > > > @@ -654,6 +656,14 @@ static void test_xfrm_tunnel(void) > > > if (attach_tc_prog(&tc_hook, tc_prog_fd, -1)) > > > goto done; > > > > > > + /* attach xdp prog to tunnel dev */ > > > + xdp_prog_fd =3D bpf_program__fd(skel->progs.xfrm_get_state_xd= p); > > > + if (!ASSERT_GE(xdp_prog_fd, 0, "bpf_program__fd")) > > > + goto done; > > > + err =3D bpf_xdp_attach(ifindex, xdp_prog_fd, XDP_FLAGS_REPLAC= E, &opts); > > > + if (!ASSERT_OK(err, "bpf_xdp_attach")) > > > + goto done; > > > + > > > /* ping from at_ns0 namespace test */ > > > nstoken =3D open_netns("at_ns0"); > > > err =3D test_ping(AF_INET, IP4_ADDR_TUNL_DEV1); > > > @@ -667,6 +677,8 @@ static void test_xfrm_tunnel(void) > > > goto done; > > > if (!ASSERT_EQ(skel->bss->xfrm_remote_ip, 0xac100164, "remote= _ip")) > > > goto done; > > > + if (!ASSERT_EQ(skel->bss->xfrm_replay_window, 42, "replay_win= dow")) > > > + goto done; > > > > > > done: > > > delete_xfrm_tunnel(); > > > diff --git a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c b/t= ools/testing/selftests/bpf/progs/test_tunnel_kern.c > > > index 3a59eb9c34de..c0dd38616562 100644 > > > --- a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c > > > +++ b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c > > > @@ -30,6 +30,10 @@ int bpf_skb_set_fou_encap(struct __sk_buff *skb_ct= x, > > > struct bpf_fou_encap *encap, int type) __ks= ym; > > > int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx, > > > struct bpf_fou_encap *encap) __ksym; > > > +struct xfrm_state * > > > +bpf_xdp_get_xfrm_state(struct xdp_md *ctx, struct bpf_xfrm_state_opt= s *opts, > > > + u32 opts__sz) __ksym; > > > +void bpf_xdp_xfrm_state_release(struct xfrm_state *x) __ksym; > > > > > > struct { > > > __uint(type, BPF_MAP_TYPE_ARRAY); > > > @@ -950,4 +954,51 @@ int xfrm_get_state(struct __sk_buff *skb) > > > return TC_ACT_OK; > > > } > > > > > > +volatile int xfrm_replay_window =3D 0; > > > + > > > +SEC("xdp") > > > +int xfrm_get_state_xdp(struct xdp_md *xdp) > > > +{ > > > + struct bpf_xfrm_state_opts opts =3D {}; > > > + struct xfrm_state *x =3D NULL; > > > + struct ip_esp_hdr *esph; > > > + struct bpf_dynptr ptr; > > > + u8 esph_buf[8] =3D {}; > > > + u8 iph_buf[20] =3D {}; > > > + struct iphdr *iph; > > > + u32 off; > > > + > > > + if (bpf_dynptr_from_xdp(xdp, 0, &ptr)) > > > + goto out; > > > + > > > + off =3D sizeof(struct ethhdr); > > > + iph =3D bpf_dynptr_slice(&ptr, off, iph_buf, sizeof(iph_buf))= ; > > > + if (!iph || iph->protocol !=3D IPPROTO_ESP) > > > + goto out; > > > + > > > + off +=3D sizeof(struct iphdr); > > > + esph =3D bpf_dynptr_slice(&ptr, off, esph_buf, sizeof(esph_bu= f)); > > > + if (!esph) > > > + goto out; > > > + > > > + opts.netns_id =3D BPF_F_CURRENT_NETNS; > > > + opts.daddr.a4 =3D iph->daddr; > > > + opts.spi =3D esph->spi; > > > + opts.proto =3D IPPROTO_ESP; > > > + opts.family =3D AF_INET; > > > + > > > + x =3D bpf_xdp_get_xfrm_state(xdp, &opts, sizeof(opts)); > > > + if (!x || opts.error) > > > > nit: how can opts.error be non zero if x =3D=3D NULL? > > Ignoring the new -ENOENT case, it can't. Which is why I'm testing that > behavior here. I'm sorry, I don't understand. AFAICT, regardless of the -ENOENT change, I don't see how (!x) is false and (opt.error) is true, and so "if (!x || opts.error)" is always equivalent to "if (!x)". What am I missing? Eyal.