From: Dmitry V. Levin Date: Sat, 28 Jan 2017 22:11:20 +0000 (+0000) Subject: bpf: move common code to a separate function X-Git-Tag: v4.16~34 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c356c40e4261b93809f0586b538946355ba6824;p=strace bpf: move common code to a separate function * bpf.c (bpf_prog_attach_detach): New function. (bpf_prog_attach, bpf_prog_detach): Use it. --- diff --git a/bpf.c b/bpf.c index d36745ed..99410183 100644 --- a/bpf.c +++ b/bpf.c @@ -207,8 +207,8 @@ bpf_obj_manage(struct tcb *const tcp, const kernel_ulong_t addr, } static int -bpf_prog_attach(struct tcb *const tcp, const kernel_ulong_t addr, - unsigned int size) +bpf_prog_attach_detach(struct tcb *const tcp, const kernel_ulong_t addr, + unsigned int size, bool print_attach_bpf_fd) { struct { uint32_t target_fd, attach_bpf_fd, attach_type; @@ -225,8 +225,10 @@ bpf_prog_attach(struct tcb *const tcp, const kernel_ulong_t addr, tprintf("{target_fd="); printfd(tcp, attr.target_fd); - tprintf(", attach_bpf_fd="); - printfd(tcp, attr.attach_bpf_fd); + if (print_attach_bpf_fd) { + tprintf(", attach_bpf_fd="); + printfd(tcp, attr.attach_bpf_fd); + } tprintf(", attach_type="); printxval(bpf_attach_type, attr.attach_type, "BPF_???"); tprintf("}"); @@ -235,29 +237,17 @@ bpf_prog_attach(struct tcb *const tcp, const kernel_ulong_t addr, } static int -bpf_prog_detach(struct tcb *const tcp, const kernel_ulong_t addr, +bpf_prog_attach(struct tcb *const tcp, const kernel_ulong_t addr, unsigned int size) { - struct { - uint32_t target_fd, attach_bpf_fd, attach_type; - } attr = {}; - - if (!size) { - printaddr(addr); - return RVAL_DECODED; - } - if (size > sizeof(attr)) - size = sizeof(attr); - if (umoven_or_printaddr(tcp, addr, size, &attr)) - return RVAL_DECODED; - - tprintf("{target_fd="); - printfd(tcp, attr.target_fd); - tprintf(", attach_type="); - printxval(bpf_attach_type, attr.attach_type, "BPF_???"); - tprintf("}"); + return bpf_prog_attach_detach(tcp, addr, size, true); +} - return RVAL_DECODED; +static int +bpf_prog_detach(struct tcb *const tcp, const kernel_ulong_t addr, + unsigned int size) +{ + return bpf_prog_attach_detach(tcp, addr, size, false); } SYS_FUNC(bpf)