aboutsummaryrefslogtreecommitdiffstats
path: root/tools/bpf/bpftool/prog.c
diff options
context:
space:
mode:
authorJakub Kicinski <jakub.kicinski@netronome.com>2018-07-10 17:43:00 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-07-11 16:13:33 -0400
commit49f2cba3e57a4d71e3e7001cc2934b563ee495f4 (patch)
treec226a462ea9fab37433185f530a664431b4a4340 /tools/bpf/bpftool/prog.c
parentb60df2a0e11fcd24186c312b0307ab8494031e27 (diff)
tools: bpftool: allow users to specify program type for prog load
Sometimes program section names don't match with libbpf's expectation. In particular XDP's default section names differ between libbpf and iproute2. Allow users to pass program type on command line. Name the types like the libbpf expected section names. 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.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index 21c74de7156f..98695585bbb6 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -688,6 +688,7 @@ static int do_load(int argc, char **argv)
688 const char *objfile, *pinfile; 688 const char *objfile, *pinfile;
689 struct bpf_object *obj; 689 struct bpf_object *obj;
690 int prog_fd; 690 int prog_fd;
691 int err;
691 692
692 if (!REQ_ARGS(2)) 693 if (!REQ_ARGS(2))
693 return -1; 694 return -1;
@@ -695,7 +696,37 @@ static int do_load(int argc, char **argv)
695 pinfile = GET_ARG(); 696 pinfile = GET_ARG();
696 697
697 while (argc) { 698 while (argc) {
698 if (is_prefix(*argv, "dev")) { 699 if (is_prefix(*argv, "type")) {
700 char *type;
701
702 NEXT_ARG();
703
704 if (attr.prog_type != BPF_PROG_TYPE_UNSPEC) {
705 p_err("program type already specified");
706 return -1;
707 }
708 if (!REQ_ARGS(1))
709 return -1;
710
711 /* Put a '/' at the end of type to appease libbpf */
712 type = malloc(strlen(*argv) + 2);
713 if (!type) {
714 p_err("mem alloc failed");
715 return -1;
716 }
717 *type = 0;
718 strcat(type, *argv);
719 strcat(type, "/");
720
721 err = libbpf_prog_type_by_name(type, &attr.prog_type,
722 &attr.expected_attach_type);
723 free(type);
724 if (err < 0) {
725 p_err("unknown program type '%s'", *argv);
726 return err;
727 }
728 NEXT_ARG();
729 } else if (is_prefix(*argv, "dev")) {
699 NEXT_ARG(); 730 NEXT_ARG();
700 731
701 if (attr.ifindex) { 732 if (attr.ifindex) {
@@ -713,7 +744,7 @@ static int do_load(int argc, char **argv)
713 } 744 }
714 NEXT_ARG(); 745 NEXT_ARG();
715 } else { 746 } else {
716 p_err("expected no more arguments or 'dev', got: '%s'?", 747 p_err("expected no more arguments, 'type' or 'dev', got: '%s'?",
717 *argv); 748 *argv);
718 return -1; 749 return -1;
719 } 750 }
@@ -753,10 +784,17 @@ static int do_help(int argc, char **argv)
753 " %s %s dump xlated PROG [{ file FILE | opcodes | visual }]\n" 784 " %s %s dump xlated PROG [{ file FILE | opcodes | visual }]\n"
754 " %s %s dump jited PROG [{ file FILE | opcodes }]\n" 785 " %s %s dump jited PROG [{ file FILE | opcodes }]\n"
755 " %s %s pin PROG FILE\n" 786 " %s %s pin PROG FILE\n"
756 " %s %s load OBJ FILE [dev NAME]\n" 787 " %s %s load OBJ FILE [type TYPE] [dev NAME]\n"
757 " %s %s help\n" 788 " %s %s help\n"
758 "\n" 789 "\n"
759 " " HELP_SPEC_PROGRAM "\n" 790 " " HELP_SPEC_PROGRAM "\n"
791 " TYPE := { socket | kprobe | kretprobe | classifier | action |\n"
792 " tracepoint | raw_tracepoint | xdp | perf_event | cgroup/skb |\n"
793 " cgroup/sock | cgroup/dev | lwt_in | lwt_out | lwt_xmit |\n"
794 " lwt_seg6local | sockops | sk_skb | sk_msg | lirc_mode2 |\n"
795 " cgroup/bind4 | cgroup/bind6 | cgroup/post_bind4 |\n"
796 " cgroup/post_bind6 | cgroup/connect4 | cgroup/connect6 |\n"
797 " cgroup/sendmsg4 | cgroup/sendmsg6 }\n"
760 " " HELP_SPEC_OPTIONS "\n" 798 " " HELP_SPEC_OPTIONS "\n"
761 "", 799 "",
762 bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2], 800 bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2],