bpf: move common code to a separate function
* bpf.c (bpf_prog_attach_detach): New function. (bpf_prog_attach, bpf_prog_detach): Use it.
This commit is contained in:
parent
0a8dd6a68c
commit
3c356c40e4
38
bpf.c
38
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("}");
|
||||
@ -234,30 +236,18 @@ bpf_prog_attach(struct tcb *const tcp, const kernel_ulong_t addr,
|
||||
return RVAL_DECODED;
|
||||
}
|
||||
|
||||
static int
|
||||
bpf_prog_attach(struct tcb *const tcp, const kernel_ulong_t addr,
|
||||
unsigned int size)
|
||||
{
|
||||
return bpf_prog_attach_detach(tcp, addr, size, true);
|
||||
}
|
||||
|
||||
static int
|
||||
bpf_prog_detach(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 RVAL_DECODED;
|
||||
return bpf_prog_attach_detach(tcp, addr, size, false);
|
||||
}
|
||||
|
||||
SYS_FUNC(bpf)
|
||||
|
Loading…
Reference in New Issue
Block a user