• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2
3.. _api:
4
5.. toctree:: Table of Contents
6
7
8LIBBPF API
9==========
10
11Error Handling
12--------------
13
14When libbpf is used in "libbpf 1.0 mode", API functions can return errors in one of two ways.
15
16You can set "libbpf 1.0" mode with the following line:
17
18.. code-block::
19
20    libbpf_set_strict_mode(LIBBPF_STRICT_DIRECT_ERRS | LIBBPF_STRICT_CLEAN_PTRS);
21
22If the function returns an error code directly, it uses 0 to indicate success
23and a negative error code to indicate what caused the error. In this case the
24error code should be checked directly from the return, you do not need to check
25errno.
26
27For example:
28
29.. code-block::
30
31    err = some_libbpf_api_with_error_return(...);
32    if (err < 0) {
33        /* Handle error accordingly */
34    }
35
36If the function returns a pointer, it will return NULL to indicate there was
37an error. In this case errno should be checked for the error code.
38
39For example:
40
41.. code-block::
42
43    ptr = some_libbpf_api_returning_ptr();
44    if (!ptr) {
45        /* note no minus sign for EINVAL and E2BIG below */
46        if (errno == EINVAL) {
47           /* handle EINVAL error */
48        } else if (errno == E2BIG) {
49           /* handle E2BIG error */
50        }
51    }
52
53libbpf.h
54--------
55.. doxygenfile:: libbpf.h
56   :project: libbpf
57   :sections: func define public-type enum
58
59bpf.h
60-----
61.. doxygenfile:: bpf.h
62   :project: libbpf
63   :sections: func define public-type enum
64
65btf.h
66-----
67.. doxygenfile:: btf.h
68   :project: libbpf
69   :sections: func define public-type enum
70
71xsk.h
72-----
73.. doxygenfile:: xsk.h
74   :project: libbpf
75   :sections: func define public-type enum
76
77bpf_tracing.h
78-------------
79.. doxygenfile:: bpf_tracing.h
80   :project: libbpf
81   :sections: func define public-type enum
82
83bpf_core_read.h
84---------------
85.. doxygenfile:: bpf_core_read.h
86   :project: libbpf
87   :sections: func define public-type enum
88
89bpf_endian.h
90------------
91.. doxygenfile:: bpf_endian.h
92   :project: libbpf
93   :sections: func define public-type enum
94