Message ID | 1674028604-7113-1-git-send-email-yangtiezhu@loongson.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2219986wrn; Wed, 18 Jan 2023 00:54:05 -0800 (PST) X-Google-Smtp-Source: AMrXdXtHCgSH28ip2iygmrZjej77hE3mToo62IQ12DEDIziNH+aWG/wp6Q60J/zHvT5hSoz9HiZC X-Received: by 2002:a05:6402:5296:b0:49c:3cf4:d9ed with SMTP id en22-20020a056402529600b0049c3cf4d9edmr7121718edb.23.1674032045200; Wed, 18 Jan 2023 00:54:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674032045; cv=none; d=google.com; s=arc-20160816; b=MfMZ3yg2aYUMImjaRfVelsKXBcFLi3MAnv+Mz/zz1fEBDEx41BExq1DfTYr+nsVxp9 VrJS1URayBtW4DKiXIdCOVOJKrSrgOimVXvzRxxbFLSsxt7mtDJXIwz7MAKTng4lV4yO x0dUJjkil9DFIKQaMWXPakgE7kUwPiNP/5cbKGJsbRC602RuF4V/16dARTpJnk0dMnaZ OPPMXsfvE9j+Wt69MNswpiyJRPyLsg42U8aPdQNw9SOACEKRtO/F68hreB3O8Jw9jwqj TLvzju98WNy2HTklZhcaN333c4SNts3X7+Ksy0SqRO8qIKmqoKSaonGxyncpSeP1Spwl FwMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=0dB4NW6ddlhXWkFFgq5XxAEWiYCTkRa4Prz4iEcIWXo=; b=xISjMYTkLL1P5H2n+TH34dhoyPIblB+GgGT1o9H7aLzDLR7QdvRlemdmUkUrWzU2xL +NZVogIPlWGd33CxuW+gHJijo2utJDCrIsgFUTPVye9PW7hwqs7d+OSX56WQ8hJuKoTT ewQXpYtXnPMHwQ5DVsC8vQUNRb/NkMClEPxfk04VAVyjSSv1Girfu3GizuoA7w8o34lP ZtBSZiUriUftBo+fKQTMCyvfY/XyLQkK1AFwtXkY8mzh0Mm2Uw1c68nh8fv61HYSbhE4 HQR6o1DjlcIZqWQnlVZ1pvGFhKry32m5BkDyib28YmsyCsdVSykryr8KXNfb39iGE6Ro KXdA== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i22-20020a0564020f1600b0049e05407b8esi12241492eda.136.2023.01.18.00.53.40; Wed, 18 Jan 2023 00:54:05 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230141AbjARIiK (ORCPT <rfc822;pfffrao@gmail.com> + 99 others); Wed, 18 Jan 2023 03:38:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjARIhK (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 18 Jan 2023 03:37:10 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 123247EE5B; Tue, 17 Jan 2023 23:56:58 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8AxrvBJpsdjy0kCAA--.7296S3; Wed, 18 Jan 2023 15:56:57 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxf+RHpsdjVzUbAA--.17363S2; Wed, 18 Jan 2023 15:56:55 +0800 (CST) From: Tiezhu Yang <yangtiezhu@loongson.cn> To: Andrii Nakryiko <andrii@kernel.org>, Mykola Lysenko <mykolal@fb.com>, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Martin KaFai Lau <martin.lau@linux.dev>, Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>, John Fastabend <john.fastabend@gmail.com>, KP Singh <kpsingh@kernel.org>, Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>, Jiri Olsa <jolsa@kernel.org>, Lorenzo Bianconi <lorenzo@kernel.org> Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2] selftests/bpf: Fix build errors if CONFIG_NF_CONNTRACK=m Date: Wed, 18 Jan 2023 15:56:44 +0800 Message-Id: <1674028604-7113-1-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf8Cxf+RHpsdjVzUbAA--.17363S2 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvJXoWxAFykGr17ZryxCFyDXr4fZrb_yoW5XrW8pa 48Z3s0yr4kGw4UuF1xAFZ7Zr4rKFs29a4UJw1kJrWSkrZ5Xr1Utr1xKr43Ar9xurW09ay3 Za42gry7AFyrAaUanT9S1TB71UUUUjUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bS8YFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWUCVW8JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26F4UJVW0owAa w2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44 I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2 jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY1x0262 kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km 07C267AKxVWUXVWUAwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r 1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWU JVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r 1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1U YxBIdaVFxhVjvjDU0xZFpf9x07jwnYwUUUUU= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755349825978570685?= X-GMAIL-MSGID: =?utf-8?q?1755349825978570685?= |
Series |
[bpf-next,v2] selftests/bpf: Fix build errors if CONFIG_NF_CONNTRACK=m
|
|
Commit Message
Tiezhu Yang
Jan. 18, 2023, 7:56 a.m. UTC
If CONFIG_NF_CONNTRACK=m, there are no definitions of NF_NAT_MANIP_SRC
and NF_NAT_MANIP_DST in vmlinux.h, build test_bpf_nf.c failed.
$ make -C tools/testing/selftests/bpf/
CLNG-BPF [test_maps] test_bpf_nf.bpf.o
progs/test_bpf_nf.c:160:42: error: use of undeclared identifier 'NF_NAT_MANIP_SRC'
bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC);
^
progs/test_bpf_nf.c:163:42: error: use of undeclared identifier 'NF_NAT_MANIP_DST'
bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST);
^
2 errors generated.
Copy the definitions in include/net/netfilter/nf_nat.h to test_bpf_nf.c,
in order to avoid redefinitions if CONFIG_NF_CONNTRACK=y, rename them with
___local suffix. This is similar with commit 1058b6a78db2 ("selftests/bpf:
Do not fail build if CONFIG_NF_CONNTRACK=m/n").
Fixes: b06b45e82b59 ("selftests/bpf: add tests for bpf_ct_set_nat_info kfunc")
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
tools/testing/selftests/bpf/progs/test_bpf_nf.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
Comments
On Wed, Jan 18, 2023 at 03:56:44PM +0800, Tiezhu Yang wrote: > If CONFIG_NF_CONNTRACK=m, there are no definitions of NF_NAT_MANIP_SRC > and NF_NAT_MANIP_DST in vmlinux.h, build test_bpf_nf.c failed. > > $ make -C tools/testing/selftests/bpf/ > > CLNG-BPF [test_maps] test_bpf_nf.bpf.o > progs/test_bpf_nf.c:160:42: error: use of undeclared identifier 'NF_NAT_MANIP_SRC' > bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC); > ^ > progs/test_bpf_nf.c:163:42: error: use of undeclared identifier 'NF_NAT_MANIP_DST' > bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST); > ^ > 2 errors generated. > > Copy the definitions in include/net/netfilter/nf_nat.h to test_bpf_nf.c, > in order to avoid redefinitions if CONFIG_NF_CONNTRACK=y, rename them with > ___local suffix. This is similar with commit 1058b6a78db2 ("selftests/bpf: > Do not fail build if CONFIG_NF_CONNTRACK=m/n"). > > Fixes: b06b45e82b59 ("selftests/bpf: add tests for bpf_ct_set_nat_info kfunc") > Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> I hit the same problem, thanks Acked-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Jiri Olsa <jolsa@kernel.org> jirka > --- > tools/testing/selftests/bpf/progs/test_bpf_nf.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c > index 227e85e..9fc603c 100644 > --- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c > +++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c > @@ -34,6 +34,11 @@ __be16 dport = 0; > int test_exist_lookup = -ENOENT; > u32 test_exist_lookup_mark = 0; > > +enum nf_nat_manip_type___local { > + NF_NAT_MANIP_SRC___local, > + NF_NAT_MANIP_DST___local > +}; > + > struct nf_conn; > > struct bpf_ct_opts___local { > @@ -58,7 +63,7 @@ int bpf_ct_change_timeout(struct nf_conn *, u32) __ksym; > int bpf_ct_set_status(struct nf_conn *, u32) __ksym; > int bpf_ct_change_status(struct nf_conn *, u32) __ksym; > int bpf_ct_set_nat_info(struct nf_conn *, union nf_inet_addr *, > - int port, enum nf_nat_manip_type) __ksym; > + int port, enum nf_nat_manip_type___local) __ksym; > > static __always_inline void > nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32, > @@ -157,10 +162,10 @@ nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32, > > /* snat */ > saddr.ip = bpf_get_prandom_u32(); > - bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC); > + bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC___local); > /* dnat */ > daddr.ip = bpf_get_prandom_u32(); > - bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST); > + bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST___local); > > ct_ins = bpf_ct_insert_entry(ct); > if (ct_ins) { > -- > 2.1.0 >
On 1/17/23 11:56 PM, Tiezhu Yang wrote: > If CONFIG_NF_CONNTRACK=m, there are no definitions of NF_NAT_MANIP_SRC > and NF_NAT_MANIP_DST in vmlinux.h, build test_bpf_nf.c failed. > > $ make -C tools/testing/selftests/bpf/ > > CLNG-BPF [test_maps] test_bpf_nf.bpf.o > progs/test_bpf_nf.c:160:42: error: use of undeclared identifier 'NF_NAT_MANIP_SRC' > bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC); > ^ > progs/test_bpf_nf.c:163:42: error: use of undeclared identifier 'NF_NAT_MANIP_DST' > bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST); > ^ > 2 errors generated. > > Copy the definitions in include/net/netfilter/nf_nat.h to test_bpf_nf.c, > in order to avoid redefinitions if CONFIG_NF_CONNTRACK=y, rename them with > ___local suffix. This is similar with commit 1058b6a78db2 ("selftests/bpf: > Do not fail build if CONFIG_NF_CONNTRACK=m/n"). > > Fixes: b06b45e82b59 ("selftests/bpf: add tests for bpf_ct_set_nat_info kfunc") > Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> Okay, LGTM. We will address enum CORE support with preserve_access_index attribute later. Acked-by: Yonghong Song <yhs@fb.com>
Hello: This patch was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <martin.lau@kernel.org>: On Wed, 18 Jan 2023 15:56:44 +0800 you wrote: > If CONFIG_NF_CONNTRACK=m, there are no definitions of NF_NAT_MANIP_SRC > and NF_NAT_MANIP_DST in vmlinux.h, build test_bpf_nf.c failed. > > $ make -C tools/testing/selftests/bpf/ > > CLNG-BPF [test_maps] test_bpf_nf.bpf.o > progs/test_bpf_nf.c:160:42: error: use of undeclared identifier 'NF_NAT_MANIP_SRC' > bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC); > ^ > progs/test_bpf_nf.c:163:42: error: use of undeclared identifier 'NF_NAT_MANIP_DST' > bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST); > ^ > 2 errors generated. > > [...] Here is the summary with links: - [bpf-next,v2] selftests/bpf: Fix build errors if CONFIG_NF_CONNTRACK=m https://git.kernel.org/bpf/bpf-next/c/92afc5329a5b You are awesome, thank you!
On Tue, Jan 17, 2023 at 11:57 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > > If CONFIG_NF_CONNTRACK=m, there are no definitions of NF_NAT_MANIP_SRC > and NF_NAT_MANIP_DST in vmlinux.h, build test_bpf_nf.c failed. > > $ make -C tools/testing/selftests/bpf/ > > CLNG-BPF [test_maps] test_bpf_nf.bpf.o > progs/test_bpf_nf.c:160:42: error: use of undeclared identifier 'NF_NAT_MANIP_SRC' > bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC); > ^ > progs/test_bpf_nf.c:163:42: error: use of undeclared identifier 'NF_NAT_MANIP_DST' > bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST); > ^ > 2 errors generated. > > Copy the definitions in include/net/netfilter/nf_nat.h to test_bpf_nf.c, > in order to avoid redefinitions if CONFIG_NF_CONNTRACK=y, rename them with > ___local suffix. This is similar with commit 1058b6a78db2 ("selftests/bpf: > Do not fail build if CONFIG_NF_CONNTRACK=m/n"). > > Fixes: b06b45e82b59 ("selftests/bpf: add tests for bpf_ct_set_nat_info kfunc") > Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> > --- > tools/testing/selftests/bpf/progs/test_bpf_nf.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c > index 227e85e..9fc603c 100644 > --- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c > +++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c > @@ -34,6 +34,11 @@ __be16 dport = 0; > int test_exist_lookup = -ENOENT; > u32 test_exist_lookup_mark = 0; > > +enum nf_nat_manip_type___local { > + NF_NAT_MANIP_SRC___local, > + NF_NAT_MANIP_DST___local > +}; > + > struct nf_conn; > > struct bpf_ct_opts___local { > @@ -58,7 +63,7 @@ int bpf_ct_change_timeout(struct nf_conn *, u32) __ksym; > int bpf_ct_set_status(struct nf_conn *, u32) __ksym; > int bpf_ct_change_status(struct nf_conn *, u32) __ksym; > int bpf_ct_set_nat_info(struct nf_conn *, union nf_inet_addr *, > - int port, enum nf_nat_manip_type) __ksym; > + int port, enum nf_nat_manip_type___local) __ksym; > > static __always_inline void > nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32, > @@ -157,10 +162,10 @@ nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32, > > /* snat */ > saddr.ip = bpf_get_prandom_u32(); > - bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC); > + bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC___local); > /* dnat */ > daddr.ip = bpf_get_prandom_u32(); > - bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST); > + bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST___local); > it would be a bit more reliable if you used `bpf_core_enum_value(enum nf_nat_manip_type___local, NF_NAT_MANIP_DST___local)`. That would make libbpf substitute correct absolute value, if actual enum nf_nat_manip_type in kernel ever changed. Please consider a follow up patch for this. > ct_ins = bpf_ct_insert_entry(ct); > if (ct_ins) { > -- > 2.1.0 >
On 01/24/2023 07:17 AM, Andrii Nakryiko wrote: > On Tue, Jan 17, 2023 at 11:57 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: >> >> If CONFIG_NF_CONNTRACK=m, there are no definitions of NF_NAT_MANIP_SRC >> and NF_NAT_MANIP_DST in vmlinux.h, build test_bpf_nf.c failed. >> >> $ make -C tools/testing/selftests/bpf/ >> >> CLNG-BPF [test_maps] test_bpf_nf.bpf.o >> progs/test_bpf_nf.c:160:42: error: use of undeclared identifier 'NF_NAT_MANIP_SRC' >> bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC); >> ^ >> progs/test_bpf_nf.c:163:42: error: use of undeclared identifier 'NF_NAT_MANIP_DST' >> bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST); >> ^ >> 2 errors generated. >> >> Copy the definitions in include/net/netfilter/nf_nat.h to test_bpf_nf.c, >> in order to avoid redefinitions if CONFIG_NF_CONNTRACK=y, rename them with >> ___local suffix. This is similar with commit 1058b6a78db2 ("selftests/bpf: >> Do not fail build if CONFIG_NF_CONNTRACK=m/n"). >> >> Fixes: b06b45e82b59 ("selftests/bpf: add tests for bpf_ct_set_nat_info kfunc") >> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> >> --- >> tools/testing/selftests/bpf/progs/test_bpf_nf.c | 11 ++++++++--- >> 1 file changed, 8 insertions(+), 3 deletions(-) >> >> diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c >> index 227e85e..9fc603c 100644 >> --- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c >> +++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c >> @@ -34,6 +34,11 @@ __be16 dport = 0; >> int test_exist_lookup = -ENOENT; >> u32 test_exist_lookup_mark = 0; >> >> +enum nf_nat_manip_type___local { >> + NF_NAT_MANIP_SRC___local, >> + NF_NAT_MANIP_DST___local >> +}; >> + >> struct nf_conn; >> >> struct bpf_ct_opts___local { >> @@ -58,7 +63,7 @@ int bpf_ct_change_timeout(struct nf_conn *, u32) __ksym; >> int bpf_ct_set_status(struct nf_conn *, u32) __ksym; >> int bpf_ct_change_status(struct nf_conn *, u32) __ksym; >> int bpf_ct_set_nat_info(struct nf_conn *, union nf_inet_addr *, >> - int port, enum nf_nat_manip_type) __ksym; >> + int port, enum nf_nat_manip_type___local) __ksym; >> >> static __always_inline void >> nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32, >> @@ -157,10 +162,10 @@ nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32, >> >> /* snat */ >> saddr.ip = bpf_get_prandom_u32(); >> - bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC); >> + bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC___local); >> /* dnat */ >> daddr.ip = bpf_get_prandom_u32(); >> - bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST); >> + bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST___local); >> > > it would be a bit more reliable if you used `bpf_core_enum_value(enum > nf_nat_manip_type___local, NF_NAT_MANIP_DST___local)`. That would make > libbpf substitute correct absolute value, if actual enum > nf_nat_manip_type in kernel ever changed. Please consider a follow up > patch for this. Sorry for the late reply, I tested the code as your suggestion, but it failed. failed to resolve CO-RE relocation <enumval_value> [101] enum nf_nat_manip_type___local::NF_NAT_MANIP_SRC___local = 0 Is it necessary to send a follow patch now? Thank you. Here are the test results. (1) bpf_nf passed with the current code if CONFIG_NF_CONNTRACK=m: [root@fedora bpf]# ./test_progs -a bpf_nf #16/1 bpf_nf/xdp-ct:OK #16/2 bpf_nf/tc-bpf-ct:OK #16/3 bpf_nf/alloc_release:OK #16/4 bpf_nf/insert_insert:OK #16/5 bpf_nf/lookup_insert:OK #16/6 bpf_nf/set_timeout_after_insert:OK #16/7 bpf_nf/set_status_after_insert:OK #16/8 bpf_nf/change_timeout_after_alloc:OK #16/9 bpf_nf/change_status_after_alloc:OK #16/10 bpf_nf/write_not_allowlisted_field:OK #16 bpf_nf:OK Summary: 1/10 PASSED, 0 SKIPPED, 0 FAILED (2) bpf_nf failed with the following changes if CONFIG_NF_CONNTRACK=m: [yangtiezhu@fedora bpf.git]$ git diff diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c index 9fc603c9d673..f56ba60ab809 100644 --- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c +++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c @@ -2,6 +2,7 @@ #include <vmlinux.h> #include <bpf/bpf_helpers.h> #include <bpf/bpf_endian.h> +#include <bpf/bpf_core_read.h> #define EAFNOSUPPORT 97 #define EPROTO 71 @@ -162,10 +163,14 @@ nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32, /* snat */ saddr.ip = bpf_get_prandom_u32(); - bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC___local); + bpf_ct_set_nat_info(ct, &saddr, sport, + bpf_core_enum_value(enum nf_nat_manip_type___local, + NF_NAT_MANIP_SRC___local)); /* dnat */ daddr.ip = bpf_get_prandom_u32(); - bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST___local); + bpf_ct_set_nat_info(ct, &daddr, dport, + bpf_core_enum_value(enum nf_nat_manip_type___local, + NF_NAT_MANIP_DST___local)); ct_ins = bpf_ct_insert_entry(ct); if (ct_ins) { [root@fedora bpf]# ./test_progs -a bpf_nf ... All error logs: libbpf: prog 'nf_xdp_ct_test': BPF program load failed: Invalid argument libbpf: prog 'nf_xdp_ct_test': -- BEGIN PROG LOAD LOG -- ... libbpf: failed to load object 'test_bpf_nf' libbpf: failed to load BPF skeleton 'test_bpf_nf': -22 test_bpf_nf_ct:FAIL:test_bpf_nf__open_and_load unexpected error: -22 #16/1 bpf_nf/xdp-ct:FAIL libbpf: prog 'nf_xdp_ct_test': BPF program load failed: Invalid argument libbpf: prog 'nf_xdp_ct_test': -- BEGIN PROG LOAD LOG -- ... 217: (bf) r1 = r7 ; R1_w=ptr_nf_conn___init(ref_obj_id=18,off=0,imm=0) R7=ptr_nf_conn___init(ref_obj_id=18,off=0,imm=0) refs=18 218: <invalid CO-RE relocation> failed to resolve CO-RE relocation <enumval_value> [101] enum nf_nat_manip_type___local::NF_NAT_MANIP_SRC___local = 0 processed 170 insns (limit 1000000) max_states_per_insn 0 total_states 12 peak_states 12 mark_read 2 -- END PROG LOAD LOG -- libbpf: prog 'nf_xdp_ct_test': failed to load: -22 libbpf: failed to load object 'test_bpf_nf' libbpf: failed to load BPF skeleton 'test_bpf_nf': -22 test_bpf_nf_ct:FAIL:test_bpf_nf__open_and_load unexpected error: -22 #16/2 bpf_nf/tc-bpf-ct:FAIL #16 bpf_nf:FAIL Summary: 0/8 PASSED, 0 SKIPPED, 1 FAILED Thanks, Tiezhu
On Sat, Jan 28, 2023 at 10:25 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > > > > On 01/24/2023 07:17 AM, Andrii Nakryiko wrote: > > On Tue, Jan 17, 2023 at 11:57 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > >> > >> If CONFIG_NF_CONNTRACK=m, there are no definitions of NF_NAT_MANIP_SRC > >> and NF_NAT_MANIP_DST in vmlinux.h, build test_bpf_nf.c failed. > >> > >> $ make -C tools/testing/selftests/bpf/ > >> > >> CLNG-BPF [test_maps] test_bpf_nf.bpf.o > >> progs/test_bpf_nf.c:160:42: error: use of undeclared identifier 'NF_NAT_MANIP_SRC' > >> bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC); > >> ^ > >> progs/test_bpf_nf.c:163:42: error: use of undeclared identifier 'NF_NAT_MANIP_DST' > >> bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST); > >> ^ > >> 2 errors generated. > >> > >> Copy the definitions in include/net/netfilter/nf_nat.h to test_bpf_nf.c, > >> in order to avoid redefinitions if CONFIG_NF_CONNTRACK=y, rename them with > >> ___local suffix. This is similar with commit 1058b6a78db2 ("selftests/bpf: > >> Do not fail build if CONFIG_NF_CONNTRACK=m/n"). > >> > >> Fixes: b06b45e82b59 ("selftests/bpf: add tests for bpf_ct_set_nat_info kfunc") > >> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> > >> --- > >> tools/testing/selftests/bpf/progs/test_bpf_nf.c | 11 ++++++++--- > >> 1 file changed, 8 insertions(+), 3 deletions(-) > >> > >> diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c > >> index 227e85e..9fc603c 100644 > >> --- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c > >> +++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c > >> @@ -34,6 +34,11 @@ __be16 dport = 0; > >> int test_exist_lookup = -ENOENT; > >> u32 test_exist_lookup_mark = 0; > >> > >> +enum nf_nat_manip_type___local { > >> + NF_NAT_MANIP_SRC___local, > >> + NF_NAT_MANIP_DST___local > >> +}; > >> + > >> struct nf_conn; > >> > >> struct bpf_ct_opts___local { > >> @@ -58,7 +63,7 @@ int bpf_ct_change_timeout(struct nf_conn *, u32) __ksym; > >> int bpf_ct_set_status(struct nf_conn *, u32) __ksym; > >> int bpf_ct_change_status(struct nf_conn *, u32) __ksym; > >> int bpf_ct_set_nat_info(struct nf_conn *, union nf_inet_addr *, > >> - int port, enum nf_nat_manip_type) __ksym; > >> + int port, enum nf_nat_manip_type___local) __ksym; > >> > >> static __always_inline void > >> nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32, > >> @@ -157,10 +162,10 @@ nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32, > >> > >> /* snat */ > >> saddr.ip = bpf_get_prandom_u32(); > >> - bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC); > >> + bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC___local); > >> /* dnat */ > >> daddr.ip = bpf_get_prandom_u32(); > >> - bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST); > >> + bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST___local); > >> > > > > it would be a bit more reliable if you used `bpf_core_enum_value(enum > > nf_nat_manip_type___local, NF_NAT_MANIP_DST___local)`. That would make > > libbpf substitute correct absolute value, if actual enum > > nf_nat_manip_type in kernel ever changed. Please consider a follow up > > patch for this. > > Sorry for the late reply, I tested the code as your suggestion, but it > failed. > > failed to resolve CO-RE relocation <enumval_value> [101] enum > nf_nat_manip_type___local::NF_NAT_MANIP_SRC___local = 0 Was nf_conntrack kernel module loaded at the time when you ran the test? If yes, what's the output of bpftool btf dump file /sys/kernel/btf/nf_conntrack | grep nf_nat_manip_type ? > > Is it necessary to send a follow patch now? Thank you. > > Here are the test results. > > (1) bpf_nf passed with the current code if CONFIG_NF_CONNTRACK=m: > > [root@fedora bpf]# ./test_progs -a bpf_nf > #16/1 bpf_nf/xdp-ct:OK > #16/2 bpf_nf/tc-bpf-ct:OK > #16/3 bpf_nf/alloc_release:OK > #16/4 bpf_nf/insert_insert:OK > #16/5 bpf_nf/lookup_insert:OK > #16/6 bpf_nf/set_timeout_after_insert:OK > #16/7 bpf_nf/set_status_after_insert:OK > #16/8 bpf_nf/change_timeout_after_alloc:OK > #16/9 bpf_nf/change_status_after_alloc:OK > #16/10 bpf_nf/write_not_allowlisted_field:OK > #16 bpf_nf:OK > Summary: 1/10 PASSED, 0 SKIPPED, 0 FAILED > > (2) bpf_nf failed with the following changes if CONFIG_NF_CONNTRACK=m: > > [yangtiezhu@fedora bpf.git]$ git diff > diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c > b/tools/testing/selftests/bpf/progs/test_bpf_nf.c > index 9fc603c9d673..f56ba60ab809 100644 > --- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c > +++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c > @@ -2,6 +2,7 @@ > #include <vmlinux.h> > #include <bpf/bpf_helpers.h> > #include <bpf/bpf_endian.h> > +#include <bpf/bpf_core_read.h> > > #define EAFNOSUPPORT 97 > #define EPROTO 71 > @@ -162,10 +163,14 @@ nf_ct_test(struct nf_conn *(*lookup_fn)(void *, > struct bpf_sock_tuple *, u32, > > /* snat */ > saddr.ip = bpf_get_prandom_u32(); > - bpf_ct_set_nat_info(ct, &saddr, sport, > NF_NAT_MANIP_SRC___local); > + bpf_ct_set_nat_info(ct, &saddr, sport, > + bpf_core_enum_value(enum > nf_nat_manip_type___local, > + > NF_NAT_MANIP_SRC___local)); > /* dnat */ > daddr.ip = bpf_get_prandom_u32(); > - bpf_ct_set_nat_info(ct, &daddr, dport, > NF_NAT_MANIP_DST___local); > + bpf_ct_set_nat_info(ct, &daddr, dport, > + bpf_core_enum_value(enum > nf_nat_manip_type___local, > + > NF_NAT_MANIP_DST___local)); > > ct_ins = bpf_ct_insert_entry(ct); > if (ct_ins) { > > [root@fedora bpf]# ./test_progs -a bpf_nf > ... > All error logs: > libbpf: prog 'nf_xdp_ct_test': BPF program load failed: Invalid argument > libbpf: prog 'nf_xdp_ct_test': -- BEGIN PROG LOAD LOG -- > ... > libbpf: failed to load object 'test_bpf_nf' > libbpf: failed to load BPF skeleton 'test_bpf_nf': -22 > test_bpf_nf_ct:FAIL:test_bpf_nf__open_and_load unexpected error: -22 > #16/1 bpf_nf/xdp-ct:FAIL > libbpf: prog 'nf_xdp_ct_test': BPF program load failed: Invalid argument > libbpf: prog 'nf_xdp_ct_test': -- BEGIN PROG LOAD LOG -- > ... > 217: (bf) r1 = r7 ; > R1_w=ptr_nf_conn___init(ref_obj_id=18,off=0,imm=0) > R7=ptr_nf_conn___init(ref_obj_id=18,off=0,imm=0) refs=18 > 218: <invalid CO-RE relocation> > failed to resolve CO-RE relocation <enumval_value> [101] enum > nf_nat_manip_type___local::NF_NAT_MANIP_SRC___local = 0 > processed 170 insns (limit 1000000) max_states_per_insn 0 total_states > 12 peak_states 12 mark_read 2 > -- END PROG LOAD LOG -- > libbpf: prog 'nf_xdp_ct_test': failed to load: -22 > libbpf: failed to load object 'test_bpf_nf' > libbpf: failed to load BPF skeleton 'test_bpf_nf': -22 > test_bpf_nf_ct:FAIL:test_bpf_nf__open_and_load unexpected error: -22 > #16/2 bpf_nf/tc-bpf-ct:FAIL > #16 bpf_nf:FAIL > Summary: 0/8 PASSED, 0 SKIPPED, 1 FAILED > > Thanks, > Tiezhu >
On 02/04/2023 06:16 AM, Andrii Nakryiko wrote: > On Sat, Jan 28, 2023 at 10:25 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: >> >> >> >> On 01/24/2023 07:17 AM, Andrii Nakryiko wrote: >>> On Tue, Jan 17, 2023 at 11:57 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: >>>> >>>> If CONFIG_NF_CONNTRACK=m, there are no definitions of NF_NAT_MANIP_SRC >>>> and NF_NAT_MANIP_DST in vmlinux.h, build test_bpf_nf.c failed. >>>> >>>> $ make -C tools/testing/selftests/bpf/ >>>> >>>> CLNG-BPF [test_maps] test_bpf_nf.bpf.o >>>> progs/test_bpf_nf.c:160:42: error: use of undeclared identifier 'NF_NAT_MANIP_SRC' >>>> bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC); >>>> ^ >>>> progs/test_bpf_nf.c:163:42: error: use of undeclared identifier 'NF_NAT_MANIP_DST' >>>> bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST); >>>> ^ >>>> 2 errors generated. >>>> >>>> Copy the definitions in include/net/netfilter/nf_nat.h to test_bpf_nf.c, >>>> in order to avoid redefinitions if CONFIG_NF_CONNTRACK=y, rename them with >>>> ___local suffix. This is similar with commit 1058b6a78db2 ("selftests/bpf: >>>> Do not fail build if CONFIG_NF_CONNTRACK=m/n"). >>>> >>>> Fixes: b06b45e82b59 ("selftests/bpf: add tests for bpf_ct_set_nat_info kfunc") >>>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> >>>> --- >>>> tools/testing/selftests/bpf/progs/test_bpf_nf.c | 11 ++++++++--- >>>> 1 file changed, 8 insertions(+), 3 deletions(-) >>>> >>>> diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c >>>> index 227e85e..9fc603c 100644 >>>> --- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c >>>> +++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c >>>> @@ -34,6 +34,11 @@ __be16 dport = 0; >>>> int test_exist_lookup = -ENOENT; >>>> u32 test_exist_lookup_mark = 0; >>>> >>>> +enum nf_nat_manip_type___local { >>>> + NF_NAT_MANIP_SRC___local, >>>> + NF_NAT_MANIP_DST___local >>>> +}; >>>> + >>>> struct nf_conn; >>>> >>>> struct bpf_ct_opts___local { >>>> @@ -58,7 +63,7 @@ int bpf_ct_change_timeout(struct nf_conn *, u32) __ksym; >>>> int bpf_ct_set_status(struct nf_conn *, u32) __ksym; >>>> int bpf_ct_change_status(struct nf_conn *, u32) __ksym; >>>> int bpf_ct_set_nat_info(struct nf_conn *, union nf_inet_addr *, >>>> - int port, enum nf_nat_manip_type) __ksym; >>>> + int port, enum nf_nat_manip_type___local) __ksym; >>>> >>>> static __always_inline void >>>> nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32, >>>> @@ -157,10 +162,10 @@ nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32, >>>> >>>> /* snat */ >>>> saddr.ip = bpf_get_prandom_u32(); >>>> - bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC); >>>> + bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC___local); >>>> /* dnat */ >>>> daddr.ip = bpf_get_prandom_u32(); >>>> - bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST); >>>> + bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST___local); >>>> >>> >>> it would be a bit more reliable if you used `bpf_core_enum_value(enum >>> nf_nat_manip_type___local, NF_NAT_MANIP_DST___local)`. That would make >>> libbpf substitute correct absolute value, if actual enum >>> nf_nat_manip_type in kernel ever changed. Please consider a follow up >>> patch for this. >> >> Sorry for the late reply, I tested the code as your suggestion, but it >> failed. >> >> failed to resolve CO-RE relocation <enumval_value> [101] enum >> nf_nat_manip_type___local::NF_NAT_MANIP_SRC___local = 0 > > > Was nf_conntrack kernel module loaded at the time when you ran the > test? If yes, what's the output of Yes, nf_conntrack was loaded when ran the test. [root@fedora bpf]# lsmod | grep -w nf_conntrack nf_conntrack 188416 4 nf_nat,nft_ct,nf_conntrack_netbios_ns,nf_conntrack_broadcast nf_defrag_ipv6 24576 1 nf_conntrack nf_defrag_ipv4 16384 1 nf_conntrack [root@fedora bpf]# ./test_progs -a bpf_nf ... 218: <invalid CO-RE relocation> failed to resolve CO-RE relocation <enumval_value> [101] enum nf_nat_manip_type___local::NF_NAT_MANIP_SRC___local = 0 processed 170 insns (limit 1000000) max_states_per_insn 0 total_states 12 peak_states 12 mark_read 2 -- END PROG LOAD LOG -- libbpf: prog 'nf_xdp_ct_test': failed to load: -22 libbpf: failed to load object 'test_bpf_nf' libbpf: failed to load BPF skeleton 'test_bpf_nf': -22 test_bpf_nf_ct:FAIL:test_bpf_nf__open_and_load unexpected error: -22 #16/2 bpf_nf/tc-bpf-ct:FAIL #16 bpf_nf:FAIL Summary: 0/8 PASSED, 0 SKIPPED, 1 FAILED > > bpftool btf dump file /sys/kernel/btf/nf_conntrack | grep nf_nat_manip_type > > ? > [root@fedora bpf]# ./bpftool btf dump file /sys/kernel/btf/nf_conntrack | grep nf_nat_manip_type [130070] ENUM 'nf_nat_manip_type' encoding=UNSIGNED size=4 vlen=2 [root@fedora bpf]# ./bpftool btf dump file /sys/kernel/btf/nf_conntrack | grep NF_NAT_MANIP_SRC 'NF_NAT_MANIP_SRC' val=0 [root@fedora bpf]# ./bpftool btf dump file /sys/kernel/btf/nf_conntrack | grep NF_NAT_MANIP_DST 'NF_NAT_MANIP_DST' val=1 Thanks, Tiezhu >> >> Is it necessary to send a follow patch now? Thank you. >> >> Here are the test results. >> >> (1) bpf_nf passed with the current code if CONFIG_NF_CONNTRACK=m: >> >> [root@fedora bpf]# ./test_progs -a bpf_nf >> #16/1 bpf_nf/xdp-ct:OK >> #16/2 bpf_nf/tc-bpf-ct:OK >> #16/3 bpf_nf/alloc_release:OK >> #16/4 bpf_nf/insert_insert:OK >> #16/5 bpf_nf/lookup_insert:OK >> #16/6 bpf_nf/set_timeout_after_insert:OK >> #16/7 bpf_nf/set_status_after_insert:OK >> #16/8 bpf_nf/change_timeout_after_alloc:OK >> #16/9 bpf_nf/change_status_after_alloc:OK >> #16/10 bpf_nf/write_not_allowlisted_field:OK >> #16 bpf_nf:OK >> Summary: 1/10 PASSED, 0 SKIPPED, 0 FAILED >> >> (2) bpf_nf failed with the following changes if CONFIG_NF_CONNTRACK=m: >> >> [yangtiezhu@fedora bpf.git]$ git diff >> diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c >> b/tools/testing/selftests/bpf/progs/test_bpf_nf.c >> index 9fc603c9d673..f56ba60ab809 100644 >> --- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c >> +++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c >> @@ -2,6 +2,7 @@ >> #include <vmlinux.h> >> #include <bpf/bpf_helpers.h> >> #include <bpf/bpf_endian.h> >> +#include <bpf/bpf_core_read.h> >> >> #define EAFNOSUPPORT 97 >> #define EPROTO 71 >> @@ -162,10 +163,14 @@ nf_ct_test(struct nf_conn *(*lookup_fn)(void *, >> struct bpf_sock_tuple *, u32, >> >> /* snat */ >> saddr.ip = bpf_get_prandom_u32(); >> - bpf_ct_set_nat_info(ct, &saddr, sport, >> NF_NAT_MANIP_SRC___local); >> + bpf_ct_set_nat_info(ct, &saddr, sport, >> + bpf_core_enum_value(enum >> nf_nat_manip_type___local, >> + >> NF_NAT_MANIP_SRC___local)); >> /* dnat */ >> daddr.ip = bpf_get_prandom_u32(); >> - bpf_ct_set_nat_info(ct, &daddr, dport, >> NF_NAT_MANIP_DST___local); >> + bpf_ct_set_nat_info(ct, &daddr, dport, >> + bpf_core_enum_value(enum >> nf_nat_manip_type___local, >> + >> NF_NAT_MANIP_DST___local)); >> >> ct_ins = bpf_ct_insert_entry(ct); >> if (ct_ins) { >> >> [root@fedora bpf]# ./test_progs -a bpf_nf >> ... >> All error logs: >> libbpf: prog 'nf_xdp_ct_test': BPF program load failed: Invalid argument >> libbpf: prog 'nf_xdp_ct_test': -- BEGIN PROG LOAD LOG -- >> ... >> libbpf: failed to load object 'test_bpf_nf' >> libbpf: failed to load BPF skeleton 'test_bpf_nf': -22 >> test_bpf_nf_ct:FAIL:test_bpf_nf__open_and_load unexpected error: -22 >> #16/1 bpf_nf/xdp-ct:FAIL >> libbpf: prog 'nf_xdp_ct_test': BPF program load failed: Invalid argument >> libbpf: prog 'nf_xdp_ct_test': -- BEGIN PROG LOAD LOG -- >> ... >> 217: (bf) r1 = r7 ; >> R1_w=ptr_nf_conn___init(ref_obj_id=18,off=0,imm=0) >> R7=ptr_nf_conn___init(ref_obj_id=18,off=0,imm=0) refs=18 >> 218: <invalid CO-RE relocation> >> failed to resolve CO-RE relocation <enumval_value> [101] enum >> nf_nat_manip_type___local::NF_NAT_MANIP_SRC___local = 0 >> processed 170 insns (limit 1000000) max_states_per_insn 0 total_states >> 12 peak_states 12 mark_read 2 >> -- END PROG LOAD LOG -- >> libbpf: prog 'nf_xdp_ct_test': failed to load: -22 >> libbpf: failed to load object 'test_bpf_nf' >> libbpf: failed to load BPF skeleton 'test_bpf_nf': -22 >> test_bpf_nf_ct:FAIL:test_bpf_nf__open_and_load unexpected error: -22 >> #16/2 bpf_nf/tc-bpf-ct:FAIL >> #16 bpf_nf:FAIL >> Summary: 0/8 PASSED, 0 SKIPPED, 1 FAILED >> >> Thanks, >> Tiezhu >>
diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c index 227e85e..9fc603c 100644 --- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c +++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c @@ -34,6 +34,11 @@ __be16 dport = 0; int test_exist_lookup = -ENOENT; u32 test_exist_lookup_mark = 0; +enum nf_nat_manip_type___local { + NF_NAT_MANIP_SRC___local, + NF_NAT_MANIP_DST___local +}; + struct nf_conn; struct bpf_ct_opts___local { @@ -58,7 +63,7 @@ int bpf_ct_change_timeout(struct nf_conn *, u32) __ksym; int bpf_ct_set_status(struct nf_conn *, u32) __ksym; int bpf_ct_change_status(struct nf_conn *, u32) __ksym; int bpf_ct_set_nat_info(struct nf_conn *, union nf_inet_addr *, - int port, enum nf_nat_manip_type) __ksym; + int port, enum nf_nat_manip_type___local) __ksym; static __always_inline void nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32, @@ -157,10 +162,10 @@ nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32, /* snat */ saddr.ip = bpf_get_prandom_u32(); - bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC); + bpf_ct_set_nat_info(ct, &saddr, sport, NF_NAT_MANIP_SRC___local); /* dnat */ daddr.ip = bpf_get_prandom_u32(); - bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST); + bpf_ct_set_nat_info(ct, &daddr, dport, NF_NAT_MANIP_DST___local); ct_ins = bpf_ct_insert_entry(ct); if (ct_ins) {