Skip to content

Commit 24d4858

Browse files
tohojokernel-patches-bot
authored andcommitted
bpf_fib_lookup: always return target ifindex
The bpf_fib_lookup() helper performs a neighbour lookup for the destination IP and returns BPF_FIB_LKUP_NO_NEIGH if this fails, with the expectation that the BPF program will pass the packet up the stack in this case. However, with the addition of bpf_redirect_neigh() that can be used instead to perform the neighbour lookup, at the cost of a bit of duplicated work. For that we still need the target ifindex, and since bpf_fib_lookup() already has that at the time it performs the neighbour lookup, there is really no reason why it can't just return it in any case. So let's just always return the ifindex if the FIB lookup itself succeeds. Cc: David Ahern <[email protected]> Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
1 parent 00fd502 commit 24d4858

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

net/core/filter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5196,7 +5196,6 @@ static int bpf_fib_set_fwd_params(struct bpf_fib_lookup *params,
51965196
memcpy(params->smac, dev->dev_addr, ETH_ALEN);
51975197
params->h_vlan_TCI = 0;
51985198
params->h_vlan_proto = 0;
5199-
params->ifindex = dev->ifindex;
52005199

52015200
return 0;
52025201
}
@@ -5293,6 +5292,7 @@ static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
52935292
dev = nhc->nhc_dev;
52945293

52955294
params->rt_metric = res.fi->fib_priority;
5295+
params->ifindex = dev->ifindex;
52965296

52975297
/* xdp and cls_bpf programs are run in RCU-bh so
52985298
* rcu_read_lock_bh is not needed here
@@ -5418,6 +5418,7 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
54185418

54195419
dev = res.nh->fib_nh_dev;
54205420
params->rt_metric = res.f6i->fib6_metric;
5421+
params->ifindex = dev->ifindex;
54215422

54225423
/* xdp and cls_bpf programs are run in RCU-bh so rcu_read_lock_bh is
54235424
* not needed here.

0 commit comments

Comments
 (0)