From: Yonghong Song <yhs@fb.com>
To: Jesper Dangaard Brouer <brouer@redhat.com>,
Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Networking <netdev@vger.kernel.org>,
"Daniel Borkmann" <borkmann@iogearbox.net>,
"Alexei Starovoitov" <alexei.starovoitov@gmail.com>,
"Maciej Żenczykowski" <maze@google.com>,
"Lorenz Bauer" <lmb@cloudflare.com>,
shaun@tigera.io, "Lorenzo Bianconi" <lorenzo@kernel.org>,
"Marek Majkowski" <marek@cloudflare.com>,
"John Fastabend" <john.fastabend@gmail.com>,
"Jakub Kicinski" <kuba@kernel.org>,
eyal.birger@gmail.com, colrack@gmail.com
Subject: Re: [PATCH bpf-next V11 4/7] bpf: add BPF-helper for MTU checking
Date: Thu, 14 Jan 2021 07:33:28 -0800 [thread overview]
Message-ID: <e0436ecc-542c-0242-bbf7-23ad6350952e@fb.com> (raw)
In-Reply-To: <20210114155228.128457c7@carbon>
On 1/14/21 6:52 AM, Jesper Dangaard Brouer wrote:
> On Tue, 12 Jan 2021 11:23:33 -0800
> Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
>
>> On Tue, Jan 12, 2021 at 9:49 AM Jesper Dangaard Brouer
>> <brouer@redhat.com> wrote:
>>>
>>> This BPF-helper bpf_check_mtu() works for both XDP and TC-BPF programs.
>>>
>>> The SKB object is complex and the skb->len value (accessible from
>>> BPF-prog) also include the length of any extra GRO/GSO segments, but
>>> without taking into account that these GRO/GSO segments get added
>>> transport (L4) and network (L3) headers before being transmitted. Thus,
>>> this BPF-helper is created such that the BPF-programmer don't need to
>>> handle these details in the BPF-prog.
>>>
>>> The API is designed to help the BPF-programmer, that want to do packet
>>> context size changes, which involves other helpers. These other helpers
>>> usually does a delta size adjustment. This helper also support a delta
>>> size (len_diff), which allow BPF-programmer to reuse arguments needed by
>>> these other helpers, and perform the MTU check prior to doing any actual
>>> size adjustment of the packet context.
>>>
>>> It is on purpose, that we allow the len adjustment to become a negative
>>> result, that will pass the MTU check. This might seem weird, but it's not
>>> this helpers responsibility to "catch" wrong len_diff adjustments. Other
>>> helpers will take care of these checks, if BPF-programmer chooses to do
>>> actual size adjustment.
>>>
>>> V9:
>>> - Use dev->hard_header_len (instead of ETH_HLEN)
>>> - Annotate with unlikely req from Daniel
>>> - Fix logic error using skb_gso_validate_network_len from Daniel
>>>
>>> V6:
>>> - Took John's advice and dropped BPF_MTU_CHK_RELAX
>>> - Returned MTU is kept at L3-level (like fib_lookup)
>>>
>>> V4: Lot of changes
>>> - ifindex 0 now use current netdev for MTU lookup
>>> - rename helper from bpf_mtu_check to bpf_check_mtu
>>> - fix bug for GSO pkt length (as skb->len is total len)
>>> - remove __bpf_len_adj_positive, simply allow negative len adj
>>>
>>> Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
>>> ---
>>> include/uapi/linux/bpf.h | 67 ++++++++++++++++++++++
>>> net/core/filter.c | 122 ++++++++++++++++++++++++++++++++++++++++
>>> tools/include/uapi/linux/bpf.h | 67 ++++++++++++++++++++++
>>> 3 files changed, 256 insertions(+)
>>>
>>> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
>>> index 649586d656b6..fa2e99351758 100644
>>> --- a/include/uapi/linux/bpf.h
>>> +++ b/include/uapi/linux/bpf.h
>>> @@ -3833,6 +3833,61 @@ union bpf_attr {
>>> * Return
>>> * A pointer to a struct socket on success or NULL if the file is
>>> * not a socket.
>>> + *
>>> + * int bpf_check_mtu(void *ctx, u32 ifindex, u32 *mtu_len, s32 len_diff, u64 flags)
>>
>> should return long, same as most other helpers
>
> Is it enough to change it here?
> (as this will be used for generating the helpers header file,
> via ./scripts/bpf_helpers_doc.py --header)
Just change here is enough.
>
> Or do I also need to change bpf_func_proto.ret_type ?
There is no need to change bpf_func_proto.ret_type.
RET_INTEGER already implies 64bit scalar.
>
>>> + * Description
>>> + * Check ctx packet size against MTU of net device (based on
>>> + * *ifindex*). This helper will likely be used in combination with
>>> + * helpers that adjust/change the packet size. The argument
>>> + * *len_diff* can be used for querying with a planned size
>>> + * change. This allows to check MTU prior to changing packet ctx.
>>> + *
>>
>> [...]
>>
>
>
>
next prev parent reply other threads:[~2021-01-14 15:34 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-12 17:45 [PATCH bpf-next V11 0/7] bpf: New approach for BPF MTU handling Jesper Dangaard Brouer
2021-01-12 17:45 ` [PATCH bpf-next V11 1/7] bpf: Remove MTU check in __bpf_skb_max_len Jesper Dangaard Brouer
2021-01-14 8:18 ` John Fastabend
2021-01-12 17:45 ` [PATCH bpf-next V11 2/7] bpf: fix bpf_fib_lookup helper MTU check for SKB ctx Jesper Dangaard Brouer
2021-01-12 17:45 ` [PATCH bpf-next V11 3/7] bpf: bpf_fib_lookup return MTU value as output when looked up Jesper Dangaard Brouer
2021-01-12 17:45 ` [PATCH bpf-next V11 4/7] bpf: add BPF-helper for MTU checking Jesper Dangaard Brouer
2021-01-12 19:23 ` Andrii Nakryiko
2021-01-14 14:52 ` Jesper Dangaard Brouer
2021-01-14 15:33 ` Yonghong Song [this message]
2021-01-13 23:07 ` Daniel Borkmann
2021-01-14 14:36 ` Jesper Dangaard Brouer
2021-01-14 22:28 ` Daniel Borkmann
2021-01-18 11:04 ` Jesper Dangaard Brouer
2021-01-12 17:45 ` [PATCH bpf-next V11 5/7] bpf: drop MTU check when doing TC-BPF redirect to ingress Jesper Dangaard Brouer
2021-01-14 9:03 ` John Fastabend
2021-01-14 16:14 ` Jesper Dangaard Brouer
2021-01-12 17:45 ` [PATCH bpf-next V11 6/7] selftests/bpf: use bpf_check_mtu in selftest test_cls_redirect Jesper Dangaard Brouer
2021-01-12 17:45 ` [PATCH bpf-next V11 7/7] bpf/selftests: tests using bpf_check_mtu BPF-helper Jesper Dangaard Brouer
2021-01-12 19:29 ` Andrii Nakryiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e0436ecc-542c-0242-bbf7-23ad6350952e@fb.com \
--to=yhs@fb.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=borkmann@iogearbox.net \
--cc=bpf@vger.kernel.org \
--cc=brouer@redhat.com \
--cc=colrack@gmail.com \
--cc=eyal.birger@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=lmb@cloudflare.com \
--cc=lorenzo@kernel.org \
--cc=marek@cloudflare.com \
--cc=maze@google.com \
--cc=netdev@vger.kernel.org \
--cc=shaun@tigera.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).