* [PATCH net-next 0/2] libbpf: minor fix and API update @ 2016-08-13 12:17 Eric Leblond 2016-08-13 12:17 ` [PATCH net-next 1/2] tools lib bpf: suppress useless include Eric Leblond ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: Eric Leblond @ 2016-08-13 12:17 UTC (permalink / raw) To: netdev; +Cc: Alexei Starovoitov, wangnan0 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, ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next 1/2] tools lib bpf: suppress useless include 2016-08-13 12:17 [PATCH net-next 0/2] libbpf: minor fix and API update Eric Leblond @ 2016-08-13 12:17 ` Eric Leblond 2016-08-15 3:20 ` Wangnan (F) 2016-08-13 12:17 ` [PATCH net-next 2/2] tools lib bpf: export function to set type Eric Leblond 2016-08-15 1:22 ` [PATCH net-next 0/2] libbpf: minor fix and API update Wangnan (F) 2 siblings, 1 reply; 6+ messages in thread From: Eric Leblond @ 2016-08-13 12:17 UTC (permalink / raw) To: netdev; +Cc: Alexei Starovoitov, wangnan0, 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 <eric@regit.org> --- tools/lib/bpf/libbpf.c | 1 + tools/lib/bpf/libbpf.h | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index b699aea..7872ff6 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -31,6 +31,7 @@ #include <linux/kernel.h> #include <linux/bpf.h> #include <linux/list.h> +#include <linux/err.h> #include <libelf.h> #include <gelf.h> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index dd7a513..a6c5cde 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -23,7 +23,6 @@ #include <stdio.h> #include <stdbool.h> -#include <linux/err.h> enum libbpf_errno { __LIBBPF_ERRNO__START = 4000, -- 2.8.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 1/2] tools lib bpf: suppress useless include 2016-08-13 12:17 ` [PATCH net-next 1/2] tools lib bpf: suppress useless include Eric Leblond @ 2016-08-15 3:20 ` Wangnan (F) 0 siblings, 0 replies; 6+ messages in thread From: Wangnan (F) @ 2016-08-15 3:20 UTC (permalink / raw) To: Eric Leblond, netdev; +Cc: Alexei Starovoitov On 2016/8/13 20:17, Eric Leblond wrote: > 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 <eric@regit.org> > --- > tools/lib/bpf/libbpf.c | 1 + > tools/lib/bpf/libbpf.h | 1 - > 2 files changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index b699aea..7872ff6 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -31,6 +31,7 @@ > #include <linux/kernel.h> > #include <linux/bpf.h> > #include <linux/list.h> > +#include <linux/err.h> > #include <libelf.h> > #include <gelf.h> > > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h > index dd7a513..a6c5cde 100644 > --- a/tools/lib/bpf/libbpf.h > +++ b/tools/lib/bpf/libbpf.h > @@ -23,7 +23,6 @@ > > #include <stdio.h> > #include <stdbool.h> > -#include <linux/err.h> > 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. > enum libbpf_errno { > __LIBBPF_ERRNO__START = 4000, ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next 2/2] tools lib bpf: export function to set type 2016-08-13 12:17 [PATCH net-next 0/2] libbpf: minor fix and API update Eric Leblond 2016-08-13 12:17 ` [PATCH net-next 1/2] tools lib bpf: suppress useless include Eric Leblond @ 2016-08-13 12:17 ` Eric Leblond 2016-08-15 3:41 ` Wangnan (F) 2016-08-15 1:22 ` [PATCH net-next 0/2] libbpf: minor fix and API update Wangnan (F) 2 siblings, 1 reply; 6+ messages in thread From: Eric Leblond @ 2016-08-13 12:17 UTC (permalink / raw) To: netdev; +Cc: Alexei Starovoitov, wangnan0, Eric Leblond 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 <eric@regit.org> --- tools/lib/bpf/libbpf.c | 15 ++++++--------- tools/lib/bpf/libbpf.h | 3 +++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 7872ff6..ff2a8c6 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1336,26 +1336,23 @@ int bpf_program__nth_fd(struct bpf_program *prog, int n) return fd; } -static void bpf_program__set_type(struct bpf_program *prog, +int bpf_program__set_type(struct bpf_program *prog, enum bpf_prog_type type) { + if (!prog) + return -EINVAL; prog->type = type; + return 0; } int bpf_program__set_tracepoint(struct bpf_program *prog) { - if (!prog) - return -EINVAL; - bpf_program__set_type(prog, BPF_PROG_TYPE_TRACEPOINT); - return 0; + return bpf_program__set_type(prog, BPF_PROG_TYPE_TRACEPOINT); } int bpf_program__set_kprobe(struct bpf_program *prog) { - if (!prog) - return -EINVAL; - bpf_program__set_type(prog, BPF_PROG_TYPE_KPROBE); - return 0; + return bpf_program__set_type(prog, BPF_PROG_TYPE_KPROBE); } static bool bpf_program__is_type(struct bpf_program *prog, diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index a6c5cde..6a84d7a 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -173,6 +173,9 @@ 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); +int bpf_program__set_type(struct bpf_program *prog, + enum bpf_prog_type type); + /* * We don't need __attribute__((packed)) now since it is * unnecessary for 'bpf_map_def' because they are all aligned. -- 2.8.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 2/2] tools lib bpf: export function to set type 2016-08-13 12:17 ` [PATCH net-next 2/2] tools lib bpf: export function to set type Eric Leblond @ 2016-08-15 3:41 ` Wangnan (F) 0 siblings, 0 replies; 6+ messages in thread From: Wangnan (F) @ 2016-08-15 3:41 UTC (permalink / raw) To: Eric Leblond, netdev; +Cc: Alexei Starovoitov On 2016/8/13 20:17, Eric Leblond wrote: > 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 <eric@regit.org> > --- > tools/lib/bpf/libbpf.c | 15 ++++++--------- > tools/lib/bpf/libbpf.h | 3 +++ > 2 files changed, 9 insertions(+), 9 deletions(-) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 7872ff6..ff2a8c6 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -1336,26 +1336,23 @@ int bpf_program__nth_fd(struct bpf_program *prog, int n) > return fd; > } > > -static void bpf_program__set_type(struct bpf_program *prog, > +int bpf_program__set_type(struct bpf_program *prog, > enum bpf_prog_type type) > { > + if (!prog) > + return -EINVAL; > prog->type = type; > + return 0; > } > We'd better add a sanity check here to prevent setting invalid program type. Plase have a look at https://lkml.org/lkml/2015/12/17/13 > int bpf_program__set_tracepoint(struct bpf_program *prog) > { > - if (!prog) > - return -EINVAL; > - bpf_program__set_type(prog, BPF_PROG_TYPE_TRACEPOINT); > - return 0; > + return bpf_program__set_type(prog, BPF_PROG_TYPE_TRACEPOINT); > } > > int bpf_program__set_kprobe(struct bpf_program *prog) > { > - if (!prog) > - return -EINVAL; > - bpf_program__set_type(prog, BPF_PROG_TYPE_KPROBE); > - return 0; > + return bpf_program__set_type(prog, BPF_PROG_TYPE_KPROBE); > } > > static bool bpf_program__is_type(struct bpf_program *prog, > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h > index a6c5cde..6a84d7a 100644 > --- a/tools/lib/bpf/libbpf.h > +++ b/tools/lib/bpf/libbpf.h > @@ -173,6 +173,9 @@ 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); > > +int bpf_program__set_type(struct bpf_program *prog, > + enum bpf_prog_type type); > + 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. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 0/2] libbpf: minor fix and API update 2016-08-13 12:17 [PATCH net-next 0/2] libbpf: minor fix and API update Eric Leblond 2016-08-13 12:17 ` [PATCH net-next 1/2] tools lib bpf: suppress useless include Eric Leblond 2016-08-13 12:17 ` [PATCH net-next 2/2] tools lib bpf: export function to set type Eric Leblond @ 2016-08-15 1:22 ` Wangnan (F) 2 siblings, 0 replies; 6+ messages in thread From: Wangnan (F) @ 2016-08-15 1:22 UTC (permalink / raw) To: Eric Leblond, netdev; +Cc: Alexei Starovoitov 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-08-15 3:42 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-08-13 12:17 [PATCH net-next 0/2] libbpf: minor fix and API update Eric Leblond 2016-08-13 12:17 ` [PATCH net-next 1/2] tools lib bpf: suppress useless include Eric Leblond 2016-08-15 3:20 ` Wangnan (F) 2016-08-13 12:17 ` [PATCH net-next 2/2] tools lib bpf: export function to set type Eric Leblond 2016-08-15 3:41 ` Wangnan (F) 2016-08-15 1:22 ` [PATCH net-next 0/2] libbpf: minor fix and API update Wangnan (F)
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).