@@ -46,13 +46,14 @@ an option to forward packets to egress ports of other interfaces (if the
46
46
corresponding driver supports this feature). This can be done using the
47
47
=bpf_redirect= or =bpf_redirect_map= helpers. These helpers will return the
48
48
=XDP_REDIRECT= value and this is what should the program return. The
49
- =bpf_redirect= helper actually shouldn't be used in production as it is slow
50
- and can't be configured from user space. However, we will use it in the
51
- Assignment 2 for the sake of simplicity. To use the =bpf_redirect_map= helper
52
- we need to setup a special map of type =BPF_MAP_TYPE_DEVMAP= which maps virtual
53
- ports to actual network devices. See [[https://lwn.net/Articles/728146][this
54
- patch series]] which implemented the XDP redirect functionality. An example of
55
- usage can be found in the
49
+ =bpf_redirect= helper takes the interface index of the redirect port as
50
+ parameter and may be used with other helpers such as =bpf_fib_lookup=. We will
51
+ use it in Assignment 2 in a simpler way, and again in Assignment 4 with a kernel
52
+ fib lookup. To use the =bpf_redirect_map= helper we need to setup a special map
53
+ of type =BPF_MAP_TYPE_DEVMAP= which maps virtual ports to actual network
54
+ devices. See [[https://lwn.net/Articles/728146][this patch series]] which
55
+ implemented the XDP redirect functionality. An example of usage can be found in
56
+ the
56
57
[[https://github.com/torvalds/linux/blob/master/samples/bpf/xdp_redirect_map_kern.c][xdp_redirect_map_kern.c]]
57
58
file and the corresponding loader.
58
59
@@ -171,9 +172,9 @@ XDP_REDIRECT 176 pkts ( 4 pps) 20 Kbytes ( 0 Mbits/
171
172
** Assignment 3: Extend to a bidirectional router
172
173
173
174
In the previous assignment we were able to pass packets from one interface to
174
- the other. However, we were using the wrong =bpf_redirect= helper and needed to
175
- hardcode interface number and MAC addresses. This is not useful and we will use
176
- better techniques in this Assignment.
175
+ the other. However, we needed to hard code the interface number and MAC
176
+ addresses. This is not useful and we will use better techniques in this
177
+ Assignment.
177
178
178
179
This Assignment will show how to use the =bpf_redirect_map= function. Besides
179
180
that, to make the program more useful we will use a map which will contain a
@@ -246,13 +247,11 @@ and return =XDP_PASS= when packets destined to outer interfaces, but this
246
247
doesn't cover all cases and wouldn't it be better to dynamically lookup
247
248
where each packet should go?
248
249
249
- This assignment teaches to use the =bpf_fib_lookup= helper. This function lets
250
- XDP and TC programs to access the kernel routing table and will return an
251
- ifindex of interface to forward packet to. As was noted the =bpf_redirect_map=
252
- function accepts virtual ports, so to use ifindexes you will need to update the
253
- =xdp_prog_user.c= program to setup 1-1 mapping between virtual ports and
254
- network devices where each virtual port corresponds to a device with the same
255
- ifindex.
250
+ This assignment teaches how to use the =bpf_fib_lookup= helper. This function
251
+ lets XDP and TC programs access the kernel routing table and will return the
252
+ ifindex of interface to forward packet to, along with source and destination
253
+ mac addresses. After updating the Ethernet header, we can then redirect the
254
+ packet to this interface with the =bpf_redirect= function.
256
255
257
256
The Assignment, for the most part, reproduces the
258
257
[[https://github.com/torvalds/linux/blob/master/samples/bpf/xdp_fwd_kern.c][xdp_fwd_kern.c]]
@@ -286,10 +285,6 @@ $ t exec -n uno -- ./xdp_loader -d veth0 -F --progsec xdp_pass
286
285
$ t exec -n dos -- ./xdp_loader -d veth0 -F --progsec xdp_pass
287
286
$ t exec -n tres -- ./xdp_loader -d veth0 -F --progsec xdp_pass
288
287
289
- $ sudo ./xdp_prog_user -d uno
290
- $ sudo ./xdp_prog_user -d dos
291
- $ sudo ./xdp_prog_user -d tres
292
-
293
288
$ sudo ./xdp_stats -d uno
294
289
$ sudo ./xdp_stats -d dos
295
290
$ sudo ./xdp_stats -d tres
0 commit comments