diff options
author | Jakub Kicinski <jakub.kicinski@netronome.com> | 2018-07-10 17:42:58 -0400 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-07-11 16:13:33 -0400 |
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 @@ | |||
39 | #include <string.h> | 39 | #include <string.h> |
40 | #include <time.h> | 40 | #include <time.h> |
41 | #include <unistd.h> | 41 | #include <unistd.h> |
42 | #include <net/if.h> | ||
42 | #include <sys/types.h> | 43 | #include <sys/types.h> |
43 | #include <sys/stat.h> | 44 | #include <sys/stat.h> |
44 | 45 | ||
@@ -681,6 +682,9 @@ static int do_pin(int argc, char **argv) | |||
681 | 682 | ||
682 | static int do_load(int argc, char **argv) | 683 | static int do_load(int argc, char **argv) |
683 | { | 684 | { |
685 | struct bpf_prog_load_attr attr = { | ||
686 | .prog_type = BPF_PROG_TYPE_UNSPEC, | ||
687 | }; | ||
684 | const char *objfile, *pinfile; | 688 | const char *objfile, *pinfile; |
685 | struct bpf_object *obj; | 689 | struct bpf_object *obj; |
686 | int prog_fd; | 690 | int prog_fd; |
@@ -690,7 +694,34 @@ static int do_load(int argc, char **argv) | |||
690 | objfile = GET_ARG(); | 694 | objfile = GET_ARG(); |
691 | pinfile = GET_ARG(); | 695 | pinfile = GET_ARG(); |
692 | 696 | ||
693 | if (bpf_prog_load(objfile, BPF_PROG_TYPE_UNSPEC, &obj, &prog_fd)) { | 697 | while (argc) { |
698 | if (is_prefix(*argv, "dev")) { | ||
699 | NEXT_ARG(); | ||
700 | |||
701 | if (attr.ifindex) { | ||
702 | p_err("offload device already specified"); | ||
703 | return -1; | ||
704 | } | ||
705 | if (!REQ_ARGS(1)) | ||
706 | return -1; | ||
707 | |||
708 | attr.ifindex = if_nametoindex(*argv); | ||
709 | if (!attr.ifindex) { | ||
710 | p_err("unrecognized netdevice '%s': %s", | ||
711 | *argv, strerror(errno)); | ||
712 | return -1; | ||
713 | } | ||
714 | NEXT_ARG(); | ||
715 | } else { | ||
716 | p_err("expected no more arguments or 'dev', got: '%s'?", | ||
717 | *argv); | ||
718 | return -1; | ||
719 | } | ||
720 | } | ||
721 | |||
722 | attr.file = objfile; | ||
723 | |||
724 | if (bpf_prog_load_xattr(&attr, &obj, &prog_fd)) { | ||
694 | p_err("failed to load program"); | 725 | p_err("failed to load program"); |
695 | return -1; | 726 | return -1; |
696 | } | 727 | } |
@@ -722,7 +753,7 @@ static int do_help(int argc, char **argv) | |||
722 | " %s %s dump xlated PROG [{ file FILE | opcodes | visual }]\n" | 753 | " %s %s dump xlated PROG [{ file FILE | opcodes | visual }]\n" |
723 | " %s %s dump jited PROG [{ file FILE | opcodes }]\n" | 754 | " %s %s dump jited PROG [{ file FILE | opcodes }]\n" |
724 | " %s %s pin PROG FILE\n" | 755 | " %s %s pin PROG FILE\n" |
725 | " %s %s load OBJ FILE\n" | 756 | " %s %s load OBJ FILE [dev NAME]\n" |
726 | " %s %s help\n" | 757 | " %s %s help\n" |
727 | "\n" | 758 | "\n" |
728 | " " HELP_SPEC_PROGRAM "\n" | 759 | " " HELP_SPEC_PROGRAM "\n" |