mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-09 14:43:16 +00:00
libbpf: Introduce libbpf_bpf_prog_type_str
This change introduces a new function, libbpf_bpf_prog_type_str, to the public libbpf API. The function allows users to get a string representation for a bpf_prog_type variant. Signed-off-by: Daniel Müller <deso@posteo.net> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Quentin Monnet <quentin@isovalent.com> Acked-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/bpf/20220523230428.3077108-2-deso@posteo.net
This commit is contained in:
parent
cc1685546d
commit
d18616e7aa
@ -72,6 +72,41 @@
|
||||
static struct bpf_map *bpf_object__add_map(struct bpf_object *obj);
|
||||
static bool prog_is_subprog(const struct bpf_object *obj, const struct bpf_program *prog);
|
||||
|
||||
static const char * const prog_type_name[] = {
|
||||
[BPF_PROG_TYPE_UNSPEC] = "unspec",
|
||||
[BPF_PROG_TYPE_SOCKET_FILTER] = "socket_filter",
|
||||
[BPF_PROG_TYPE_KPROBE] = "kprobe",
|
||||
[BPF_PROG_TYPE_SCHED_CLS] = "sched_cls",
|
||||
[BPF_PROG_TYPE_SCHED_ACT] = "sched_act",
|
||||
[BPF_PROG_TYPE_TRACEPOINT] = "tracepoint",
|
||||
[BPF_PROG_TYPE_XDP] = "xdp",
|
||||
[BPF_PROG_TYPE_PERF_EVENT] = "perf_event",
|
||||
[BPF_PROG_TYPE_CGROUP_SKB] = "cgroup_skb",
|
||||
[BPF_PROG_TYPE_CGROUP_SOCK] = "cgroup_sock",
|
||||
[BPF_PROG_TYPE_LWT_IN] = "lwt_in",
|
||||
[BPF_PROG_TYPE_LWT_OUT] = "lwt_out",
|
||||
[BPF_PROG_TYPE_LWT_XMIT] = "lwt_xmit",
|
||||
[BPF_PROG_TYPE_SOCK_OPS] = "sock_ops",
|
||||
[BPF_PROG_TYPE_SK_SKB] = "sk_skb",
|
||||
[BPF_PROG_TYPE_CGROUP_DEVICE] = "cgroup_device",
|
||||
[BPF_PROG_TYPE_SK_MSG] = "sk_msg",
|
||||
[BPF_PROG_TYPE_RAW_TRACEPOINT] = "raw_tracepoint",
|
||||
[BPF_PROG_TYPE_CGROUP_SOCK_ADDR] = "cgroup_sock_addr",
|
||||
[BPF_PROG_TYPE_LWT_SEG6LOCAL] = "lwt_seg6local",
|
||||
[BPF_PROG_TYPE_LIRC_MODE2] = "lirc_mode2",
|
||||
[BPF_PROG_TYPE_SK_REUSEPORT] = "sk_reuseport",
|
||||
[BPF_PROG_TYPE_FLOW_DISSECTOR] = "flow_dissector",
|
||||
[BPF_PROG_TYPE_CGROUP_SYSCTL] = "cgroup_sysctl",
|
||||
[BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE] = "raw_tracepoint_writable",
|
||||
[BPF_PROG_TYPE_CGROUP_SOCKOPT] = "cgroup_sockopt",
|
||||
[BPF_PROG_TYPE_TRACING] = "tracing",
|
||||
[BPF_PROG_TYPE_STRUCT_OPS] = "struct_ops",
|
||||
[BPF_PROG_TYPE_EXT] = "ext",
|
||||
[BPF_PROG_TYPE_LSM] = "lsm",
|
||||
[BPF_PROG_TYPE_SK_LOOKUP] = "sk_lookup",
|
||||
[BPF_PROG_TYPE_SYSCALL] = "syscall",
|
||||
};
|
||||
|
||||
static int __base_pr(enum libbpf_print_level level, const char *format,
|
||||
va_list args)
|
||||
{
|
||||
@ -9300,6 +9335,14 @@ int libbpf_prog_type_by_name(const char *name, enum bpf_prog_type *prog_type,
|
||||
return libbpf_err(-ESRCH);
|
||||
}
|
||||
|
||||
const char *libbpf_bpf_prog_type_str(enum bpf_prog_type t)
|
||||
{
|
||||
if (t < 0 || t >= ARRAY_SIZE(prog_type_name))
|
||||
return NULL;
|
||||
|
||||
return prog_type_name[t];
|
||||
}
|
||||
|
||||
static struct bpf_map *find_struct_ops_map_by_offset(struct bpf_object *obj,
|
||||
size_t offset)
|
||||
{
|
||||
|
@ -51,6 +51,15 @@ enum libbpf_errno {
|
||||
|
||||
LIBBPF_API int libbpf_strerror(int err, char *buf, size_t size);
|
||||
|
||||
/**
|
||||
* @brief **libbpf_bpf_prog_type_str()** converts the provided program type
|
||||
* value into a textual representation.
|
||||
* @param t The program type.
|
||||
* @return Pointer to a static string identifying the program type. NULL is
|
||||
* returned for unknown **bpf_prog_type** values.
|
||||
*/
|
||||
LIBBPF_API const char *libbpf_bpf_prog_type_str(enum bpf_prog_type t);
|
||||
|
||||
enum libbpf_print_level {
|
||||
LIBBPF_WARN,
|
||||
LIBBPF_INFO,
|
||||
|
@ -461,5 +461,8 @@ LIBBPF_0.8.0 {
|
||||
} LIBBPF_0.7.0;
|
||||
|
||||
LIBBPF_1.0.0 {
|
||||
global:
|
||||
libbpf_bpf_prog_type_str;
|
||||
|
||||
local: *;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user