diff options
author | Jakub Kicinski <jakub.kicinski@netronome.com> | 2018-07-10 14:42:58 -0700 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-07-11 22:13:33 +0200 |
commit | ba6dd679a3e81af023ec091c2fb7c82003a27316 (patch) | |
tree | 594f63980c71e8ab46b3af7eec80d9bf01abc6c6 /tools/bpf/bpftool/prog.c | |
parent | 8d1fc3de3d9f9bda0d8ec719d8686e9c5b432573 (diff) |
tools: bpftool: add support for loading programs for offload
Extend the bpftool prog load command to also accept "dev"
parameter, which will allow us to load programs onto devices.
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/bpf/bpftool/prog.c')
-rw-r--r-- | tools/bpf/bpftool/prog.c | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index a5ef46c59029..21c74de7156f 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -39,6 +39,7 @@ #include <string.h> #include <time.h> #include <unistd.h> +#include <net/if.h> #include <sys/types.h> #include <sys/stat.h> @@ -681,6 +682,9 @@ static int do_pin(int argc, char **argv) static int do_load(int argc, char **argv) { + struct bpf_prog_load_attr attr = { + .prog_type = BPF_PROG_TYPE_UNSPEC, + }; const char *objfile, *pinfile; struct bpf_object *obj; int prog_fd; @@ -690,7 +694,34 @@ static int do_load(int argc, char **argv) objfile = GET_ARG(); pinfile = GET_ARG(); - if (bpf_prog_load(objfile, BPF_PROG_TYPE_UNSPEC, &obj, &prog_fd)) { + while (argc) { + if (is_prefix(*argv, "dev")) { + NEXT_ARG(); + + if (attr.ifindex) { + p_err("offload device already specified"); + return -1; + } + if (!REQ_ARGS(1)) + return -1; + + attr.ifindex = if_nametoindex(*argv); + if (!attr.ifindex) { + p_err("unrecognized netdevice '%s': %s", + *argv, strerror(errno)); + return -1; + } + NEXT_ARG(); + } else { + p_err("expected no more arguments or 'dev', got: '%s'?", + *argv); + return -1; + } + } + + attr.file = objfile; + + if (bpf_prog_load_xattr(&attr, &obj, &prog_fd)) { p_err("failed to load program"); return -1; } @@ -722,7 +753,7 @@ static int do_help(int argc, char **argv) " %s %s dump xlated PROG [{ file FILE | opcodes | visual }]\n" " %s %s dump jited PROG [{ file FILE | opcodes }]\n" " %s %s pin PROG FILE\n" - " %s %s load OBJ FILE\n" + " %s %s load OBJ FILE [dev NAME]\n" " %s %s help\n" "\n" " " HELP_SPEC_PROGRAM "\n" |