Message ID | 1673844908-11533-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 s9csp1031097wrn; Sun, 15 Jan 2023 21:28:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXvLZ4NAqcjaNOK3+hWha0h63FEAL/vZtz70XOykD3ne/mEKtBkJlMnau5XSYGJoDN3naAZj X-Received: by 2002:a05:6a20:2a22:b0:b8:8a94:5bf with SMTP id e34-20020a056a202a2200b000b88a9405bfmr2059959pzh.21.1673846909219; Sun, 15 Jan 2023 21:28:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673846909; cv=none; d=google.com; s=arc-20160816; b=Q30fCwmGg2tzbDb9oww7jq7FUrP7EtJO/knCyBgHUzR25cCqnQuMfab5rcnze6u+ln HZY+S4ZvP8mV6AySLMF4nmshp02vEiecb0uisNGEcFG7lvpD7YrStorpX0tb6oeQLDwc xogqzKCAP4oNwiHtrmVCE0c7U+Gt3veHV/6Jt/TLWeyrgztTlgQ2QvIDDYaw/3mra6fd 4NddswKXZCxQ+lMZtl9l0y4qgQWgVQpKspWr1Kp2Mp7XnDR8cQHJwZME8LjCmlYVZ14I FwEGzoro0GTlu3UxoFl1cM3bJsoxsdRaMAf0KSHRLhaamdidkvGz8euhLp3o8kFlI+vE YZGg== 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=ULQFEFKMbJAoRlaEQZ5C/kmHaZzvahSLY+BHF8jcxTc=; b=KjybtrhlONDtUge4diHjKGui3Ya3e6GghHxC7ofIA69J5HljQP9jFq2ozEMPZYFbLE Yj3pgjjsHfFnRCOZO0oZ06YftbBgnzS4x884GQNWHMiWElFC8wdeMQUM4fWefnU/suFo sM+arFrnuGWa1yEg1saI8Muwdume+RixvGUlU3ZSUsuHgZYTrfsFRkOTeXRrttiTCyQn KKjHfP2BvnlzaleQRnPuHmnmhQ68Dt0cZIrqiEFJUyxyeoTBa96LPCdqvbWPl3yOShUa RDErsdn5bBefKJQnoHgB0afddC42RmyQafjExkMIABpEoT7+tmFEHCcA3IbRkrX5BllP 446A== 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 h184-20020a6383c1000000b004cd1e13283fsi2094520pge.318.2023.01.15.21.28.16; Sun, 15 Jan 2023 21:28:29 -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 S231788AbjAPEzY (ORCPT <rfc822;stefanalexe802@gmail.com> + 99 others); Sun, 15 Jan 2023 23:55:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231857AbjAPEzU (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 15 Jan 2023 23:55:20 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5BA2F559F; Sun, 15 Jan 2023 20:55:16 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8Ax3eqz2MRjp84BAA--.5634S3; Mon, 16 Jan 2023 12:55:15 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxX+Sx2MRjIQ8aAA--.13747S2; Mon, 16 Jan 2023 12:55:14 +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] selftests/bpf: Fix undeclared identifier build errors of test_bpf_nf.c Date: Mon, 16 Jan 2023 12:55:08 +0800 Message-Id: <1673844908-11533-1-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf8AxX+Sx2MRjIQ8aAA--.13747S2 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvJXoW7WF13Kr4kCFW3Xr17ZryrWFg_yoW8JFW3pa 48Z3s0yFs5Ka1UuFn3CrW2vr4FyFs2vayUJw18ArW3Kr95Xr17tr4xKF47Jr9xGrWFq3s3 Za4IgFZrZF18A3JanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bSxYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JrI_Jryl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWUJVWUCwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l n4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6x ACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E 87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxV Aaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxY O2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGV WUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_ Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rV WUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4U JbIYCTnIWIevJa73UjIFyTuYvjxU4Z2-UUUUU 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?1755155696885642353?= X-GMAIL-MSGID: =?utf-8?q?1755155696885642353?= |
Series |
[bpf-next] selftests/bpf: Fix undeclared identifier build errors of test_bpf_nf.c
|
|
Commit Message
Tiezhu Yang
Jan. 16, 2023, 4:55 a.m. UTC
$ 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
to fix the above build errors.
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 | 5 +++++
1 file changed, 5 insertions(+)
Comments
On Mon, 2023-01-16 at 12:55 +0800, Tiezhu Yang wrote: > $ 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 > to fix the above build errors. > > 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 | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c > index 227e85e..114f961 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 { > + NF_NAT_MANIP_SRC, > + NF_NAT_MANIP_DST > +}; > + This is confusing, when I build the kernel/tests I get the declaration of the "enum nf_nat_manip_type" from the vmlinux.h (which is included from test_bpf_nf.c). Which means that this patch results in compilation error with my configuration. Is there a chance that your kernel is configured without some necessary netfilter configuration options? Have you tried this patch with BPF CI? > struct nf_conn; > > struct bpf_ct_opts___local {
On 16/01/2023 12:30, Eduard Zingerman wrote: > On Mon, 2023-01-16 at 12:55 +0800, Tiezhu Yang wrote: >> $ 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 >> to fix the above build errors. >> >> 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 | 5 +++++ >> 1 file changed, 5 insertions(+) >> >> diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c >> index 227e85e..114f961 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 { >> + NF_NAT_MANIP_SRC, >> + NF_NAT_MANIP_DST >> +}; >> + > > This is confusing, when I build the kernel/tests I get the declaration > the "enum nf_nat_manip_type" from the vmlinux.h (which is included from test_bpf_nf.c). > Which means that this patch results in compilation error with my configuration. > Is there a chance that your kernel is configured without some necessary netfilter > configuration options? Have you tried this patch with BPF CI? > Yep; I suspect if CONFIG_NF_NAT=m , the required definitions won't make it into vmlinux.h. The reference tools/testing/seftests/bpf/config has CONFIG_NF_NAT=y so it is at least documented in the referenced config. I'd suggest going the route of commit aa67961f3243dfff26c47769f87b4d94b07ec71f Author: Martin KaFai Lau <martin.lau@kernel.org> Date: Tue Dec 6 11:35:54 2022 -0800 selftests/bpf: Allow building bpf tests with CONFIG_XFRM_INTERFACE=[m|n] ...and adding/using local definitons like: enum nf_nat_manip_type_local { NF_NAT_MANIP_SRC_LOCAL, NF_NAT_MANIP_DST_LOCAL }; ...to avoid the name clash. Alan
On 1/16/23 5:54 AM, Alan Maguire wrote: > On 16/01/2023 12:30, Eduard Zingerman wrote: >> On Mon, 2023-01-16 at 12:55 +0800, Tiezhu Yang wrote: >>> $ 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 >>> to fix the above build errors. >>> >>> 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 | 5 +++++ >>> 1 file changed, 5 insertions(+) >>> >>> diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c >>> index 227e85e..114f961 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 { >>> + NF_NAT_MANIP_SRC, >>> + NF_NAT_MANIP_DST >>> +}; >>> + >> >> This is confusing, when I build the kernel/tests I get the declaration >> the "enum nf_nat_manip_type" from the vmlinux.h (which is included from test_bpf_nf.c). >> Which means that this patch results in compilation error with my configuration. >> Is there a chance that your kernel is configured without some necessary netfilter >> configuration options? Have you tried this patch with BPF CI? >> > > Yep; I suspect if CONFIG_NF_NAT=m , the required definitions won't make it > into vmlinux.h. The reference tools/testing/seftests/bpf/config has > CONFIG_NF_NAT=y so it is at least documented in the referenced config. > > I'd suggest going the route of > > commit aa67961f3243dfff26c47769f87b4d94b07ec71f > Author: Martin KaFai Lau <martin.lau@kernel.org> > Date: Tue Dec 6 11:35:54 2022 -0800 > > selftests/bpf: Allow building bpf tests with CONFIG_XFRM_INTERFACE=[m|n] > > ...and adding/using local definitons like: > > enum nf_nat_manip_type_local { > NF_NAT_MANIP_SRC_LOCAL, > NF_NAT_MANIP_DST_LOCAL > }; The above won't support core, and since preserve_access_index attribute does not support enum for now. We need to use bpf_core_enum_value to retrieve the proper value through CORE. could you try the following? enum nf_nat_manip_type___local { NF_NAT_MANIP_SRC___LOCAL, NF_NAT_MANIP_DST___LOCAL, }; ... bpf_ct_set_nat_info(ct, &saddr, sport, bpf_core_enum_value(enum nf_nat_manip_type___local, NF_NAT_MANIP_SRC___LOCAL)); ... bpf_ct_set_nat_info(ct, &daddr, dport, bpf_core_enum_value(enum nf_nat_manip_type___local, NF_NAT_MANIP_DST___LOCAL)); whether it works or not? Could you also try if the enumerator sequence in enum nf_nat_manip_type___local changed? > > ...to avoid the name clash. > > > Alan
On 01/17/2023 02:48 PM, Yonghong Song wrote: > > > On 1/16/23 5:54 AM, Alan Maguire wrote: >> On 16/01/2023 12:30, Eduard Zingerman wrote: >>> On Mon, 2023-01-16 at 12:55 +0800, Tiezhu Yang wrote: >>>> $ 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 >>>> to fix the above build errors. >>>> >>>> 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 | 5 +++++ >>>> 1 file changed, 5 insertions(+) >>>> >>>> diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c >>>> b/tools/testing/selftests/bpf/progs/test_bpf_nf.c >>>> index 227e85e..114f961 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 { >>>> + NF_NAT_MANIP_SRC, >>>> + NF_NAT_MANIP_DST >>>> +}; >>>> + >>> >>> This is confusing, when I build the kernel/tests I get the declaration >>> the "enum nf_nat_manip_type" from the vmlinux.h (which is included >>> from test_bpf_nf.c). >>> Which means that this patch results in compilation error with my >>> configuration. >>> Is there a chance that your kernel is configured without some >>> necessary netfilter >>> configuration options? Have you tried this patch with BPF CI? >>> >> >> Yep; I suspect if CONFIG_NF_NAT=m , the required definitions won't >> make it >> into vmlinux.h. The reference tools/testing/seftests/bpf/config has >> CONFIG_NF_NAT=y so it is at least documented in the referenced config. >> >> I'd suggest going the route of >> >> commit aa67961f3243dfff26c47769f87b4d94b07ec71f >> Author: Martin KaFai Lau <martin.lau@kernel.org> >> Date: Tue Dec 6 11:35:54 2022 -0800 >> >> selftests/bpf: Allow building bpf tests with >> CONFIG_XFRM_INTERFACE=[m|n] >> ...and adding/using local definitons like: >> >> enum nf_nat_manip_type_local { >> NF_NAT_MANIP_SRC_LOCAL, >> NF_NAT_MANIP_DST_LOCAL >> }; > > The above won't support core, and since preserve_access_index attribute > does not support enum for now. We need to use bpf_core_enum_value to > retrieve the proper value through CORE. > > could you try the following? > > enum nf_nat_manip_type___local { > NF_NAT_MANIP_SRC___LOCAL, > NF_NAT_MANIP_DST___LOCAL, > }; This is OK, it is similar with commit 1058b6a78db2 ("selftests/bpf: Do not fail build if CONFIG_NF_CONNTRACK=m/n"). > > ... > bpf_ct_set_nat_info(ct, &saddr, sport, bpf_core_enum_value(enum > nf_nat_manip_type___local, NF_NAT_MANIP_SRC___LOCAL)); > ... > > bpf_ct_set_nat_info(ct, &daddr, dport, bpf_core_enum_value(enum > nf_nat_manip_type___local, NF_NAT_MANIP_DST___LOCAL)); > > whether it works or not? Could you also try if the > enumerator sequence in enum nf_nat_manip_type___local changed? > >> >> ...to avoid the name clash. >> >> >> Alan I tested this on x86_64 fedora 36, using config-5.17.5-300.fc36.x86_64 to generate .config, CONFIG_NF_CONNTRACK=m, CONFIG_NF_NAT=m, there are no definitions of NF_NAT_MANIP_SRC and NF_NAT_MANIP_DST in vmlinux.h, build test_bpf_nf.c failed. $ grep -w CONFIG_NF_CONNTRACK /boot/config-5.17.5-300.fc36.x86_64 CONFIG_NF_CONNTRACK=m $ grep -w CONFIG_NF_NAT /boot/config-5.17.5-300.fc36.x86_64 CONFIG_NF_NAT=m I tested with various configs, the definitions of NF_NAT_MANIP_SRC and NF_NAT_MANIP_DST in vmlinux.h only depend on CONFIG_NF_CONNTRACK=y. (1) CONFIG_NF_CONNTRACK=m, CONFIG_NF_NAT=m, no definitions $ grep -w CONFIG_NF_CONNTRACK .config CONFIG_NF_CONNTRACK=m $ grep -w CONFIG_NF_NAT .config CONFIG_NF_NAT=m $ grep NF_NAT_MANIP_SRC tools/testing/selftests/bpf/tools/include/vmlinux.h $ grep NF_NAT_MANIP_DST tools/testing/selftests/bpf/tools/include/vmlinux.h $ (2) CONFIG_NF_CONNTRACK=m, CONFIG_NF_NAT=y, no definitions This case is unable, because CONFIG_NF_NAT depends on CONFIG_NF_CONNTRACK. (3) CONFIG_NF_CONNTRACK=m, CONFIG_NF_NAT=n, no definitions $ grep -w CONFIG_NF_CONNTRACK .config CONFIG_NF_CONNTRACK=m $ grep -w CONFIG_NF_NAT .config # CONFIG_NF_NAT is not set $ grep NF_NAT_MANIP_SRC tools/testing/selftests/bpf/tools/include/vmlinux.h $ grep NF_NAT_MANIP_DST tools/testing/selftests/bpf/tools/include/vmlinux.h $ (4) CONFIG_NF_CONNTRACK=y, CONFIG_NF_NAT=m, have definitions $ grep -w CONFIG_NF_CONNTRACK .config CONFIG_NF_CONNTRACK=y $ grep -w CONFIG_NF_NAT .config CONFIG_NF_NAT=m $ grep NF_NAT_MANIP_SRC tools/testing/selftests/bpf/tools/include/vmlinux.h NF_NAT_MANIP_SRC = 0, $ grep NF_NAT_MANIP_DST tools/testing/selftests/bpf/tools/include/vmlinux.h NF_NAT_MANIP_DST = 1, (5) CONFIG_NF_CONNTRACK=y, CONFIG_NF_NAT=y, have definitions $ grep -w CONFIG_NF_CONNTRACK .config CONFIG_NF_CONNTRACK=y $ grep -w CONFIG_NF_NAT .config CONFIG_NF_NAT=y $ grep NF_NAT_MANIP_SRC tools/testing/selftests/bpf/tools/include/vmlinux.h NF_NAT_MANIP_SRC = 0, $ grep NF_NAT_MANIP_DST tools/testing/selftests/bpf/tools/include/vmlinux.h NF_NAT_MANIP_DST = 1, (6) CONFIG_NF_CONNTRACK=y, CONFIG_NF_NAT=n, have definitions $ grep -w CONFIG_NF_CONNTRACK .config CONFIG_NF_CONNTRACK=y $ grep -w CONFIG_NF_NAT .config # CONFIG_NF_NAT is not set $ grep NF_NAT_MANIP_SRC tools/testing/selftests/bpf/tools/include/vmlinux.h NF_NAT_MANIP_SRC = 0, $ grep NF_NAT_MANIP_DST tools/testing/selftests/bpf/tools/include/vmlinux.h NF_NAT_MANIP_DST = 1, (7) CONFIG_NF_CONNTRACK=n, CONFIG_NF_NAT=n, no definitions $ grep -w CONFIG_NF_CONNTRACK .config # CONFIG_NF_CONNTRACK is not set $ grep -w CONFIG_NF_NAT .config $ grep NF_NAT_MANIP_SRC tools/testing/selftests/bpf/tools/include/vmlinux.h $ grep NF_NAT_MANIP_DST tools/testing/selftests/bpf/tools/include/vmlinux.h $ (8) CONFIG_NF_CONNTRACK=n, CONFIG_NF_NAT=y, no definitions This case is unable, because CONFIG_NF_NAT depends on CONFIG_NF_CONNTRACK. Here is an alternative change to check whether CONFIG_NF_CONNTRACK is m, enum nf_nat_manip_type___local is simple, which one is better? $ git diff tools/testing/selftests/bpf/ diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index 22533a18705e..f3cf02046c20 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -325,7 +325,7 @@ endif CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) BPF_CFLAGS = -g -Werror -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \ - -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \ + -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) -I$(TOOLSINCDIR) \ -I$(abspath $(OUTPUT)/../usr/include) CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \ diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c index 227e85e85dda..f2101807072f 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 <linux/kconfig.h> #define EAFNOSUPPORT 97 #define EPROTO 71 @@ -34,6 +35,13 @@ __be16 dport = 0; int test_exist_lookup = -ENOENT; u32 test_exist_lookup_mark = 0; +#if IS_MODULE(CONFIG_NF_CONNTRACK) +enum nf_nat_manip_type { + NF_NAT_MANIP_SRC, + NF_NAT_MANIP_DST +}; +#endif + struct nf_conn; struct bpf_ct_opts___local { Note that when unset CONFIG_NF_CONNTRACK, there are much more build errors, I do not know whether it is necessary to fix it and how to fix it properly. Here, I only consider the failed case CONFIG_NF_CONNTRACK=m. Thanks, Tiezhu
On 1/17/23 1:52 AM, Tiezhu Yang wrote: > > > On 01/17/2023 02:48 PM, Yonghong Song wrote: >> >> >> On 1/16/23 5:54 AM, Alan Maguire wrote: >>> On 16/01/2023 12:30, Eduard Zingerman wrote: >>>> On Mon, 2023-01-16 at 12:55 +0800, Tiezhu Yang wrote: >>>>> $ 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 >>>>> to fix the above build errors. >>>>> >>>>> 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 | 5 +++++ >>>>> 1 file changed, 5 insertions(+) >>>>> >>>>> diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c >>>>> b/tools/testing/selftests/bpf/progs/test_bpf_nf.c >>>>> index 227e85e..114f961 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 { >>>>> + NF_NAT_MANIP_SRC, >>>>> + NF_NAT_MANIP_DST >>>>> +}; >>>>> + >>>> >>>> This is confusing, when I build the kernel/tests I get the declaration >>>> the "enum nf_nat_manip_type" from the vmlinux.h (which is included >>>> from test_bpf_nf.c). >>>> Which means that this patch results in compilation error with my >>>> configuration. >>>> Is there a chance that your kernel is configured without some >>>> necessary netfilter >>>> configuration options? Have you tried this patch with BPF CI? >>>> >>> >>> Yep; I suspect if CONFIG_NF_NAT=m , the required definitions won't >>> make it >>> into vmlinux.h. The reference tools/testing/seftests/bpf/config has >>> CONFIG_NF_NAT=y so it is at least documented in the referenced config. >>> >>> I'd suggest going the route of >>> >>> commit aa67961f3243dfff26c47769f87b4d94b07ec71f >>> Author: Martin KaFai Lau <martin.lau@kernel.org> >>> Date: Tue Dec 6 11:35:54 2022 -0800 >>> >>> selftests/bpf: Allow building bpf tests with >>> CONFIG_XFRM_INTERFACE=[m|n] >>> ...and adding/using local definitons like: >>> >>> enum nf_nat_manip_type_local { >>> NF_NAT_MANIP_SRC_LOCAL, >>> NF_NAT_MANIP_DST_LOCAL >>> }; >> >> The above won't support core, and since preserve_access_index attribute >> does not support enum for now. We need to use bpf_core_enum_value to >> retrieve the proper value through CORE. >> >> could you try the following? >> >> enum nf_nat_manip_type___local { >> NF_NAT_MANIP_SRC___LOCAL, >> NF_NAT_MANIP_DST___LOCAL, >> }; > > This is OK, it is similar with commit 1058b6a78db2 ("selftests/bpf: Do > not fail build if CONFIG_NF_CONNTRACK=m/n"). > >> >> ... >> bpf_ct_set_nat_info(ct, &saddr, sport, bpf_core_enum_value(enum >> nf_nat_manip_type___local, NF_NAT_MANIP_SRC___LOCAL)); >> ... >> >> bpf_ct_set_nat_info(ct, &daddr, dport, bpf_core_enum_value(enum >> nf_nat_manip_type___local, NF_NAT_MANIP_DST___LOCAL)); >> >> whether it works or not? Could you also try if the >> enumerator sequence in enum nf_nat_manip_type___local changed? >> >>> >>> ...to avoid the name clash. >>> >>> >>> Alan > > I tested this on x86_64 fedora 36, using config-5.17.5-300.fc36.x86_64 > to generate .config, CONFIG_NF_CONNTRACK=m, CONFIG_NF_NAT=m, there are > no definitions of NF_NAT_MANIP_SRC and NF_NAT_MANIP_DST in vmlinux.h, > build test_bpf_nf.c failed. Thanks for trying. Yes, I tried in my environment and it failed because I didn't change the enum nf_nat_manip_type type for kfunc: int bpf_ct_set_nat_info(struct nf_conn *, union nf_inet_addr *, int port, enum nf_nat_manip_type) __ksym; But when I changed 'enum nf_nat_manip_type' to 'enum nf_nat_manip_type___local', kernel complains kfunc argument mismatch. The reason most likely is 'enum nf_nat_manip_type___local' is not converted to 'enum nf_nat_manip_type' by libbpf. This might be expected as preserve_access_index attribute only supports record (struct/union) type and libbpf might just do that. Could you double check whether this is the case or not? Maybe it is time to implement preserve_access_index support for enum type in clang now. But we need to resolve the issue, even temporarily for now. See below. > > $ grep -w CONFIG_NF_CONNTRACK /boot/config-5.17.5-300.fc36.x86_64 > CONFIG_NF_CONNTRACK=m > $ grep -w CONFIG_NF_NAT /boot/config-5.17.5-300.fc36.x86_64 > CONFIG_NF_NAT=m > > I tested with various configs, the definitions of NF_NAT_MANIP_SRC and > NF_NAT_MANIP_DST in vmlinux.h only depend on CONFIG_NF_CONNTRACK=y. > > (1) CONFIG_NF_CONNTRACK=m, CONFIG_NF_NAT=m, no definitions > $ grep -w CONFIG_NF_CONNTRACK .config > CONFIG_NF_CONNTRACK=m > $ grep -w CONFIG_NF_NAT .config > CONFIG_NF_NAT=m > $ grep NF_NAT_MANIP_SRC tools/testing/selftests/bpf/tools/include/vmlinux.h > $ grep NF_NAT_MANIP_DST tools/testing/selftests/bpf/tools/include/vmlinux.h > $ > > (2) CONFIG_NF_CONNTRACK=m, CONFIG_NF_NAT=y, no definitions > This case is unable, because CONFIG_NF_NAT depends on CONFIG_NF_CONNTRACK. > > (3) CONFIG_NF_CONNTRACK=m, CONFIG_NF_NAT=n, no definitions > $ grep -w CONFIG_NF_CONNTRACK .config > CONFIG_NF_CONNTRACK=m > $ grep -w CONFIG_NF_NAT .config > # CONFIG_NF_NAT is not set > $ grep NF_NAT_MANIP_SRC tools/testing/selftests/bpf/tools/include/vmlinux.h > $ grep NF_NAT_MANIP_DST tools/testing/selftests/bpf/tools/include/vmlinux.h > $ > > (4) CONFIG_NF_CONNTRACK=y, CONFIG_NF_NAT=m, have definitions > $ grep -w CONFIG_NF_CONNTRACK .config > CONFIG_NF_CONNTRACK=y > $ grep -w CONFIG_NF_NAT .config > CONFIG_NF_NAT=m > $ grep NF_NAT_MANIP_SRC tools/testing/selftests/bpf/tools/include/vmlinux.h > NF_NAT_MANIP_SRC = 0, > $ grep NF_NAT_MANIP_DST tools/testing/selftests/bpf/tools/include/vmlinux.h > NF_NAT_MANIP_DST = 1, > > (5) CONFIG_NF_CONNTRACK=y, CONFIG_NF_NAT=y, have definitions > $ grep -w CONFIG_NF_CONNTRACK .config > CONFIG_NF_CONNTRACK=y > $ grep -w CONFIG_NF_NAT .config > CONFIG_NF_NAT=y > $ grep NF_NAT_MANIP_SRC tools/testing/selftests/bpf/tools/include/vmlinux.h > NF_NAT_MANIP_SRC = 0, > $ grep NF_NAT_MANIP_DST tools/testing/selftests/bpf/tools/include/vmlinux.h > NF_NAT_MANIP_DST = 1, > > (6) CONFIG_NF_CONNTRACK=y, CONFIG_NF_NAT=n, have definitions > $ grep -w CONFIG_NF_CONNTRACK .config > CONFIG_NF_CONNTRACK=y > $ grep -w CONFIG_NF_NAT .config > # CONFIG_NF_NAT is not set > $ grep NF_NAT_MANIP_SRC tools/testing/selftests/bpf/tools/include/vmlinux.h > NF_NAT_MANIP_SRC = 0, > $ grep NF_NAT_MANIP_DST tools/testing/selftests/bpf/tools/include/vmlinux.h > NF_NAT_MANIP_DST = 1, > > (7) CONFIG_NF_CONNTRACK=n, CONFIG_NF_NAT=n, no definitions > $ grep -w CONFIG_NF_CONNTRACK .config > # CONFIG_NF_CONNTRACK is not set > $ grep -w CONFIG_NF_NAT .config > $ grep NF_NAT_MANIP_SRC tools/testing/selftests/bpf/tools/include/vmlinux.h > $ grep NF_NAT_MANIP_DST tools/testing/selftests/bpf/tools/include/vmlinux.h > $ > > (8) CONFIG_NF_CONNTRACK=n, CONFIG_NF_NAT=y, no definitions > This case is unable, because CONFIG_NF_NAT depends on CONFIG_NF_CONNTRACK. > > Here is an alternative change to check whether CONFIG_NF_CONNTRACK > is m, enum nf_nat_manip_type___local is simple, which one is better? > > $ git diff tools/testing/selftests/bpf/ > diff --git a/tools/testing/selftests/bpf/Makefile > b/tools/testing/selftests/bpf/Makefile > index 22533a18705e..f3cf02046c20 100644 > --- a/tools/testing/selftests/bpf/Makefile > +++ b/tools/testing/selftests/bpf/Makefile > @@ -325,7 +325,7 @@ endif > > CLANG_SYS_INCLUDES = $(call > get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) > BPF_CFLAGS = -g -Werror -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \ > - -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \ > + -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) -I$(TOOLSINCDIR) \ > -I$(abspath $(OUTPUT)/../usr/include) > > CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \ > diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c > b/tools/testing/selftests/bpf/progs/test_bpf_nf.c > index 227e85e85dda..f2101807072f 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 <linux/kconfig.h> > > #define EAFNOSUPPORT 97 > #define EPROTO 71 > @@ -34,6 +35,13 @@ __be16 dport = 0; > int test_exist_lookup = -ENOENT; > u32 test_exist_lookup_mark = 0; > > +#if IS_MODULE(CONFIG_NF_CONNTRACK) > +enum nf_nat_manip_type { > + NF_NAT_MANIP_SRC, > + NF_NAT_MANIP_DST > +}; > +#endif > + The above change does not work for me. The complication failed with CLNG-BPF [test_maps] btf__core_reloc_nesting___err_missing_container.bpf.o CLNG-BPF [test_maps] test_sysctl_loop2.bpf.o progs/test_bpf_nf.c:168: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:171: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. Apparently, IS_MODULE(...) is recognized but it returns 0. I do have CONFIG_NF_CONNTRACK=m in my config. Note that I build the kernel with KBUILD_OUTPUT=<another dir> (make -j LLVM=1) so vmlinux is in a different place. While I build selftest with 'make -C tools/testing/selftests/bpf -j LLVM=1' which is in-tree. > struct nf_conn; > > struct bpf_ct_opts___local { > > Note that when unset CONFIG_NF_CONNTRACK, there are much more > build errors, I do not know whether it is necessary to fix it > and how to fix it properly. Here, I only consider the failed > case CONFIG_NF_CONNTRACK=m. > > Thanks, > Tiezhu >
On 01/18/2023 02:29 AM, Yonghong Song wrote: > > > On 1/17/23 1:52 AM, Tiezhu Yang wrote: >> >> >> On 01/17/2023 02:48 PM, Yonghong Song wrote: >>> >>> >>> On 1/16/23 5:54 AM, Alan Maguire wrote: >>>> On 16/01/2023 12:30, Eduard Zingerman wrote: >>>>> On Mon, 2023-01-16 at 12:55 +0800, Tiezhu Yang wrote: >>>>>> $ 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 >>>>>> to fix the above build errors. >>>>>> >>>>>> 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 | 5 +++++ >>>>>> 1 file changed, 5 insertions(+) >>>>>> >>>>>> diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c >>>>>> b/tools/testing/selftests/bpf/progs/test_bpf_nf.c >>>>>> index 227e85e..114f961 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 { >>>>>> + NF_NAT_MANIP_SRC, >>>>>> + NF_NAT_MANIP_DST >>>>>> +}; >>>>>> + >>>>> >>>>> This is confusing, when I build the kernel/tests I get the declaration >>>>> the "enum nf_nat_manip_type" from the vmlinux.h (which is included >>>>> from test_bpf_nf.c). >>>>> Which means that this patch results in compilation error with my >>>>> configuration. >>>>> Is there a chance that your kernel is configured without some >>>>> necessary netfilter >>>>> configuration options? Have you tried this patch with BPF CI? >>>>> >>>> >>>> Yep; I suspect if CONFIG_NF_NAT=m , the required definitions won't >>>> make it >>>> into vmlinux.h. The reference tools/testing/seftests/bpf/config has >>>> CONFIG_NF_NAT=y so it is at least documented in the referenced config. >>>> >>>> I'd suggest going the route of >>>> >>>> commit aa67961f3243dfff26c47769f87b4d94b07ec71f >>>> Author: Martin KaFai Lau <martin.lau@kernel.org> >>>> Date: Tue Dec 6 11:35:54 2022 -0800 >>>> >>>> selftests/bpf: Allow building bpf tests with >>>> CONFIG_XFRM_INTERFACE=[m|n] >>>> ...and adding/using local definitons like: >>>> >>>> enum nf_nat_manip_type_local { >>>> NF_NAT_MANIP_SRC_LOCAL, >>>> NF_NAT_MANIP_DST_LOCAL >>>> }; >>> >>> The above won't support core, and since preserve_access_index attribute >>> does not support enum for now. We need to use bpf_core_enum_value to >>> retrieve the proper value through CORE. >>> >>> could you try the following? >>> >>> enum nf_nat_manip_type___local { >>> NF_NAT_MANIP_SRC___LOCAL, >>> NF_NAT_MANIP_DST___LOCAL, >>> }; >> >> This is OK, it is similar with commit 1058b6a78db2 ("selftests/bpf: Do >> not fail build if CONFIG_NF_CONNTRACK=m/n"). >> >>> >>> ... >>> bpf_ct_set_nat_info(ct, &saddr, sport, bpf_core_enum_value(enum >>> nf_nat_manip_type___local, NF_NAT_MANIP_SRC___LOCAL)); >>> ... >>> >>> bpf_ct_set_nat_info(ct, &daddr, dport, bpf_core_enum_value(enum >>> nf_nat_manip_type___local, NF_NAT_MANIP_DST___LOCAL)); >>> >>> whether it works or not? Could you also try if the >>> enumerator sequence in enum nf_nat_manip_type___local changed? >>> >>>> >>>> ...to avoid the name clash. >>>> >>>> >>>> Alan >> >> I tested this on x86_64 fedora 36, using config-5.17.5-300.fc36.x86_64 >> to generate .config, CONFIG_NF_CONNTRACK=m, CONFIG_NF_NAT=m, there are >> no definitions of NF_NAT_MANIP_SRC and NF_NAT_MANIP_DST in vmlinux.h, >> build test_bpf_nf.c failed. > > Thanks for trying. Yes, I tried in my environment and it failed because > I didn't change the enum nf_nat_manip_type type for kfunc: > int bpf_ct_set_nat_info(struct nf_conn *, union nf_inet_addr *, > int port, enum nf_nat_manip_type) __ksym; > > But when I changed 'enum nf_nat_manip_type' to > 'enum nf_nat_manip_type___local', kernel complains kfunc argument > mismatch. The reason most likely is 'enum nf_nat_manip_type___local' > is not converted to 'enum nf_nat_manip_type' by libbpf. > > This might be expected as preserve_access_index attribute only > supports record (struct/union) type and libbpf might just do that. > Could you double check whether this is the case or not? > > Maybe it is time to implement preserve_access_index support > for enum type in clang now. > > But we need to resolve the issue, even temporarily for now. > See below. > >> >> $ grep -w CONFIG_NF_CONNTRACK /boot/config-5.17.5-300.fc36.x86_64 >> CONFIG_NF_CONNTRACK=m >> $ grep -w CONFIG_NF_NAT /boot/config-5.17.5-300.fc36.x86_64 >> CONFIG_NF_NAT=m >> >> I tested with various configs, the definitions of NF_NAT_MANIP_SRC and >> NF_NAT_MANIP_DST in vmlinux.h only depend on CONFIG_NF_CONNTRACK=y. >> >> (1) CONFIG_NF_CONNTRACK=m, CONFIG_NF_NAT=m, no definitions >> $ grep -w CONFIG_NF_CONNTRACK .config >> CONFIG_NF_CONNTRACK=m >> $ grep -w CONFIG_NF_NAT .config >> CONFIG_NF_NAT=m >> $ grep NF_NAT_MANIP_SRC >> tools/testing/selftests/bpf/tools/include/vmlinux.h >> $ grep NF_NAT_MANIP_DST >> tools/testing/selftests/bpf/tools/include/vmlinux.h >> $ >> >> (2) CONFIG_NF_CONNTRACK=m, CONFIG_NF_NAT=y, no definitions >> This case is unable, because CONFIG_NF_NAT depends on >> CONFIG_NF_CONNTRACK. >> >> (3) CONFIG_NF_CONNTRACK=m, CONFIG_NF_NAT=n, no definitions >> $ grep -w CONFIG_NF_CONNTRACK .config >> CONFIG_NF_CONNTRACK=m >> $ grep -w CONFIG_NF_NAT .config >> # CONFIG_NF_NAT is not set >> $ grep NF_NAT_MANIP_SRC >> tools/testing/selftests/bpf/tools/include/vmlinux.h >> $ grep NF_NAT_MANIP_DST >> tools/testing/selftests/bpf/tools/include/vmlinux.h >> $ >> >> (4) CONFIG_NF_CONNTRACK=y, CONFIG_NF_NAT=m, have definitions >> $ grep -w CONFIG_NF_CONNTRACK .config >> CONFIG_NF_CONNTRACK=y >> $ grep -w CONFIG_NF_NAT .config >> CONFIG_NF_NAT=m >> $ grep NF_NAT_MANIP_SRC >> tools/testing/selftests/bpf/tools/include/vmlinux.h >> NF_NAT_MANIP_SRC = 0, >> $ grep NF_NAT_MANIP_DST >> tools/testing/selftests/bpf/tools/include/vmlinux.h >> NF_NAT_MANIP_DST = 1, >> >> (5) CONFIG_NF_CONNTRACK=y, CONFIG_NF_NAT=y, have definitions >> $ grep -w CONFIG_NF_CONNTRACK .config >> CONFIG_NF_CONNTRACK=y >> $ grep -w CONFIG_NF_NAT .config >> CONFIG_NF_NAT=y >> $ grep NF_NAT_MANIP_SRC >> tools/testing/selftests/bpf/tools/include/vmlinux.h >> NF_NAT_MANIP_SRC = 0, >> $ grep NF_NAT_MANIP_DST >> tools/testing/selftests/bpf/tools/include/vmlinux.h >> NF_NAT_MANIP_DST = 1, >> >> (6) CONFIG_NF_CONNTRACK=y, CONFIG_NF_NAT=n, have definitions >> $ grep -w CONFIG_NF_CONNTRACK .config >> CONFIG_NF_CONNTRACK=y >> $ grep -w CONFIG_NF_NAT .config >> # CONFIG_NF_NAT is not set >> $ grep NF_NAT_MANIP_SRC >> tools/testing/selftests/bpf/tools/include/vmlinux.h >> NF_NAT_MANIP_SRC = 0, >> $ grep NF_NAT_MANIP_DST >> tools/testing/selftests/bpf/tools/include/vmlinux.h >> NF_NAT_MANIP_DST = 1, >> >> (7) CONFIG_NF_CONNTRACK=n, CONFIG_NF_NAT=n, no definitions >> $ grep -w CONFIG_NF_CONNTRACK .config >> # CONFIG_NF_CONNTRACK is not set >> $ grep -w CONFIG_NF_NAT .config >> $ grep NF_NAT_MANIP_SRC >> tools/testing/selftests/bpf/tools/include/vmlinux.h >> $ grep NF_NAT_MANIP_DST >> tools/testing/selftests/bpf/tools/include/vmlinux.h >> $ >> >> (8) CONFIG_NF_CONNTRACK=n, CONFIG_NF_NAT=y, no definitions >> This case is unable, because CONFIG_NF_NAT depends on >> CONFIG_NF_CONNTRACK. >> >> Here is an alternative change to check whether CONFIG_NF_CONNTRACK >> is m, enum nf_nat_manip_type___local is simple, which one is better? >> >> $ git diff tools/testing/selftests/bpf/ >> diff --git a/tools/testing/selftests/bpf/Makefile >> b/tools/testing/selftests/bpf/Makefile >> index 22533a18705e..f3cf02046c20 100644 >> --- a/tools/testing/selftests/bpf/Makefile >> +++ b/tools/testing/selftests/bpf/Makefile >> @@ -325,7 +325,7 @@ endif >> >> CLANG_SYS_INCLUDES = $(call >> get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) >> BPF_CFLAGS = -g -Werror -D__TARGET_ARCH_$(SRCARCH) >> $(MENDIAN) \ >> - -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \ >> + -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) -I$(TOOLSINCDIR) \ >> -I$(abspath $(OUTPUT)/../usr/include) >> >> CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \ >> diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c >> b/tools/testing/selftests/bpf/progs/test_bpf_nf.c >> index 227e85e85dda..f2101807072f 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 <linux/kconfig.h> >> >> #define EAFNOSUPPORT 97 >> #define EPROTO 71 >> @@ -34,6 +35,13 @@ __be16 dport = 0; >> int test_exist_lookup = -ENOENT; >> u32 test_exist_lookup_mark = 0; >> >> +#if IS_MODULE(CONFIG_NF_CONNTRACK) >> +enum nf_nat_manip_type { >> + NF_NAT_MANIP_SRC, >> + NF_NAT_MANIP_DST >> +}; >> +#endif >> + > > The above change does not work for me. The complication failed with > > CLNG-BPF [test_maps] > btf__core_reloc_nesting___err_missing_container.bpf.o > CLNG-BPF [test_maps] test_sysctl_loop2.bpf.o > progs/test_bpf_nf.c:168: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:171: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. > > > Apparently, IS_MODULE(...) is recognized but it returns 0. > I do have CONFIG_NF_CONNTRACK=m in my config. > Note that I build the kernel with KBUILD_OUTPUT=<another dir> > (make -j LLVM=1) so vmlinux is in a different place. > While I build selftest > with 'make -C tools/testing/selftests/bpf -j LLVM=1' which > is in-tree. > >> struct nf_conn; >> >> struct bpf_ct_opts___local { >> >> Note that when unset CONFIG_NF_CONNTRACK, there are much more >> build errors, I do not know whether it is necessary to fix it >> and how to fix it properly. Here, I only consider the failed >> case CONFIG_NF_CONNTRACK=m. >> >> Thanks, >> Tiezhu >> I have the following test environment: system: x86_64 fedora 36 kernel: the latest bpf-next clang: version 14.0.5 (Fedora 14.0.5-1.fc36) gcc: 12.2.1 20220819 (Red Hat 12.2.1-2) With the following changes, there are no any build errors and warnings if (1) CONFIG_NF_CONNTRACK=m, CONFIG_NF_NAT=m (2) CONFIG_NF_CONNTRACK=y, CONFIG_NF_NAT=m (3) CONFIG_NF_CONNTRACK=y, CONFIG_NF_NAT=y $ 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 227e85e85dda..9fc603c9d673 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) { I will send it as a normal patch for your review, let us see what is the status of BPF CI. 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..114f961 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 { + NF_NAT_MANIP_SRC, + NF_NAT_MANIP_DST +}; + struct nf_conn; struct bpf_ct_opts___local {