Commit ba6dd679 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by Daniel Borkmann

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: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: default avatarQuentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent 8d1fc3de
...@@ -24,7 +24,7 @@ MAP COMMANDS ...@@ -24,7 +24,7 @@ MAP COMMANDS
| **bpftool** **prog dump xlated** *PROG* [{**file** *FILE* | **opcodes** | **visual**}] | **bpftool** **prog dump xlated** *PROG* [{**file** *FILE* | **opcodes** | **visual**}]
| **bpftool** **prog dump jited** *PROG* [{**file** *FILE* | **opcodes**}] | **bpftool** **prog dump jited** *PROG* [{**file** *FILE* | **opcodes**}]
| **bpftool** **prog pin** *PROG* *FILE* | **bpftool** **prog pin** *PROG* *FILE*
| **bpftool** **prog load** *OBJ* *FILE* | **bpftool** **prog load** *OBJ* *FILE* [**dev** *NAME*]
| **bpftool** **prog help** | **bpftool** **prog help**
| |
| *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* } | *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
...@@ -64,8 +64,10 @@ DESCRIPTION ...@@ -64,8 +64,10 @@ DESCRIPTION
Note: *FILE* must be located in *bpffs* mount. Note: *FILE* must be located in *bpffs* mount.
**bpftool prog load** *OBJ* *FILE* **bpftool prog load** *OBJ* *FILE* [**dev** *NAME*]
Load bpf program from binary *OBJ* and pin as *FILE*. Load bpf program from binary *OBJ* and pin as *FILE*.
If **dev** *NAME* is specified program will be loaded onto
given networking device (offload).
Note: *FILE* must be located in *bpffs* mount. Note: *FILE* must be located in *bpffs* mount.
......
...@@ -99,6 +99,12 @@ _bpftool_get_prog_tags() ...@@ -99,6 +99,12 @@ _bpftool_get_prog_tags()
command sed -n 's/.*"tag": "\(.*\)",$/\1/p' )" -- "$cur" ) ) command sed -n 's/.*"tag": "\(.*\)",$/\1/p' )" -- "$cur" ) )
} }
_sysfs_get_netdevs()
{
COMPREPLY+=( $( compgen -W "$( ls /sys/class/net 2>/dev/null )" -- \
"$cur" ) )
}
# For bpftool map update: retrieve type of the map to update. # For bpftool map update: retrieve type of the map to update.
_bpftool_map_update_map_type() _bpftool_map_update_map_type()
{ {
...@@ -262,8 +268,21 @@ _bpftool() ...@@ -262,8 +268,21 @@ _bpftool()
return 0 return 0
;; ;;
load) load)
_filedir if [[ ${#words[@]} -lt 6 ]]; then
return 0 _filedir
return 0
fi
case $prev in
dev)
_sysfs_get_netdevs
return 0
;;
*)
_bpftool_once_attr 'dev'
return 0
;;
esac
;; ;;
*) *)
[[ $prev == $object ]] && \ [[ $prev == $object ]] && \
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <net/if.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -681,6 +682,9 @@ static int do_pin(int argc, char **argv) ...@@ -681,6 +682,9 @@ static int do_pin(int argc, char **argv)
static int do_load(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; const char *objfile, *pinfile;
struct bpf_object *obj; struct bpf_object *obj;
int prog_fd; int prog_fd;
...@@ -690,7 +694,34 @@ static int do_load(int argc, char **argv) ...@@ -690,7 +694,34 @@ static int do_load(int argc, char **argv)
objfile = GET_ARG(); objfile = GET_ARG();
pinfile = 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"); p_err("failed to load program");
return -1; return -1;
} }
...@@ -722,7 +753,7 @@ static int do_help(int argc, char **argv) ...@@ -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 xlated PROG [{ file FILE | opcodes | visual }]\n"
" %s %s dump jited PROG [{ file FILE | opcodes }]\n" " %s %s dump jited PROG [{ file FILE | opcodes }]\n"
" %s %s pin PROG FILE\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" " %s %s help\n"
"\n" "\n"
" " HELP_SPEC_PROGRAM "\n" " " HELP_SPEC_PROGRAM "\n"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment