On Tue, Aug 30, 2022 at 1:13 PM Shmulik Ladkani <shmulik@xxxxxxxxxxxxxxxx> wrote: > > On Tue, 30 Aug 2022 23:02:57 +0300 > Shmulik Ladkani <shmulik@xxxxxxxxxxxxxxxx> wrote: > > > On Thu, 25 Aug 2022 11:20:31 -0700 > > Andrii Nakryiko <andrii.nakryiko@xxxxxxxxx> wrote: > > > > > > + * 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. > > > > Alright. > > > > For my usecase I need to use *part* of the tunnel options that were > > previously stored as a dynptr. > > > > Therefore I need to introduce a new bpf helper that adjusts the dynptr. > > > > How about this suggestion (sketch, not yet tried): > > > > // adjusts the dynptr to point to *len* bytes starting from the > > // specified *offset* > > > > BPF_CALL_3(bpf_dynptr_slice, struct bpf_dynptr_kern *, ptr, u32, offset, u32, len) > > { > > int err; > > u32 size; > > > > if (!ptr->data) > > return -EINVAL; > > > > err = bpf_dynptr_check_off_len(ptr, offset, len); > > if (err) > > return err; > > > > ptr->offset += offset; > > size = bpf_dynptr_get_size(ptr) - len; > > ptr->size = (ptr->size & ~(u32)DYNPTR_SIZE_MASK) | size; > > return 0; > > } > > > > Correction, meant: > ptr->offset += offset; > ptr->size = (ptr->size & ~(u32)DYNPTR_SIZE_MASK) | len; > I have a patchset for dynptr convenience helpers that I plan to tidy up and push out later this week or mid-next week. it includes "bpf_dynptr_advance()" and "bpf_dynptr_trim()", which will let you adjust the dynptr ("_advance()" advances the offset, "_trim()" trims the size)