From: Daniel Borkmann <daniel@iogearbox•net>
To: David Ahern <dsa@cumulusnetworks•com>,
netdev@vger•kernel.org, stephen@networkplumber•org
Subject: Re: [iproute2 net-next 1/8] lib bpf: Add support for BPF_PROG_ATTACH and BPF_PROG_DETACH
Date: Sat, 10 Dec 2016 22:21:52 +0100 [thread overview]
Message-ID: <584C71F0.3000203@iogearbox.net> (raw)
In-Reply-To: <584C70C0.8040506@iogearbox.net>
On 12/10/2016 10:16 PM, Daniel Borkmann wrote:
> On 12/10/2016 09:32 PM, David Ahern wrote:
>> For consistency with other bpf commands, the functions are named
>> bpf_prog_attach and bpf_prog_detach. The existing bpf_prog_attach is
>> renamed to bpf_prog_load_and_report since it calls bpf_prog_load and
>> bpf_prog_report.
>>
>> Signed-off-by: David Ahern <dsa@cumulusnetworks•com>
>> ---
>> include/bpf_util.h | 3 +++
>> lib/bpf.c | 31 ++++++++++++++++++++++++++-----
>> 2 files changed, 29 insertions(+), 5 deletions(-)
>>
>> diff --git a/include/bpf_util.h b/include/bpf_util.h
>> index 05baeecda57f..49b96bbc208f 100644
>> --- a/include/bpf_util.h
>> +++ b/include/bpf_util.h
>> @@ -75,6 +75,9 @@ int bpf_trace_pipe(void);
>>
>> void bpf_print_ops(FILE *f, struct rtattr *bpf_ops, __u16 len);
>>
>> +int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type);
>> +int bpf_prog_detach(int target_fd, enum bpf_attach_type type);
>> +
>> #ifdef HAVE_ELF
>> int bpf_send_map_fds(const char *path, const char *obj);
>> int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux,
>> diff --git a/lib/bpf.c b/lib/bpf.c
>> index 2a8cd51d4dae..103fc1ef0593 100644
>> --- a/lib/bpf.c
>> +++ b/lib/bpf.c
>> @@ -850,6 +850,27 @@ int bpf_graft_map(const char *map_path, uint32_t *key, int argc, char **argv)
>> return ret;
>> }
>>
>> +int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type)
>> +{
>> + union bpf_attr attr = {
>> + .target_fd = target_fd,
>> + .attach_bpf_fd = prog_fd,
>> + .attach_type = type,
>> + };
>
> Please make this consistent with the other bpf(2) cmds we
> have in the current lib code. There were some gcc issues in
> the past, see:
>
> https://git.kernel.org/cgit/linux/kernel/git/shemminger/iproute2.git/commit/?id=67584e3ab289a22eb9a2e51f90d23e2ced2e76b0
>
> F.e. bpf_map_create() currently looks like:
>
> union bpf_attr attr = {};
>
> attr.map_type = type;
> attr.key_size = size_key;
> attr.value_size = size_value;
> attr.max_entries = max_elem;
> attr.map_flags = flags;
>
>> + return bpf(BPF_PROG_ATTACH, &attr, sizeof(attr));
>> +}
>> +
>> +int bpf_prog_detach(int target_fd, enum bpf_attach_type type)
>> +{
>> + union bpf_attr attr = {
>> + .target_fd = target_fd,
>> + .attach_type = type,
>> + };
>
> Ditto.
>
>> + return bpf(BPF_PROG_DETACH, &attr, sizeof(attr));
>> +}
>> +
>> #ifdef HAVE_ELF
>> struct bpf_elf_prog {
>> enum bpf_prog_type type;
>> @@ -1262,9 +1283,9 @@ static void bpf_prog_report(int fd, const char *section,
>> bpf_dump_error(ctx, "Verifier analysis:\n\n");
>> }
>>
>> -static int bpf_prog_attach(const char *section,
>> - const struct bpf_elf_prog *prog,
>> - struct bpf_elf_ctx *ctx)
>> +static int bpf_prog_load_and_report(const char *section,
>> + const struct bpf_elf_prog *prog,
>> + struct bpf_elf_ctx *ctx)
>> {
>
> Please name it bpf_prog_create() then, it would be consistent to
> bpf_map_create() and shorter as well.
Sorry, lack of coffee, scratch that.
Can't the current bpf_prog_attach() stay as is, and you name the above new
functions bpf_prog_attach_fd() and bpf_prog_detach_fd()? I think that would
be better.
>> int tries = 0, fd;
>> retry:
>> @@ -1656,7 +1677,7 @@ static int bpf_fetch_prog(struct bpf_elf_ctx *ctx, const char *section,
>> prog.size = data.sec_data->d_size;
>> prog.license = ctx->license;
>>
>> - fd = bpf_prog_attach(section, &prog, ctx);
>> + fd = bpf_prog_load_and_report(section, &prog, ctx);
>> if (fd < 0)
>> return fd;
>>
>> @@ -1755,7 +1776,7 @@ static int bpf_fetch_prog_relo(struct bpf_elf_ctx *ctx, const char *section,
>> prog.size = data_insn.sec_data->d_size;
>> prog.license = ctx->license;
>>
>> - fd = bpf_prog_attach(section, &prog, ctx);
>> + fd = bpf_prog_load_and_report(section, &prog, ctx);
>> if (fd < 0) {
>> *lderr = true;
>> return fd;
>>
>
next prev parent reply other threads:[~2016-12-10 21:21 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-10 20:32 [iproute2 v2 net-next 0/8] Add support for vrf helper David Ahern
2016-12-10 20:32 ` [iproute2 net-next 1/8] lib bpf: Add support for BPF_PROG_ATTACH and BPF_PROG_DETACH David Ahern
2016-12-10 21:16 ` Daniel Borkmann
2016-12-10 21:21 ` Daniel Borkmann [this message]
2016-12-10 22:15 ` David Ahern
2016-12-10 23:18 ` Daniel Borkmann
2016-12-10 20:32 ` [iproute2 net-next 2/8] bpf: export bpf_prog_load David Ahern
2016-12-10 21:24 ` Daniel Borkmann
2016-12-10 20:32 ` [iproute2 net-next 3/8] Add libbpf.h header with BPF_ macros David Ahern
2016-12-10 21:27 ` Daniel Borkmann
2016-12-10 20:32 ` [iproute2 net-next 4/8] move cmd_exec to lib utils David Ahern
2016-12-10 20:32 ` [iproute2 net-next 5/8] Add filesystem APIs to lib David Ahern
2016-12-10 20:32 ` [iproute2 net-next 6/8] change name_is_vrf to return index David Ahern
2016-12-10 20:32 ` [iproute2 net-next 7/8] libnetlink: Add variant of rtnl_talk that does not display RTNETLINK answers error David Ahern
2016-12-10 20:32 ` [iproute2 net-next 8/8] Introduce ip vrf command David Ahern
2016-12-12 23:43 ` [iproute2 v2 net-next 0/8] Add support for vrf helper Stephen Hemminger
-- strict thread matches above, loose matches on Subject: below --
2016-12-12 0:53 [iproute2 v3 " David Ahern
2016-12-12 0:53 ` [iproute2 net-next 1/8] lib bpf: Add support for BPF_PROG_ATTACH and BPF_PROG_DETACH David Ahern
2016-12-12 9:14 ` Daniel Borkmann
2016-12-10 17:47 [iproute2 net-next 0/8] Add support for vrf helper David Ahern
2016-12-10 17:47 ` [iproute2 net-next 1/8] lib bpf: Add support for BPF_PROG_ATTACH and BPF_PROG_DETACH David Ahern
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=584C71F0.3000203@iogearbox.net \
--to=daniel@iogearbox$(echo .)net \
--cc=dsa@cumulusnetworks$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
--cc=stephen@networkplumber$(echo .)org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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