# RE: \[PATCH bpf-next V1 1/2\] bpf: BPF-helper for MTU checking add length input

- From: John Fastabend \<john.fastabend@gmail.com\>
- Date: 2021-02-17 20:21:46 
- List: netdev
- Page: https://ratatoskr.run/netdev/2021/02/7760608
- Thread: https://ratatoskr.run/bpf/2021/02/7760441/t.md

```text
Jesper Dangaard Brouer wrote:
> The FIB lookup example[1] show how the IP-header field tot_len
> (iph->tot_len) is used as input to perform the MTU check.
> 
> This patch extend the BPF-helper bpf_check_mtu() with the same ability
> to provide the length as user parameter input, via mtu_len parameter.
> 
> [1] samples/bpf/xdp_fwd_kern.c
> 
> Signed-off-by: Jesper Dangaard Brouer <redacted>
> ---
>  include/uapi/linux/bpf.h |   17 +++++++++++------
>  net/core/filter.c        |   12 ++++++++++--
>  2 files changed, 21 insertions(+), 8 deletions(-)
> 
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index 4c24daa43bac..9c8aa50dc8a5 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -3850,8 +3850,7 @@ union bpf_attr {
>   *
>   * long bpf_check_mtu(void *ctx, u32 ifindex, u32 *mtu_len, s32 len_diff, u64 flags)
>   *	Description
> -
> - *		Check ctx packet size against exceeding MTU of net device (based
> + *		Check packet size against exceeding MTU of net device (based
>   *		on *ifindex*).  This helper will likely be used in combination
>   *		with helpers that adjust/change the packet size.
>   *
> @@ -3868,6 +3867,14 @@ union bpf_attr {
>   *		against the current net device.  This is practical if this isn't
>   *		used prior to redirect.
>   *
> + *		On input *mtu_len* must be a valid pointer, else verifier will
> + *		reject BPF program.  If the value *mtu_len* is initialized to
> + *		zero then the ctx packet size is use.  When value *mtu_len* is
> + *		provided as input this specify the L3 length that the MTU check
> + *		is done against. Remeber XDP and TC length operate at L2, but
                                 ^^^^^^^
typo, Remember

Acked-by: John Fastabend <john.fastabend@gmail.com>
```
