You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The libbpf API provides more than the basic system call wrappers (which are
21
-
defined in libbpf [[https://github.com/libbpf/libbpf/blob/master/src/bpf.h][bpf.h]]). The libbpf API provides "[[https://github.com/libbpf/libbpf/blob/master/src/README.rst#objects][objects]]" and functions to
21
+
The libbpf API not only provides the basic system call wrappers (which are
22
+
defined in libbpf [[https://github.com/libbpf/libbpf/blob/master/src/bpf.h][bpf.h]]). The API also provides "[[https://github.com/libbpf/libbpf/blob/master/src/README.rst#objects][objects]]" and functions to
22
23
work with them (defined in include [[https://github.com/libbpf/libbpf/blob/master/src/libbpf.h][libbpf.h]]).
23
24
24
-
The corresponding object struct's are:
25
+
The C structs corresponding to the libbpf objects are:
25
26
- struct =bpf_object=
26
27
- struct =bpf_program=
27
28
- struct =bpf_map=
28
29
29
30
These structs are for libbpf internal use, and you must use the API
30
31
functions to interact with the objects. Functions that work with an object
31
-
have the struct name plus double underscore, and then part that describes
32
-
function purpose.
32
+
have are named after the struct, followed by a double underscore, and a
33
+
descriptive name.
33
34
34
35
Lets look at a practical usage of =bpf_object= and =bpf_program=.
35
36
36
-
** Lesson#1: bpf_object
37
+
** Basic bpf_object usage
37
38
38
39
In [[file:xdp_loader.c]] the function =__load_bpf_object_file()= now returns a
39
-
libbpf struct =bpf_object= pointer (while basic01 assignment returned the
40
-
file-descriptor to the first BPF-prog).
40
+
libbpf struct =bpf_object= pointer (while in the basic01 lesson we just
41
+
returned the filedescriptor to the first BPFprog).
41
42
42
-
The struct =bpf_object= represents ELF object itself.
43
+
The struct =bpf_object= represents an ELF object, which can be of various
44
+
types.
43
45
44
-
** Lesson#2: bpf_object to bpf_program
46
+
** Converting a bpf_object to bpf_program
45
47
46
-
In [[file:xdp_loader.c]] the function =__load_bpf_and_xdp_attach()= use
47
-
=bpf_object__find_program_by_title()= on the bpf_object, which is the "SEC"
48
-
name, not the C-function name. This returns an struct =bpf_program= object,
49
-
and we use the function =bpf_program__fd()= is used for getting the
50
-
file-descriptor that we want to attach to the XDP hook.
48
+
In [[file:xdp_loader.c]] the function =__load_bpf_and_xdp_attach()= uses
49
+
=bpf_object__find_program_by_title()= on the bpf_object, which finds a
50
+
program by the "SEC" name (not the C-function name). The return type is a
51
+
struct =bpf_program= object, and we can use the function =bpf_program__fd()=
52
+
for getting the filedescriptor that we want to attach to the XDP hook.
51
53
52
-
** Lesson#3: Hardware offloading
54
+
** Hardware offloading
53
55
54
-
XDP can also be hardware offloaded to capable NICs.
56
+
XDP can also be offloaded to run in the NIC hardware (on some
57
+
offload-capable NICs).
55
58
56
-
The XDP-flag XDP_FLAGS_HW_MODE enables/request hardware offloading, and is
57
-
set with long-option =--offload-mode=. The [[file:xdp_loader.c][loader-code]] also need to use a
58
-
more advanced libbpf API call =bpf_prog_load_xattr()=, which allows us to
59
-
set the ifindex, as this is also needed for HW offloading.
59
+
The XDPflag XDP_FLAGS_HW_MODE enables (requests) hardware offloading, and
60
+
is set with the long-option =--offload-mode=. The [[file:xdp_loader.c][loadercode]] also needs to
61
+
use a more advanced libbpf API call =bpf_prog_load_xattr()=, which allows us
62
+
to set the ifindex, as this is needed at load time to enable HW offloading.
60
63
61
64
There are some details on how to get hardware offloading working on
62
-
Netronome's Agilio SmartNICs in [[file:xdp_offload_nfp.org]], like updating the
63
-
firmware to support eBPF.
65
+
Netronome's Agilio SmartNICs in [[file:xdp_offload_nfp.org]]; for instance, the
66
+
firmware needs updating to support eBPF.
64
67
65
68
* Assignments
66
69
67
-
** Assignment#1: Setup testlab
70
+
** Assignment1: Setting up your test lab
68
71
69
72
As this lesson involves loading and selecting an XDP program that simply
70
-
drops all packets (via action =XDP_DROP=), you need to establish a testlab
71
-
environment. In the directory [[file:../testenv/][testenv/]] there is a script =testenv.sh= that
72
-
helps you setup a testlab based on =veth= and network namespaces.
73
+
drops all packets (via action =XDP_DROP=), you will need to load it on a
74
+
real interface to observe what is happening. To do this, we establish a test
75
+
lab environment. In the [[file:../testenv/][testenv/]] directory you will find a script
76
+
=testenv.sh= that helps you setup a test lab based on =veth= devices and
77
+
network namespaces.
73
78
74
79
E.g. run the script like:
75
80
#+begin_example sh
@@ -78,15 +83,15 @@ Setting up new environment 'veth-basic02'
78
83
Setup environment 'veth-basic02' with peer ip fc00:dead:cafe:1::2.
79
84
#+end_example
80
85
81
-
This result in the creation of an (outer) interface named: =veth-basic02=.
82
-
You can test that the environment network is operational by pinging the IPv6
83
-
address =fc00:dead:cafe:1::2=.
86
+
This results in the creation of an (outer) interface named: =veth-basic02=.
87
+
You can test that the environment network is operational by pinging the peer
88
+
IPv6 address =fc00:dead:cafe:1::2= (as seen in the script output).
84
89
85
-
The *assignment* is to manually load the compiled xdp program in ELF-OBJ file
86
-
=xdp_prog_kern.o=, using the =xdp_loader= program in this directory. Observe
87
-
the available options you can give the xdp_loader via =--help=. Try to
88
-
select the program section named =xdp_drop= via =--progsec=, and observe via
89
-
ping that packets gets dropped.
90
+
The *assignment* is to manually load the compiled xdp program in the ELF OBJ
91
+
file =xdp_prog_kern.o=, using the =xdp_loader= program in this directory.
92
+
Observe the available options you can give the xdp_loader via =--help=. Try
93
+
to select the program section named =xdp_drop= via =--progsec=, and observe
0 commit comments