Skip to content

Commit abcce73

Browse files
netoptimizerborkmann
authored andcommitted
samples/bpf: xdp_fwd explain bpf_fib_lookup return codes
Make it clear that this XDP program depend on the network stack to do the ARP resolution. This is connected with the BPF_FIB_LKUP_RET_NO_NEIGH return code from bpf_fib_lookup(). Another common mistake (seen via XDP-tutorial) is that users don't realize that sysctl net.ipv{4,6}.conf.all.forwarding setting is honored by bpf_fib_lookup. Reported-by: Anton Protopopov <[email protected]> Signed-off-by: Jesper Dangaard Brouer <[email protected]> Reviewed-by: David Ahern <[email protected]> Acked-by: Yonghong Song <[email protected]> Reviewed-by: Toke Høiland-Jørgensen <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent a32a32c commit abcce73

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

samples/bpf/xdp_fwd_kern.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,23 @@ static __always_inline int xdp_fwd_flags(struct xdp_md *ctx, u32 flags)
103103
fib_params.ifindex = ctx->ingress_ifindex;
104104

105105
rc = bpf_fib_lookup(ctx, &fib_params, sizeof(fib_params), flags);
106-
107-
if (rc == 0) {
106+
/*
107+
* Some rc (return codes) from bpf_fib_lookup() are important,
108+
* to understand how this XDP-prog interacts with network stack.
109+
*
110+
* BPF_FIB_LKUP_RET_NO_NEIGH:
111+
* Even if route lookup was a success, then the MAC-addresses are also
112+
* needed. This is obtained from arp/neighbour table, but if table is
113+
* (still) empty then BPF_FIB_LKUP_RET_NO_NEIGH is returned. To avoid
114+
* doing ARP lookup directly from XDP, then send packet to normal
115+
* network stack via XDP_PASS and expect it will do ARP resolution.
116+
*
117+
* BPF_FIB_LKUP_RET_FWD_DISABLED:
118+
* The bpf_fib_lookup respect sysctl net.ipv{4,6}.conf.all.forwarding
119+
* setting, and will return BPF_FIB_LKUP_RET_FWD_DISABLED if not
120+
* enabled this on ingress device.
121+
*/
122+
if (rc == BPF_FIB_LKUP_RET_SUCCESS) {
108123
/* Verify egress index has been configured as TX-port.
109124
* (Note: User can still have inserted an egress ifindex that
110125
* doesn't support XDP xmit, which will result in packet drops).

0 commit comments

Comments
 (0)