• Quentin Monnet's avatar
    tools: bpftool: add C-style "#define" output for probes · d267cff4
    Quentin Monnet authored
    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 ***/
        /*
         * Use FOO_HAVE_PROG_TYPE_HELPER(prog_type_name, helper_name)
         * to determine if <helper_name> is available for <prog_type_name>,
         * e.g.
         *      #if FOO_HAVE_PROG_TYPE_HELPER(xdp, bpf_redirect)
         *              // do stuff with this helper
         *      #elif
         *              // use a workaround
         *      #endif
         */
        #define FOO_HAVE_PROG_TYPE_HELPER(prog_type, helper)        \
                FOO_BPF__PROG_TYPE_ ## prog_type ## __HELPER_ ## helper
        ...
        #define FOO_BPF__PROG_TYPE_socket_filter__HELPER_bpf_probe_read 0
        #define FOO_BPF__PROG_TYPE_socket_filter__HELPER_bpf_ktime_get_ns 1
        #define FOO_BPF__PROG_TYPE_socket_filter__HELPER_bpf_trace_printk 1
        ...
    
    v3:
    - Change output for helpers again: add a
      HAVE_PROG_TYPE_HELPER(type, helper) macro that can be used to tell
      if <helper> is available for program <type>.
    
    v2:
    - #define-based output added as a distinct patch.
    - "HAVE_" prefix appended to macro names.
    - Output limited to bpf() syscall availability, BPF prog and map types,
      helper functions. In this version kernel config options, procfs
      parameter or kernel version are intentionally left aside.
    - Following the change on helper probes, format for helper probes in
      this output style has changed (now a list of compatible program
      types).
    Signed-off-by: default avatarQuentin Monnet <quentin.monnet@netronome.com>
    Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
    Reviewed-by: default avatarStanislav Fomichev <sdf@google.com>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    d267cff4
feature.c 16.9 KB