/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
/*
* Common eBPF ELF object loading operations.
*
* Copyright (C) 2013-2015 Alexei Starovoitov <ast@kernel.org>
* Copyright (C) 2015 Wang Nan <wangnan0@huawei.com>
* Copyright (C) 2015 Huawei Inc.
*/
#ifndef __LIBBPF_LIBBPF_H
#define __LIBBPF_LIBBPF_H
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <sys/types.h> // for size_t
#include <linux/bpf.h>
#include "libbpf_common.h"
#include "libbpf_legacy.h"
#ifdef __cplusplus
extern "C" {
#endif
LIBBPF_API __u32 libbpf_major_version(void);
LIBBPF_API __u32 libbpf_minor_version(void);
LIBBPF_API const char *libbpf_version_string(void);
enum libbpf_errno {
__LIBBPF_ERRNO__START = 4000,
/* Something wrong in libelf */
LIBBPF_ERRNO__LIBELF = __LIBBPF_ERRNO__START,
LIBBPF_ERRNO__FORMAT, /* BPF object format invalid */
LIBBPF_ERRNO__KVERSION, /* Incorrect or no 'version' section */
LIBBPF_ERRNO__ENDIAN, /* Endian mismatch */
LIBBPF_ERRNO__INTERNAL, /* Internal error in libbpf */
LIBBPF_ERRNO__RELOC, /* Relocation failed */
LIBBPF_ERRNO__LOAD, /* Load program failure for unknown reason */
LIBBPF_ERRNO__VERIFY, /* Kernel verifier blocks program loading */
LIBBPF_ERRNO__PROG2BIG, /* Program too big */
LIBBPF_ERRNO__KVER, /* Incorrect kernel version */
LIBBPF_ERRNO__PROGTYPE, /* Kernel doesn't support this program type */
LIBBPF_ERRNO__WRNGPID, /* Wrong pid in netlink message */
LIBBPF_ERRNO__INVSEQ, /* Invalid netlink sequence */
LIBBPF_ERRNO__NLPARSE, /* netlink parsing error */
__LIBBPF_ERRNO__END,
};
LIBBPF_API int libbpf_strerror(int err, char *buf, size_t size);
/**
* @brief **libbpf_bpf_attach_type_str()** converts the provided attach type
* value into a textual representation.
* @param t The attach type.
* @return Pointer to a static string identifying the attach type. NULL is
* returned for unknown **bpf_attach_type** values.
*/
LIBBPF_API const char *libbpf_bpf_attach_type_str(enum bpf_attach_type t);
/**
* @brief **libbpf_bpf_link_type_str()** converts the provided link type value
* into a textual representation.
* @param t The link type.
* @return Pointer to a static string identifying the link type. NULL is
* returned for unknown **bpf_link_type** values.
*/
LIBBPF_API const char *libbpf_bpf_link_type_str(enum bpf_link_type t);
/**
* @brief **libbpf_bpf_map_type_str()** converts the provided map type value
* into a textual representation.
* @param t The map type.
* @return Pointer to a static string identifying the map type. NULL is
* returned for unknown **bpf_map_type** values.
*/
LIBBPF_API const char *libbpf_bpf_map_type_str(enum bpf_map_type t);
/**
* @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,
LIBBPF_DEBUG,
};
typedef int (*libbpf_print_fn_t)(enum libbpf_print_level level,
const char *, va_list ap);
LIBBPF_API libbpf_print_fn_t libbpf_set_print(libbpf_print_fn_t fn);
/* Hide internal to user */
struct bpf_object;
struct bpf_object_open_opts {
/* size of this struct, for forward/backward compatibility */
size_t sz;
/* object name override, if provided:
* - for object open from file, this will override setting object