Skip to content

Simplify netfilter and network namespaces (take 2)

Eric W. Biederman netdev netfilter-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest43 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/43netfilter: Kill unused copies of RCV_SKB_FAILnet/netfilter/nfnetlink_log.c net/netfilter/nfnetlink_queue_core.c+0 -40 replies
2/43netfilter: Pass struct net into the netfilter hooksinclude/linux/netfilter.h include/linux/netfilter_ingress.h net/bridge/br_forward.c +27 more+190 -1510 replies
3/43netfilter: Use nf_hook_state.netnet/bridge/netfilter/ebtable_filter.c net/bridge/netfilter/ebtable_nat.c net/ipv4/netfilter/arptable_filter.c +18 more+41 -580 replies
4/43ebtables: Simplify the arguments to ebt_do_tableinclude/linux/netfilter_bridge/ebtables.h net/bridge/netfilter/ebtable_broute.c net/bridge/netfilter/ebtable_filter.c +2 more+20 -190 replies
5/43inet netfilter: Remove hook from ip6t_do_table, arp_do_table, ipt_do_tableinclude/linux/netfilter_arp/arp_tables.h include/linux/netfilter_ipv4/ip_tables.h include/linux/netfilter_ipv6/ip6_tables.h +14 more+25 -410 replies
6/43inet netfilter: Prefer state->hook to ops->hooknumnet/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c net/ipv4/netfilter/nf_defrag_ipv4.c net/ipv4/netfilter/nf_nat_l3proto_ipv4.c +3 more+21 -210 replies
7/43nftables: kill nft_pktinfo.opsinclude/net/netfilter/nf_tables.h include/net/netfilter/nf_tables_ipv4.h include/net/netfilter/nf_tables_ipv6.h +20 more+52 -620 replies
8/43tc: Simplify em_ipset_matchnet/sched/em_ipset.c+2 -20 replies
9/43x_tables: Pass struct net in xt_action_paraminclude/linux/netfilter/x_tables.h include/net/netfilter/nf_tables.h net/bridge/netfilter/ebtables.c +5 more+9 -00 replies
10/43x_tables: Use par->net instead of computing from the passed net devicesnet/bridge/netfilter/ebt_log.c net/bridge/netfilter/ebt_nflog.c net/ipv4/netfilter/ipt_SYNPROXY.c +15 more+45 -630 replies
11/43nftables: Pass struct net in nft_pktinfoinclude/net/netfilter/nf_tables.h+2 -10 replies
12/43nf_tables: Use pkt->net instead of computing net from the passed net_devicesnet/bridge/netfilter/nft_reject_bridge.c net/ipv6/netfilter/nft_reject_ipv6.c net/netfilter/nf_tables_core.c +2 more+14 -190 replies
13/43nf_conntrack: Add a struct net parameter to l4_pkt_to_tupleinclude/net/netfilter/nf_conntrack.h include/net/netfilter/nf_conntrack_core.h include/net/netfilter/nf_conntrack_l4proto.h +12 more+23 -170 replies
14/43ipv4: Pass struct net into ip_defrag and ip_check_defragdrivers/net/macvlan.c include/net/ip.h net/ipv4/ip_fragment.c +4 more+20 -190 replies
15/43ipv6: Pass struct net into nf_ct_frag6_gatherinclude/net/netfilter/ipv6/nf_defrag_ipv6.h net/ipv6/netfilter/nf_conntrack_reasm.c net/ipv6/netfilter/nf_defrag_ipv6_hooks.c+4 -50 replies
16/43net: include missing headers in net/net_namespace.hinclude/net/net_namespace.h+2 -00 replies
17/43netfilter: use forward declaration instead of including linux/proc_fs.hinclude/net/netns/netfilter.h net/netfilter/nf_synproxy_core.c+2 -10 replies
18/43netfilter: don't pull include/linux/netfilter.h from netns headersinclude/linux/netfilter.h include/linux/netfilter_defs.h include/net/netns/netfilter.h +3 more+16 -70 replies
19/43ipvs: Read hooknum from state rather than ops->hooknumnet/netfilter/ipvs/ip_vs_core.c+8 -80 replies
20/43netfilter: Pass priv instead of nf_hook_ops to netfilter hooksinclude/linux/netfilter.h include/net/netfilter/nf_nat_l3proto.h include/net/netfilter/nf_tables.h +38 more+155 -1570 replies
21/43netfilter: Add a network namespace Kconfig conflictinit/Kconfig+1 -00 replies
22/43netfilter: Add a struct net parameter to nf_register_hook[s]include/linux/netfilter.h net/bridge/br_netfilter.c net/bridge/netfilter/ebtable_filter.c +18 more+32 -240 replies
23/43netfilter: Add a struct net parameter to nf_unregister_hook[s]include/linux/netfilter.h net/bridge/br_netfilter.c net/bridge/netfilter/ebtable_filter.c +16 more+30 -290 replies
24/43netfilter: Make the netfilter hooks per network namespaceinclude/linux/netfilter.h include/net/netns/netfilter.h net/netfilter/core.c+17 -160 replies
25/43netfilter: Make nf_hook_ops just a parameter structureinclude/linux/netfilter.h include/net/netfilter/nf_queue.h net/netfilter/core.c +2 more+80 -470 replies
26/43netfitler: Remove spurios included of netfilter.hdrivers/net/hamradio/bpqether.c drivers/net/ppp/pptp.c drivers/net/wan/lapbether.c +9 more+0 -150 replies
27/43x_tables: Add magical hook registration in the common caseinclude/linux/netfilter/x_tables.h net/ipv4/netfilter/arptable_filter.c net/netfilter/x_tables.c+75 -10 replies
28/43x_tables: Where possible convert to the new hook registration methodnet/ipv4/netfilter/arptable_filter.c net/ipv4/netfilter/iptable_filter.c net/ipv4/netfilter/iptable_mangle.c +6 more+27 -1720 replies
29/43x_tables: Kill xt_[un]hook_linkinclude/linux/netfilter/x_tables.h net/netfilter/x_tables.c+0 -570 replies
30/43x_tables: Update ip?table_nat to register their hooks in all network namespacesnet/ipv4/netfilter/iptable_nat.c net/ipv6/netfilter/ip6table_nat.c+24 -360 replies
31/43netfilter: nf_tables: adapt it to pernet hooksnet/netfilter/nf_tables_api.c+6 -20 replies
32/43netfilter: ipt_CLUSTERIP: adapt it to support pernet hooksnet/ipv4/netfilter/ipt_CLUSTERIP.c+7 -70 replies
33/43netfilter: ebtables: adapt the filter and nat table to pernet hooksnet/bridge/netfilter/ebtable_filter.c net/bridge/netfilter/ebtable_nat.c+25 -240 replies
34/43netfilter: bridge: adapt it to pernet hooksnet/bridge/br_netfilter.c+16 -20 replies
35/43ipvs: Register netfilter hooks in all network namespacesnet/netfilter/ipvs/ip_vs_core.c+8 -100 replies
36/43netfilter: nf_conntract: Register netfilter hooks in all network namespacesnet/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c+23 -230 replies
37/43netfilter: nf_defrag: Register netfilter hooks in all network namespacesnet/ipv4/netfilter/nf_defrag_ipv4.c net/ipv6/netfilter/nf_defrag_ipv6_hooks.c+36 -60 replies
38/43netfilter: synproxy: Register netfilter hooks in all network namespacesnet/ipv4/netfilter/ipt_SYNPROXY.c net/ipv6/netfilter/ip6t_SYNPROXY.c+40 -80 replies
39/43selinux: adapt it to pernet hookssecurity/selinux/hooks.c+18 -30 replies
40/43smack: adapt it to pernet hookssecurity/smack/smack_netfilter.c+16 -20 replies
41/43netfilter: Remove the network namespace Kconfig conflictinit/Kconfig+0 -10 replies
42/43netfilter bridge: Make the sysctl knobs per network namespaceinclude/net/netns/netfilter.h net/bridge/br_netfilter.c+103 -590 replies
43/43netfilter: Skip unnecessary calls to synchronize_netnet/netfilter/core.c+3 -12 replies

