From: "Toke Høiland-Jørgensen" <toke@kernel.org>
To: Florian Westphal <fw@strlen.de>
Cc: Florian Westphal <fw@strlen.de>,
bpf@vger.kernel.org, netfilter-devel@vger.kernel.org
Subject: Re: [RFC] bpf: add bpf_link support for BPF_NETFILTER programs
Date: Mon, 30 Jan 2023 22:10:45 +0100 [thread overview]
Message-ID: <87o7qfwwx6.fsf@toke.dk> (raw)
In-Reply-To: <20230130180115.GB12902@breakpoint.cc>
Florian Westphal <fw@strlen.de> writes:
> Toke Høiland-Jørgensen <toke@kernel.org> wrote:
>> > Is BPF_LINK the right place? Hook gets removed automatically if the calling program
>> > exits, afaict this is intended.
>>
>> Yes, this is indeed intended for bpf_link. This plays well with
>> applications that use the API and stick around (because things get
>> cleaned up after them automatically even if they crash, say), but it
>> doesn't work so well for programs that don't (which, notably, includes
>> command line utilities like 'nft').
>
> Right, but I did not want to create a dependency on nfnetlink or
> nftables netlink right from the start.
Dependency how? For userspace consumers, you mean?
>> For XDP and TC users can choose between bpf_link and netlink for
>> attachment and get one of the two semantics (goes away on close or stays
>> put). Not sure if it would make sense to do the same for nftables?
>
> For nftables I suspect that, if nft can emit bpf, it would make sense to
> pass the bpf descriptor together with nftables netlink, i.e. along with
> the normal netlink data.
>
> nftables kernel side would then know to use the bpf prog for the
> datapath instead of the interpreter and could even fallback to
> interpreter.
>
> But for the raw hook use case that Alexei and Daniel preferred (cf.
> initial proposal to call bpf progs from nf_tables interpreter) I think
> that there should be no nftables dependency.
>
> I could add a new nfnetlink subtype for nf-bpf if bpf_link is not
> appropriate as an alternative.
I don't think there's anything wrong with bpf_link as an initial
interface at least. I just think it should (eventually) be possible to
load a BPF-based firewall from the command line via this interface,
without having to resort to pinning. There was some talk about adding
this as a mode to the bpf_link interface itself at some point, but that
never materialised (probably because the need is not great since the
netlink interface serves this purpose for TC/XDP).
>> > Things like nf_hook_state->in (net_device) could then be exposed via
>> > kfuncs.
>>
>> Right, so like:
>>
>> state = bpf_nf_get_hook_state(ctx); ?
>>
>> Sounds OK to me.
>
> Yes, something like that. Downside is that the nf_hook_state struct
> is no longer bound by any abi contract, but as I understood it thats
> fine.
Well, there's an ongoing discussion about what, if any, should be the
expectations around kfunc stability:
https://lore.kernel.org/r/20230117212731.442859-1-toke@redhat.com
I certainly don't think it's problematic for a subsystem to give *more*
stability guarantees than BPF core. I mean, if you want the kfunc
interface to be stable you just... don't change it? :)
>> > nf_hook_run_bpf() (c-function that creates the program context and
>> > calls the real bpf prog) would be "updated" to use the bpf dispatcher to
>> > avoid the indirect call overhead.
>>
>> What 'bpf dispatcher' are you referring to here? We have way too many
>> things with that name :P
>
> I meant 'DEFINE_BPF_DISPATCHER(nf_user_progs);'
Ah, right. Yeah, that can definitely be added later!
-Toke
next prev parent reply other threads:[~2023-01-30 21:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-30 15:04 [RFC] bpf: add bpf_link support for BPF_NETFILTER programs Florian Westphal
2023-01-30 17:38 ` Toke Høiland-Jørgensen
2023-01-30 18:01 ` Florian Westphal
2023-01-30 21:10 ` Toke Høiland-Jørgensen [this message]
2023-01-30 21:44 ` Alexei Starovoitov
2023-01-31 14:18 ` Florian Westphal
2023-01-31 16:19 ` Toke Høiland-Jørgensen
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=87o7qfwwx6.fsf@toke.dk \
--to=toke@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.