aboutsummaryrefslogtreecommitdiffstats
path: root/tools/bpf/bpftool/prog.c
diff options
context:
space:
mode:
authorRoman Gushchin <guro@fb.com>2017-12-13 10:18:53 -0500
committerDaniel Borkmann <daniel@iogearbox.net>2017-12-14 07:37:13 -0500
commit49a086c201a9356287471aa5846a427bdcecc4f7 (patch)
tree0fc32d8eb8543ded1ccef6f36cbebd070dafc0b3 /tools/bpf/bpftool/prog.c
parentfe4d44b23f6b38194a92c6b8a50d921a071c4db4 (diff)
bpftool: implement prog load command
Add the prog load command to load a bpf program from a specified binary file and pin it to bpffs. Usage description and examples are given in the corresponding man page. Syntax: $ bpftool prog load OBJ FILE FILE is a non-existing file on bpffs. Signed-off-by: Roman Gushchin <guro@fb.com> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Cc: Martin KaFai Lau <kafai@fb.com> Cc: Quentin Monnet <quentin.monnet@netronome.com> Cc: David Ahern <dsahern@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/bpf/bpftool/prog.c')
-rw-r--r--tools/bpf/bpftool/prog.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index ad619b96c276..037484ceaeaf 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -45,6 +45,7 @@
45#include <sys/stat.h> 45#include <sys/stat.h>
46 46
47#include <bpf.h> 47#include <bpf.h>
48#include <libbpf.h>
48 49
49#include "main.h" 50#include "main.h"
50#include "disasm.h" 51#include "disasm.h"
@@ -635,6 +636,30 @@ static int do_pin(int argc, char **argv)
635 return err; 636 return err;
636} 637}
637 638
639static int do_load(int argc, char **argv)
640{
641 struct bpf_object *obj;
642 int prog_fd;
643
644 if (argc != 2)
645 usage();
646
647 if (bpf_prog_load(argv[0], BPF_PROG_TYPE_UNSPEC, &obj, &prog_fd)) {
648 p_err("failed to load program\n");
649 return -1;
650 }
651
652 if (do_pin_fd(prog_fd, argv[1])) {
653 p_err("failed to pin program\n");
654 return -1;
655 }
656
657 if (json_output)
658 jsonw_null(json_wtr);
659
660 return 0;
661}
662
638static int do_help(int argc, char **argv) 663static int do_help(int argc, char **argv)
639{ 664{
640 if (json_output) { 665 if (json_output) {
@@ -647,13 +672,14 @@ static int do_help(int argc, char **argv)
647 " %s %s dump xlated PROG [{ file FILE | opcodes }]\n" 672 " %s %s dump xlated PROG [{ file FILE | opcodes }]\n"
648 " %s %s dump jited PROG [{ file FILE | opcodes }]\n" 673 " %s %s dump jited PROG [{ file FILE | opcodes }]\n"
649 " %s %s pin PROG FILE\n" 674 " %s %s pin PROG FILE\n"
675 " %s %s load OBJ FILE\n"
650 " %s %s help\n" 676 " %s %s help\n"
651 "\n" 677 "\n"
652 " " HELP_SPEC_PROGRAM "\n" 678 " " HELP_SPEC_PROGRAM "\n"
653 " " HELP_SPEC_OPTIONS "\n" 679 " " HELP_SPEC_OPTIONS "\n"
654 "", 680 "",
655 bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2], 681 bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2],
656 bin_name, argv[-2], bin_name, argv[-2]); 682 bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2]);
657 683
658 return 0; 684 return 0;
659} 685}
@@ -663,6 +689,7 @@ static const struct cmd cmds[] = {
663 { "help", do_help }, 689 { "help", do_help },
664 { "dump", do_dump }, 690 { "dump", do_dump },
665 { "pin", do_pin }, 691 { "pin", do_pin },
692 { "load", do_load },
666 { 0 } 693 { 0 }
667}; 694};
668 695