Reviews trailers per patch

None of the 43 patches has a Reviewed-by or Acked-by.

PatchPablo Neira Ayuso
1/43
2/43
3/43
4/43
5/43
6/43
7/43
8/43
9/43
10/43
11/43
12/43
13/43
14/43
15/43
16/43
17/43
18/43
19/43
20/43
21/43
22/43
23/43
24/43Inspired-by
25/43
26/43
27/43
28/43
29/43
30/43
31/43
32/43
33/43
34/43
35/43
36/43
37/43
38/43Inspired-by
39/43
40/43
41/43
42/43
43/43

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH net-next 00/43] Simplify netfilter and network namespaces (take 2)

While looking into what it would take to route packets out to network devices in other network namespaces I started looking at the netfilter hooks, and there is a lot of nasty code to figure out which network namespace to filter the packets in.

Passing the network namespace into the netfilter hooks is a significant simplication in the code, and worth it as the first thing most netfilter hooks do is compute the network namespace.

I collided with Pablos work on per network namespace netfilter hooks the first time I submitted his changes, so now this patchset includes a per network namespace nftable hooks. Inspired by Pablos work but largely rewritten to fix and avoid the bugs I was finding in Pablos work to register the netfilter hooks per network namespace.

These per network namespace netfilter hooks fix a long standing bug in nftables, where packets passing through nftables would be run against the nftables configuration of every network namespace.

