Commit ed794073 authored by Joe Stringer's avatar Joe Stringer Committed by Arnaldo Carvalho de Melo

tools lib bpf: Define prog_type fns with macro

Turning this into a macro allows future prog types to be added with a
single line per type.
Signed-off-by: default avatarJoe Stringer <joe@ovn.org>
Acked-by: default avatarWang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: netdev@vger.kernel.org
Link: http://lkml.kernel.org/r/20170123011128.26534-3-joe@ovn.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 94e5adec
...@@ -1428,37 +1428,28 @@ static void bpf_program__set_type(struct bpf_program *prog, ...@@ -1428,37 +1428,28 @@ static void bpf_program__set_type(struct bpf_program *prog,
prog->type = type; prog->type = type;
} }
int bpf_program__set_tracepoint(struct bpf_program *prog)
{
if (!prog)
return -EINVAL;
bpf_program__set_type(prog, BPF_PROG_TYPE_TRACEPOINT);
return 0;
}
int bpf_program__set_kprobe(struct bpf_program *prog)
{
if (!prog)
return -EINVAL;
bpf_program__set_type(prog, BPF_PROG_TYPE_KPROBE);
return 0;
}
static bool bpf_program__is_type(struct bpf_program *prog, static bool bpf_program__is_type(struct bpf_program *prog,
enum bpf_prog_type type) enum bpf_prog_type type)
{ {
return prog ? (prog->type == type) : false; return prog ? (prog->type == type) : false;
} }
bool bpf_program__is_tracepoint(struct bpf_program *prog) #define BPF_PROG_TYPE_FNS(NAME, TYPE) \
{ int bpf_program__set_##NAME(struct bpf_program *prog) \
return bpf_program__is_type(prog, BPF_PROG_TYPE_TRACEPOINT); { \
} if (!prog) \
return -EINVAL; \
bool bpf_program__is_kprobe(struct bpf_program *prog) bpf_program__set_type(prog, TYPE); \
{ return 0; \
return bpf_program__is_type(prog, BPF_PROG_TYPE_KPROBE); } \
} \
bool bpf_program__is_##NAME(struct bpf_program *prog) \
{ \
return bpf_program__is_type(prog, TYPE); \
} \
BPF_PROG_TYPE_FNS(kprobe, BPF_PROG_TYPE_KPROBE);
BPF_PROG_TYPE_FNS(tracepoint, BPF_PROG_TYPE_TRACEPOINT);
int bpf_map__fd(struct bpf_map *map) int bpf_map__fd(struct bpf_map *map)
{ {
......
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