[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190612213046.e7tkduk5nfuv5s6a@kafai-mbp.dhcp.thefacebook.com>
Date: Wed, 12 Jun 2019 21:30:48 +0000
From: Martin Lau <kafai@...com>
To: Stanislav Fomichev <sdf@...ichev.me>
CC: "bpf@...r.kernel.org" <bpf@...r.kernel.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
Alexei Starovoitov <ast@...com>,
Daniel Borkmann <daniel@...earbox.net>,
David Miller <davem@...emloft.net>,
Kernel Team <Kernel-team@...com>
Subject: Re: [PATCH bpf-next 2/2] bpf: Add test for SO_REUSEPORT_DETACH_BPF
On Wed, Jun 12, 2019 at 12:59:17PM -0700, Stanislav Fomichev wrote:
> On 06/12, Martin KaFai Lau wrote:
> > This patch adds a test for the new sockopt SO_REUSEPORT_DETACH_BPF.
> >
> > '-I../../../../usr/include/' is added to the Makefile to get
> > the newly added SO_REUSEPORT_DETACH_BPF.
> >
> > Signed-off-by: Martin KaFai Lau <kafai@...com>
> > ---
> > tools/testing/selftests/bpf/Makefile | 1 +
> > .../selftests/bpf/test_select_reuseport.c | 50 +++++++++++++++++++
> > 2 files changed, 51 insertions(+)
> >
> > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> > index 44fb61f4d502..c7370361fa81 100644
> > --- a/tools/testing/selftests/bpf/Makefile
> > +++ b/tools/testing/selftests/bpf/Makefile
> > @@ -16,6 +16,7 @@ LLVM_OBJCOPY ?= llvm-objcopy
> > LLVM_READELF ?= llvm-readelf
> > BTF_PAHOLE ?= pahole
> > CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(BPFDIR) -I$(GENDIR) $(GENFLAGS) -I../../../include \
> > + -I../../../../usr/include/ \
> Why not copy inlude/uapi/asm-generic/socket.h into tools/include
> instead? Will that work?
Sure. I am ok with copy. I don't think we need to sync very often.
Do you know how to do that considering multiple arch's socket.h
have been changed in Patch 1?
Is copy better?
>
> > -Dbpf_prog_load=bpf_prog_test_load \
> > -Dbpf_load_program=bpf_test_load_program
> > LDLIBS += -lcap -lelf -lrt -lpthread
> > diff --git a/tools/testing/selftests/bpf/test_select_reuseport.c b/tools/testing/selftests/bpf/test_select_reuseport.c
> > index 75646d9b34aa..5aa00b4a4702 100644
> > --- a/tools/testing/selftests/bpf/test_select_reuseport.c
> > +++ b/tools/testing/selftests/bpf/test_select_reuseport.c
> > @@ -523,6 +523,54 @@ static void test_pass_on_err(int type, sa_family_t family)
> > printf("OK\n");
> > }
> >
> > +static void test_detach_bpf(int type, sa_family_t family)
> > +{
> > + __u32 nr_run_before = 0, nr_run_after = 0, tmp, i;
> > + struct epoll_event ev;
> > + int cli_fd, err, nev;
> > + struct cmd cmd = {};
> > + int optvalue = 0;
> > +
> > + printf("%s: ", __func__);
> > + err = setsockopt(sk_fds[0], SOL_SOCKET, SO_DETACH_REUSEPORT_BPF,
> > + &optvalue, sizeof(optvalue));
> > + CHECK(err == -1, "setsockopt(SO_DETACH_REUSEPORT_BPF)",
> > + "err:%d errno:%d\n", err, errno);
> > +
> > + err = setsockopt(sk_fds[1], SOL_SOCKET, SO_DETACH_REUSEPORT_BPF,
> > + &optvalue, sizeof(optvalue));
> > + CHECK(err == 0 || errno != ENOENT, "setsockopt(SO_DETACH_REUSEPORT_BPF)",
> > + "err:%d errno:%d\n", err, errno);
> > +
> > + for (i = 0; i < NR_RESULTS; i++) {
> > + err = bpf_map_lookup_elem(result_map, &i, &tmp);
> > + CHECK(err == -1, "lookup_elem(result_map)",
> > + "i:%u err:%d errno:%d\n", i, err, errno);
> > + nr_run_before += tmp;
> > + }
> > +
> > + cli_fd = send_data(type, family, &cmd, sizeof(cmd), PASS);
> > + nev = epoll_wait(epfd, &ev, 1, 5);
> > + CHECK(nev <= 0, "nev <= 0",
> > + "nev:%d expected:1 type:%d family:%d data:(0, 0)\n",
> > + nev, type, family);
> > +
> > + for (i = 0; i < NR_RESULTS; i++) {
> > + err = bpf_map_lookup_elem(result_map, &i, &tmp);
> > + CHECK(err == -1, "lookup_elem(result_map)",
> > + "i:%u err:%d errno:%d\n", i, err, errno);
> > + nr_run_after += tmp;
> > + }
> > +
> > + CHECK(nr_run_before != nr_run_after,
> > + "nr_run_before != nr_run_after",
> > + "nr_run_before:%u nr_run_after:%u\n",
> > + nr_run_before, nr_run_after);
> > +
> > + printf("OK\n");
> > + close(cli_fd);
> > +}
> > +
> > static void prepare_sk_fds(int type, sa_family_t family, bool inany)
> > {
> > const int first = REUSEPORT_ARRAY_SIZE - 1;
> > @@ -664,6 +712,8 @@ static void test_all(void)
> > test_pass(type, family);
> > test_syncookie(type, family);
> > test_pass_on_err(type, family);
> > + /* Must be the last test */
> > + test_detach_bpf(type, family);
> >
> > cleanup_per_test();
> > printf("\n");
> > --
> > 2.17.1
> >
Powered by blists - more mailing lists