On Tue, Aug 23, 2022 at 9:41 PM Shmulik Ladkani <shmulik@xxxxxxxxxxxxxxxx> wrote: > > Existing 'bpf_skb_set_tunnel_opt' allows setting tunnel options given > an option buffer (ARG_PTR_TO_MEM) and the compile-time fixed buffer > size (ARG_CONST_SIZE). > > However, in certain cases we wish to set tunnel options of dynamic > length. > > For example, we have an ebpf program that gets geneve options on > incoming packets, stores them into a map (using a key representing > the incoming flow), and later needs to assign *same* options to > reply packets (belonging to same flow). > > This is currently imposssible without knowing sender's exact geneve > options length, which unfortunately is dymamic. > > Introduce 'bpf_skb_set_tunnel_opt_dynptr'. > > This is a variant of 'bpf_skb_set_tunnel_opt' which gets a bpf dynamic > pointer (ARG_PTR_TO_DYNPTR) parameter 'ptr' whose data points to the > options buffer, and 'len', the byte length of options data caller wishes > to copy into ip_tunnnel_info. > 'len' must never exceed the dynptr's internal size, o/w EINVAL is > returned. > > Signed-off-by: Shmulik Ladkani <shmulik.ladkani@xxxxxxxxx> > --- > v3: Avoid 'inline' for the __bpf_skb_set_tunopt helper function > v4: change API to be based on bpf_dynptr, suggested by John Fastabend <john.fastabend@xxxxxxxxx> > --- > include/uapi/linux/bpf.h | 12 ++++++++++++ > net/core/filter.c | 36 ++++++++++++++++++++++++++++++++-- > tools/include/uapi/linux/bpf.h | 12 ++++++++++++ > 3 files changed, 58 insertions(+), 2 deletions(-) > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > index 644600dbb114..c7b313e30635 100644 > --- a/include/uapi/linux/bpf.h > +++ b/include/uapi/linux/bpf.h > @@ -5367,6 +5367,17 @@ union bpf_attr { > * Return > * Current *ktime*. > * > + * long bpf_skb_set_tunnel_opt_dynptr(struct sk_buff *skb, struct bpf_dynptr *opt, u32 len) why can't we rely on dynptr's len instead of specifying extra one here? dynptr is a range of memory, so just specify that you take that entire range? And then we'll have (or partially already have) generic dynptr helpers to adjust internal dynptr offset and len. > + * Description > + * Set tunnel options metadata for the packet associated to *skb* > + * to the variable length *len* bytes of option data pointed to > + * by the *opt* dynptr. > + * > + * See also the description of the **bpf_skb_get_tunnel_opt**\ () > + * helper for additional information. > + * Return > + * 0 on success, or a negative error in case of failure. > + * > */ [...]