I have noticed what appears to be one more bug in nftables. Today the nf_queue code takes a module reference count to prevent the netfilter hook that it stops at from being unregistered. As it is the module initialization and module cleanup code that call nf_unregister_hook[s] in everything but nftables this works. Unfortunately it appears that someone can cause a packet to be queued, delete the nftable chain that caused the queueing and then cause the packet to be reinjected. So it looks like nfqnl_rcv_dev_event is needed for netfilter hook unregistration.

The first group of changes roots out all of the very weird network namespace computation logic (except for the code in ipvs) and fixes it. I really don't like how the code has been essentially guessing which network namespace to use.

Probably the worst guessing is in ipvs in the function skb_net. I have some preliminary changes to fix ipvs but they are not quite ready yet. Cleaning up ipvs enough that I can kill skb_net is on my short list.

There are a few extra cleanups in the first group of changes sprinkled in as I noticed a few other things as I was sorting out the network namespace computation logic.

There rest of the changes are based on Pablos per network namespace netfilter hook work and include related cleanups and simplifications. The most non-obvious detail were the necessary header file cleanups.

The changes where I started with Pablos patches in some cases the credits get a little weird and the descriptions are a little weaker than I would like but overall I think it is all close enough.

Eric W. Biederman (36):
ipvs: Read hooknum from state rather than ops->hooknum
netfilter: Pass priv instead of nf_hook_ops to netfilter hooks
netfilter: Add a network namespace Kconfig conflict
netfilter: Add a struct net parameter to nf_register_hook[s]
netfilter: Add a struct net parameter to nf_unregister_hook[s]
netfilter: Make the netfilter hooks per network namespace
netfilter: Make nf_hook_ops just a parameter structure
netfitler: Remove spurios included of netfilter.h
x_tables: Add magical hook registration in the common case
x_tables: Where possible convert to the new hook registration method
x_tables: Kill xt_[un]hook_link
x_tables: Update ip?table_nat to register their hooks in all network namespaces
netfilter: bridge: adapt it to pernet hooks
ipvs: Register netfilter hooks in all network namespaces
netfilter: nf_conntract: Register netfilter hooks in all network namespaces
netfilter: nf_defrag: Register netfilter hooks in all network namespaces
netfilter: synproxy: Register netfilter hooks in all network namespaces
smack: adapt it to pernet hooks
netfilter bridge: Make the sysctl knobs per network namespace
netfilter: Skip unnecessary calls to synchronize_net
netfilter: Kill unused copies of RCV_SKB_FAIL
netfilter: Pass struct net into the netfilter hooks
netfilter: Use nf_hook_state.net
ebtables: Simplify the arguments to ebt_do_table
inet netfilter: Remove hook from ip6t_do_table, arp_do_table, ipt_do_table inet netfilter: Prefer state->hook to ops->hooknum
nftables: kill nft_pktinfo.ops
tc: Simplify em_ipset_match
x_tables: Pass struct net in xt_action_param
x_tables: Use par->net instead of computing from the passed net devices
nftables: Pass struct net in nft_pktinfo
nf_tables: Use pkt->net instead of computing net from the passed net_devices
nf_conntrack: Add a struct net parameter to l4_pkt_to_tuple
ipv4: Pass struct net into ip_defrag and ip_check_defrag
ipv6: Pass struct net into nf_ct_frag6_gather
netfilter: Remove the network namespace Kconfig conflict

Pablo Neira Ayuso (7):
net: include missing headers in net/net_namespace.h
netfilter: use forward declaration instead of including linux/proc_fs.h
netfilter: don't pull include/linux/netfilter.h from netns headers
netfilter: nf_tables: adapt it to pernet hooks
netfilter: ipt_CLUSTERIP: adapt it to support pernet hooks
netfilter: ebtables: adapt the filter and nat table to pernet hooks
selinux: adapt it to pernet hooks

Eric