On 5/13/20 10:40 AM, Lorenz Bauer wrote: > Really, I'd like to get rid of step 1, and instead rely on the network > stack to switch or route > the packet for me. The bpf_fib_lookup helper is very close to what I need. I've > hacked around a bit, and come up with the following replacement for step 1: > > switch (bpf_fib_lookup(skb, &fib, sizeof(fib), 0)) { > case BPF_FIB_LKUP_RET_SUCCESS: > /* There is a cached neighbour, bpf_redirect without going > through the stack. */ > return bpf_redirect(...); BTW, as shown in samples/bpf/xdp_fwd_kern.c, you have a bit more work to do for proper L3 forwarding: if (rc == BPF_FIB_LKUP_RET_SUCCESS) { ... if (h_proto == htons(ETH_P_IP)) ip_decrease_ttl(iph); else if (h_proto == htons(ETH_P_IPV6)) ip6h->hop_limit--; memcpy(eth->h_dest, fib_params.dmac, ETH_ALEN); memcpy(eth->h_source, fib_params.smac, ETH_ALEN); return bpf_redirect_map(&xdp_tx_ports, fib_params.ifindex, 0); The ttl / hoplimit decrements assumed you checked it earlier to be > 1