Thread (10 messages) flat view 10 messages, 2 authors, 2020-05-18

Re: "Forwarding" from TC classifier

From: David Ahern <hidden>
Date: 2020-05-13 21:23:06
Also in: bpf

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help