From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Fastabend Subject: Re: [PATCH] bpf: bpftool, add support for attaching programs to maps Date: Wed, 10 Oct 2018 10:53:11 -0700 Message-ID: <390f3e39-9cd9-e61c-93bd-d5b5908bbb08@gmail.com> References: <20181010164426.9321.42364.stgit@john-Precision-Tower-5810> <20181010101146.18e7d3ff@cakuba.netronome.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org To: Jakub Kicinski Return-path: Received: from mail-it1-f195.google.com ([209.85.166.195]:55257 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726902AbeJKBQh (ORCPT ); Wed, 10 Oct 2018 21:16:37 -0400 Received: by mail-it1-f195.google.com with SMTP id l191-v6so9382029ita.4 for ; Wed, 10 Oct 2018 10:53:23 -0700 (PDT) In-Reply-To: <20181010101146.18e7d3ff@cakuba.netronome.com> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 10/10/2018 10:11 AM, Jakub Kicinski wrote: > On Wed, 10 Oct 2018 09:44:26 -0700, John Fastabend wrote: >> Sock map/hash introduce support for attaching programs to maps. To >> date I have been doing this with custom tooling but this is less than >> ideal as we shift to using bpftool as the single CLI for our BPF uses. >> This patch adds new sub commands 'attach' and 'detach' to the 'prog' >> command to attach programs to maps and then detach them. >> >> Signed-off-by: John Fastabend >> --- >> tools/bpf/bpftool/main.h | 1 + >> tools/bpf/bpftool/prog.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++ >> 2 files changed, 92 insertions(+), 1 deletion(-) >> >> diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h >> index 40492cd..9ceb2b6 100644 >> --- a/tools/bpf/bpftool/main.h >> +++ b/tools/bpf/bpftool/main.h >> @@ -137,6 +137,7 @@ int cmd_select(const struct cmd *cmds, int argc, char **argv, >> int do_cgroup(int argc, char **arg); >> int do_perf(int argc, char **arg); >> int do_net(int argc, char **arg); >> +int do_attach_cmd(int argc, char **arg); > > Looks like a leftover? > Yeah original I made attach/detach its own top level command but it seems better fit under prog. [..] >> + if (!REQ_ARGS(4)) { > > Hm, 4 or 5? id $prog $type id $map ? > Yep thanks. [...] >> + >> + NEXT_ARG(); > > nit: maybe NEXT_ARG() should be grouped with the code that consumes the > parameter, i.e. new line after not before? sure. > >> + mapfd = map_parse_fd(&argc, &argv); >> + if (mapfd < 0) >> + return mapfd; >> + >> + err = bpf_prog_attach(progfd, mapfd, attach_type, 0); >> + if (err) { >> + p_err("failed prog attach to map"); >> + return -EINVAL; >> + } > > Could you plunk a > > if (json_output) > jsonw_null(json_wtr); > > here to always produce valid JSON even for commands with no output > today? > Makes sense. > Same comments for detach. [...] > Would you mind updating the man page and the bash completions? > Will do this. Thanks.