2018-12-20 18:25 UTC+0100 ~ Daniel Borkmann <dan...@iogearbox.net>
On 12/20/2018 01:24 PM, Quentin Monnet wrote:
Make bpftool able to dump a subset of the parameters collected by
probing the system as a listing of C-style #define macros, so that
external projects can reuse the result of this probing and build
BPF-based project in accordance with the features available on the
system.
The new "macros" keyword is used to select this output. An additional
"prefix" keyword is added so that users can select a custom prefix for
macro names, in order to avoid any namespace conflict.
Sample output:
# bpftool feature probe kernel macros prefix FOO_
/*** System call availability ***/
#define FOO_HAVE_BPF_SYSCALL
/*** eBPF program types ***/
#define FOO_HAVE_SOCKET_FILTER_PROG_TYPE
#define FOO_HAVE_KPROBE_PROG_TYPE
#define FOO_HAVE_SCHED_CLS_PROG_TYPE
...
/*** eBPF map types ***/
#define FOO_HAVE_HASH_MAP_TYPE
#define FOO_HAVE_ARRAY_MAP_TYPE
#define FOO_HAVE_PROG_ARRAY_MAP_TYPE
...
/*** eBPF helper functions ***/
...
#define FOO_BPF_SKB_CHANGE_HEAD_HELPER_COMPAT_LIST "" \
"lwt_xmit " \
"sk_skb "
#define FOO_BPF_XDP_ADJUST_HEAD_HELPER_COMPAT_LIST "" \
"xdp "
#define FOO_BPF_PROBE_READ_STR_HELPER_COMPAT_LIST "" \
"kprobe " \
"tracepoint " \
"perf_event " \
"raw_tracepoint "
...
Rest looks good to me, just a comment here. How would programs use the
compat list? Wouldn't it be nicer to provide a PROG(HELPER) availability
query along the lines of ...
#if FOO_HAVE_SOCKET_FILTER(skb_load_bytes) == 1
// ...
#endif
... where the helper provides these macro functions and results in the
header file? So they can be used easily in the code from BPF prog or
normal C applications?
I was thinking about strstr() here, but it is true it is limited to
runtime and will not work with the preprocessor :s.
How would you dump parameters to make your PROG(HELPER) work? Something
along the following?
#define BPF__PROG_TYPE_SOCKET_FILTER__HELPER_skb_load_bytes 1
#define BPF__PROG_TYPE_SOCKET_FILTER__HELPER_bind 0
...
#define HAVE_SOCKET_FILTER_HELPER(name) \
BPF__PROG_TYPE_SOCKET_FILTER__HELPER_ ## name
or even
#define HAVE_PROG_TYPE_HELPER(type, helper) \
BPF__PROG_TYPE_ ## type ## __HELPER_ ## helper
Does that correspond to what you have in mind?
Thanks,
Quentin