diff mbox series

[bpf-next,v1,2/2] bpf: sockopt_sk: fix 'undeclared' definition error

Message ID 20250204023946.16031-3-kerneljasonxing@gmail.com (mailing list archive)
State New
Delegated to: BPF
Headers show
Series selftests: fix two small compilation errors | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat-kernel
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-18 success Logs for s390x-gcc / veristat-meta
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for s390x-gcc / veristat-kernel
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-11 success Logs for aarch64-gcc / veristat-meta
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-19 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-gcc / veristat-meta / x86_64-gcc veristat_meta
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-42 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-17 / veristat-meta
bpf/vmtest-bpf-next-VM_Test-44 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-43 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-46 success Logs for x86_64-llvm-18 / veristat-meta
bpf/vmtest-bpf-next-VM_Test-45 success Logs for x86_64-llvm-18 / veristat-kernel
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-17 / veristat-kernel
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-gcc / veristat-kernel / x86_64-gcc veristat_kernel
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for bpf-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success Errors and warnings before: 26 (+1) this patch: 26 (+1)
netdev/cc_maintainers warning 1 maintainers not CCed: alexis.lothore@bootlin.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jason Xing Feb. 4, 2025, 2:39 a.m. UTC
Error messages:
selftests/bpf/prog_tests/sockopt_sk.c: In function ‘getsetsockopt’:
selftests/bpf/prog_tests/sockopt_sk.c:22:31: error: field ‘zc’ has incomplete type
   struct tcp_zerocopy_receive zc;
                               ^~
selftests/bpf/prog_tests/sockopt_sk.c:169:32: error: ‘TCP_ZEROCOPY_RECEIVE’ undeclared (first use in this function)
  err = getsockopt(fd, SOL_TCP, TCP_ZEROCOPY_RECEIVE, &buf, &optlen);
                                ^~~~~~~~~~~~~~~~~~~~

Fix it by introducing the right header.

Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
---
 tools/testing/selftests/bpf/prog_tests/sockopt_sk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Hou Tao Feb. 5, 2025, 2:57 a.m. UTC | #1
Hi,

On 2/4/2025 10:39 AM, Jason Xing wrote:
> Error messages:
> selftests/bpf/prog_tests/sockopt_sk.c: In function ‘getsetsockopt’:
> selftests/bpf/prog_tests/sockopt_sk.c:22:31: error: field ‘zc’ has incomplete type
>    struct tcp_zerocopy_receive zc;
>                                ^~
> selftests/bpf/prog_tests/sockopt_sk.c:169:32: error: ‘TCP_ZEROCOPY_RECEIVE’ undeclared (first use in this function)
>   err = getsockopt(fd, SOL_TCP, TCP_ZEROCOPY_RECEIVE, &buf, &optlen);
>                                 ^~~~~~~~~~~~~~~~~~~~
>
> Fix it by introducing the right header.
>
> Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
> ---
>  tools/testing/selftests/bpf/prog_tests/sockopt_sk.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> index ba6b3ec1156a..e0a9785ffcdc 100644
> --- a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> @@ -2,7 +2,7 @@
>  #include <test_progs.h>
>  #include "cgroup_helpers.h"
>  
> -#include <netinet/tcp.h>
> +#include <uapi/linux/tcp.h>

Should it be <linux/tcp.h> instead ? Directly including uapi header file
in application seems weird.
>  #include <linux/netlink.h>
>  #include "sockopt_sk.skel.h"
>
Jason Xing Feb. 5, 2025, 3:27 a.m. UTC | #2
On Wed, Feb 5, 2025 at 10:57 AM Hou Tao <houtao@huaweicloud.com> wrote:
>
> Hi,
>
> On 2/4/2025 10:39 AM, Jason Xing wrote:
> > Error messages:
> > selftests/bpf/prog_tests/sockopt_sk.c: In function ‘getsetsockopt’:
> > selftests/bpf/prog_tests/sockopt_sk.c:22:31: error: field ‘zc’ has incomplete type
> >    struct tcp_zerocopy_receive zc;
> >                                ^~
> > selftests/bpf/prog_tests/sockopt_sk.c:169:32: error: ‘TCP_ZEROCOPY_RECEIVE’ undeclared (first use in this function)
> >   err = getsockopt(fd, SOL_TCP, TCP_ZEROCOPY_RECEIVE, &buf, &optlen);
> >                                 ^~~~~~~~~~~~~~~~~~~~
> >
> > Fix it by introducing the right header.
> >
> > Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
> > ---
> >  tools/testing/selftests/bpf/prog_tests/sockopt_sk.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> > index ba6b3ec1156a..e0a9785ffcdc 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> > @@ -2,7 +2,7 @@
> >  #include <test_progs.h>
> >  #include "cgroup_helpers.h"
> >
> > -#include <netinet/tcp.h>
> > +#include <uapi/linux/tcp.h>
>
> Should it be <linux/tcp.h> instead ?

I thought that too, but I altered my thoughts after reading this
commit[1], totally without knowing why the tcp part should be changed.
Should I change it back?

> Directly including uapi header file
> in application seems weird.

After greping the tools/testing/selftests/bpf, we see some similar
usage like including a uapi header file.

[1]
commit a2f482c34a52176ae89d143979bbc9e7a72857c8
Author: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
Date:   Wed Nov 20 08:43:21 2024 +0100

    selftests/bpf: use the same udp and tcp headers in tests under test_progs

    Trying to add udp-dedicated helpers in network_helpers involves
    including some udp header, which makes multiple test_progs tests build
    fail:

    In file included from ./progs/test_cls_redirect.h:13,
                     from [...]/prog_tests/cls_redirect.c:15:
    [...]/usr/include/linux/udp.h:23:8: error: redefinition of ‘struct udphdr’
       23 | struct udphdr {
          |        ^~~~~~
    In file included from ./network_helpers.h:17,
                     from [...]/prog_tests/cls_redirect.c:13:
    [...]/usr/include/netinet/udp.h:55:8: note: originally defined here
       55 | struct udphdr
          |        ^~~~~~

    This error is due to struct udphdr being defined in both <linux/udp.h>
    and <netinet/udp.h>.

    Use only <netinet/udp.h> in every test. While at it, perform the same
    for tcp.h. For some tests, the change needs to be done in the eBPF
    program part as well, because of some headers sharing between both
    sides.

Thanks,
Jason
Hou Tao Feb. 5, 2025, 9:30 a.m. UTC | #3
Hi,

On 2/5/2025 11:27 AM, Jason Xing wrote:
> On Wed, Feb 5, 2025 at 10:57 AM Hou Tao <houtao@huaweicloud.com> wrote:
>> Hi,
>>
>> On 2/4/2025 10:39 AM, Jason Xing wrote:
>>> Error messages:
>>> selftests/bpf/prog_tests/sockopt_sk.c: In function ‘getsetsockopt’:
>>> selftests/bpf/prog_tests/sockopt_sk.c:22:31: error: field ‘zc’ has incomplete type
>>>    struct tcp_zerocopy_receive zc;
>>>                                ^~
>>> selftests/bpf/prog_tests/sockopt_sk.c:169:32: error: ‘TCP_ZEROCOPY_RECEIVE’ undeclared (first use in this function)
>>>   err = getsockopt(fd, SOL_TCP, TCP_ZEROCOPY_RECEIVE, &buf, &optlen);
>>>                                 ^~~~~~~~~~~~~~~~~~~~
>>>
>>> Fix it by introducing the right header.
>>>
>>> Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
>>> ---
>>>  tools/testing/selftests/bpf/prog_tests/sockopt_sk.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
>>> index ba6b3ec1156a..e0a9785ffcdc 100644
>>> --- a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
>>> +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
>>> @@ -2,7 +2,7 @@
>>>  #include <test_progs.h>
>>>  #include "cgroup_helpers.h"
>>>
>>> -#include <netinet/tcp.h>
>>> +#include <uapi/linux/tcp.h>
>> Should it be <linux/tcp.h> instead ?
> I thought that too, but I altered my thoughts after reading this
> commit[1], totally without knowing why the tcp part should be changed.
> Should I change it back?

Thanks for pointing the commit to me. Under my local environment, it
seems both netinet/tcp.h and linux/tcp define tcp_zerocopy_receive and
tcphdr, and I think that is the reason why the commit changes tcp as
well. For the following build error:

selftests/bpf/prog_tests/sockopt_sk.c:22:31: error: field ‘zc’ has
incomplete type
   struct tcp_zerocopy_receive zc;

I think maybe your local environment is a bit out-of-date. I prefer to
keep it as-is.
>
>> Directly including uapi header file
>> in application seems weird.
> After greping the tools/testing/selftests/bpf, we see some similar
> usage like including a uapi header file.
>
> [1]
> commit a2f482c34a52176ae89d143979bbc9e7a72857c8
> Author: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
> Date:   Wed Nov 20 08:43:21 2024 +0100
>
>     selftests/bpf: use the same udp and tcp headers in tests under test_progs
>
>     Trying to add udp-dedicated helpers in network_helpers involves
>     including some udp header, which makes multiple test_progs tests build
>     fail:
>
>     In file included from ./progs/test_cls_redirect.h:13,
>                      from [...]/prog_tests/cls_redirect.c:15:
>     [...]/usr/include/linux/udp.h:23:8: error: redefinition of ‘struct udphdr’
>        23 | struct udphdr {
>           |        ^~~~~~
>     In file included from ./network_helpers.h:17,
>                      from [...]/prog_tests/cls_redirect.c:13:
>     [...]/usr/include/netinet/udp.h:55:8: note: originally defined here
>        55 | struct udphdr
>           |        ^~~~~~
>
>     This error is due to struct udphdr being defined in both <linux/udp.h>
>     and <netinet/udp.h>.
>
>     Use only <netinet/udp.h> in every test. While at it, perform the same
>     for tcp.h. For some tests, the change needs to be done in the eBPF
>     program part as well, because of some headers sharing between both
>     sides.
>
> Thanks,
> Jason
>
> .
Jason Xing Feb. 5, 2025, 9:38 a.m. UTC | #4
On Wed, Feb 5, 2025 at 5:30 PM Hou Tao <houtao@huaweicloud.com> wrote:
>
> Hi,
>
> On 2/5/2025 11:27 AM, Jason Xing wrote:
> > On Wed, Feb 5, 2025 at 10:57 AM Hou Tao <houtao@huaweicloud.com> wrote:
> >> Hi,
> >>
> >> On 2/4/2025 10:39 AM, Jason Xing wrote:
> >>> Error messages:
> >>> selftests/bpf/prog_tests/sockopt_sk.c: In function ‘getsetsockopt’:
> >>> selftests/bpf/prog_tests/sockopt_sk.c:22:31: error: field ‘zc’ has incomplete type
> >>>    struct tcp_zerocopy_receive zc;
> >>>                                ^~
> >>> selftests/bpf/prog_tests/sockopt_sk.c:169:32: error: ‘TCP_ZEROCOPY_RECEIVE’ undeclared (first use in this function)
> >>>   err = getsockopt(fd, SOL_TCP, TCP_ZEROCOPY_RECEIVE, &buf, &optlen);
> >>>                                 ^~~~~~~~~~~~~~~~~~~~
> >>>
> >>> Fix it by introducing the right header.
> >>>
> >>> Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
> >>> ---
> >>>  tools/testing/selftests/bpf/prog_tests/sockopt_sk.c | 2 +-
> >>>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> >>> index ba6b3ec1156a..e0a9785ffcdc 100644
> >>> --- a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> >>> +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
> >>> @@ -2,7 +2,7 @@
> >>>  #include <test_progs.h>
> >>>  #include "cgroup_helpers.h"
> >>>
> >>> -#include <netinet/tcp.h>
> >>> +#include <uapi/linux/tcp.h>
> >> Should it be <linux/tcp.h> instead ?
> > I thought that too, but I altered my thoughts after reading this
> > commit[1], totally without knowing why the tcp part should be changed.
> > Should I change it back?
>
> Thanks for pointing the commit to me. Under my local environment, it
> seems both netinet/tcp.h and linux/tcp define tcp_zerocopy_receive and
> tcphdr, and I think that is the reason why the commit changes tcp as
> well. For the following build error:
>
> selftests/bpf/prog_tests/sockopt_sk.c:22:31: error: field ‘zc’ has
> incomplete type
>    struct tcp_zerocopy_receive zc;
>
> I think maybe your local environment is a bit out-of-date. I prefer to
> keep it as-is.

Thanks for your review.

Right, but I believe many users can't manage to upgrade to the latest
version for the whole system. The selftests are supposed to be
compatible, I reckon. It's surely not bad to consider the
compatibility after adjusting the header file.

Thanks,
Jason
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
index ba6b3ec1156a..e0a9785ffcdc 100644
--- a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
+++ b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c
@@ -2,7 +2,7 @@ 
 #include <test_progs.h>
 #include "cgroup_helpers.h"
 
-#include <netinet/tcp.h>
+#include <uapi/linux/tcp.h>
 #include <linux/netlink.h>
 #include "sockopt_sk.skel.h"