Re: [PATCH v5 bpf-next 2/4] bpf: Support setting variable-length tunnel options

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;
}




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux