netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Sitnicki <jakub@cloudflare.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Lorenz Bauer <lmb@cloudflare.com>, bpf <bpf@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>,
	kernel-team <kernel-team@cloudflare.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>
Subject: Re: [PATCH bpf-next v3 16/16] selftests/bpf: Tests for BPF_SK_LOOKUP attach point
Date: Thu, 09 Jul 2020 17:54:11 +0200	[thread overview]
Message-ID: <87fta0adlo.fsf@cloudflare.com> (raw)
In-Reply-To: <CAEf4BzawjM=CnCBSbY2boGAD4qn+vMHwaKxT-SB-CzY1Zv507g@mail.gmail.com>

On Thu, Jul 09, 2020 at 06:28 AM CEST, Andrii Nakryiko wrote:
> On Thu, Jul 2, 2020 at 6:00 AM Jakub Sitnicki <jakub@cloudflare.com> wrote:
>>
>> On Thu, Jul 02, 2020 at 01:01 PM CEST, Lorenz Bauer wrote:
>> > On Thu, 2 Jul 2020 at 10:24, Jakub Sitnicki <jakub@cloudflare.com> wrote:
>> >>
>> >> Add tests to test_progs that exercise:
>> >>
>> >>  - attaching/detaching/querying programs to BPF_SK_LOOKUP hook,
>> >>  - redirecting socket lookup to a socket selected by BPF program,
>> >>  - failing a socket lookup on BPF program's request,
>> >>  - error scenarios for selecting a socket from BPF program,
>> >>  - accessing BPF program context,
>> >>  - attaching and running multiple BPF programs.
>> >>
>> >> Run log:
>> >> | # ./test_progs -n 68
>> >> | #68/1 query lookup prog:OK
>> >> | #68/2 TCP IPv4 redir port:OK
>> >> | #68/3 TCP IPv4 redir addr:OK
>> >> | #68/4 TCP IPv4 redir with reuseport:OK
>> >> | #68/5 TCP IPv4 redir skip reuseport:OK
>> >> | #68/6 TCP IPv6 redir port:OK
>> >> | #68/7 TCP IPv6 redir addr:OK
>> >> | #68/8 TCP IPv4->IPv6 redir port:OK
>> >> | #68/9 TCP IPv6 redir with reuseport:OK
>> >> | #68/10 TCP IPv6 redir skip reuseport:OK
>> >> | #68/11 UDP IPv4 redir port:OK
>> >> | #68/12 UDP IPv4 redir addr:OK
>> >> | #68/13 UDP IPv4 redir with reuseport:OK
>> >> | #68/14 UDP IPv4 redir skip reuseport:OK
>> >> | #68/15 UDP IPv6 redir port:OK
>> >> | #68/16 UDP IPv6 redir addr:OK
>> >> | #68/17 UDP IPv4->IPv6 redir port:OK
>> >> | #68/18 UDP IPv6 redir and reuseport:OK
>> >> | #68/19 UDP IPv6 redir skip reuseport:OK
>> >> | #68/20 TCP IPv4 drop on lookup:OK
>> >> | #68/21 TCP IPv6 drop on lookup:OK
>> >> | #68/22 UDP IPv4 drop on lookup:OK
>> >> | #68/23 UDP IPv6 drop on lookup:OK
>> >> | #68/24 TCP IPv4 drop on reuseport:OK
>> >> | #68/25 TCP IPv6 drop on reuseport:OK
>> >> | #68/26 UDP IPv4 drop on reuseport:OK
>> >> | #68/27 TCP IPv6 drop on reuseport:OK
>> >> | #68/28 sk_assign returns EEXIST:OK
>> >> | #68/29 sk_assign honors F_REPLACE:OK
>> >> | #68/30 access ctx->sk:OK
>> >> | #68/31 sk_assign rejects TCP established:OK
>> >> | #68/32 sk_assign rejects UDP connected:OK
>> >> | #68/33 multi prog - pass, pass:OK
>> >> | #68/34 multi prog - pass, inval:OK
>> >> | #68/35 multi prog - inval, pass:OK
>> >> | #68/36 multi prog - drop, drop:OK
>> >> | #68/37 multi prog - pass, drop:OK
>> >> | #68/38 multi prog - drop, pass:OK
>> >> | #68/39 multi prog - drop, inval:OK
>> >> | #68/40 multi prog - inval, drop:OK
>> >> | #68/41 multi prog - pass, redir:OK
>> >> | #68/42 multi prog - redir, pass:OK
>> >> | #68/43 multi prog - drop, redir:OK
>> >> | #68/44 multi prog - redir, drop:OK
>> >> | #68/45 multi prog - inval, redir:OK
>> >> | #68/46 multi prog - redir, inval:OK
>> >> | #68/47 multi prog - redir, redir:OK
>> >> | #68 sk_lookup:OK
>> >> | Summary: 1/47 PASSED, 0 SKIPPED, 0 FAILED
>> >>
>> >> Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
>> >> ---
>> >>
>> >> Notes:
>> >>     v3:
>> >>     - Extend tests to cover new functionality in v3:
>> >>       - multi-prog attachments (query, running, verdict precedence)
>> >>       - socket selecting for the second time with bpf_sk_assign
>> >>       - skipping over reuseport load-balancing
>> >>
>> >>     v2:
>> >>      - Adjust for fields renames in struct bpf_sk_lookup.
>> >>
>> >>  .../selftests/bpf/prog_tests/sk_lookup.c      | 1353 +++++++++++++++++
>> >>  .../selftests/bpf/progs/test_sk_lookup_kern.c |  399 +++++
>> >>  2 files changed, 1752 insertions(+)
>> >>  create mode 100644 tools/testing/selftests/bpf/prog_tests/sk_lookup.c
>> >>  create mode 100644 tools/testing/selftests/bpf/progs/test_sk_lookup_kern.c
>> >>
>> >> diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c
>> >> new file mode 100644
>> >> index 000000000000..2859dc7e65b0
>> >> --- /dev/null
>> >> +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c
>>
>> [...]
>>
>
> [...]
>
>> >> +static void run_lookup_prog(const struct test *t)
>> >> +{
>> >> +       int client_fd, server_fds[MAX_SERVERS] = { -1 };
>> >> +       struct bpf_link *lookup_link;
>> >> +       int i, err;
>> >> +
>> >> +       lookup_link = attach_lookup_prog(t->lookup_prog);
>> >> +       if (!lookup_link)
>> >
>> > Why doesn't this fail the test? Same for the other error paths in the
>> > function, and the other helpers.
>>
>> I took the approach of placing CHECK_FAIL checks only right after the
>> failure point. So a syscall or a call to libbpf.
>>
>> This way if I'm calling a helper, I know it already fails the test if
>> anything goes wrong, and I can have less CHECK_FAILs peppered over the
>> code.
>
> Please prefere CHECK() over CHECK_FAIL(), unless you are making
> hundreds of checks and it's extremely unlikely they will ever fail.
> Using CHECK_FAIL makes even knowing where the test fails hard. CHECK()
> leaves a trail, so it's easier to pinpoint what and why failed.

I'll convert it in v4. I wrote most of these tests before we chatted
about CHECK vs CHECK_FAIL some time ago and just haven't gotten around
to it so far.

>
>
> [...]


  reply	other threads:[~2020-07-09 15:54 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-02  9:24 [PATCH bpf-next v3 00/16] Run a BPF program on socket lookup Jakub Sitnicki
2020-07-02  9:24 ` [PATCH bpf-next v3 01/16] bpf, netns: Handle multiple link attachments Jakub Sitnicki
2020-07-09  3:44   ` Andrii Nakryiko
2020-07-09 12:49     ` Jakub Sitnicki
2020-07-09 22:02       ` Andrii Nakryiko
2020-07-10 19:23         ` Jakub Sitnicki
2020-07-02  9:24 ` [PATCH bpf-next v3 02/16] bpf: Introduce SK_LOOKUP program type with a dedicated attach point Jakub Sitnicki
2020-07-04 18:42   ` Yonghong Song
2020-07-06 11:44     ` Jakub Sitnicki
2020-07-05  9:20   ` kernel test robot
2020-07-05  9:20   ` [RFC PATCH] bpf: sk_lookup_prog_ops can be static kernel test robot
2020-07-07  9:21   ` [PATCH bpf-next v3 02/16] bpf: Introduce SK_LOOKUP program type with a dedicated attach point Jakub Sitnicki
2020-07-09  4:08   ` Andrii Nakryiko
2020-07-09 13:25     ` Jakub Sitnicki
2020-07-09 23:09       ` Andrii Nakryiko
2020-07-10  8:55         ` Jakub Sitnicki
2020-07-02  9:24 ` [PATCH bpf-next v3 03/16] inet: Extract helper for selecting socket from reuseport group Jakub Sitnicki
2020-07-02  9:24 ` [PATCH bpf-next v3 04/16] inet: Run SK_LOOKUP BPF program on socket lookup Jakub Sitnicki
2020-07-02 10:27   ` Lorenz Bauer
2020-07-02 12:46     ` Jakub Sitnicki
2020-07-02 13:19       ` Lorenz Bauer
2020-07-06 11:24         ` Jakub Sitnicki
2020-07-06 12:06   ` Jakub Sitnicki
2020-07-02  9:24 ` [PATCH bpf-next v3 05/16] inet6: Extract helper for selecting socket from reuseport group Jakub Sitnicki
2020-07-02  9:24 ` [PATCH bpf-next v3 06/16] inet6: Run SK_LOOKUP BPF program on socket lookup Jakub Sitnicki
2020-07-02  9:24 ` [PATCH bpf-next v3 07/16] udp: Extract helper for selecting socket from reuseport group Jakub Sitnicki
2020-07-02  9:24 ` [PATCH bpf-next v3 08/16] udp: Run SK_LOOKUP BPF program on socket lookup Jakub Sitnicki
2020-07-02  9:24 ` [PATCH bpf-next v3 09/16] udp6: Extract helper for selecting socket from reuseport group Jakub Sitnicki
2020-07-02  9:24 ` [PATCH bpf-next v3 10/16] udp6: Run SK_LOOKUP BPF program on socket lookup Jakub Sitnicki
2020-07-02 14:51   ` kernel test robot
2020-07-03 13:04     ` Jakub Sitnicki
2020-07-02  9:24 ` [PATCH bpf-next v3 11/16] bpf: Sync linux/bpf.h to tools/ Jakub Sitnicki
2020-07-02  9:24 ` [PATCH bpf-next v3 12/16] libbpf: Add support for SK_LOOKUP program type Jakub Sitnicki
2020-07-09  4:23   ` Andrii Nakryiko
2020-07-09 15:51     ` Jakub Sitnicki
2020-07-09 23:13       ` Andrii Nakryiko
2020-07-10  8:37         ` Jakub Sitnicki
2020-07-10 18:55           ` Andrii Nakryiko
2020-07-10 19:24             ` Jakub Sitnicki
2020-07-02  9:24 ` [PATCH bpf-next v3 13/16] tools/bpftool: Add name mappings for SK_LOOKUP prog and attach type Jakub Sitnicki
2020-07-02  9:24 ` [PATCH bpf-next v3 14/16] selftests/bpf: Add verifier tests for bpf_sk_lookup context access Jakub Sitnicki
2020-07-02  9:24 ` [PATCH bpf-next v3 15/16] selftests/bpf: Rename test_sk_lookup_kern.c to test_ref_track_kern.c Jakub Sitnicki
2020-07-02  9:24 ` [PATCH bpf-next v3 16/16] selftests/bpf: Tests for BPF_SK_LOOKUP attach point Jakub Sitnicki
2020-07-02 11:01   ` Lorenz Bauer
2020-07-02 12:59     ` Jakub Sitnicki
2020-07-09  4:28       ` Andrii Nakryiko
2020-07-09 15:54         ` Jakub Sitnicki [this message]
2020-07-02 11:05 ` [PATCH bpf-next v3 00/16] Run a BPF program on socket lookup Lorenz Bauer

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=87fta0adlo.fsf@cloudflare.com \
    --to=jakub@cloudflare.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=kernel-team@cloudflare.com \
    --cc=kuba@kernel.org \
    --cc=lmb@cloudflare.com \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).