Re: [iproute2 net-next 2/8] bpf: export bpf_prog_load
On 12/12/2016 01:53 AM, David Ahern wrote: Code move only; no functional change intended. Signed-off-by: David Ahern Acked-by: Daniel Borkmann
[iproute2 net-next 2/8] bpf: export bpf_prog_load
Code move only; no functional change intended. Signed-off-by: David Ahern --- include/bpf_util.h | 4 lib/bpf.c | 40 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/include/bpf_util.h b/include/bpf_util.h index b038379684a8..726e3455 100644 --- a/include/bpf_util.h +++ b/include/bpf_util.h @@ -75,6 +75,10 @@ int bpf_trace_pipe(void); void bpf_print_ops(FILE *f, struct rtattr *bpf_ops, __u16 len); +int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns, + size_t size_insns, const char *license, char *log, + size_t size_log); + int bpf_prog_attach_fd(int prog_fd, int target_fd, enum bpf_attach_type type); int bpf_prog_detach_fd(int target_fd, enum bpf_attach_type type); diff --git a/lib/bpf.c b/lib/bpf.c index 5d6dcaa949de..bd939f53fb6e 100644 --- a/lib/bpf.c +++ b/lib/bpf.c @@ -871,6 +871,26 @@ int bpf_prog_detach_fd(int target_fd, enum bpf_attach_type type) return bpf(BPF_PROG_DETACH, &attr, sizeof(attr)); } +int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns, + size_t size_insns, const char *license, char *log, + size_t size_log) +{ + union bpf_attr attr = {}; + + attr.prog_type = type; + attr.insns = bpf_ptr_to_u64(insns); + attr.insn_cnt = size_insns / sizeof(struct bpf_insn); + attr.license = bpf_ptr_to_u64(license); + + if (size_log > 0) { + attr.log_buf = bpf_ptr_to_u64(log); + attr.log_size = size_log; + attr.log_level = 1; + } + + return bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); +} + #ifdef HAVE_ELF struct bpf_elf_prog { enum bpf_prog_type type; @@ -988,26 +1008,6 @@ static int bpf_map_create(enum bpf_map_type type, uint32_t size_key, return bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); } -static int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns, -size_t size_insns, const char *license, char *log, -size_t size_log) -{ - union bpf_attr attr = {}; - - attr.prog_type = type; - attr.insns = bpf_ptr_to_u64(insns); - attr.insn_cnt = size_insns / sizeof(struct bpf_insn); - attr.license = bpf_ptr_to_u64(license); - - if (size_log > 0) { - attr.log_buf = bpf_ptr_to_u64(log); - attr.log_size = size_log; - attr.log_level = 1; - } - - return bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); -} - static int bpf_obj_pin(int fd, const char *pathname) { union bpf_attr attr = {}; -- 2.1.4
Re: [iproute2 net-next 2/8] bpf: export bpf_prog_load
On 12/10/2016 09:32 PM, David Ahern wrote: Code move only; no functional change intended. Signed-off-by: David Ahern --- include/bpf_util.h | 3 +++ lib/bpf.c | 40 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/include/bpf_util.h b/include/bpf_util.h index 49b96bbc208f..dcbdca6978d6 100644 --- a/include/bpf_util.h +++ b/include/bpf_util.h @@ -75,6 +75,9 @@ int bpf_trace_pipe(void); void bpf_print_ops(FILE *f, struct rtattr *bpf_ops, __u16 len); +int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns, + size_t size_insns, const char *license, char *log, + size_t size_log); Just a really minor nit: please add a newline here. int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type); int bpf_prog_detach(int target_fd, enum bpf_attach_type type);
[iproute2 net-next 2/8] bpf: export bpf_prog_load
Code move only; no functional change intended. Signed-off-by: David Ahern --- include/bpf_util.h | 3 +++ lib/bpf.c | 40 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/include/bpf_util.h b/include/bpf_util.h index 49b96bbc208f..dcbdca6978d6 100644 --- a/include/bpf_util.h +++ b/include/bpf_util.h @@ -75,6 +75,9 @@ int bpf_trace_pipe(void); void bpf_print_ops(FILE *f, struct rtattr *bpf_ops, __u16 len); +int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns, + size_t size_insns, const char *license, char *log, + size_t size_log); int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type); int bpf_prog_detach(int target_fd, enum bpf_attach_type type); diff --git a/lib/bpf.c b/lib/bpf.c index 103fc1ef0593..b04c3a678b9c 100644 --- a/lib/bpf.c +++ b/lib/bpf.c @@ -871,6 +871,26 @@ int bpf_prog_detach(int target_fd, enum bpf_attach_type type) return bpf(BPF_PROG_DETACH, &attr, sizeof(attr)); } +int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns, + size_t size_insns, const char *license, char *log, + size_t size_log) +{ + union bpf_attr attr = {}; + + attr.prog_type = type; + attr.insns = bpf_ptr_to_u64(insns); + attr.insn_cnt = size_insns / sizeof(struct bpf_insn); + attr.license = bpf_ptr_to_u64(license); + + if (size_log > 0) { + attr.log_buf = bpf_ptr_to_u64(log); + attr.log_size = size_log; + attr.log_level = 1; + } + + return bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); +} + #ifdef HAVE_ELF struct bpf_elf_prog { enum bpf_prog_type type; @@ -988,26 +1008,6 @@ static int bpf_map_create(enum bpf_map_type type, uint32_t size_key, return bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); } -static int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns, -size_t size_insns, const char *license, char *log, -size_t size_log) -{ - union bpf_attr attr = {}; - - attr.prog_type = type; - attr.insns = bpf_ptr_to_u64(insns); - attr.insn_cnt = size_insns / sizeof(struct bpf_insn); - attr.license = bpf_ptr_to_u64(license); - - if (size_log > 0) { - attr.log_buf = bpf_ptr_to_u64(log); - attr.log_size = size_log; - attr.log_level = 1; - } - - return bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); -} - static int bpf_obj_pin(int fd, const char *pathname) { union bpf_attr attr = {}; -- 2.1.4
[iproute2 net-next 2/8] bpf: export bpf_prog_load
Code move only; no functional change intended. Signed-off-by: David Ahern --- include/bpf_util.h | 3 +++ lib/bpf.c | 40 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/include/bpf_util.h b/include/bpf_util.h index 49b96bbc208f..dcbdca6978d6 100644 --- a/include/bpf_util.h +++ b/include/bpf_util.h @@ -75,6 +75,9 @@ int bpf_trace_pipe(void); void bpf_print_ops(FILE *f, struct rtattr *bpf_ops, __u16 len); +int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns, + size_t size_insns, const char *license, char *log, + size_t size_log); int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type); int bpf_prog_detach(int target_fd, enum bpf_attach_type type); diff --git a/lib/bpf.c b/lib/bpf.c index 103fc1ef0593..b04c3a678b9c 100644 --- a/lib/bpf.c +++ b/lib/bpf.c @@ -871,6 +871,26 @@ int bpf_prog_detach(int target_fd, enum bpf_attach_type type) return bpf(BPF_PROG_DETACH, &attr, sizeof(attr)); } +int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns, + size_t size_insns, const char *license, char *log, + size_t size_log) +{ + union bpf_attr attr = {}; + + attr.prog_type = type; + attr.insns = bpf_ptr_to_u64(insns); + attr.insn_cnt = size_insns / sizeof(struct bpf_insn); + attr.license = bpf_ptr_to_u64(license); + + if (size_log > 0) { + attr.log_buf = bpf_ptr_to_u64(log); + attr.log_size = size_log; + attr.log_level = 1; + } + + return bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); +} + #ifdef HAVE_ELF struct bpf_elf_prog { enum bpf_prog_type type; @@ -988,26 +1008,6 @@ static int bpf_map_create(enum bpf_map_type type, uint32_t size_key, return bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); } -static int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns, -size_t size_insns, const char *license, char *log, -size_t size_log) -{ - union bpf_attr attr = {}; - - attr.prog_type = type; - attr.insns = bpf_ptr_to_u64(insns); - attr.insn_cnt = size_insns / sizeof(struct bpf_insn); - attr.license = bpf_ptr_to_u64(license); - - if (size_log > 0) { - attr.log_buf = bpf_ptr_to_u64(log); - attr.log_size = size_log; - attr.log_level = 1; - } - - return bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); -} - static int bpf_obj_pin(int fd, const char *pathname) { union bpf_attr attr = {}; -- 2.1.4