Message ID | 20221224000402.476079-1-qde@naccy.de (mailing list archive) |
---|---|
Headers | show |
Series | bpfilter | expand |
On Sat, Dec 24, 2022 at 01:03:46AM +0100, Quentin Deslandes wrote: > > Due to poor hardware availability on my side, I've not been able to > benchmark those changes. I plan to get some numbers for the next iteration. Yeah. Performance numbers would be my main question :) > FORWARD filter chain is now supported, however, it's attached to > TC INGRESS along with INPUT filter chain. This is due to XDP not supporting > multiple programs to be attached. I could generate a single program > out of both INPUT and FORWARD chains, but that would prevent another > BPF program to be attached to the interface anyway. If a solution > exists to attach both those programs to XDP while allowing for other > programs to be attached, it requires more investigation. In the meantime, > INPUT and FORWARD filtering is supported using TC. I think we can ignore XDP chaining for now assuming that Daniel's bpf_link-tc work will be applicable to XDP as well, so we'll have a simple chaining for XDP eventually. As far as attaching to TC... I think it would be great to combine bpfilter codegen and attach to Florian's bpf hooks exactly at netfilter. See https://git.breakpoint.cc/cgit/fw/nf-next.git/commit/?h=nf_hook_jit_bpf_29&id=0c1ec06503cb8a142d3ad9f760b72d94ea0091fa With nf_hook_ingress() calling either into classic iptable or into bpf_prog_run_nf which is either generated by Florian's optimizer of nf chains or into bpfilter generated code would be ideal.
Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote: > codegen and attach to Florian's bpf hooks exactly at netfilter. > See > https://git.breakpoint.cc/cgit/fw/nf-next.git/commit/?h=nf_hook_jit_bpf_29&id=0c1ec06503cb8a142d3ad9f760b72d94ea0091fa FWIW I plan to submit this patchset for 6.2.
Quentin Deslandes <qde@naccy.de> wrote: > The patchset is based on the patches from David S. Miller [1], > Daniel Borkmann [2], and Dmitrii Banshchikov [3]. > > Note: I've partially sent this patchset earlier due to a > mistake on my side, sorry for then noise. > > 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. Beside that the code generation > is introduced. > > The first version of the code generation supports only "inline" > mode - all chains and their rules emit instructions in linear > approach. > > Things that are not implemented yet: > 1) The process of switching from the previous BPF programs to the > new set isn't atomic. You can't make this atomic from userspace perspective, the get/setsockopt API of iptables uses a read-modify-write model. Tentatively I'd try to extend libnftnl and generate bpf code there, since its used by both iptables(-nft) and nftables we'd automatically get support for both. I was planning to look into "attach bpf progs to raw netfilter hooks" in Q1 2023, once the initial nf-bpf-codegen is merged.
Le 27/12/2022 à 19:22, Alexei Starovoitov a écrit : > On Sat, Dec 24, 2022 at 01:03:46AM +0100, Quentin Deslandes wrote: >> >> Due to poor hardware availability on my side, I've not been able to >> benchmark those changes. I plan to get some numbers for the next iteration. > > Yeah. Performance numbers would be my main question :) Hardware is on the way! :) >> FORWARD filter chain is now supported, however, it's attached to >> TC INGRESS along with INPUT filter chain. This is due to XDP not supporting >> multiple programs to be attached. I could generate a single program >> out of both INPUT and FORWARD chains, but that would prevent another >> BPF program to be attached to the interface anyway. If a solution >> exists to attach both those programs to XDP while allowing for other >> programs to be attached, it requires more investigation. In the meantime, >> INPUT and FORWARD filtering is supported using TC. > > I think we can ignore XDP chaining for now assuming that Daniel's bpf_link-tc work > will be applicable to XDP as well, so we'll have a simple chaining > for XDP eventually. > > As far as attaching to TC... I think it would be great to combine bpfilter > codegen and attach to Florian's bpf hooks exactly at netfilter. > See > https://git.breakpoint.cc/cgit/fw/nf-next.git/commit/?h=nf_hook_jit_bpf_29&id=0c1ec06503cb8a142d3ad9f760b72d94ea0091fa > With nf_hook_ingress() calling either into classic iptable or into bpf_prog_run_nf > which is either generated by Florian's optimizer of nf chains or into > bpfilter generated code would be ideal. That sounds interesting. If my understanding is correct, Florian's work doesn't yet allow for userspace-generated programs to be attached, which will be required for bpfilter.
Le 03/01/2023 à 12:45, Florian Westphal a écrit : > Quentin Deslandes <qde@naccy.de> wrote: >> The patchset is based on the patches from David S. Miller [1], >> Daniel Borkmann [2], and Dmitrii Banshchikov [3]. >> >> Note: I've partially sent this patchset earlier due to a >> mistake on my side, sorry for then noise. >> >> 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. Beside that the code generation >> is introduced. >> >> The first version of the code generation supports only "inline" >> mode - all chains and their rules emit instructions in linear >> approach. >> >> Things that are not implemented yet: >> 1) The process of switching from the previous BPF programs to the >> new set isn't atomic. > > You can't make this atomic from userspace perspective, the > get/setsockopt API of iptables uses a read-modify-write model. This refers to updating the programs from bpfilter's side. It won't be atomic from iptables point of view, but currently bpfilter will remove the program associated to a table, before installing the new one. This means packets received in between those operations are not filtered. I assume a better solution is possible. > Tentatively I'd try to extend libnftnl and generate bpf code there, > since its used by both iptables(-nft) and nftables we'd automatically > get support for both. That's one of the option, this could also remain in the kernel tree or in a dedicated git repository. I don't know which one would be the best, I'm open to suggestions. > I was planning to look into "attach bpf progs to raw netfilter hooks" > in Q1 2023, once the initial nf-bpf-codegen is merged. Is there any plan to support non raw hooks? That's mainly out of curiosity, I don't even know whether that would be a good thing or not.
Quentin Deslandes <qde@naccy.de> wrote: > That sounds interesting. If my understanding is correct, Florian's > work doesn't yet allow for userspace-generated programs to be attached, > which will be required for bpfilter. Yes, but I started working on the attachment side. It doesn't depend on the nf-bpf generator patch set. I think I can share PoC/RFC draft next week.
Quentin Deslandes <qde@naccy.de> wrote: > Le 03/01/2023 à 12:45, Florian Westphal a écrit : > > You can't make this atomic from userspace perspective, the > > get/setsockopt API of iptables uses a read-modify-write model. > > This refers to updating the programs from bpfilter's side. It won't > be atomic from iptables point of view, but currently bpfilter will > remove the program associated to a table, before installing the new > one. This means packets received in between those operations are > not filtered. I assume a better solution is possible. Ah, I see, thanks. > > Tentatively I'd try to extend libnftnl and generate bpf code there, > > since its used by both iptables(-nft) and nftables we'd automatically > > get support for both. > > That's one of the option, this could also remain in the kernel > tree or in a dedicated git repository. I don't know which one would > be the best, I'm open to suggestions. I can imagine that this will see a flurry of activity in the early phase so I think a 'semi test repo' makes sense. Provideded license allows this, useable bits and pieces can then be grafted on to libnftnl (or iptables or whatever). > > I was planning to look into "attach bpf progs to raw netfilter hooks" > > in Q1 2023, once the initial nf-bpf-codegen is merged. > > Is there any plan to support non raw hooks? That's mainly out > of curiosity, I don't even know whether that would be a good thing > or not. Not sure what 'non raw hook' is. Idea was to expose 1. protcocol family 2. hook number (prerouting, input etc) 3. priority to userspace via bpf syscall/bpf link. userspace would then provide the above info to kernel via bpf(... BPF_LINK_CREATE ) which would then end up doing: -------------- h.hook = nf_hook_run_bpf; // wrapper to call BPF_PROG_RUN h.priv = prog; // the bpf program to run h.pf = attr->netfilter.pf; h.priority = attr->netfilter.priority; h.hooknum = attr->netfilter.hooknum; nf_register_net_hook(net, &h); -------------- After that nf_hook_slow() calls the bpf program just like any other of the netfilter hooks. Does that make sense or did you have something else in mind?
On Thu, Jan 12, 2023 at 04:17:28AM +0100, Florian Westphal wrote: > Quentin Deslandes <qde@naccy.de> wrote: > > Le 03/01/2023 à 12:45, Florian Westphal a écrit : > > > You can't make this atomic from userspace perspective, the > > > get/setsockopt API of iptables uses a read-modify-write model. > > > > This refers to updating the programs from bpfilter's side. It won't > > be atomic from iptables point of view, but currently bpfilter will > > remove the program associated to a table, before installing the new > > one. This means packets received in between those operations are > > not filtered. I assume a better solution is possible. > > Ah, I see, thanks. > > > > Tentatively I'd try to extend libnftnl and generate bpf code there, > > > since its used by both iptables(-nft) and nftables we'd automatically > > > get support for both. > > > > That's one of the option, this could also remain in the kernel > > tree or in a dedicated git repository. I don't know which one would > > be the best, I'm open to suggestions. > > I can imagine that this will see a flurry of activity in the early > phase so I think a 'semi test repo' makes sense. > > Provideded license allows this, useable bits and pieces can then > be grafted on to libnftnl (or iptables or whatever). > > > > I was planning to look into "attach bpf progs to raw netfilter hooks" > > > in Q1 2023, once the initial nf-bpf-codegen is merged. > > > > Is there any plan to support non raw hooks? That's mainly out > > of curiosity, I don't even know whether that would be a good thing > > or not. > > Not sure what 'non raw hook' is. Idea was to expose > > 1. protcocol family > 2. hook number (prerouting, input etc) > 3. priority > > to userspace via bpf syscall/bpf link. > > userspace would then provide the above info to kernel via > bpf(... BPF_LINK_CREATE ) > > which would then end up doing: > -------------- > h.hook = nf_hook_run_bpf; // wrapper to call BPF_PROG_RUN > h.priv = prog; // the bpf program to run > h.pf = attr->netfilter.pf; > h.priority = attr->netfilter.priority; > h.hooknum = attr->netfilter.hooknum; > > nf_register_net_hook(net, &h); > -------------- > > After that nf_hook_slow() calls the bpf program just like any > other of the netfilter hooks. > > Does that make sense or did you have something else in mind? Sounds good to me. I thought you were referring to hooks available for the RAW table (as in `iptables --table raw...`). Thanks, Quentin