xref: /openbmc/linux/tools/lib/bpf/libbpf_legacy.h (revision e87c4f66)
1 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
2 
3 /*
4  * Libbpf legacy APIs (either discouraged or deprecated, as mentioned in [0])
5  *
6  *   [0] https://docs.google.com/document/d/1UyjTZuPFWiPFyKk1tV5an11_iaRuec6U-ZESZ54nNTY
7  *
8  * Copyright (C) 2021 Facebook
9  */
10 #ifndef __LIBBPF_LEGACY_BPF_H
11 #define __LIBBPF_LEGACY_BPF_H
12 
13 #include <linux/bpf.h>
14 #include <stdbool.h>
15 #include <stddef.h>
16 #include <stdint.h>
17 #include "libbpf_common.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 enum libbpf_strict_mode {
24 	/* Turn on all supported strict features of libbpf to simulate libbpf
25 	 * v1.0 behavior.
26 	 * This will be the default behavior in libbpf v1.0.
27 	 */
28 	LIBBPF_STRICT_ALL = 0xffffffff,
29 
30 	/*
31 	 * Disable any libbpf 1.0 behaviors. This is the default before libbpf
32 	 * v1.0. It won't be supported anymore in v1.0, please update your
33 	 * code so that it handles LIBBPF_STRICT_ALL mode before libbpf v1.0.
34 	 */
35 	LIBBPF_STRICT_NONE = 0x00,
36 	/*
37 	 * Return NULL pointers on error, not ERR_PTR(err).
38 	 * Additionally, libbpf also always sets errno to corresponding Exx
39 	 * (positive) error code.
40 	 */
41 	LIBBPF_STRICT_CLEAN_PTRS = 0x01,
42 	/*
43 	 * Return actual error codes from low-level APIs directly, not just -1.
44 	 * Additionally, libbpf also always sets errno to corresponding Exx
45 	 * (positive) error code.
46 	 */
47 	LIBBPF_STRICT_DIRECT_ERRS = 0x02,
48 
49 	/*
50 	 * Enforce strict BPF program section (SEC()) names.
51 	 * E.g., while prefiously SEC("xdp_whatever") or SEC("perf_event_blah") were
52 	 * allowed, with LIBBPF_STRICT_SEC_PREFIX this will become
53 	 * unrecognized by libbpf and would have to be just SEC("xdp") and
54 	 * SEC("xdp") and SEC("perf_event").
55 	 *
56 	 * Note, in this mode the program pin path will be based on the
57 	 * function name instead of section name.
58 	 */
59 	LIBBPF_STRICT_SEC_NAME = 0x04,
60 	/*
61 	 * Disable the global 'bpf_objects_list'. Maintaining this list adds
62 	 * a race condition to bpf_object__open() and bpf_object__close().
63 	 * Clients can maintain it on their own if it is valuable for them.
64 	 */
65 	LIBBPF_STRICT_NO_OBJECT_LIST = 0x08,
66 
67 	__LIBBPF_STRICT_LAST,
68 };
69 
70 LIBBPF_API int libbpf_set_strict_mode(enum libbpf_strict_mode mode);
71 
72 
73 #ifdef __cplusplus
74 } /* extern "C" */
75 #endif
76 
77 #endif /* __LIBBPF_LEGACY_BPF_H */
78