Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1853663rwb; Fri, 28 Jul 2023 16:36:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlHPe5IAD6c5W6q0fb+Jssd6O5nGazwc8GP+0u07BwxlQLHJJ5fb2k0nTZpvCZ48GIktq8+U X-Received: by 2002:a17:902:b197:b0:1bb:a771:3542 with SMTP id s23-20020a170902b19700b001bba7713542mr2586442plr.58.1690587402145; Fri, 28 Jul 2023 16:36:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690587402; cv=none; d=google.com; s=arc-20160816; b=jDNxiEcbABR5XJE1gLTxyON2nAg7agIo6Rimyz0f3QyYayK9OleyHbjb6UmIKSYRW2 B6HLqqmkD7Q73duLQ4bVlEWH5K1MHfTs8qtxhvrNi3DMZ1RV/zmTDIYKc8pmQm0cWJpC r4Byo128ByFFglURDlxWvvN66V9lYcBkxNCZBY9tDoLEtdTF8q1c8ayOja4QhjbJ3j/G 6xsxa0EsthZNt5O2x1cBIwFedIGH7UpwMAHeM2Bg9hWwNjE5AcOBwrW34APl6FMZ+Eyy VSF2ShMkzF43MGHJVOiVz0xzpML2352kLSoBeBXV1mev41ZijC1vd5OSv5ala/Z20Eef C2UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:mime-version:date :dkim-signature:message-id; bh=rVZMCx5Zounfu2IwD4zBIt/Lk5NqzK7Uhgpsb3XYxGU=; fh=Y9oS8IEtZ89Fm0x8bg3UBmK/eL30cPuOlM1f8vIZueo=; b=R+Lb70/Yhzodmm1gpodhL8a1LalQzaDLe6ibg8/kHNZ9jV1U0Q0tV8HaAVvHAFweZL CGmlAnMIXI/fQ4yyuPn1qvPgTtMz9BBIqUY2aN9h9NFoUgP8b9Fz3UmL3wawJLOzrbAB ZyLjOs+PjXhp8Dc/GpX2Vr5O+LS3rwRvSWlVkH8vEZ20Xrftp64LabuyxvQg6StZ6e1h Pvd12RixGT6hlC0tGNQmGizMNPCOz54DtbGzYZg0GFDbFP9/J9r49p1wWLf0t/JKqdS1 LZ1m3v+pqiVHoxvKINIDMMxYc56k/9yPoXuZedo9mB2pyZdD3dFtdzdJ9GLmvUV8zU6u mMXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=miAD6Xpn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e16-20020a170902cf5000b001bb8a57d518si3607603plg.379.2023.07.28.16.36.30; Fri, 28 Jul 2023 16:36:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=miAD6Xpn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230187AbjG1Wr4 (ORCPT + 99 others); Fri, 28 Jul 2023 18:47:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233689AbjG1Wry (ORCPT ); Fri, 28 Jul 2023 18:47:54 -0400 Received: from out-107.mta0.migadu.com (out-107.mta0.migadu.com [IPv6:2001:41d0:1004:224b::6b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D60341984 for ; Fri, 28 Jul 2023 15:47:51 -0700 (PDT) Message-ID: <791b919c-de82-6dc8-905a-520543f975cd@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1690584469; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rVZMCx5Zounfu2IwD4zBIt/Lk5NqzK7Uhgpsb3XYxGU=; b=miAD6XpnNrSPSzFemTiSEGLsOBUhb/xoNmXZEtVHXAsYbl7GcWaePtQyfPdWGvuVzUoPys c3WVoRo/ghKGhO2pvBCu7WXk3WdeePVw0RywsLcBzajLcA6lRmauMJEwkzVv5Sgtb/xJoj EnMV7xkteVq4ENQMSjMisc/CC7aMDXc= Date: Fri, 28 Jul 2023 15:47:40 -0700 MIME-Version: 1.0 Subject: Re: [PATCH v4 bpf 2/2] bpf: selftests: add lwt redirect regression test cases Content-Language: en-US To: Yan Zhai Cc: bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Mykola Lysenko , Shuah Khan , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-team@cloudflare.com, Jordan Griege , Markus Elfring , Jakub Sitnicki References: <9c4896b109a39c3fa088844addaa1737a84bbbb5.1690332693.git.yan@cloudflare.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau In-Reply-To: <9c4896b109a39c3fa088844addaa1737a84bbbb5.1690332693.git.yan@cloudflare.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 On 7/25/23 6:09 PM, Yan Zhai wrote: > diff --git a/tools/testing/selftests/bpf/progs/test_lwt_redirect.c b/tools/testing/selftests/bpf/progs/test_lwt_redirect.c > new file mode 100644 > index 000000000000..3674e101f68f > --- /dev/null > +++ b/tools/testing/selftests/bpf/progs/test_lwt_redirect.c > @@ -0,0 +1,66 @@ > +// SPDX-License-Identifier: GPL-2.0 > +#include > +#include > +#include "bpf_tracing_net.h" > + > +/* We don't care about whether the packet can be received by network stack. > + * Just care if the packet is sent to the correct device at correct direction > + * and not panic the kernel. > + */ > +static __always_inline int prepend_dummy_mac(struct __sk_buff *skb) > +{ __always_inline is no longer a must for a long time. > + char mac[] = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0xf, > + 0xe, 0xd, 0xc, 0xb, 0xa, 0x08, 0x00}; > + > + if (bpf_skb_change_head(skb, ETH_HLEN, 0)) { > + bpf_printk("%s: fail to change head", __func__); Avoid using bpf_printk(). The bpf CI runs other tests also. > + return -1; > + } > + > + if (bpf_skb_store_bytes(skb, 0, mac, sizeof(mac), 0)) { > + bpf_printk("%s: fail to update mac", __func__); > + return -1; > + } > + > + return 0; > +} > + > +SEC("redir_ingress") Use SEC("lwt_xmit"). Then the libbpf will figure out the prog type. > +int test_lwt_redirect_in(struct __sk_buff *skb) > +{ > + if (prepend_dummy_mac(skb)) > + return BPF_DROP; > + > + bpf_printk("Redirect skb to link %d ingress", skb->mark); > + return bpf_redirect(skb->mark, BPF_F_INGRESS); > +} > + > +SEC("redir_egress") > +int test_lwt_redirect_out(struct __sk_buff *skb) > +{ > + if (prepend_dummy_mac(skb)) > + return BPF_DROP; > + > + bpf_printk("Redirect skb to link %d egress", skb->mark); > + return bpf_redirect(skb->mark, 0); > +} > + > +SEC("redir_egress_nomac") > +int test_lwt_redirect_out_nomac(struct __sk_buff *skb) > +{ > + int ret = bpf_redirect(skb->mark, 0); > + > + bpf_printk("Redirect skb to link %d egress nomac: %d", skb->mark, ret); > + return ret; > +} > + > +SEC("redir_ingress_nomac") > +int test_lwt_redirect_in_nomac(struct __sk_buff *skb) > +{ > + int ret = bpf_redirect(skb->mark, BPF_F_INGRESS); > + > + bpf_printk("Redirect skb to link %d ingress nomac: %d", skb->mark, ret); > + return ret; > +} > + > +char _license[] SEC("license") = "GPL"; > diff --git a/tools/testing/selftests/bpf/test_lwt_redirect.sh b/tools/testing/selftests/bpf/test_lwt_redirect.sh > new file mode 100755 > index 000000000000..1b7b78b48174 > --- /dev/null > +++ b/tools/testing/selftests/bpf/test_lwt_redirect.sh This has to be written in the test_progs infrastructure in C. Only test_progs is run by the BPF CI. Take a look at other tests in prog_tests/. For example, tc_redirect.c and xdp_metadata.c which are having setup in netns/link/...etc. It currently has helpers to add tc qdisc and filter but not adding route yet which could be a useful addition. -- pw-bot: cr