From: Eric Leblond <hidden> Date: 2016-08-13 12:39:16
Hello,
Here's a small patchset on libbpf fixing two issues I've encountered
when adding some eBPF related features to Suricata.
Patchset statistics:
tools/lib/bpf/libbpf.c | 16 +++++++---------
tools/lib/bpf/libbpf.h | 4 +++-
2 files changed, 10 insertions(+), 10 deletions(-)
BR,
From: Eric Leblond <hidden> Date: 2016-08-13 12:39:15
The include of err.h is not explicitely needed in exported
functions and it was causing include conflict with some existing
code due to redefining some macros.
Signed-off-by: Eric Leblond <redacted>
---
tools/lib/bpf/libbpf.c | 1 +
tools/lib/bpf/libbpf.h | 1 -
2 files changed, 1 insertion(+), 1 deletion(-)
From: Eric Leblond <hidden> Date: 2016-08-13 12:39:18
Current API was not allowing the user to set a type like socket
filter. To avoid a setter function for each type, the patch simply
exports a set function that takes the type in parameter.
Signed-off-by: Eric Leblond <redacted>
---
tools/lib/bpf/libbpf.c | 15 ++++++---------
tools/lib/bpf/libbpf.h | 3 +++
2 files changed, 9 insertions(+), 9 deletions(-)
@@ -1336,26 +1336,23 @@ int bpf_program__nth_fd(struct bpf_program *prog, int n)returnfd;}-staticvoidbpf_program__set_type(structbpf_program*prog,+intbpf_program__set_type(structbpf_program*prog,enumbpf_prog_typetype){+if(!prog)+return-EINVAL;prog->type=type;+return0;}intbpf_program__set_tracepoint(structbpf_program*prog){-if(!prog)-return-EINVAL;-bpf_program__set_type(prog,BPF_PROG_TYPE_TRACEPOINT);-return0;+returnbpf_program__set_type(prog,BPF_PROG_TYPE_TRACEPOINT);}intbpf_program__set_kprobe(structbpf_program*prog){-if(!prog)-return-EINVAL;-bpf_program__set_type(prog,BPF_PROG_TYPE_KPROBE);-return0;+returnbpf_program__set_type(prog,BPF_PROG_TYPE_KPROBE);}staticboolbpf_program__is_type(structbpf_program*prog,
I think you should cc linux-kernel@vger.kernel.org for code in
tools/ .
Thank you.
On 2016/8/13 20:17, Eric Leblond wrote:
Hello,
Here's a small patchset on libbpf fixing two issues I've encountered
when adding some eBPF related features to Suricata.
Patchset statistics:
tools/lib/bpf/libbpf.c | 16 +++++++---------
tools/lib/bpf/libbpf.h | 4 +++-
2 files changed, 10 insertions(+), 10 deletions(-)
BR,
--
Eric Leblond
The include of err.h is not explicitely needed in exported
functions and it was causing include conflict with some existing
code due to redefining some macros.
Signed-off-by: Eric Leblond <redacted>
---
tools/lib/bpf/libbpf.c | 1 +
tools/lib/bpf/libbpf.h | 1 -
2 files changed, 1 insertion(+), 1 deletion(-)
Functions declared in this header require PTR_ERR
to decode error number. Logically speaking, this
header depends linux/err.h, so this include is
required. If not, there must have another way for
caller to decode error numbers.
I know the problem you try to solve. Please have a look at thread
https://lkml.org/lkml/2015/12/17/20
At that time I think we should create a wrapper in libbpf.h like this:
#ifdef USE_LINUX_ERR
#include <linux/err.h>
#endif
...
int libbpf_ptr_err(void *ptr);
...
It is acceptable but ugly. Can you find a better method?
Thank you.
Current API was not allowing the user to set a type like socket
filter. To avoid a setter function for each type, the patch simply
exports a set function that takes the type in parameter.
Signed-off-by: Eric Leblond <redacted>
---
tools/lib/bpf/libbpf.c | 15 ++++++---------
tools/lib/bpf/libbpf.h | 3 +++
2 files changed, 9 insertions(+), 9 deletions(-)
@@ -1336,26 +1336,23 @@ int bpf_program__nth_fd(struct bpf_program *prog, int n)returnfd;}-staticvoidbpf_program__set_type(structbpf_program*prog,+intbpf_program__set_type(structbpf_program*prog,enumbpf_prog_typetype){+if(!prog)+return-EINVAL;prog->type=type;+return0;}
@@ -173,6 +173,9 @@ int bpf_program__set_kprobe(struct bpf_program *prog);boolbpf_program__is_tracepoint(structbpf_program*prog);boolbpf_program__is_kprobe(structbpf_program*prog);+intbpf_program__set_type(structbpf_program*prog,+enumbpf_prog_typetype);+
This makes libbpf.h depend on kernel's uapi/linux/bpf.h.
Although I did this in the above patch, I don't like this
dependency. This is the reason why I introduce
int bpf_program__set_tracepoint(struct bpf_program *prog);
int bpf_program__set_kprobe(struct bpf_program *prog);
bool bpf_program__is_tracepoint(struct bpf_program *prog);
bool bpf_program__is_kprobe(struct bpf_program *prog);
and hide bpf_program__set_type inside the .c file.
Please add type setting functions, or pass int value to
bpf_program__set_type and add sanity checking.
Thank you.