From: Jesper Dangaard Brouer <brouer@redhat.com>
To: Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
Daniel Borkmann <borkmann@iogearbox.net>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
maze@google.com, lmb@cloudflare.com, shaun@tigera.io,
Lorenzo Bianconi <lorenzo@kernel.org>,
marek@cloudflare.com, John Fastabend <john.fastabend@gmail.com>,
Jakub Kicinski <kuba@kernel.org>,
eyal.birger@gmail.com, colrack@gmail.com, brouer@redhat.com
Subject: Re: [PATCH bpf-next V11 4/7] bpf: add BPF-helper for MTU checking
Date: Mon, 18 Jan 2021 12:04:59 +0100 [thread overview]
Message-ID: <20210118120459.4a7ac2e1@carbon> (raw)
In-Reply-To: <776c5832-da48-cc6b-730f-e70aebe73de8@iogearbox.net>
On Thu, 14 Jan 2021 23:28:57 +0100
Daniel Borkmann <daniel@iogearbox.net> wrote:
> On 1/14/21 3:36 PM, Jesper Dangaard Brouer wrote:
> [...]
> >>> +BPF_CALL_5(bpf_skb_check_mtu, struct sk_buff *, skb,
> >>> + u32, ifindex, u32 *, mtu_len, s32, len_diff, u64, flags)
> >>> +{
> >>> + int ret = BPF_MTU_CHK_RET_FRAG_NEEDED;
> >>> + struct net_device *dev = skb->dev;
> >>> + int skb_len, dev_len;
> >>> + int mtu;
> >>> +
> >>> + if (unlikely(flags & ~(BPF_MTU_CHK_SEGS)))
> >>> + return -EINVAL;
> >>> +
> >>> + dev = __dev_via_ifindex(dev, ifindex);
> >>> + if (unlikely(!dev))
> >>> + return -ENODEV;
> >>> +
> >>> + mtu = READ_ONCE(dev->mtu);
> >>> +
> >>> + dev_len = mtu + dev->hard_header_len;
> >>> + skb_len = skb->len + len_diff; /* minus result pass check */
> >>> + if (skb_len <= dev_len) {
> >>> + ret = BPF_MTU_CHK_RET_SUCCESS;
> >>> + goto out;
> >>> + }
> >>> + /* At this point, skb->len exceed MTU, but as it include length of all
> >>> + * segments, it can still be below MTU. The SKB can possibly get
> >>> + * re-segmented in transmit path (see validate_xmit_skb). Thus, user
> >>> + * must choose if segs are to be MTU checked. Last SKB "headlen" is
> >>> + * checked against MTU.
> >>> + */
> >>> + if (skb_is_gso(skb)) {
> >>> + ret = BPF_MTU_CHK_RET_SUCCESS;
> >>> +
> >>> + if (!(flags & BPF_MTU_CHK_SEGS))
> >>> + goto out;
> >>> +
> >>> + if (!skb_gso_validate_network_len(skb, mtu)) {
> >>> + ret = BPF_MTU_CHK_RET_SEGS_TOOBIG;
> >>> + goto out;
> >>> + }
> >>> +
> >>> + skb_len = skb_headlen(skb) + len_diff;
> >>> + if (skb_len > dev_len) {
> [...]
> >> Do you have a particular use case for the BPF_MTU_CHK_SEGS?
> >
> > The complaint from Maze (and others) were that when skb_is_gso then all
> > the MTU checks are bypassed. This flag enables checking the GSO part
> > via skb_gso_validate_network_len(). We cannot enable it per default,
> > as you say, it is universally correct in all cases.
>
> If there is a desire to have access to the skb_gso_validate_network_len(), I'd
> keep that behind the flag then, but would drop the skb_headlen(skb) + len_diff
> case given the mentioned case on rx where it would yield misleading results to
> users that might be unintuitive & hard to debug.
Okay, I will update the patch, and drop those lines.
> >> I also don't see the flag being used anywhere in your selftests, so I presume
> >> not as otherwise you would have added an example there?
> >
> > I'm using the flag in the bpf-examples code[1], this is how I've tested
> > the code path.
> >
> > I've not found a way to generate GSO packet via the selftests
> > infrastructure via bpf_prog_test_run_xattr(). I'm
> >
> > [1] https://github.com/xdp-project/bpf-examples/blob/master/MTU-tests/tc_mtu_enforce.c
>
> Haven't checked but likely something as prog_tests/skb_ctx.c might not be sufficient
> to pass it into the helper. For real case you might need a netns + veth setup like
> some of the other tests are doing and then generating TCP stream from one end to the
> other.
I have looked at prog_tests/skb_ctx.c and (as you say yourself) this is
not sufficient. I can look into creating a netns+veth setup, but I
will appreciate if we can merge this patchset to make forward progress,
as I'm sure the netns+veth setup will require its own round of nitpicking.
I have created netns+veth test scripts before (see test_xdp_vlan.sh),
but my experience is that people/maintainers forget/don't to run these
separate shell scripts. Thus, if I create a netns+veth test, then I
will prefer if I can integrate this into the "test_progs", as I know
that will be run by people/maintainers.
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer
next prev parent reply other threads:[~2021-01-18 11:07 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
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 [this message]
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=20210118120459.4a7ac2e1@carbon \
--to=brouer@redhat.com \
--cc=alexei.starovoitov@gmail.com \
--cc=borkmann@iogearbox.net \
--cc=bpf@vger.kernel.org \
--cc=colrack@gmail.com \
--cc=daniel@iogearbox.net \
--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).