History

bpf: Fix bpf_redirect_neigh helper api to support supplying nexthop

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/

Toke Høiland-Jørgensen committed 6 years ago

Commit ba452c91 parent c5eb48e5 files · +145 −67Browse files

Showing the changes to include/uapi/linux (1 of 5 files). Show all

Unified · Split

include/uapi/linux/bpf.h+18−4
@@ -3677,15 +3677,19 @@ union bpf_attr { · 3676 unmodified lines
36773677 * Return
36783678 * The id is returned or 0 in case the id could not be retrieved.
36793679 *
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)
36813681 * Description
36823682 * Redirect the packet to another net device of index *ifindex*
36833683 * and fill in L2 addresses from neighboring subsystem. This helper
36843684 * is somewhat similar to **bpf_redirect**\ (), except that it
36853685 * 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.
36893693 *
36903694 * The *flags* argument is reserved and must be 0. The helper is
36913695 * currently only supported for tc BPF program types, and enabled
@@ -4906,6 +4910,16 @@ struct bpf_fib_lookup { · 1214 unmodified lines
49064910 __u8 dmac[6]; /* ETH_ALEN */
49074911 };
49084912
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+
49094923 enum bpf_task_fd_type {
49104924 BPF_FD_TYPE_RAW_TRACEPOINT, /* tp name */
49114925 BPF_FD_TYPE_TRACEPOINT, /* tp name */