netfilter: x_tables: remove ipt_unregister_table
Subsystems (3)
Florian Westphal
maintainerv2 cover netfilter: x_tables: remove ipt_unregister_table
This change removes all xt_table pointers from struct net.
v2: fix "no previous prototype for 'ipt_unregister_table'" warning in patch 2.
The various ip(6)table_foo incarnations are updated to expect that the table is passed as 'void *priv' argument that netfilter core passes to the hook functions.
This reduces the struct net size by 2 cachelines on x86_64.
Florian Westphal (12):
netfilter: ebtables: remove the 3 ebtables pointers from struct net
netfilter: x_tables: remove ipt_unregister_table
netfilter: add xt_find_table
netfilter: iptables: unregister the tables by name
netfilter: ip6tables: unregister the tables by name
netfilter: arptables: unregister the tables by name
netfilter: x_tables: remove paranoia tests
netfilter: xt_nat: pass table to hookfn
netfilter: ip_tables: pass table pointer via nf_hook_ops
netfilter: arp_tables: pass table pointer via nf_hook_ops
netfilter: ip6_tables: pass table pointer via nf_hook_ops
netfilter: remove all xt_table anchors from struct net
include/linux/netfilter/x_tables.h | 4 ++ include/linux/netfilter_arp/arp_tables.h | 6 +- include/linux/netfilter_bridge/ebtables.h | 9 ++- include/linux/netfilter_ipv4/ip_tables.h | 9 +-- include/linux/netfilter_ipv6/ip6_tables.h | 9 +-- include/net/netns/ipv4.h | 10 ---- include/net/netns/ipv6.h | 9 --- include/net/netns/x_tables.h | 8 --- net/bridge/netfilter/ebtable_broute.c | 10 ++-- net/bridge/netfilter/ebtable_filter.c | 26 +++------ net/bridge/netfilter/ebtable_nat.c | 27 +++------ net/bridge/netfilter/ebtables.c | 42 ++++++++++---- net/ipv4/netfilter/arp_tables.c | 57 ++++++++++++------ net/ipv4/netfilter/arptable_filter.c | 17 ++---- net/ipv4/netfilter/ip_tables.c | 70 ++++++++++++++--------- net/ipv4/netfilter/iptable_filter.c | 17 ++---- net/ipv4/netfilter/iptable_mangle.c | 23 +++----- net/ipv4/netfilter/iptable_nat.c | 59 +++++++++++++------ net/ipv4/netfilter/iptable_raw.c | 17 ++---- net/ipv4/netfilter/iptable_security.c | 17 ++---- net/ipv6/netfilter/ip6_tables.c | 68 +++++++++++++--------- net/ipv6/netfilter/ip6table_filter.c | 17 ++---- net/ipv6/netfilter/ip6table_mangle.c | 24 +++----- net/ipv6/netfilter/ip6table_nat.c | 58 +++++++++++++------ net/ipv6/netfilter/ip6table_raw.c | 17 ++---- net/ipv6/netfilter/ip6table_security.c | 17 ++---- net/netfilter/x_tables.c | 18 ++++++ 27 files changed, 332 insertions(+), 333 deletions(-)
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 1/12 netfilter: ebtables: remove the 3 ebtables pointers from struct net
ebtables stores the table internal data (what gets passed to the ebt_do_table() interpreter) in struct net.
nftables keeps the internal interpreter format in pernet lists and passes it via the netfilter core infrastructure (priv pointer).
Do the same for ebtables: the nf_hook_ops are duplicated via kmemdup, then the ops->priv pointer is set to the table that is being registered.
After that, the netfilter core passes this table info to the hookfn.
This allows to remove the pointers from struct net.
Same pattern can be applied to ip/ip6/arptables.
--- include/linux/netfilter_bridge/ebtables.h | 9 +++-- include/net/netns/x_tables.h | 8 ----- net/bridge/netfilter/ebtable_broute.c | 10 +++--- net/bridge/netfilter/ebtable_filter.c | 26 +++++--------- net/bridge/netfilter/ebtable_nat.c | 27 +++++---------- net/bridge/netfilter/ebtables.c | 42 +++++++++++++++++------ 6 files changed, 58 insertions(+), 64 deletions(-)
include/linux/netfilter_bridge/ebtables.h +4 -5
@@ -100,6 +100,7 @@ struct ebt_table { unsigned int valid_hooks);/* the data used by the kernel */ struct ebt_table_info *private; +struct nf_hook_ops *ops;struct module *me; };
@@ -108,11 +109,9 @@ struct ebt_table {extern int ebt_register_table (struct net *net,const struct ebt_table *table, -const struct nf_hook_ops *ops, -struct ebt_table **res); -extern void ebt_unregister_table (struct net *net,struct ebt_table *table); -void ebt_unregister_table_pre_exit (struct net *net,const char *tablename, -const struct nf_hook_ops *ops); +const struct nf_hook_ops *ops); +extern void ebt_unregister_table (struct net *net,const char *tablename); +void ebt_unregister_table_pre_exit (struct net *net,const char *tablename);extern unsigned int ebt_do_table (struct sk_buff *skb,const struct nf_hook_state *state,struct ebt_table *table);
include/net/netns/x_tables.h +0 -8
@@ -5,16 +5,8 @@#include <linux/list.h> #include <linux/netfilter_defs.h> -struct ebt_table ; -struct netns_xt {bool notrack_deprecated_warning;bool clusterip_deprecated_warning; -#if defined(CONFIG_BRIDGE_NF_EBTABLES ) || \ - defined(CONFIG_BRIDGE_NF_EBTABLES_MODULE ) -struct ebt_table *broute_table; -struct ebt_table *frame_filter; -struct ebt_table *frame_nat; -#endif };#endif
net/bridge/netfilter/ebtable_broute.c +4 -6
@@ -66,8 +66,7 @@ static unsigned int ebt_broute(void *priv, struct sk_buff *skb,NFPROTO_BRIDGE , s->in,NULL ,NULL , s->net, NULL); - ret =ebt_do_table (skb, &state, state.net->xt.broute_table); - + ret =ebt_do_table (skb, &state, priv);if (ret !=NF_DROP )return ret;
@@ -101,18 +100,17 @@ static const struct nf_hook_ops ebt_ops_broute = {static int __net_init broute_net_init (struct net *net) { -return ebt_register_table (net, &broute_table, &ebt_ops_broute, - &net->xt.broute_table); +return ebt_register_table (net, &broute_table, &ebt_ops_broute); } static void __net_exit broute_net_pre_exit(struct net *net) { -ebt_unregister_table_pre_exit (net,"broute" , &ebt_ops_broute); +ebt_unregister_table_pre_exit (net,"broute" ); } static void __net_exit broute_net_exit(struct net *net) { -ebt_unregister_table (net, net->xt.broute_table); +ebt_unregister_table (net,"broute" ); }static struct pernet_operations broute_net_ops = {
net/bridge/netfilter/ebtable_filter.c +9 -17
@@ -59,34 +59,27 @@ static const struct ebt_table frame_filter = { };static unsigned int -ebt_in_hook (void *priv,struct sk_buff *skb, -const struct nf_hook_state *state) +ebt_filter_hook (void *priv,struct sk_buff *skb, +const struct nf_hook_state *state) { -return ebt_do_table (skb, state, state->net->xt.frame_filter); -} - -static unsigned int -ebt_out_hook (void *priv,struct sk_buff *skb, -const struct nf_hook_state *state) -{ -return ebt_do_table (skb, state, state->net->xt.frame_filter); +return ebt_do_table (skb, state, priv); }static const struct nf_hook_ops ebt_ops_filter[] = { { - .hook = ebt_in_hook, + .hook = ebt_filter_hook, .pf =NFPROTO_BRIDGE , .hooknum =NF_BR_LOCAL_IN , .priority =NF_BR_PRI_FILTER_BRIDGED , }, { - .hook = ebt_in_hook, + .hook = ebt_filter_hook, .pf =NFPROTO_BRIDGE , .hooknum =NF_BR_FORWARD , .priority =NF_BR_PRI_FILTER_BRIDGED , }, { - .hook = ebt_out_hook, + .hook = ebt_filter_hook, .pf =NFPROTO_BRIDGE , .hooknum =NF_BR_LOCAL_OUT , .priority =NF_BR_PRI_FILTER_OTHER ,
@@ -95,18 +88,17 @@ static const struct nf_hook_ops ebt_ops_filter[] = {static int __net_init frame_filter_net_init (struct net *net) { -return ebt_register_table (net, &frame_filter, ebt_ops_filter, - &net->xt.frame_filter); +return ebt_register_table (net, &frame_filter, ebt_ops_filter); } static void __net_exit frame_filter_net_pre_exit(struct net *net) { -ebt_unregister_table_pre_exit (net,"filter" , ebt_ops_filter); +ebt_unregister_table_pre_exit (net,"filter" ); } static void __net_exit frame_filter_net_exit(struct net *net) { -ebt_unregister_table (net, net->xt.frame_filter); +ebt_unregister_table (net,"filter" ); }static struct pernet_operations frame_filter_net_ops = {
net/bridge/netfilter/ebtable_nat.c +9 -18
@@ -58,35 +58,27 @@ static const struct ebt_table frame_nat = { .me = THIS_MODULE, }; -static unsigned int -ebt_nat_in (void *priv,struct sk_buff *skb, -const struct nf_hook_state *state) +static unsigned int ebt_nat_hook (void *priv,struct sk_buff *skb, +const struct nf_hook_state *state) { -return ebt_do_table (skb, state, state->net->xt.frame_nat); -} - -static unsigned int -ebt_nat_out (void *priv,struct sk_buff *skb, -const struct nf_hook_state *state) -{ -return ebt_do_table (skb, state, state->net->xt.frame_nat); +return ebt_do_table (skb, state, priv); }static const struct nf_hook_ops ebt_ops_nat[] = { { - .hook = ebt_nat_out, + .hook = ebt_nat_hook, .pf =NFPROTO_BRIDGE , .hooknum =NF_BR_LOCAL_OUT , .priority =NF_BR_PRI_NAT_DST_OTHER , }, { - .hook = ebt_nat_out, + .hook = ebt_nat_hook, .pf =NFPROTO_BRIDGE , .hooknum =NF_BR_POST_ROUTING , .priority =NF_BR_PRI_NAT_SRC , }, { - .hook = ebt_nat_in, + .hook = ebt_nat_hook, .pf =NFPROTO_BRIDGE , .hooknum =NF_BR_PRE_ROUTING , .priority =NF_BR_PRI_NAT_DST_BRIDGED ,
@@ -95,18 +87,17 @@ static const struct nf_hook_ops ebt_ops_nat[] = {static int __net_init frame_nat_net_init (struct net *net) { -return ebt_register_table (net, &frame_nat, ebt_ops_nat, - &net->xt.frame_nat); +return ebt_register_table (net, &frame_nat, ebt_ops_nat); } static void __net_exit frame_nat_net_pre_exit(struct net *net) { -ebt_unregister_table_pre_exit (net,"nat" , ebt_ops_nat); +ebt_unregister_table_pre_exit (net,"nat" ); } static void __net_exit frame_nat_net_exit(struct net *net) { -ebt_unregister_table (net, net->xt.frame_nat); +ebt_unregister_table (net,"nat" ); }static struct pernet_operations frame_nat_net_ops = {
net/bridge/netfilter/ebtables.c +32 -10
80 lines not on this page · raw message
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 2/12 netfilter: x_tables: remove ipt_unregister_table
In reply to Florian WestphalIts the same function as ipt_unregister_table_exit.
--- include/linux/netfilter_ipv4/ip_tables.h | 3 --- include/linux/netfilter_ipv6/ip6_tables.h | 2 -- net/ipv4/netfilter/ip_tables.c | 9 --------- net/ipv4/netfilter/iptable_nat.c | 2 +- net/ipv6/netfilter/ip6_tables.c | 9 --------- net/ipv6/netfilter/ip6table_nat.c | 2 +- 6 files changed, 2 insertions(+), 25 deletions(-)
include/linux/netfilter_ipv4/ip_tables.h +0 -3
@@ -31,9 +31,6 @@ void ipt_unregister_table_pre_exit(struct net *net, struct xt_table *table,void ipt_unregister_table_exit (struct net *net,struct xt_table *table); -void ipt_unregister_table (struct net *net,struct xt_table *table, -const struct nf_hook_ops *ops); -/* Standard entry. */ struct ipt_standard {struct ipt_entry entry;
include/linux/netfilter_ipv6/ip6_tables.h +0 -2
@@ -27,8 +27,6 @@ extern void *ip6t_alloc_initial_table(const struct xt_table *);int ip6t_register_table (struct net *net,const struct xt_table *table,const struct ip6t_replace *repl,const struct nf_hook_ops *ops,struct xt_table **res); -void ip6t_unregister_table (struct net *net,struct xt_table *table, -const struct nf_hook_ops *ops);void ip6t_unregister_table_pre_exit (struct net *net,struct xt_table *table,const struct nf_hook_ops *ops);void ip6t_unregister_table_exit (struct net *net,struct xt_table *table);
net/ipv4/netfilter/ip_tables.c +0 -9
@@ -1770,14 +1770,6 @@ void ipt_unregister_table_exit(struct net *net, struct xt_table *table)__ipt_unregister_table (net, table); } -void ipt_unregister_table (struct net *net,struct xt_table *table, -const struct nf_hook_ops *ops) -{ -if (ops) -ipt_unregister_table_pre_exit (net, table, ops); -__ipt_unregister_table (net, table); -} -/* Returns 1 if the type and code is matched by the range, 0 otherwise */ static inline bool icmp_type_code_match(u_int8_t test_type, u_int8_t min_code, u_int8_t max_code,
@@ -1924,7 +1916,6 @@ static void __exit ip_tables_fini(void) }EXPORT_SYMBOL (ipt_register_table); -EXPORT_SYMBOL (ipt_unregister_table);EXPORT_SYMBOL (ipt_unregister_table_pre_exit);EXPORT_SYMBOL (ipt_unregister_table_exit);EXPORT_SYMBOL (ipt_do_table);
net/ipv4/netfilter/iptable_nat.c +1 -1
@@ -105,7 +105,7 @@ static int __net_init iptable_nat_table_init(struct net *net) ret =ipt_nat_register_lookups (net);if (ret <0 ) { -ipt_unregister_table (net, net->ipv4.nat_table,NULL ); +ipt_unregister_table_exit (net, net->ipv4.nat_table); net->ipv4.nat_table =NULL ; }
net/ipv6/netfilter/ip6_tables.c +0 -9
@@ -1780,14 +1780,6 @@ void ip6t_unregister_table_exit(struct net *net, struct xt_table *table)__ip6t_unregister_table (net, table); } -void ip6t_unregister_table (struct net *net,struct xt_table *table, -const struct nf_hook_ops *ops) -{ -if (ops) -ip6t_unregister_table_pre_exit (net, table, ops); -__ip6t_unregister_table (net, table); -} -/* Returns 1 if the type and code is matched by the range, 0 otherwise */ static inline bool icmp6_type_code_match(u_int8_t test_type, u_int8_t min_code, u_int8_t max_code,
@@ -1935,7 +1927,6 @@ static void __exit ip6_tables_fini(void) }EXPORT_SYMBOL (ip6t_register_table); -EXPORT_SYMBOL (ip6t_unregister_table);EXPORT_SYMBOL (ip6t_unregister_table_pre_exit);EXPORT_SYMBOL (ip6t_unregister_table_exit);EXPORT_SYMBOL (ip6t_do_table);
net/ipv6/netfilter/ip6table_nat.c +1 -1
@@ -107,7 +107,7 @@ static int __net_init ip6table_nat_table_init(struct net *net) ret =ip6t_nat_register_lookups (net);if (ret <0 ) { -ip6t_unregister_table (net, net->ipv6.ip6table_nat,NULL ); +ip6t_unregister_table_exit (net, net->ipv6.ip6table_nat); net->ipv6.ip6table_nat =NULL ; }kfree (repl);
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 3/12 netfilter: add xt_find_table
In reply to Florian WestphalThis will be used to obtain the xt_table struct given address family and table name.
Followup patches will reduce the number of direct accesses to the xt_table structures via net->ipv{4,6}.ip(6)table_{nat,mangle,...} pointers, then remove them.
--- include/linux/netfilter/x_tables.h | 1 + net/netfilter/x_tables.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)
include/linux/netfilter/x_tables.h +1 -0
@@ -322,6 +322,7 @@ struct xt_target *xt_request_find_target(u8 af, const char *name, u8 revision);int xt_find_revision (u8 af,const char *name,u8 revision,int target,int *err); +struct xt_table *xt_find_table (struct net *net,u8 af,const char *name);struct xt_table *xt_find_table_lock (struct net *net,u_int8_t af,const char *name); struct xt_table *xt_request_find_table_lock(struct net *net, u_int8_t af,
net/netfilter/x_tables.c +17 -0
@@ -1199,6 +1199,23 @@ void xt_free_table_info(struct xt_table_info *info) }EXPORT_SYMBOL (xt_free_table_info); +struct xt_table *xt_find_table (struct net *net,u8 af,const char *name) +{ +struct xt_pernet *xt_net =net_generic (net, xt_pernet_id); +struct xt_table *t; + +mutex_lock (&xt[af].mutex); +list_for_each_entry (t, &xt_net->tables[af], list) { +if (strcmp (t->name, name) ==0 ) { +mutex_unlock (&xt[af].mutex); +return t; + } + } +mutex_unlock (&xt[af].mutex); +return NULL ; +} +EXPORT_SYMBOL (xt_find_table); +/* Find table by name, grabs mutex & ref. Returns ERR_PTR on error. */ struct xt_table *xt_find_table_lock (struct net *net,u_int8_t af,const char *name)
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 4/12 netfilter: iptables: unregister the tables by name
In reply to Florian Westphalxtables stores the xt_table structs in the struct net. This isn't needed anymore, the structures could be passed via the netfilter hook 'private' pointer to the hook functions, which would allow us to remove those pointers from struct net.
As a first step, reduce the number of accesses to the net->ipv4.ip6table_{raw,filter,...} pointers.
This allows the tables to get unregistered by name instead of having to pass the raw address.
The xt_table structure cane looked up by name+address family instead.
This patch is useless as-is (the backends still have the raw pointer address), but it lowers the bar to remove those.
It also allows to put the 'was table registered in the first place' check into ip_tables.c rather than have it in each table sub module.
--- include/linux/netfilter_ipv4/ip_tables.h | 6 +++--- net/ipv4/netfilter/ip_tables.c | 14 ++++++++++---- net/ipv4/netfilter/iptable_filter.c | 8 ++------ net/ipv4/netfilter/iptable_mangle.c | 8 ++------ net/ipv4/netfilter/iptable_nat.c | 6 ++---- net/ipv4/netfilter/iptable_raw.c | 8 ++------ net/ipv4/netfilter/iptable_security.c | 8 ++------ 7 files changed, 23 insertions(+), 35 deletions(-)
include/linux/netfilter_ipv4/ip_tables.h +3 -3
@@ -26,10 +26,10 @@ int ipt_register_table(struct net *net, const struct xt_table *table,const struct ipt_replace *repl, const struct nf_hook_ops *ops, struct xt_table **res); -void ipt_unregister_table_pre_exit (struct net *net,struct xt_table *table, -const struct nf_hook_ops *ops); +void ipt_unregister_table_pre_exit (struct net *net,const char *name, +const struct nf_hook_ops *ops); -void ipt_unregister_table_exit (struct net *net,struct xt_table *table); +void ipt_unregister_table_exit (struct net *net,const char *name);/* Standard entry. */ struct ipt_standard {
net/ipv4/netfilter/ip_tables.c +10 -4
@@ -1759,15 +1759,21 @@ int ipt_register_table(struct net *net, const struct xt_table *table,return ret; } -void ipt_unregister_table_pre_exit (struct net *net,struct xt_table *table, +void ipt_unregister_table_pre_exit (struct net *net,const char *name,const struct nf_hook_ops *ops) { -nf_unregister_net_hooks (net, ops,hweight32 (table->valid_hooks)); +struct xt_table *table =xt_find_table (net,NFPROTO_IPV4 , name); + +if (table) +nf_unregister_net_hooks (net, ops,hweight32 (table->valid_hooks)); } -void ipt_unregister_table_exit (struct net *net,struct xt_table *table) +void ipt_unregister_table_exit (struct net *net,const char *name) { -__ipt_unregister_table (net, table); +struct xt_table *table =xt_find_table (net,NFPROTO_IPV4 , name); + +if (table) +__ipt_unregister_table (net, table); }/* Returns 1 if the type and code is matched by the range, 0 otherwise */
net/ipv4/netfilter/iptable_filter.c +2 -6
@@ -74,16 +74,12 @@ static int __net_init iptable_filter_net_init(struct net *net) static void __net_exit iptable_filter_net_pre_exit(struct net *net) { -if (net->ipv4.iptable_filter) -ipt_unregister_table_pre_exit (net, net->ipv4.iptable_filter, - filter_ops); +ipt_unregister_table_pre_exit (net,"filter" , filter_ops); } static void __net_exit iptable_filter_net_exit(struct net *net) { -if (!net->ipv4.iptable_filter) -return ; -ipt_unregister_table_exit (net, net->ipv4.iptable_filter); +ipt_unregister_table_exit (net,"filter" ); net->ipv4.iptable_filter =NULL ; }
net/ipv4/netfilter/iptable_mangle.c +2 -6
@@ -102,16 +102,12 @@ static int __net_init iptable_mangle_table_init(struct net *net) static void __net_exit iptable_mangle_net_pre_exit(struct net *net) { -if (net->ipv4.iptable_mangle) -ipt_unregister_table_pre_exit (net, net->ipv4.iptable_mangle, - mangle_ops); +ipt_unregister_table_pre_exit (net,"mangle" , mangle_ops); } static void __net_exit iptable_mangle_net_exit(struct net *net) { -if (!net->ipv4.iptable_mangle) -return ; -ipt_unregister_table_exit (net, net->ipv4.iptable_mangle); +ipt_unregister_table_exit (net,"mangle" ); net->ipv4.iptable_mangle =NULL ; }
net/ipv4/netfilter/iptable_nat.c +2 -4
@@ -105,7 +105,7 @@ static int __net_init iptable_nat_table_init(struct net *net) ret =ipt_nat_register_lookups (net);if (ret <0 ) { -ipt_unregister_table_exit (net, net->ipv4.nat_table); +ipt_unregister_table_exit (net,"nat" ); net->ipv4.nat_table =NULL ; }
@@ -121,9 +121,7 @@ static void __net_exit iptable_nat_net_pre_exit(struct net *net) static void __net_exit iptable_nat_net_exit(struct net *net) { -if (!net->ipv4.nat_table) -return ; -ipt_unregister_table_exit (net, net->ipv4.nat_table); +ipt_unregister_table_exit (net,"nat" ); net->ipv4.nat_table =NULL ; }
net/ipv4/netfilter/iptable_raw.c +2 -6
@@ -69,16 +69,12 @@ static int __net_init iptable_raw_table_init(struct net *net) static void __net_exit iptable_raw_net_pre_exit(struct net *net) { -if (net->ipv4.iptable_raw) -ipt_unregister_table_pre_exit (net, net->ipv4.iptable_raw, - rawtable_ops); +ipt_unregister_table_pre_exit (net,"raw" , rawtable_ops); } static void __net_exit iptable_raw_net_exit(struct net *net) { -if (!net->ipv4.iptable_raw) -return ; -ipt_unregister_table_exit (net, net->ipv4.iptable_raw); +ipt_unregister_table_exit (net,"raw" ); net->ipv4.iptable_raw =NULL ; }
net/ipv4/netfilter/iptable_security.c +2 -6
@@ -64,16 +64,12 @@ static int __net_init iptable_security_table_init(struct net *net) static void __net_exit iptable_security_net_pre_exit(struct net *net) { -if (net->ipv4.iptable_security) -ipt_unregister_table_pre_exit (net, net->ipv4.iptable_security, - sectbl_ops); +ipt_unregister_table_pre_exit (net,"security" , sectbl_ops); } static void __net_exit iptable_security_net_exit(struct net *net) { -if (!net->ipv4.iptable_security) -return ; -ipt_unregister_table_exit (net, net->ipv4.iptable_security); +ipt_unregister_table_exit (net,"security" ); net->ipv4.iptable_security =NULL ; }
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 5/12 netfilter: ip6tables: unregister the tables by name
In reply to Florian WestphalSame as the previous patch, but for ip6tables.
--- include/linux/netfilter_ipv6/ip6_tables.h | 4 ++-- net/ipv6/netfilter/ip6_tables.c | 14 ++++++++++---- net/ipv6/netfilter/ip6table_filter.c | 9 +++------ net/ipv6/netfilter/ip6table_mangle.c | 9 ++------- net/ipv6/netfilter/ip6table_nat.c | 6 ++---- net/ipv6/netfilter/ip6table_raw.c | 9 +++------ net/ipv6/netfilter/ip6table_security.c | 8 ++------ 7 files changed, 24 insertions(+), 35 deletions(-)
include/linux/netfilter_ipv6/ip6_tables.h +2 -2
@@ -27,9 +27,9 @@ extern void *ip6t_alloc_initial_table(const struct xt_table *);int ip6t_register_table (struct net *net,const struct xt_table *table,const struct ip6t_replace *repl,const struct nf_hook_ops *ops,struct xt_table **res); -void ip6t_unregister_table_pre_exit (struct net *net,struct xt_table *table, +void ip6t_unregister_table_pre_exit (struct net *net,const char *name,const struct nf_hook_ops *ops); -void ip6t_unregister_table_exit (struct net *net,struct xt_table *table); +void ip6t_unregister_table_exit (struct net *net,const char *name);extern unsigned int ip6t_do_table (struct sk_buff *skb,const struct nf_hook_state *state,struct xt_table *table);
net/ipv6/netfilter/ip6_tables.c +10 -4
@@ -1769,15 +1769,21 @@ int ip6t_register_table(struct net *net, const struct xt_table *table,return ret; } -void ip6t_unregister_table_pre_exit (struct net *net,struct xt_table *table, +void ip6t_unregister_table_pre_exit (struct net *net,const char *name,const struct nf_hook_ops *ops) { -nf_unregister_net_hooks (net, ops,hweight32 (table->valid_hooks)); +struct xt_table *table =xt_find_table (net,NFPROTO_IPV6 , name); + +if (table) +nf_unregister_net_hooks (net, ops,hweight32 (table->valid_hooks)); } -void ip6t_unregister_table_exit (struct net *net,struct xt_table *table) +void ip6t_unregister_table_exit (struct net *net,const char *name) { -__ip6t_unregister_table (net, table); +struct xt_table *table =xt_find_table (net,NFPROTO_IPV6 , name); + +if (table) +__ip6t_unregister_table (net, table); }/* Returns 1 if the type and code is matched by the range, 0 otherwise */
net/ipv6/netfilter/ip6table_filter.c +3 -6
@@ -75,16 +75,13 @@ static int __net_init ip6table_filter_net_init(struct net *net) static void __net_exit ip6table_filter_net_pre_exit(struct net *net) { -if (net->ipv6.ip6table_filter) -ip6t_unregister_table_pre_exit (net, net->ipv6.ip6table_filter, - filter_ops); +ip6t_unregister_table_pre_exit (net,"filter" , + filter_ops); } static void __net_exit ip6table_filter_net_exit(struct net *net) { -if (!net->ipv6.ip6table_filter) -return ; -ip6t_unregister_table_exit (net, net->ipv6.ip6table_filter); +ip6t_unregister_table_exit (net,"filter" ); net->ipv6.ip6table_filter =NULL ; }
net/ipv6/netfilter/ip6table_mangle.c +2 -7
@@ -95,17 +95,12 @@ static int __net_init ip6table_mangle_table_init(struct net *net) static void __net_exit ip6table_mangle_net_pre_exit(struct net *net) { -if (net->ipv6.ip6table_mangle) -ip6t_unregister_table_pre_exit (net, net->ipv6.ip6table_mangle, - mangle_ops); +ip6t_unregister_table_pre_exit (net,"mangle" , mangle_ops); } static void __net_exit ip6table_mangle_net_exit(struct net *net) { -if (!net->ipv6.ip6table_mangle) -return ; - -ip6t_unregister_table_exit (net, net->ipv6.ip6table_mangle); +ip6t_unregister_table_exit (net,"mangle" ); net->ipv6.ip6table_mangle =NULL ; }
net/ipv6/netfilter/ip6table_nat.c +2 -4
@@ -107,7 +107,7 @@ static int __net_init ip6table_nat_table_init(struct net *net) ret =ip6t_nat_register_lookups (net);if (ret <0 ) { -ip6t_unregister_table_exit (net, net->ipv6.ip6table_nat); +ip6t_unregister_table_exit (net,"nat" ); net->ipv6.ip6table_nat =NULL ; }kfree (repl);
@@ -122,9 +122,7 @@ static void __net_exit ip6table_nat_net_pre_exit(struct net *net) static void __net_exit ip6table_nat_net_exit(struct net *net) { -if (!net->ipv6.ip6table_nat) -return ; -ip6t_unregister_table_exit (net, net->ipv6.ip6table_nat); +ip6t_unregister_table_exit (net,"nat" ); net->ipv6.ip6table_nat =NULL ; }
net/ipv6/netfilter/ip6table_raw.c +3 -6
@@ -68,16 +68,13 @@ static int __net_init ip6table_raw_table_init(struct net *net) static void __net_exit ip6table_raw_net_pre_exit(struct net *net) { -if (net->ipv6.ip6table_raw) -ip6t_unregister_table_pre_exit (net, net->ipv6.ip6table_raw, - rawtable_ops); +ip6t_unregister_table_pre_exit (net,"raw" , + rawtable_ops); } static void __net_exit ip6table_raw_net_exit(struct net *net) { -if (!net->ipv6.ip6table_raw) -return ; -ip6t_unregister_table_exit (net, net->ipv6.ip6table_raw); +ip6t_unregister_table_exit (net,"raw" ); net->ipv6.ip6table_raw =NULL ; }
net/ipv6/netfilter/ip6table_security.c +2 -6
@@ -63,16 +63,12 @@ static int __net_init ip6table_security_table_init(struct net *net) static void __net_exit ip6table_security_net_pre_exit(struct net *net) { -if (net->ipv6.ip6table_security) -ip6t_unregister_table_pre_exit (net, net->ipv6.ip6table_security, - sectbl_ops); +ip6t_unregister_table_pre_exit (net,"security" , sectbl_ops); } static void __net_exit ip6table_security_net_exit(struct net *net) { -if (!net->ipv6.ip6table_security) -return ; -ip6t_unregister_table_exit (net, net->ipv6.ip6table_security); +ip6t_unregister_table_exit (net,"security" ); net->ipv6.ip6table_security =NULL ; }
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 6/12 netfilter: arptables: unregister the tables by name
In reply to Florian Westphaland again, this time for arptables.
--- include/linux/netfilter_arp/arp_tables.h | 4 ++-- net/ipv4/netfilter/arp_tables.c | 14 ++++++++++---- net/ipv4/netfilter/arptable_filter.c | 8 ++------ 3 files changed, 14 insertions(+), 12 deletions(-)
include/linux/netfilter_arp/arp_tables.h +2 -2
@@ -52,8 +52,8 @@ extern void *arpt_alloc_initial_table(const struct xt_table *);int arpt_register_table (struct net *net,const struct xt_table *table,const struct arpt_replace *repl,const struct nf_hook_ops *ops,struct xt_table **res); -void arpt_unregister_table (struct net *net,struct xt_table *table); -void arpt_unregister_table_pre_exit (struct net *net,struct xt_table *table, +void arpt_unregister_table (struct net *net,const char *name); +void arpt_unregister_table_pre_exit (struct net *net,const char *name,const struct nf_hook_ops *ops); extern unsigned int arpt_do_table(struct sk_buff *skb, const struct nf_hook_state *state,
net/ipv4/netfilter/arp_tables.c +10 -4
@@ -1541,16 +1541,22 @@ int arpt_register_table(struct net *net,return ret; } -void arpt_unregister_table_pre_exit (struct net *net,struct xt_table *table, +void arpt_unregister_table_pre_exit (struct net *net,const char *name,const struct nf_hook_ops *ops) { -nf_unregister_net_hooks (net, ops,hweight32 (table->valid_hooks)); +struct xt_table *table =xt_find_table (net,NFPROTO_ARP , name); + +if (table) +nf_unregister_net_hooks (net, ops,hweight32 (table->valid_hooks)); }EXPORT_SYMBOL (arpt_unregister_table_pre_exit); -void arpt_unregister_table (struct net *net,struct xt_table *table) +void arpt_unregister_table (struct net *net,const char *name) { -__arpt_unregister_table (net, table); +struct xt_table *table =xt_find_table (net,NFPROTO_ARP , name); + +if (table) +__arpt_unregister_table (net, table); }/* The built-in targets: standard (NULL) and error. */
net/ipv4/netfilter/arptable_filter.c +2 -6
@@ -58,16 +58,12 @@ static int __net_init arptable_filter_table_init(struct net *net) static void __net_exit arptable_filter_net_pre_exit(struct net *net) { -if (net->ipv4.arptable_filter) -arpt_unregister_table_pre_exit (net, net->ipv4.arptable_filter, - arpfilter_ops); +arpt_unregister_table_pre_exit (net,"filter" , arpfilter_ops); } static void __net_exit arptable_filter_net_exit(struct net *net) { -if (!net->ipv4.arptable_filter) -return ; -arpt_unregister_table (net, net->ipv4.arptable_filter); +arpt_unregister_table (net,"filter" ); net->ipv4.arptable_filter =NULL ; }
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 7/12 netfilter: x_tables: remove paranoia tests
In reply to Florian WestphalNo need for these.
There is only one caller, the xtables core, when the table is registered for the first time with a particular network namespace.
After ->table_init() call, the table is linked into the tables[af] list, so next call to that function will skip the ->table_init().
--- net/ipv4/netfilter/arptable_filter.c | 3 --- net/ipv4/netfilter/iptable_filter.c | 3 --- net/ipv4/netfilter/iptable_mangle.c | 3 --- net/ipv4/netfilter/iptable_nat.c | 3 --- net/ipv4/netfilter/iptable_raw.c | 3 --- net/ipv4/netfilter/iptable_security.c | 3 --- net/ipv6/netfilter/ip6table_filter.c | 3 --- net/ipv6/netfilter/ip6table_mangle.c | 3 --- net/ipv6/netfilter/ip6table_nat.c | 3 --- net/ipv6/netfilter/ip6table_raw.c | 3 --- net/ipv6/netfilter/ip6table_security.c | 3 --- 11 files changed, 33 deletions(-)
net/ipv4/netfilter/arptable_filter.c +0 -3
@@ -44,9 +44,6 @@ static int __net_init arptable_filter_table_init(struct net *net)struct arpt_replace *repl;int err; -if (net->ipv4.arptable_filter) -return 0 ; - repl =arpt_alloc_initial_table (&packet_filter);if (repl ==NULL )return -ENOMEM ;
net/ipv4/netfilter/iptable_filter.c +0 -3
@@ -48,9 +48,6 @@ static int __net_init iptable_filter_table_init(struct net *net)struct ipt_replace *repl;int err; -if (net->ipv4.iptable_filter) -return 0 ; - repl =ipt_alloc_initial_table (&packet_filter);if (repl ==NULL )return -ENOMEM ;
net/ipv4/netfilter/iptable_mangle.c +0 -3
@@ -88,9 +88,6 @@ static int __net_init iptable_mangle_table_init(struct net *net)struct ipt_replace *repl;int ret; -if (net->ipv4.iptable_mangle) -return 0 ; - repl =ipt_alloc_initial_table (&packet_mangler);if (repl ==NULL )return -ENOMEM ;
net/ipv4/netfilter/iptable_nat.c +0 -3
@@ -90,9 +90,6 @@ static int __net_init iptable_nat_table_init(struct net *net)struct ipt_replace *repl;int ret; -if (net->ipv4.nat_table) -return 0 ; - repl =ipt_alloc_initial_table (&nf_nat_ipv4_table);if (repl ==NULL )return -ENOMEM ;
net/ipv4/netfilter/iptable_raw.c +0 -3
@@ -55,9 +55,6 @@ static int __net_init iptable_raw_table_init(struct net *net)if (raw_before_defrag) table = &packet_raw_before_defrag; -if (net->ipv4.iptable_raw) -return 0 ; - repl =ipt_alloc_initial_table (table);if (repl ==NULL )return -ENOMEM ;
net/ipv4/netfilter/iptable_security.c +0 -3
@@ -50,9 +50,6 @@ static int __net_init iptable_security_table_init(struct net *net)struct ipt_replace *repl;int ret; -if (net->ipv4.iptable_security) -return 0 ; - repl =ipt_alloc_initial_table (&security_table);if (repl ==NULL )return -ENOMEM ;
net/ipv6/netfilter/ip6table_filter.c +0 -3
@@ -49,9 +49,6 @@ static int __net_init ip6table_filter_table_init(struct net *net)struct ip6t_replace *repl;int err; -if (net->ipv6.ip6table_filter) -return 0 ; - repl =ip6t_alloc_initial_table (&packet_filter);if (repl ==NULL )return -ENOMEM ;
net/ipv6/netfilter/ip6table_mangle.c +0 -3
@@ -81,9 +81,6 @@ static int __net_init ip6table_mangle_table_init(struct net *net)struct ip6t_replace *repl;int ret; -if (net->ipv6.ip6table_mangle) -return 0 ; - repl =ip6t_alloc_initial_table (&packet_mangler);if (repl ==NULL )return -ENOMEM ;
net/ipv6/netfilter/ip6table_nat.c +0 -3
@@ -92,9 +92,6 @@ static int __net_init ip6table_nat_table_init(struct net *net)struct ip6t_replace *repl;int ret; -if (net->ipv6.ip6table_nat) -return 0 ; - repl =ip6t_alloc_initial_table (&nf_nat_ipv6_table);if (repl ==NULL )return -ENOMEM ;
net/ipv6/netfilter/ip6table_raw.c +0 -3
@@ -54,9 +54,6 @@ static int __net_init ip6table_raw_table_init(struct net *net)if (raw_before_defrag) table = &packet_raw_before_defrag; -if (net->ipv6.ip6table_raw) -return 0 ; - repl =ip6t_alloc_initial_table (table);if (repl ==NULL )return -ENOMEM ;
net/ipv6/netfilter/ip6table_security.c +0 -3
@@ -49,9 +49,6 @@ static int __net_init ip6table_security_table_init(struct net *net)struct ip6t_replace *repl;int ret; -if (net->ipv6.ip6table_security) -return 0 ; - repl =ip6t_alloc_initial_table (&security_table);if (repl ==NULL )return -ENOMEM ;
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 8/12 netfilter: xt_nat: pass table to hookfn
In reply to Florian WestphalThis changes how ip(6)table nat passes the ruleset/table to the evaluation loop.
At the moment, it will fetch the table from struct net.
This change stores the table in the hook_ops 'priv' argument instead.
This requires to duplicate the hook_ops for each netns, so they can store the (per-net) xt_table structure.
The dupliated nat hook_ops get stored in net_generic data area. They are free'd in the namespace exit path.
This is a pre-requisite to remove the xt_table/ruleset pointers from struct net.
--- net/ipv4/netfilter/iptable_nat.c | 44 +++++++++++++++++++++++------- net/ipv6/netfilter/ip6table_nat.c | 45 ++++++++++++++++++++++++------- 2 files changed, 69 insertions(+), 20 deletions(-)
net/ipv4/netfilter/iptable_nat.c +34 -10
@@ -13,8 +13,14 @@#include <net/netfilter/nf_nat.h> +struct iptable_nat_pernet { +struct nf_hook_ops *nf_nat_ops; +}; +static int __net_init iptable_nat_table_init (struct net *net); +static unsigned int iptable_nat_net_id__read_mostly ; +static const struct xt_table nf_nat_ipv4_table = { .name ="nat" , .valid_hooks = (1 << NF_INET_PRE_ROUTING) |
@@ -30,7 +36,7 @@ static unsigned int iptable_nat_do_chain(void *priv,struct sk_buff *skb, const struct nf_hook_state *state) { - return ipt_do_table(skb, state, state->net->ipv4.nat_table); + return ipt_do_table(skb, state, priv); } static const struct nf_hook_ops nf_nat_ipv4_ops[] = {
@@ -60,50 +66,67 @@ static const struct nf_hook_ops nf_nat_ipv4_ops[] = { }, }; -static int ipt_nat_register_lookups (struct net *net) +static int ipt_nat_register_lookups (struct net *net,struct xt_table *table) { +struct nf_hook_ops *ops =kmemdup (nf_nat_ipv4_ops,sizeof (nf_nat_ipv4_ops),GFP_KERNEL ); +struct iptable_nat_pernet *xt_nat_net =net_generic (net, iptable_nat_net_id);int i, ret; +if (!ops) +return -ENOMEM ; +for (i =0 ; i <ARRAY_SIZE (nf_nat_ipv4_ops); i++) { - ret =nf_nat_ipv4_register_fn (net, &nf_nat_ipv4_ops[i]); + ops[i].priv = table; + ret =nf_nat_ipv4_register_fn (net, &ops[i]);if (ret) {while (i) -nf_nat_ipv4_unregister_fn (net, &nf_nat_ipv4_ops[--i]); +nf_nat_ipv4_unregister_fn (net, &ops[--i]); +kfree (ops);return ret; } } + xt_nat_net->nf_nat_ops = ops;return 0 ; }static void ipt_nat_unregister_lookups (struct net *net) { +struct iptable_nat_pernet *xt_nat_net =net_generic (net, iptable_nat_net_id); +struct nf_hook_ops *ops = xt_nat_net->nf_nat_ops;int i; +if (!ops) +return ; +for (i =0 ; i <ARRAY_SIZE (nf_nat_ipv4_ops); i++) -nf_nat_ipv4_unregister_fn (net, &nf_nat_ipv4_ops[i]); +nf_nat_ipv4_unregister_fn (net, &ops[i]); + +kfree (ops); }static int __net_init iptable_nat_table_init (struct net *net) {struct ipt_replace *repl; +struct xt_table *table;int ret; repl =ipt_alloc_initial_table (&nf_nat_ipv4_table);if (repl ==NULL )return -ENOMEM ; ret =ipt_register_table (net, &nf_nat_ipv4_table, repl, -NULL , &net->ipv4.nat_table); +NULL , &table);if (ret <0 ) {kfree (repl);return ret; } - ret =ipt_nat_register_lookups (net); + ret =ipt_nat_register_lookups (net, table);if (ret <0 ) {ipt_unregister_table_exit (net,"nat" ); - net->ipv4.nat_table =NULL ; + }else { + net->ipv4.nat_table = table; }kfree (repl);
@@ -112,8 +135,7 @@ static int __net_init iptable_nat_table_init(struct net *net) static void __net_exit iptable_nat_net_pre_exit(struct net *net) { -if (net->ipv4.nat_table) -ipt_nat_unregister_lookups (net); +ipt_nat_unregister_lookups (net); } static void __net_exit iptable_nat_net_exit(struct net *net)
@@ -125,6 +147,8 @@ static void __net_exit iptable_nat_net_exit(struct net *net)static struct pernet_operations iptable_nat_net_ops = { .pre_exit = iptable_nat_net_pre_exit, .exit = iptable_nat_net_exit, + .id = &iptable_nat_net_id, + .size =sizeof (struct iptable_nat_pernet ), };static int __init iptable_nat_init (void )
net/ipv6/netfilter/ip6table_nat.c +35 -10
115 lines not on this page · raw message
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 9/12 netfilter: ip_tables: pass table pointer via nf_hook_ops
In reply to Florian Westphaliptable_x modules rely on 'struct net' to contain a pointer to the table that should be evaluated.
In order to remove these pointers from struct net, pass them via the 'priv' pointer in a similar fashion as nf_tables passes the rule data.
To do that, duplicate the nf_hook_info array passed in from the iptable_x modules, update the ops->priv pointers of the copy to refer to the table and then change the hookfn implementations to just pass the 'priv' argument to the traverser.
After this patch, the xt_table pointers can already be removed from struct net.
However, changes to struct net result in re-compile of the entire network stack, so do the removal after arptables and ip6tables have been converted as well.
--- include/linux/netfilter/x_tables.h | 3 ++ include/linux/netfilter_ipv4/ip_tables.h | 6 +-- net/ipv4/netfilter/ip_tables.c | 53 ++++++++++++++++-------- net/ipv4/netfilter/iptable_filter.c | 8 ++-- net/ipv4/netfilter/iptable_mangle.c | 14 +++---- net/ipv4/netfilter/iptable_nat.c | 26 ++++++------ net/ipv4/netfilter/iptable_raw.c | 8 ++-- net/ipv4/netfilter/iptable_security.c | 8 ++-- net/netfilter/x_tables.c | 1 + 9 files changed, 71 insertions(+), 56 deletions(-)
include/linux/netfilter/x_tables.h +3 -0
@@ -229,6 +229,9 @@ struct xt_table {/* Man behind the curtain... */ struct xt_table_info *private; +/* hook ops that register the table with the netfilter core */ +struct nf_hook_ops *ops; +/* Set this to THIS_MODULE if you are a module, otherwise NULL */ struct module *me;
include/linux/netfilter_ipv4/ip_tables.h +2 -4
@@ -24,11 +24,9 @@int ipt_register_table (struct net *net,const struct xt_table *table,const struct ipt_replace *repl, -const struct nf_hook_ops *ops,struct xt_table **res); - -void ipt_unregister_table_pre_exit (struct net *net,const char *name, -const struct nf_hook_ops *ops); +const struct nf_hook_ops *ops); +void ipt_unregister_table_pre_exit (struct net *net,const char *name);void ipt_unregister_table_exit (struct net *net,const char *name);/* Standard entry. */
net/ipv4/netfilter/ip_tables.c +36 -17
85 lines not on this page · raw message
net/ipv4/netfilter/iptable_filter.c +3 -5
@@ -34,7 +34,7 @@ static unsigned int iptable_filter_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -return ipt_do_table (skb, state, state->net->ipv4.iptable_filter); +return ipt_do_table (skb, state, priv); }static struct nf_hook_ops *filter_ops__read_mostly ;
@@ -55,8 +55,7 @@ static int __net_init iptable_filter_table_init(struct net *net) ((struct ipt_standard *)repl->entries)[1 ].target.verdict = forward ? -NF_ACCEPT -1 : -NF_DROP -1 ; - err =ipt_register_table (net, &packet_filter, repl, filter_ops, - &net->ipv4.iptable_filter); + err =ipt_register_table (net, &packet_filter, repl, filter_ops);kfree (repl);return err; }
@@ -71,13 +70,12 @@ static int __net_init iptable_filter_net_init(struct net *net) static void __net_exit iptable_filter_net_pre_exit(struct net *net) { -ipt_unregister_table_pre_exit (net,"filter" , filter_ops); +ipt_unregister_table_pre_exit (net,"filter" ); } static void __net_exit iptable_filter_net_exit(struct net *net) {ipt_unregister_table_exit (net,"filter" ); - net->ipv4.iptable_filter =NULL ; }static struct pernet_operations iptable_filter_net_ops = {
net/ipv4/netfilter/iptable_mangle.c +6 -8
@@ -37,7 +37,7 @@ static const struct xt_table packet_mangler = { };static unsigned int -ipt_mangle_out (struct sk_buff *skb,const struct nf_hook_state *state) +ipt_mangle_out (struct sk_buff *skb,const struct nf_hook_state *state,void *priv) {unsigned int ret;const struct iphdr *iph;
@@ -53,7 +53,7 @@ ipt_mangle_out(struct sk_buff *skb, const struct nf_hook_state *state) daddr = iph->daddr; tos = iph->tos; - ret =ipt_do_table (skb, state, state->net->ipv4.iptable_mangle); + ret =ipt_do_table (skb, state, priv);/* Reroute for ANY change. */ if (ret !=NF_DROP && ret !=NF_STOLEN ) { iph =ip_hdr (skb);
@@ -78,8 +78,8 @@ iptable_mangle_hook(void *priv, const struct nf_hook_state *state) {if (state->hook ==NF_INET_LOCAL_OUT ) -return ipt_mangle_out (skb, state); -return ipt_do_table (skb, state, state->net->ipv4.iptable_mangle); +return ipt_mangle_out (skb, state, priv); +return ipt_do_table (skb, state, priv); }static struct nf_hook_ops *mangle_ops__read_mostly ;
@@ -91,21 +91,19 @@ static int __net_init iptable_mangle_table_init(struct net *net) repl =ipt_alloc_initial_table (&packet_mangler);if (repl ==NULL )return -ENOMEM ; - ret =ipt_register_table (net, &packet_mangler, repl, mangle_ops, - &net->ipv4.iptable_mangle); + ret =ipt_register_table (net, &packet_mangler, repl, mangle_ops);kfree (repl);return ret; } static void __net_exit iptable_mangle_net_pre_exit(struct net *net) { -ipt_unregister_table_pre_exit (net,"mangle" , mangle_ops); +ipt_unregister_table_pre_exit (net,"mangle" ); } static void __net_exit iptable_mangle_net_exit(struct net *net) {ipt_unregister_table_exit (net,"mangle" ); - net->ipv4.iptable_mangle =NULL ; }static struct pernet_operations iptable_mangle_net_ops = {
net/ipv4/netfilter/iptable_nat.c +14 -12
@@ -66,12 +66,19 @@ static const struct nf_hook_ops nf_nat_ipv4_ops[] = { }, }; -static int ipt_nat_register_lookups (struct net *net,struct xt_table *table) +static int ipt_nat_register_lookups (struct net *net) { -struct nf_hook_ops *ops =kmemdup (nf_nat_ipv4_ops,sizeof (nf_nat_ipv4_ops),GFP_KERNEL ); -struct iptable_nat_pernet *xt_nat_net =net_generic (net, iptable_nat_net_id); +struct iptable_nat_pernet *xt_nat_net; +struct nf_hook_ops *ops; +struct xt_table *table;int i, ret; + xt_nat_net =net_generic (net, iptable_nat_net_id); + table =xt_find_table (net,NFPROTO_IPV4 ,"nat" ); +if (WARN_ON_ONCE (!table)) +return -ENOENT ; + + ops =kmemdup (nf_nat_ipv4_ops,sizeof (nf_nat_ipv4_ops),GFP_KERNEL );if (!ops)return -ENOMEM ;
@@ -109,25 +116,21 @@ static void ipt_nat_unregister_lookups(struct net *net)static int __net_init iptable_nat_table_init (struct net *net) {struct ipt_replace *repl; -struct xt_table *table;int ret; repl =ipt_alloc_initial_table (&nf_nat_ipv4_table);if (repl ==NULL )return -ENOMEM ; - ret =ipt_register_table (net, &nf_nat_ipv4_table, repl, -NULL , &table); + + ret =ipt_register_table (net, &nf_nat_ipv4_table, repl,NULL );if (ret <0 ) {kfree (repl);return ret; } - ret =ipt_nat_register_lookups (net, table); -if (ret <0 ) { + ret =ipt_nat_register_lookups (net); +if (ret <0 )ipt_unregister_table_exit (net,"nat" ); - }else { - net->ipv4.nat_table = table; - }kfree (repl);return ret;
@@ -141,7 +144,6 @@ static void __net_exit iptable_nat_net_pre_exit(struct net *net) static void __net_exit iptable_nat_net_exit(struct net *net) {ipt_unregister_table_exit (net,"nat" ); - net->ipv4.nat_table =NULL ; }static struct pernet_operations iptable_nat_net_ops = {
net/ipv4/netfilter/iptable_raw.c +3 -5
@@ -41,7 +41,7 @@ static unsigned int iptable_raw_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -return ipt_do_table (skb, state, state->net->ipv4.iptable_raw); +return ipt_do_table (skb, state, priv); }static struct nf_hook_ops *rawtable_ops__read_mostly ;
@@ -58,21 +58,19 @@ static int __net_init iptable_raw_table_init(struct net *net) repl =ipt_alloc_initial_table (table);if (repl ==NULL )return -ENOMEM ; - ret =ipt_register_table (net, table, repl, rawtable_ops, - &net->ipv4.iptable_raw); + ret =ipt_register_table (net, table, repl, rawtable_ops);kfree (repl);return ret; } static void __net_exit iptable_raw_net_pre_exit(struct net *net) { -ipt_unregister_table_pre_exit (net,"raw" , rawtable_ops); +ipt_unregister_table_pre_exit (net,"raw" ); } static void __net_exit iptable_raw_net_exit(struct net *net) {ipt_unregister_table_exit (net,"raw" ); - net->ipv4.iptable_raw =NULL ; }static struct pernet_operations iptable_raw_net_ops = {
net/ipv4/netfilter/iptable_security.c +3 -5
@@ -40,7 +40,7 @@ static unsigned int iptable_security_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -return ipt_do_table (skb, state, state->net->ipv4.iptable_security); +return ipt_do_table (skb, state, priv); }static struct nf_hook_ops *sectbl_ops__read_mostly ;
@@ -53,21 +53,19 @@ static int __net_init iptable_security_table_init(struct net *net) repl =ipt_alloc_initial_table (&security_table);if (repl ==NULL )return -ENOMEM ; - ret =ipt_register_table (net, &security_table, repl, sectbl_ops, - &net->ipv4.iptable_security); + ret =ipt_register_table (net, &security_table, repl, sectbl_ops);kfree (repl);return ret; } static void __net_exit iptable_security_net_pre_exit(struct net *net) { -ipt_unregister_table_pre_exit (net,"security" , sectbl_ops); +ipt_unregister_table_pre_exit (net,"security" ); } static void __net_exit iptable_security_net_exit(struct net *net) {ipt_unregister_table_exit (net,"security" ); - net->ipv4.iptable_security =NULL ; }static struct pernet_operations iptable_security_net_ops = {
net/netfilter/x_tables.c +1 -0
@@ -1498,6 +1498,7 @@ void *xt_unregister_table(struct xt_table *table)mutex_unlock (&xt[table->af].mutex);audit_log_nfcfg (table->name, table->af, private->number,AUDIT_XT_OP_UNREGISTER ,GFP_KERNEL ); +kfree (table->ops);kfree (table);return private;
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 10/12 netfilter: arp_tables: pass table pointer via nf_hook_ops
In reply to Florian WestphalSame change as previous patch. Only difference:
no need to handle NULL template_ops parameter, the only caller (arptable_filter) always passes non-NULL argument.
This removes all remaining accesses to net->ipv4.arptable_filter.
--- include/linux/netfilter_arp/arp_tables.h | 2 +- net/ipv4/netfilter/arp_tables.c | 43 ++++++++++++++++-------- net/ipv4/netfilter/arptable_filter.c | 6 ++-- 3 files changed, 32 insertions(+), 19 deletions(-)
include/linux/netfilter_arp/arp_tables.h +1 -1
@@ -51,7 +51,7 @@ struct arpt_error {extern void *arpt_alloc_initial_table (const struct xt_table *);int arpt_register_table (struct net *net,const struct xt_table *table,const struct arpt_replace *repl, -const struct nf_hook_ops *ops,struct xt_table **res); +const struct nf_hook_ops *ops);void arpt_unregister_table (struct net *net,const char *name);void arpt_unregister_table_pre_exit (struct net *net,const char *name,const struct nf_hook_ops *ops);
net/ipv4/netfilter/arp_tables.c +29 -14
67 lines not on this page · raw message
net/ipv4/netfilter/arptable_filter.c +2 -4
@@ -34,7 +34,7 @@ static unsigned int arptable_filter_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -return arpt_do_table (skb, state, state->net->ipv4.arptable_filter); +return arpt_do_table (skb, state, priv); }static struct nf_hook_ops *arpfilter_ops__read_mostly ;
@@ -47,8 +47,7 @@ static int __net_init arptable_filter_table_init(struct net *net) repl =arpt_alloc_initial_table (&packet_filter);if (repl ==NULL )return -ENOMEM ; - err =arpt_register_table (net, &packet_filter, repl, arpfilter_ops, - &net->ipv4.arptable_filter); + err =arpt_register_table (net, &packet_filter, repl, arpfilter_ops);kfree (repl);return err; }
@@ -61,7 +60,6 @@ static void __net_exit arptable_filter_net_pre_exit(struct net *net) static void __net_exit arptable_filter_net_exit(struct net *net) {arpt_unregister_table (net,"filter" ); - net->ipv4.arptable_filter =NULL ; }static struct pernet_operations arptable_filter_net_ops = {
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 12/12 netfilter: remove all xt_table anchors from struct net
In reply to Florian WestphalNo longer needed, table pointer arg is now passed via netfilter core.
--- include/net/netns/ipv4.h | 10 ---------- include/net/netns/ipv6.h | 9 --------- 2 files changed, 19 deletions(-)
include/net/netns/ipv4.h +0 -10
@@ -76,16 +76,6 @@ struct netns_ipv4 {struct inet_peer_base *peers;struct sock *__percpu *tcp_sk;struct fqdir *fqdir; -#ifdef CONFIG_NETFILTER -struct xt_table *iptable_filter; -struct xt_table *iptable_mangle; -struct xt_table *iptable_raw; -struct xt_table *arptable_filter; -#ifdef CONFIG_SECURITY -struct xt_table *iptable_security; -#endif -struct xt_table *nat_table; -#endif u8 sysctl_icmp_echo_ignore_all;u8 sysctl_icmp_echo_enable_probe;
include/net/netns/ipv6.h +0 -9
@@ -63,15 +63,6 @@ struct netns_ipv6 {struct ipv6_devconf *devconf_dflt;struct inet_peer_base *peers;struct fqdir *fqdir; -#ifdef CONFIG_NETFILTER -struct xt_table *ip6table_filter; -struct xt_table *ip6table_mangle; -struct xt_table *ip6table_raw; -#ifdef CONFIG_SECURITY -struct xt_table *ip6table_security; -#endif -struct xt_table *ip6table_nat; -#endif struct fib6_info *fib6_null_entry;struct rt6_info *ip6_null_entry;struct rt6_statistics *rt6_stats;
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 11/12 netfilter: ip6_tables: pass table pointer via nf_hook_ops
In reply to Florian WestphalSame patch as the ip_tables one: removal of all accesses to ip6_tables xt_table pointers. After this patch the struct net xt_table anchors can be removed.
--- include/linux/netfilter_ipv6/ip6_tables.h | 5 +-- net/ipv6/netfilter/ip6_tables.c | 51 +++++++++++++++-------- net/ipv6/netfilter/ip6table_filter.c | 9 ++-- net/ipv6/netfilter/ip6table_mangle.c | 14 +++---- net/ipv6/netfilter/ip6table_nat.c | 24 ++++++----- net/ipv6/netfilter/ip6table_raw.c | 9 ++-- net/ipv6/netfilter/ip6table_security.c | 8 ++-- 7 files changed, 63 insertions(+), 57 deletions(-)
include/linux/netfilter_ipv6/ip6_tables.h +2 -3
@@ -26,9 +26,8 @@ extern void *ip6t_alloc_initial_table(const struct xt_table *);int ip6t_register_table (struct net *net,const struct xt_table *table,const struct ip6t_replace *repl, -const struct nf_hook_ops *ops,struct xt_table **res); -void ip6t_unregister_table_pre_exit (struct net *net,const char *name, -const struct nf_hook_ops *ops); +const struct nf_hook_ops *ops); +void ip6t_unregister_table_pre_exit (struct net *net,const char *name);void ip6t_unregister_table_exit (struct net *net,const char *name); extern unsigned int ip6t_do_table(struct sk_buff *skb, const struct nf_hook_state *state,
net/ipv6/netfilter/ip6_tables.c +33 -18
83 lines not on this page · raw message
net/ipv6/netfilter/ip6table_filter.c +3 -6
@@ -35,7 +35,7 @@ static unsigned int ip6table_filter_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -return ip6t_do_table (skb, state, state->net->ipv6.ip6table_filter); +return ip6t_do_table (skb, state, priv); }static struct nf_hook_ops *filter_ops__read_mostly ;
@@ -56,8 +56,7 @@ static int __net_init ip6table_filter_table_init(struct net *net) ((struct ip6t_standard *)repl->entries)[1 ].target.verdict = forward ? -NF_ACCEPT -1 : -NF_DROP -1 ; - err =ip6t_register_table (net, &packet_filter, repl, filter_ops, - &net->ipv6.ip6table_filter); + err =ip6t_register_table (net, &packet_filter, repl, filter_ops);kfree (repl);return err; }
@@ -72,14 +71,12 @@ static int __net_init ip6table_filter_net_init(struct net *net) static void __net_exit ip6table_filter_net_pre_exit(struct net *net) { -ip6t_unregister_table_pre_exit (net,"filter" , - filter_ops); +ip6t_unregister_table_pre_exit (net,"filter" ); } static void __net_exit ip6table_filter_net_exit(struct net *net) {ip6t_unregister_table_exit (net,"filter" ); - net->ipv6.ip6table_filter =NULL ; }static struct pernet_operations ip6table_filter_net_ops = {
net/ipv6/netfilter/ip6table_mangle.c +6 -8
@@ -32,7 +32,7 @@ static const struct xt_table packet_mangler = { };static unsigned int -ip6t_mangle_out (struct sk_buff *skb,const struct nf_hook_state *state) +ip6t_mangle_out (struct sk_buff *skb,const struct nf_hook_state *state,void *priv) {unsigned int ret;struct in6_addr saddr, daddr;
@@ -49,7 +49,7 @@ ip6t_mangle_out(struct sk_buff *skb, const struct nf_hook_state *state)/* flowlabel and prio (includes version, which shouldn't change either */ flowlabel = *((u_int32_t *)ipv6_hdr (skb)); - ret =ip6t_do_table (skb, state, state->net->ipv6.ip6table_mangle); + ret =ip6t_do_table (skb, state, priv); if (ret != NF_DROP && ret != NF_STOLEN && (!ipv6_addr_equal(&ipv6_hdr(skb)->saddr, &saddr) ||
@@ -71,8 +71,8 @@ ip6table_mangle_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) {if (state->hook ==NF_INET_LOCAL_OUT ) -return ip6t_mangle_out (skb, state); -return ip6t_do_table (skb, state, state->net->ipv6.ip6table_mangle); +return ip6t_mangle_out (skb, state, priv); +return ip6t_do_table (skb, state, priv); }static struct nf_hook_ops *mangle_ops__read_mostly ;
@@ -84,21 +84,19 @@ static int __net_init ip6table_mangle_table_init(struct net *net) repl =ip6t_alloc_initial_table (&packet_mangler);if (repl ==NULL )return -ENOMEM ; - ret =ip6t_register_table (net, &packet_mangler, repl, mangle_ops, - &net->ipv6.ip6table_mangle); + ret =ip6t_register_table (net, &packet_mangler, repl, mangle_ops);kfree (repl);return ret; } static void __net_exit ip6table_mangle_net_pre_exit(struct net *net) { -ip6t_unregister_table_pre_exit (net,"mangle" , mangle_ops); +ip6t_unregister_table_pre_exit (net,"mangle" ); } static void __net_exit ip6table_mangle_net_exit(struct net *net) {ip6t_unregister_table_exit (net,"mangle" ); - net->ipv6.ip6table_mangle =NULL ; }static struct pernet_operations ip6table_mangle_net_ops = {
net/ipv6/netfilter/ip6table_nat.c +13 -11
@@ -68,12 +68,19 @@ static const struct nf_hook_ops nf_nat_ipv6_ops[] = { }, }; -static int ip6t_nat_register_lookups (struct net *net,struct xt_table *table) +static int ip6t_nat_register_lookups (struct net *net) { -struct nf_hook_ops *ops =kmemdup (nf_nat_ipv6_ops,sizeof (nf_nat_ipv6_ops),GFP_KERNEL ); -struct ip6table_nat_pernet *xt_nat_net =net_generic (net, ip6table_nat_net_id); +struct ip6table_nat_pernet *xt_nat_net; +struct nf_hook_ops *ops; +struct xt_table *table;int i, ret; + table =xt_find_table (net,NFPROTO_IPV6 ,"nat" ); +if (WARN_ON_ONCE (!table)) +return -ENOENT ; + + xt_nat_net =net_generic (net, ip6table_nat_net_id); + ops =kmemdup (nf_nat_ipv6_ops,sizeof (nf_nat_ipv6_ops),GFP_KERNEL );if (!ops)return -ENOMEM ;
@@ -111,25 +118,21 @@ static void ip6t_nat_unregister_lookups(struct net *net)static int __net_init ip6table_nat_table_init (struct net *net) {struct ip6t_replace *repl; -struct xt_table *table;int ret; repl =ip6t_alloc_initial_table (&nf_nat_ipv6_table);if (repl ==NULL )return -ENOMEM ; ret =ip6t_register_table (net, &nf_nat_ipv6_table, repl, -NULL , &table); +NULL );if (ret <0 ) {kfree (repl);return ret; } - ret =ip6t_nat_register_lookups (net, table); -if (ret <0 ) { + ret =ip6t_nat_register_lookups (net); +if (ret <0 )ip6t_unregister_table_exit (net,"nat" ); - }else { - net->ipv6.ip6table_nat = table; - }kfree (repl);return ret;
@@ -143,7 +146,6 @@ static void __net_exit ip6table_nat_net_pre_exit(struct net *net) static void __net_exit ip6table_nat_net_exit(struct net *net) {ip6t_unregister_table_exit (net,"nat" ); - net->ipv6.ip6table_nat =NULL ; }static struct pernet_operations ip6table_nat_net_ops = {
net/ipv6/netfilter/ip6table_raw.c +3 -6
@@ -40,7 +40,7 @@ static unsigned int ip6table_raw_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -return ip6t_do_table (skb, state, state->net->ipv6.ip6table_raw); +return ip6t_do_table (skb, state, priv); }static struct nf_hook_ops *rawtable_ops__read_mostly ;
@@ -57,22 +57,19 @@ static int __net_init ip6table_raw_table_init(struct net *net) repl =ip6t_alloc_initial_table (table);if (repl ==NULL )return -ENOMEM ; - ret =ip6t_register_table (net, table, repl, rawtable_ops, - &net->ipv6.ip6table_raw); + ret =ip6t_register_table (net, table, repl, rawtable_ops);kfree (repl);return ret; } static void __net_exit ip6table_raw_net_pre_exit(struct net *net) { -ip6t_unregister_table_pre_exit (net,"raw" , - rawtable_ops); +ip6t_unregister_table_pre_exit (net,"raw" ); } static void __net_exit ip6table_raw_net_exit(struct net *net) {ip6t_unregister_table_exit (net,"raw" ); - net->ipv6.ip6table_raw =NULL ; }static struct pernet_operations ip6table_raw_net_ops = {
net/ipv6/netfilter/ip6table_security.c +3 -5
@@ -39,7 +39,7 @@ static unsigned int ip6table_security_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -return ip6t_do_table (skb, state, state->net->ipv6.ip6table_security); +return ip6t_do_table (skb, state, priv); }static struct nf_hook_ops *sectbl_ops__read_mostly ;
@@ -52,21 +52,19 @@ static int __net_init ip6table_security_table_init(struct net *net) repl =ip6t_alloc_initial_table (&security_table);if (repl ==NULL )return -ENOMEM ; - ret =ip6t_register_table (net, &security_table, repl, sectbl_ops, - &net->ipv6.ip6table_security); + ret =ip6t_register_table (net, &security_table, repl, sectbl_ops);kfree (repl);return ret; } static void __net_exit ip6table_security_net_pre_exit(struct net *net) { -ip6t_unregister_table_pre_exit (net,"security" , sectbl_ops); +ip6t_unregister_table_pre_exit (net,"security" ); } static void __net_exit ip6table_security_net_exit(struct net *net) {ip6t_unregister_table_exit (net,"security" ); - net->ipv6.ip6table_security =NULL ; }static struct pernet_operations ip6table_security_net_ops = {
Signature · 1 line
2.26.3
Pablo Neira Ayuso
maintainerQuoted 10 lines · Florian Westphal
This change removes all
xt_tablepointers from struct net.v2: fix "no previous prototype for '
ipt_unregister_table'" warning in patch 2.The various ip(6)table_foo incarnations are updated to expect that the table is passed as 'void *priv' argument that netfilter core passes to the hook functions.
This reduces the struct net size by 2 cachelines on
x86_64.
Series applied, thanks.