summaryrefslogtreecommitdiffstats
path: root/lib/libbpf/docs/api.rst
blob: 7a8e709b3401ba440ec391b11aa90c566253a587 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
.. SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)

.. _api:

.. toctree:: Table of Contents


LIBBPF API
==========

Error Handling
--------------

When libbpf is used in "libbpf 1.0 mode", API functions can return errors in one of two ways.

You can set "libbpf 1.0" mode with the following line:

.. code-block::

    libbpf_set_strict_mode(LIBBPF_STRICT_DIRECT_ERRS | LIBBPF_STRICT_CLEAN_PTRS);

If the function returns an error code directly, it uses 0 to indicate success
and a negative error code to indicate what caused the error. In this case the
error code should be checked directly from the return, you do not need to check
errno.

For example:

.. code-block::

    err = some_libbpf_api_with_error_return(...);
    if (err < 0) {
        /* Handle error accordingly */
    }

If the function returns a pointer, it will return NULL to indicate there was
an error. In this case errno should be checked for the error code.

For example:

.. code-block::

    ptr = some_libbpf_api_returning_ptr();
    if (!ptr) {
        /* note no minus sign for EINVAL and E2BIG below */
        if (errno == EINVAL) {
           /* handle EINVAL error */
        } else if (errno == E2BIG) {
           /* handle E2BIG error */
        }
    }

libbpf.h
--------
.. doxygenfile:: libbpf.h
   :project: libbpf
   :sections: func define public-type enum

bpf.h
-----
.. doxygenfile:: bpf.h
   :project: libbpf
   :sections: func define public-type enum

btf.h
-----
.. doxygenfile:: btf.h
   :project: libbpf
   :sections: func define public-type enum

xsk.h
-----
.. doxygenfile:: xsk.h
   :project: libbpf
   :sections: func define public-type enum

bpf_tracing.h
-------------
.. doxygenfile:: bpf_tracing.h
   :project: libbpf
   :sections: func define public-type enum

bpf_core_read.h
---------------
.. doxygenfile:: bpf_core_read.h
   :project: libbpf
   :sections: func define public-type enum

bpf_endian.h
------------
.. doxygenfile:: bpf_endian.h
   :project: libbpf
   :sections: func define public-type enum