Based on the discussion in [0], update the bpf_redirect_neigh() helper to accept an optional parameter specifying the nexthop information. This makes it possible to combine bpf_fib_lookup() and bpf_redirect_neigh() without incurring a duplicate FIB lookup - since the FIB lookup helper will return the nexthop information even if no neighbour is present, this can simply be passed on to bpf_redirect_neigh() if bpf_fib_lookup() returns BPF_FIB_LKUP_RET_NO_NEIGH. Thus fix & extend it before helper API is frozen. [0] https://lore.kernel.org/bpf/393e17fc-d187-3a8d-2f0d-a627c7c63fca@iogearbox.net/
Showing the changes to include/uapi/linux (1 of 5 files). Show all
Unified · Split
| @@ -3677,15 +3677,19 @@ union bpf_attr { · 3676 unmodified lines | ||
| 3677 | 3677 | * Return |
| 3678 | 3678 | * The id is returned or 0 in case the id could not be retrieved. |
| 3679 | 3679 | * |
| 3680 | − * long bpf_redirect_neigh(u32 ifindex, u64 flags) | |
| 3680 | + * long bpf_redirect_neigh(u32 ifindex, struct bpf_redir_neigh *params, int plen, u64 flags) | |
| 3681 | 3681 | * Description |
| 3682 | 3682 | * Redirect the packet to another net device of index *ifindex* |
| 3683 | 3683 | * and fill in L2 addresses from neighboring subsystem. This helper |
| 3684 | 3684 | * is somewhat similar to **bpf_redirect**\ (), except that it |
| 3685 | 3685 | * populates L2 addresses as well, meaning, internally, the helper |
| 3686 | − * performs a FIB lookup based on the skb's networking header to | |
| 3687 | − * get the address of the next hop and then relies on the neighbor | |
| 3688 | − * lookup for the L2 address of the nexthop. | |
| 3686 | + * relies on the neighbor lookup for the L2 address of the nexthop. | |
| 3687 | + * | |
| 3688 | + * The helper will perform a FIB lookup based on the skb's | |
| 3689 | + * networking header to get the address of the next hop, unless | |
| 3690 | + * this is supplied by the caller in the *params* argument. The | |
| 3691 | + * *plen* argument indicates the len of *params* and should be set | |
| 3692 | + * to 0 if *params* is NULL. | |
| 3689 | 3693 | * |
| 3690 | 3694 | * The *flags* argument is reserved and must be 0. The helper is |
| 3691 | 3695 | * currently only supported for tc BPF program types, and enabled |
| @@ -4906,6 +4910,16 @@ struct bpf_fib_lookup { · 1214 unmodified lines | ||
| 4906 | 4910 | __u8 dmac[6]; /* ETH_ALEN */ |
| 4907 | 4911 | }; |
| 4908 | 4912 | |
| 4913 | +struct bpf_redir_neigh { | |
| 4914 | + /* network family for lookup (AF_INET, AF_INET6) */ | |
| 4915 | + __u32 nh_family; | |
| 4916 | + /* network address of nexthop; skips fib lookup to find gateway */ | |
| 4917 | + union { | |
| 4918 | + __be32 ipv4_nh; | |
| 4919 | + __u32 ipv6_nh[4]; /* in6_addr; network order */ | |
| 4920 | + }; | |
| 4921 | +}; | |
| 4922 | + | |
| 4909 | 4923 | enum bpf_task_fd_type { |
| 4910 | 4924 | BPF_FD_TYPE_RAW_TRACEPOINT, /* tp name */ |
| 4911 | 4925 | BPF_FD_TYPE_TRACEPOINT, /* tp name */ |