libbpf: Teach bpf_object__open to guess program types
authorAndrii Nakryiko <andriin@fb.com>
Mon, 21 Oct 2019 03:38:59 +0000 (20:38 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 21 Oct 2019 12:49:12 +0000 (14:49 +0200)
commitdd4436bb838338cfda253d7f012610a73e4078fd
treef5850fc06b0ff394341dd5d782d1b6269f84f762
parent32dff6db29acc1d2b9fe0423ab033f15c717d776
libbpf: Teach bpf_object__open to guess program types

Teach bpf_object__open how to guess program type and expected attach
type from section names, similar to what bpf_prog_load() does. This
seems like a really useful features and an oversight to not have this
done during bpf_object_open(). To preserver backwards compatible
behavior of bpf_prog_load(), its attr->prog_type is treated as an
override of bpf_object__open() decisions, if attr->prog_type is not
UNSPECIFIED.

There is a slight difference in behavior for bpf_prog_load().
Previously, if bpf_prog_load() was loading BPF object with more than one
program, first program's guessed program type and expected attach type
would determine corresponding attributes of all the subsequent program
types, even if their sections names suggest otherwise. That seems like
a rather dubious behavior and with this change it will behave more
sanely: each program's type is determined individually, unless they are
forced to uniformity through attr->prog_type.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20191021033902.3856966-5-andriin@fb.com
tools/lib/bpf/libbpf.c