• Andrey Ignatov's avatar
    libbpf: Introduce libbpf_attach_type_by_name · 956b620f
    Andrey Ignatov authored
    There is a common use-case when ELF object contains multiple BPF
    programs and every program has its own section name. If it's cgroup-bpf
    then programs have to be 1) loaded and 2) attached to a cgroup.
    
    It's convenient to have information necessary to load BPF program
    together with program itself. This is where section name works fine in
    conjunction with libbpf_prog_type_by_name that identifies prog_type and
    expected_attach_type and these can be used with BPF_PROG_LOAD.
    
    But there is currently no way to identify attach_type by section name
    and it leads to messy code in user space that reinvents guessing logic
    every time it has to identify attach type to use with BPF_PROG_ATTACH.
    
    The patch introduces libbpf_attach_type_by_name that guesses attach type
    by section name if a program can be attached.
    
    The difference between expected_attach_type provided by
    libbpf_prog_type_by_name and attach_type provided by
    libbpf_attach_type_by_name is the former is used at BPF_PROG_LOAD time
    and can be zero if a program of prog_type X has only one corresponding
    attach type Y whether the latter provides specific attach type to use
    with BPF_PROG_ATTACH.
    
    No new section names were added to section_names array. Only existing
    ones were reorganized and attach_type was added where appropriate.
    Signed-off-by: default avatarAndrey Ignatov <rdna@fb.com>
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    956b620f
libbpf.h 11.2 KB