From: Dmitrii Banshchikov <me@ubique.spb.ru>
To: Yonghong Song <yhs@fb.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, davem@davemloft.net,
daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com,
songliubraving@fb.com, john.fastabend@gmail.com,
kpsingh@kernel.org, netdev@vger.kernel.org, rdna@fb.com
Subject: Re: [PATCH bpf-next v1 00/10] bpfilter
Date: Thu, 10 Jun 2021 17:36:55 +0400 [thread overview]
Message-ID: <20210610133655.d25say2ialzhtdhq@amnesia> (raw)
In-Reply-To: <4dd3feeb-8b4a-0bdb-683e-c5c5643b1195@fb.com>
On Wed, Jun 09, 2021 at 05:50:13PM -0700, Yonghong Song wrote:
>
>
> On 6/3/21 3:14 AM, Dmitrii Banshchikov wrote:
> > The patchset is based on the patches from David S. Miller [1] and
> > Daniel Borkmann [2].
> >
> > The main goal of the patchset is to prepare bpfilter for
> > iptables' configuration blob parsing and code generation.
> >
> > The patchset introduces data structures and code for matches,
> > targets, rules and tables.
> >
> > The current version misses handling of counters. Postpone its
> > implementation until the code generation phase as it's not clear
> > yet how to better handle them.
> >
> > Beside that there is no support of net namespaces at all.
> >
> > In the next iteration basic code generation shall be introduced.
> >
> > The rough plan for the code generation.
> >
> > It seems reasonable to assume that the first rules should cover
> > most of the packet flow. This is why they are critical from the
> > performance point of view. At the same time number of user
> > defined rules might be pretty large. Also there is a limit on
> > size and complexity of a BPF program introduced by the verifier.
> >
> > There are two approaches how to handle iptables' rules in
> > generated BPF programs.
> >
> > The first approach is to generate a BPF program that is an
> > equivalent to a set of rules on a rule by rule basis. This
> > approach should give the best performance. The drawback is the
> > limitation from the verifier on size and complexity of BPF
> > program.
> >
> > The second approach is to use an internal representation of rules
> > stored in a BPF map and use bpf_for_each_map_elem() helper to
> > iterate over them. In this case the helper's callback is a BPF
> > function that is able to process any valid rule.
> >
> > Combination of the two approaches should give most of the
> > benefits - a heuristic should help to select a small subset of
> > the rules for code generation on a rule by rule basis. All other
> > rules are cold and it should be possible to store them in an
> > internal form in a BPF map. The rules will be handled by
> > bpf_for_each_map_elem(). This should remove the limit on the
> > number of supported rules.
>
> Agree. A bpf program inlines some hot rule handling and put
> the rest in for_each_map_elem() sounds reasonable to me.
>
> >
> > During development it was useful to use statically linked
> > sanitizers in bpfilter usermode helper. Also it is possible to
> > use fuzzers but it's not clear if it is worth adding them to the
> > test infrastructure - because there are no other fuzzers under
> > tools/testing/selftests currently.
> >
> > Patch 1 adds definitions of the used types.
> > Patch 2 adds logging to bpfilter.
> > Patch 3 adds bpfilter header to tools
> > Patch 4 adds an associative map.
> > Patches 5/6/7/8 add code for matches, targets, rules and table.
> > Patch 9 handles hooked setsockopt(2) calls.
> > Patch 10 uses prepared code in main().
> >
> > Here is an example:
> > % dmesg | tail -n 2
> > [ 23.636102] bpfilter: Loaded bpfilter_umh pid 181
> > [ 23.658529] bpfilter: started
> > % /usr/sbin/iptables-legacy -L -n
>
> So this /usr/sbin/iptables-legacy is your iptables variant to
> translate iptable command lines to BPFILTER_IPT_SO_*,
> right? It could be good to provide a pointer to the source
> or binary so people can give a try.
>
> I am not an expert in iptables. Reading codes, I kind of
> can grasp the high-level ideas of the patch, but probably
> Alexei or Daniel can review some details whether the
> design is sufficient to be an iptable replacement.
>
The goal of a complete iptables replacement is too ambigious for
the moment - because existings hooks and helpers don't cover all
required functionality.
A more achievable goal is to have something simple that could
replace a significant part of use cases for filter table.
Having something simple that would work as a stateless firewall
and provide some performance benefits is a good start. For more
complex scenarios there is a safe fallback to the existing
implementation.
>
> > Chain INPUT (policy ACCEPT)
> > target prot opt source destination
> >
> > Chain FORWARD (policy ACCEPT)
> > target prot opt source destination
> >
> [...]
--
Dmitrii Banshchikov
next prev parent reply other threads:[~2021-06-10 13:38 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-03 10:14 [PATCH bpf-next v1 00/10] bpfilter Dmitrii Banshchikov
2021-06-03 10:14 ` [PATCH bpf-next v1 01/10] bpfilter: Add types for usermode helper Dmitrii Banshchikov
2021-06-03 10:14 ` [PATCH bpf-next v1 02/10] bpfilter: Add logging facility Dmitrii Banshchikov
2021-06-03 10:14 ` [PATCH bpf-next v1 03/10] tools: Add bpfilter usermode helper header Dmitrii Banshchikov
2021-06-08 16:20 ` Yonghong Song
2021-06-09 10:07 ` Dmitrii Banshchikov
2021-06-03 10:14 ` [PATCH bpf-next v1 04/10] bpfilter: Add map container Dmitrii Banshchikov
2021-06-03 10:14 ` [PATCH bpf-next v1 05/10] bpfilter: Add struct match Dmitrii Banshchikov
2021-06-03 10:14 ` [PATCH bpf-next v1 06/10] bpfilter: Add struct target Dmitrii Banshchikov
2021-06-03 16:47 ` Dmitrii Banshchikov
2021-06-03 10:14 ` [PATCH bpf-next v1 07/10] bpfilter: Add struct rule Dmitrii Banshchikov
2021-06-10 0:30 ` Yonghong Song
2021-06-10 13:16 ` Dmitrii Banshchikov
2021-06-03 10:14 ` [PATCH bpf-next v1 08/10] bpfilter: Add struct table Dmitrii Banshchikov
2021-06-03 10:14 ` [PATCH bpf-next v1 09/10] bpfilter: Add handling of setsockopt() calls Dmitrii Banshchikov
2021-06-03 10:14 ` [PATCH bpf-next v1 10/10] bpfilter: Handle setsockopts Dmitrii Banshchikov
2021-06-10 0:50 ` [PATCH bpf-next v1 00/10] bpfilter Yonghong Song
2021-06-10 13:36 ` Dmitrii Banshchikov [this message]
2021-06-10 13:58 ` Daniel Borkmann
2021-06-10 14:56 ` Yonghong Song
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=20210610133655.d25say2ialzhtdhq@amnesia \
--to=me@ubique.spb.ru \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rdna@fb.com \
--cc=songliubraving@fb.com \
--cc=yhs@fb.com \
/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