From: Andrey Ignatov <rdna@fb.com>
To: Yonghong Song <yhs@fb.com>
Cc: <bpf@vger.kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>,
<kernel-team@fb.com>
Subject: Re: [PATCH v2 bpf-next 5/5] selftests/bpf: Test for sk helpers in cgroup skb
Date: Thu, 14 May 2020 10:46:14 -0700 [thread overview]
Message-ID: <20200514174614.GC22366@rdna-mbp> (raw)
In-Reply-To: <a1360303-220c-5bde-5657-b8f5497190ad@fb.com>
Yonghong Song <yhs@fb.com> [Thu, 2020-05-14 09:07 -0700]:
> On 5/13/20 2:38 PM, Andrey Ignatov wrote:
> > @@ -0,0 +1,99 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +// Copyright (c) 2020 Facebook
> > +
> > +#include <test_progs.h>
> > +
> > +#include "network_helpers.h"
> > +#include "cgroup_skb_sk_lookup_kern.skel.h"
> > +
> > +static void run_lookup_test(int map_fd, int out_sk)
> > +{
> > + int serv_sk = -1, in_sk = -1, serv_in_sk = -1, err;
> > + __u32 serv_port_key = 0, duration = 0;
> > + struct sockaddr_in6 addr = {};
> > + socklen_t addr_len = sizeof(addr);
> > +
> > + serv_sk = start_server(AF_INET6, SOCK_STREAM);
> > + if (CHECK(serv_sk < 0, "start_server", "failed to start server\n"))
> > + return;
> > +
> > + err = getsockname(serv_sk, (struct sockaddr *)&addr, &addr_len);
> > + if (CHECK(err, "getsockname", "errno %d\n", errno))
> > + goto cleanup;
> > +
> > + err = bpf_map_update_elem(map_fd, &serv_port_key, &addr.sin6_port, 0);
> > + if (CHECK(err < 0, "map_update", "errno %d", errno))
> > + goto cleanup;
> > +
> > + /* Client outside of test cgroup should fail to connect by timeout. */
> > + err = connect_fd_to_fd(out_sk, serv_sk);
> > + if (CHECK(!err || errno != EINPROGRESS, "connect_fd_to_fd",
> > + "unexpected result err %d errno %d\n", err, errno))
> > + goto cleanup;
> > +
> > + err = connect_wait(out_sk);
> > + if (CHECK(err, "connect_wait", "unexpected result %d\n", err))
> > + goto cleanup;
> > +
> > + /* Client inside test cgroup should connect just fine. */
> > + in_sk = connect_to_fd(AF_INET6, SOCK_STREAM, serv_sk);
> > + if (CHECK(in_sk < 0, "connect_to_fd", "errno %d\n", errno))
> > + goto cleanup;
> > +
> > + serv_in_sk = accept(serv_sk, NULL, NULL);
> > + if (CHECK(serv_in_sk < 0, "accept", "errno %d\n", errno))
> > + goto cleanup;
> > +
> > +cleanup:
> > + close(serv_in_sk);
> > + close(in_sk);
> > + close(serv_sk);
> > +}
> > +
> > +static void run_cgroup_bpf_test(const char *cg_path, const char *bpf_file,
>
> You are using skeleton, bpf_file parameter is not needed any more.
Oops, forgot to remove it while switching to skeleton. Will fix. Thanks.
> > +struct {
> > + __uint(type, BPF_MAP_TYPE_ARRAY);
> > + __uint(max_entries, 1);
> > + __type(key, __u32);
> > + __type(value, __u16);
> > +} serv_port SEC(".maps");
>
> This can be simplified as a global variable, e.g.,
>
> __u16 serv_port = 0;
>
> and use skeleton to access this variable in user space
> and in kernel you can directly use this variable.
No strong preference here. Ok, will try global var.
--
Andrey Ignatov
prev parent reply other threads:[~2020-05-14 17:46 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-13 21:38 [PATCH v2 bpf-next 0/5] bpf: sk lookup, cgroup id helpers in cgroup skb Andrey Ignatov
2020-05-13 21:38 ` [PATCH v2 bpf-next 1/5] bpf: Allow sk lookup " Andrey Ignatov
2020-05-14 15:06 ` Yonghong Song
2020-05-13 21:38 ` [PATCH v2 bpf-next 2/5] bpf: Allow skb_ancestor_cgroup_id helper " Andrey Ignatov
2020-05-14 15:06 ` Yonghong Song
2020-05-13 21:38 ` [PATCH v2 bpf-next 3/5] bpf: Introduce bpf_sk_{,ancestor_}cgroup_id helpers Andrey Ignatov
2020-05-14 15:16 ` Yonghong Song
2020-05-14 16:55 ` Andrey Ignatov
2020-05-14 17:24 ` Yonghong Song
2020-05-14 18:01 ` Andrey Ignatov
2020-05-14 18:15 ` Yonghong Song
2020-05-13 21:38 ` [PATCH v2 bpf-next 4/5] selftests/bpf: Add connect_fd_to_fd, connect_wait net helpers Andrey Ignatov
2020-05-14 15:56 ` Yonghong Song
2020-05-14 17:42 ` Andrey Ignatov
2020-05-13 21:38 ` [PATCH v2 bpf-next 5/5] selftests/bpf: Test for sk helpers in cgroup skb Andrey Ignatov
2020-05-14 16:07 ` Yonghong Song
2020-05-14 17:46 ` Andrey Ignatov [this message]
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=20200514174614.GC22366@rdna-mbp \
--to=rdna@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=yhs@fb.com \
/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