diff options
| author | David S. Miller <davem@davemloft.net> | 2017-05-10 14:42:48 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2017-05-11 14:19:00 -0400 |
| commit | 91045f5e5238a6d2ad21d41d7e86e2fa65f90d76 (patch) | |
| tree | e9acd575376236e1715bfa6704fdef67f7981a72 /tools/lib | |
| parent | e07b98d9bffe410019dfcf62c3428d4a96c56a2c (diff) | |
bpf: Add bpf_verify_program() to the library.
This allows a test case to load a BPF program and unconditionally
acquire the verifier log.
It also allows specification of the strict alignment flag.
Signed-off-by: David S. Miller <davem@davemloft.net>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/lib')
| -rw-r--r-- | tools/lib/bpf/bpf.c | 22 | ||||
| -rw-r--r-- | tools/lib/bpf/bpf.h | 4 |
2 files changed, 26 insertions, 0 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 4fe444b8092e..6e178987af8e 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c | |||
| @@ -117,6 +117,28 @@ int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, | |||
| 117 | return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); | 117 | return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns, | ||
| 121 | size_t insns_cnt, int strict_alignment, | ||
| 122 | const char *license, __u32 kern_version, | ||
| 123 | char *log_buf, size_t log_buf_sz) | ||
| 124 | { | ||
| 125 | union bpf_attr attr; | ||
| 126 | |||
| 127 | bzero(&attr, sizeof(attr)); | ||
| 128 | attr.prog_type = type; | ||
| 129 | attr.insn_cnt = (__u32)insns_cnt; | ||
| 130 | attr.insns = ptr_to_u64(insns); | ||
| 131 | attr.license = ptr_to_u64(license); | ||
| 132 | attr.log_buf = ptr_to_u64(log_buf); | ||
| 133 | attr.log_size = log_buf_sz; | ||
| 134 | attr.log_level = 2; | ||
| 135 | log_buf[0] = 0; | ||
| 136 | attr.kern_version = kern_version; | ||
| 137 | attr.prog_flags = strict_alignment ? BPF_F_STRICT_ALIGNMENT : 0; | ||
| 138 | |||
| 139 | return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); | ||
| 140 | } | ||
| 141 | |||
| 120 | int bpf_map_update_elem(int fd, const void *key, const void *value, | 142 | int bpf_map_update_elem(int fd, const void *key, const void *value, |
| 121 | __u64 flags) | 143 | __u64 flags) |
| 122 | { | 144 | { |
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index edb4daeff7a5..972bd8333eb7 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h | |||
| @@ -35,6 +35,10 @@ int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, | |||
| 35 | size_t insns_cnt, const char *license, | 35 | size_t insns_cnt, const char *license, |
| 36 | __u32 kern_version, char *log_buf, | 36 | __u32 kern_version, char *log_buf, |
| 37 | size_t log_buf_sz); | 37 | size_t log_buf_sz); |
| 38 | int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns, | ||
| 39 | size_t insns_cnt, int strict_alignment, | ||
| 40 | const char *license, __u32 kern_version, | ||
| 41 | char *log_buf, size_t log_buf_sz); | ||
| 38 | 42 | ||
| 39 | int bpf_map_update_elem(int fd, const void *key, const void *value, | 43 | int bpf_map_update_elem(int fd, const void *key, const void *value, |
| 40 | __u64 flags); | 44 | __u64 flags); |
