Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Jason Xing <kerneljasonxing@gmail.com>
Cc: bpf@vger.kernel.org, Hou Tao <houtao@huaweicloud.com>,
	linux-kselftest@vger.kernel.org, ast@kernel.org,
	daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com,
	mykolal@fb.com, song@kernel.org, yonghong.song@linux.dev,
	john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me,
	haoluo@google.com, jolsa@kernel.org, shuah@kernel.org
Subject: Re: [PATCH bpf-next v1 2/2] bpf: sockopt_sk: fix 'undeclared' definition error
Date: Tue, 11 Feb 2025 11:40:58 -0800	[thread overview]
Message-ID: <8c9b4179-cacc-42b6-ae6a-4b786bef8b60@linux.dev> (raw)
In-Reply-To: <CAL+tcoAkyjDQd48wKuA8V_RE6j1OYTL2iGxT8HdVKpryD3SaUA@mail.gmail.com>

On 2/4/25 7:27 PM, 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?

afaik, uapi/ or not does not make a difference.

> 
>> 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
>            |        ^~~~~~

e.g. this will happen to the tcphdr also when sockopt_sk.c starts including 
network_helpers.h.

> 
>      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

This patch just undo exactly what this commit a2f482c34a52 tries to solve for 
tcp.h also, no?

pw-bot: cr

>      program part as well, because of some headers sharing between both
>      sides.
> 
> Thanks,
> Jason


  parent reply	other threads:[~2025-02-11 19:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-04  2:39 [PATCH bpf-next v1 0/2] selftests: fix two small compilation errors Jason Xing
2025-02-04  2:39 ` [PATCH bpf-next v1 1/2] bpf: changes_pkt_data: correct the 'main' error Jason Xing
2025-02-07  6:04   ` Martin KaFai Lau
2025-02-07  6:48     ` Jason Xing
2025-02-11 20:06       ` Martin KaFai Lau
2025-02-04  2:39 ` [PATCH bpf-next v1 2/2] bpf: sockopt_sk: fix 'undeclared' definition error Jason Xing
2025-02-05  2:57   ` Hou Tao
2025-02-05  3:27     ` Jason Xing
2025-02-05  9:30       ` Hou Tao
2025-02-05  9:38         ` Jason Xing
2025-02-11 19:40       ` Martin KaFai Lau [this message]
2025-02-11  7:52 ` [PATCH bpf-next v1 0/2] selftests: fix two small compilation errors Jason Xing

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8c9b4179-cacc-42b6-ae6a-4b786bef8b60@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=houtao@huaweicloud.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kerneljasonxing@gmail.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mykolal@fb.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox