netfilter: conntrack: remove extension register api
Subsystems (3)
Florian Westphal
maintainercover netfilter: conntrack: remove extension register api
This starts to simplify the extension infra. Should have no impact on functionality.
Extension IDs already need compile-time allocation, the dynamic registration isn't necessary, just place the sizes in the extension core and handle the only instance of the ->destroy hook manually.
Also avoids the ->destroy hook invocation during ct destruction if the conntrack wasn't added to the bysource hash list.
Florian Westphal (4):
netfilter: conntrack: make all extensions 8-byte alignned
netfilter: conntrack: move extension sizes into core
netfilter: conntrack: hande ->destroy hook via nat_ops instead
netfilter: conntrack: remove extension register api
include/linux/netfilter.h | 1 + include/net/netfilter/nf_conntrack_acct.h | 1 - include/net/netfilter/nf_conntrack_ecache.h | 13 -- include/net/netfilter/nf_conntrack_extend.h | 18 +-- include/net/netfilter/nf_conntrack_labels.h | 3 - include/net/netfilter/nf_conntrack_seqadj.h | 3 - include/net/netfilter/nf_conntrack_timeout.h | 12 -- .../net/netfilter/nf_conntrack_timestamp.h | 13 -- net/netfilter/nf_conntrack_acct.c | 19 --- net/netfilter/nf_conntrack_core.c | 94 ++----------- net/netfilter/nf_conntrack_ecache.c | 24 +--- net/netfilter/nf_conntrack_extend.c | 132 ++++++++++-------- net/netfilter/nf_conntrack_helper.c | 17 --- net/netfilter/nf_conntrack_labels.c | 20 +-- net/netfilter/nf_conntrack_seqadj.c | 16 --- net/netfilter/nf_conntrack_timeout.c | 19 --- net/netfilter/nf_conntrack_timestamp.c | 20 --- net/netfilter/nf_nat_core.c | 28 +--- net/netfilter/nf_synproxy_core.c | 24 +--- net/sched/act_ct.c | 13 -- 20 files changed, 95 insertions(+), 395 deletions(-)
Signature · 1 line
2.34.1
Florian Westphal
maintainerPATCH 1/4 netfilter: conntrack: make all extensions 8-byte alignned
All extensions except one need 8 byte alignment, so just make that the default.
--- include/net/netfilter/nf_conntrack_extend.h | 5 +---- net/netfilter/nf_conntrack_acct.c | 1 - net/netfilter/nf_conntrack_ecache.c | 1 - net/netfilter/nf_conntrack_extend.c | 2 +- net/netfilter/nf_conntrack_helper.c | 1 - net/netfilter/nf_conntrack_labels.c | 1 - net/netfilter/nf_conntrack_seqadj.c | 1 - net/netfilter/nf_conntrack_timeout.c | 1 - net/netfilter/nf_conntrack_timestamp.c | 1 - net/netfilter/nf_nat_core.c | 1 - net/netfilter/nf_synproxy_core.c | 1 - net/sched/act_ct.c | 1 - 12 files changed, 2 insertions(+), 15 deletions(-)
include/net/netfilter/nf_conntrack_extend.h +1 -4
@@ -49,7 +49,7 @@ enum nf_ct_ext_id {struct nf_ct_ext {u8 offset[NF_CT_EXT_NUM ];u8 len; -char data[]; +char data[]__aligned(8) ; };static inline bool __nf_ct_ext_exist (const struct nf_ct_ext *ext,u8 id)
@@ -83,10 +83,7 @@ struct nf_ct_ext_type {void (*destroy)(struct nf_conn *ct);enum nf_ct_ext_id id; - -/* Length and min alignment. */ u8 len; -u8 align; };int nf_ct_extend_register (const struct nf_ct_ext_type *type);
net/netfilter/nf_conntrack_acct.c +0 -1
@@ -24,7 +24,6 @@ MODULE_PARM_DESC(acct, "Enable connection tracking flow accounting.");static const struct nf_ct_ext_type acct_extend = { .len =sizeof (struct nf_conn_acct ), - .align = __alignof__(struct nf_conn_acct ), .id =NF_CT_EXT_ACCT , };
net/netfilter/nf_conntrack_ecache.c +0 -1
@@ -306,7 +306,6 @@ static int nf_ct_events __read_mostly = NF_CT_EVENTS_DEFAULT;static const struct nf_ct_ext_type event_extend = { .len =sizeof (struct nf_conntrack_ecache ), - .align = __alignof__(struct nf_conntrack_ecache ), .id =NF_CT_EXT_ECACHE , };
net/netfilter/nf_conntrack_extend.c +1 -1
@@ -65,7 +65,7 @@ void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)return NULL ; } - newoff =ALIGN (oldlen, t->align); + newoff =ALIGN (oldlen, __alignof__(struct nf_ct_ext )); newlen = newoff + t->len;rcu_read_unlock ();
net/netfilter/nf_conntrack_helper.c +0 -1
@@ -552,7 +552,6 @@ EXPORT_SYMBOL_GPL(nf_nat_helper_unregister);static const struct nf_ct_ext_type helper_extend = { .len =sizeof (struct nf_conn_help ), - .align = __alignof__(struct nf_conn_help ), .id =NF_CT_EXT_HELPER , };
net/netfilter/nf_conntrack_labels.c +0 -1
@@ -81,7 +81,6 @@ EXPORT_SYMBOL_GPL(nf_connlabels_put);static const struct nf_ct_ext_type labels_extend = { .len =sizeof (struct nf_conn_labels ), - .align = __alignof__(struct nf_conn_labels ), .id =NF_CT_EXT_LABELS , };
net/netfilter/nf_conntrack_seqadj.c +0 -1
@@ -235,7 +235,6 @@ EXPORT_SYMBOL_GPL(nf_ct_seq_offset);static const struct nf_ct_ext_type nf_ct_seqadj_extend = { .len =sizeof (struct nf_conn_seqadj ), - .align = __alignof__(struct nf_conn_seqadj ), .id =NF_CT_EXT_SEQADJ , };
net/netfilter/nf_conntrack_timeout.c +0 -1
@@ -137,7 +137,6 @@ EXPORT_SYMBOL_GPL(nf_ct_destroy_timeout);static const struct nf_ct_ext_type timeout_extend = { .len =sizeof (struct nf_conn_timeout ), - .align = __alignof__(struct nf_conn_timeout ), .id =NF_CT_EXT_TIMEOUT , };
net/netfilter/nf_conntrack_timestamp.c +0 -1
@@ -21,7 +21,6 @@ MODULE_PARM_DESC(tstamp, "Enable connection tracking flow timestamping.");static const struct nf_ct_ext_type tstamp_extend = { .len =sizeof (struct nf_conn_tstamp ), - .align = __alignof__(struct nf_conn_tstamp ), .id =NF_CT_EXT_TSTAMP , };
net/netfilter/nf_nat_core.c +0 -1
@@ -877,7 +877,6 @@ static void nf_nat_cleanup_conntrack(struct nf_conn *ct)static struct nf_ct_ext_type nat_extend__read_mostly = { .len =sizeof (struct nf_conn_nat ), - .align = __alignof__(struct nf_conn_nat ), .destroy = nf_nat_cleanup_conntrack, .id =NF_CT_EXT_NAT , };
net/netfilter/nf_synproxy_core.c +0 -1
@@ -238,7 +238,6 @@ synproxy_tstamp_adjust(struct sk_buff *skb, unsigned int protoff,static struct nf_ct_ext_type nf_ct_synproxy_extend__read_mostly = { .len =sizeof (struct nf_conn_synproxy ), - .align = __alignof__(struct nf_conn_synproxy ), .id =NF_CT_EXT_SYNPROXY , };
net/sched/act_ct.c +0 -1
@@ -59,7 +59,6 @@ static const struct rhashtable_params zones_params = {static struct nf_ct_ext_type act_ct_extend__read_mostly = { .len =sizeof (struct nf_conn_act_ct_ext ), - .align = __alignof__(struct nf_conn_act_ct_ext ), .id =NF_CT_EXT_ACT_CT , };
Signature · 1 line
2.34.1
Florian Westphal
maintainerPATCH 2/4 netfilter: conntrack: move extension sizes into core
In reply to Florian WestphalNo need to specify this in the registration modules, we already collect all sizes for build-time checks on the maximum combined size.
After this change, all extensions except nat have no meaningful content in their nf_ct_ext_type struct definition.
Next patch handles nat, this will then allow to remove the dynamic register api completely.
--- include/net/netfilter/nf_conntrack_extend.h | 1 - net/netfilter/nf_conntrack_acct.c | 1 - net/netfilter/nf_conntrack_core.c | 37 --------- net/netfilter/nf_conntrack_ecache.c | 1 - net/netfilter/nf_conntrack_extend.c | 86 ++++++++++++++++++--- net/netfilter/nf_conntrack_helper.c | 1 - net/netfilter/nf_conntrack_labels.c | 1 - net/netfilter/nf_conntrack_seqadj.c | 1 - net/netfilter/nf_conntrack_timeout.c | 1 - net/netfilter/nf_conntrack_timestamp.c | 1 - net/netfilter/nf_nat_core.c | 1 - net/netfilter/nf_synproxy_core.c | 1 - net/sched/act_ct.c | 1 - 13 files changed, 76 insertions(+), 58 deletions(-)
include/net/netfilter/nf_conntrack_extend.h +0 -1
@@ -83,7 +83,6 @@ struct nf_ct_ext_type {void (*destroy)(struct nf_conn *ct);enum nf_ct_ext_id id; -u8 len; };int nf_ct_extend_register (const struct nf_ct_ext_type *type);
net/netfilter/nf_conntrack_acct.c +0 -1
@@ -23,7 +23,6 @@ module_param_named(acct, nf_ct_acct, bool, 0644);MODULE_PARM_DESC (acct,"Enable connection tracking flow accounting." );static const struct nf_ct_ext_type acct_extend = { - .len =sizeof (struct nf_conn_acct ), .id =NF_CT_EXT_ACCT , };
net/netfilter/nf_conntrack_core.c +0 -37
@@ -47,7 +47,6 @@#include <net/netfilter/nf_conntrack_timeout.h> #include <net/netfilter/nf_conntrack_labels.h> #include <net/netfilter/nf_conntrack_synproxy.h> -#include <net/netfilter/nf_conntrack_act_ct.h> #include <net/netfilter/nf_nat.h> #include <net/netfilter/nf_nat_helper.h> #include <net/netns/hash.h>
@@ -2626,39 +2625,6 @@ int nf_conntrack_set_hashsize(const char *val, const struct kernel_param *kp)return nf_conntrack_hash_resize (hashsize); } -static __always_inline unsigned int total_extension_size(void) -{ -/* remember to add new extensions below */ -BUILD_BUG_ON (NF_CT_EXT_NUM >10 ); - -return sizeof (struct nf_ct_ext ) + -sizeof (struct nf_conn_help ) -#if IS_ENABLED(CONFIG_NF_NAT) - +sizeof (struct nf_conn_nat ) -#endif - +sizeof (struct nf_conn_seqadj ) - +sizeof (struct nf_conn_acct ) -#ifdef CONFIG_NF_CONNTRACK_EVENTS - +sizeof (struct nf_conntrack_ecache ) -#endif -#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP - +sizeof (struct nf_conn_tstamp ) -#endif -#ifdef CONFIG_NF_CONNTRACK_TIMEOUT - +sizeof (struct nf_conn_timeout ) -#endif -#ifdef CONFIG_NF_CONNTRACK_LABELS - +sizeof (struct nf_conn_labels ) -#endif -#if IS_ENABLED(CONFIG_NETFILTER_SYNPROXY) - +sizeof (struct nf_conn_synproxy ) -#endif -#if IS_ENABLED(CONFIG_NET_ACT_CT) - +sizeof (struct nf_conn_act_ct_ext ) -#endif - ; -}; -int nf_conntrack_init_start (void ) {unsigned long nr_pages =totalram_pages ();
@@ -2666,9 +2632,6 @@ int nf_conntrack_init_start(void)int ret = -ENOMEM ;int i; -/* struct nf_ct_ext uses u8 to store offsets/size */ -BUILD_BUG_ON (total_extension_size () >255u ); -seqcount_spinlock_init (&nf_conntrack_generation, &nf_conntrack_locks_all_lock);
net/netfilter/nf_conntrack_ecache.c +0 -1
@@ -305,7 +305,6 @@ void nf_conntrack_ecache_work(struct net *net, enum nf_ct_ecache_state state)static int nf_ct_events__read_mostly =NF_CT_EVENTS_DEFAULT ;static const struct nf_ct_ext_type event_extend = { - .len =sizeof (struct nf_conntrack_ecache ), .id =NF_CT_EXT_ECACHE , };
net/netfilter/nf_conntrack_extend.c +76 -10
115 lines not on this page · raw message
net/netfilter/nf_conntrack_helper.c +0 -1
@@ -551,7 +551,6 @@ void nf_nat_helper_unregister(struct nf_conntrack_nat_helper *nat)EXPORT_SYMBOL_GPL (nf_nat_helper_unregister);static const struct nf_ct_ext_type helper_extend = { - .len =sizeof (struct nf_conn_help ), .id =NF_CT_EXT_HELPER , };
net/netfilter/nf_conntrack_labels.c +0 -1
@@ -80,7 +80,6 @@ void nf_connlabels_put(struct net *net)EXPORT_SYMBOL_GPL (nf_connlabels_put);static const struct nf_ct_ext_type labels_extend = { - .len =sizeof (struct nf_conn_labels ), .id =NF_CT_EXT_LABELS , };
net/netfilter/nf_conntrack_seqadj.c +0 -1
@@ -234,7 +234,6 @@ s32 nf_ct_seq_offset(const struct nf_conn *ct,EXPORT_SYMBOL_GPL (nf_ct_seq_offset);static const struct nf_ct_ext_type nf_ct_seqadj_extend = { - .len =sizeof (struct nf_conn_seqadj ), .id =NF_CT_EXT_SEQADJ , };
net/netfilter/nf_conntrack_timeout.c +0 -1
@@ -136,7 +136,6 @@ void nf_ct_destroy_timeout(struct nf_conn *ct)EXPORT_SYMBOL_GPL (nf_ct_destroy_timeout);static const struct nf_ct_ext_type timeout_extend = { - .len =sizeof (struct nf_conn_timeout ), .id =NF_CT_EXT_TIMEOUT , };
net/netfilter/nf_conntrack_timestamp.c +0 -1
@@ -20,7 +20,6 @@ module_param_named(tstamp, nf_ct_tstamp, bool, 0644);MODULE_PARM_DESC (tstamp,"Enable connection tracking flow timestamping." );static const struct nf_ct_ext_type tstamp_extend = { - .len =sizeof (struct nf_conn_tstamp ), .id =NF_CT_EXT_TSTAMP , };
net/netfilter/nf_nat_core.c +0 -1
@@ -876,7 +876,6 @@ static void nf_nat_cleanup_conntrack(struct nf_conn *ct) }static struct nf_ct_ext_type nat_extend__read_mostly = { - .len =sizeof (struct nf_conn_nat ), .destroy = nf_nat_cleanup_conntrack, .id =NF_CT_EXT_NAT , };
net/netfilter/nf_synproxy_core.c +0 -1
@@ -237,7 +237,6 @@ synproxy_tstamp_adjust(struct sk_buff *skb, unsigned int protoff, }static struct nf_ct_ext_type nf_ct_synproxy_extend__read_mostly = { - .len =sizeof (struct nf_conn_synproxy ), .id =NF_CT_EXT_SYNPROXY , };
net/sched/act_ct.c +0 -1
@@ -58,7 +58,6 @@ static const struct rhashtable_params zones_params = { };static struct nf_ct_ext_type act_ct_extend__read_mostly = { - .len =sizeof (struct nf_conn_act_ct_ext ), .id =NF_CT_EXT_ACT_CT , };
Signature · 1 line
2.34.1
Florian Westphal
maintainerPATCH 3/4 netfilter: conntrack: hande ->destroy hook via nat_ops instead
In reply to Florian WestphalThe nat module already exposes a few functions to the conntrack core. Move the nat extension destroy hook to it.
After this, no conntrack extension needs a destroy hook. 'struct nf_ct_ext_type' and the register/unregister api can be removed in a followup patch.
--- include/linux/netfilter.h | 1 + include/net/netfilter/nf_conntrack_extend.h | 3 --- net/netfilter/nf_conntrack_core.c | 14 ++++++++++++-- net/netfilter/nf_conntrack_extend.c | 21 --------------------- net/netfilter/nf_nat_core.c | 13 +++---------- 5 files changed, 16 insertions(+), 36 deletions(-)
include/linux/netfilter.h +1 -0
@@ -379,6 +379,7 @@ struct nf_nat_hook {unsigned int (*manip_pkt)(struct sk_buff *skb,struct nf_conn *ct,enum nf_nat_manip_type mtype,enum ip_conntrack_dir dir); +void (*remove_nat_bysrc)(struct nf_conn *ct); };extern const struct nf_nat_hook __rcu *nf_nat_hook;
include/net/netfilter/nf_conntrack_extend.h +0 -3
@@ -79,9 +79,6 @@ void nf_ct_ext_destroy(struct nf_conn *ct);void *nf_ct_ext_add (struct nf_conn *ct,enum nf_ct_ext_id id,gfp_t gfp);struct nf_ct_ext_type { -/* Destroys relationships (can be NULL). */ -void (*destroy)(struct nf_conn *ct); -enum nf_ct_ext_id id; };
net/netfilter/nf_conntrack_core.c +12 -2
@@ -593,7 +593,7 @@ EXPORT_SYMBOL_GPL(nf_ct_tmpl_alloc);void nf_ct_tmpl_free (struct nf_conn *tmpl) { -nf_ct_ext_destroy (tmpl); +kfree (tmpl->ext);if (ARCH_KMALLOC_MINALIGN <=NFCT_INFOMASK )kfree ((char *)tmpl - tmpl->proto.tmpl_padto);
@@ -1596,7 +1596,17 @@ void nf_conntrack_free(struct nf_conn *ct)*/ WARN_ON (refcount_read (&ct->ct_general.use) !=0 ); -nf_ct_ext_destroy (ct); +if (ct->status &IPS_SRC_NAT_DONE ) { +const struct nf_nat_hook *nat_hook; + +rcu_read_lock (); + nat_hook =rcu_dereference (nf_nat_hook); +if (nat_hook) + nat_hook->remove_nat_bysrc (ct); +rcu_read_unlock (); + } + +kfree (ct->ext);kmem_cache_free (nf_conntrack_cachep, ct); cnet =nf_ct_pernet (net);
net/netfilter/nf_conntrack_extend.c +0 -21
@@ -89,27 +89,6 @@ static __always_inline unsigned int total_extension_size(void) ; } -void nf_ct_ext_destroy (struct nf_conn *ct) -{ -unsigned int i; -struct nf_ct_ext_type *t; - -for (i =0 ; i <NF_CT_EXT_NUM ; i++) { -rcu_read_lock (); - t =rcu_dereference (nf_ct_ext_types[i]); - -/* Here the nf_ct_ext_type might have been unregisterd. -* I.e., it has responsible to cleanup private -* area in all conntracks when it is unregisterd. -*/ -if (t && t->destroy) - t->destroy (ct); -rcu_read_unlock (); - } - -kfree (ct->ext); -} -void *nf_ct_ext_add (struct nf_conn *ct,enum nf_ct_ext_id id,gfp_t gfp) {unsigned int newlen, newoff, oldlen, alloc;
net/netfilter/nf_nat_core.c +3 -10
@@ -838,7 +838,7 @@ static int nf_nat_proto_remove(struct nf_conn *i, void *data)return i->status &IPS_NAT_MASK ?1 :0 ; } -static void __nf_nat_cleanup_conntrack (struct nf_conn *ct) +static void nf_nat_cleanup_conntrack (struct nf_conn *ct) {unsigned int h;
@@ -860,7 +860,7 @@ static int nf_nat_proto_clean(struct nf_conn *ct, void *data)* will delete entry from already-freed table. */ if (test_and_clear_bit (IPS_SRC_NAT_DONE_BIT , &ct->status)) -__nf_nat_cleanup_conntrack (ct); +nf_nat_cleanup_conntrack (ct);/* don't delete conntrack. Although that would make things a lot * simpler, we'd end up flushing all conntracks on nat rmmod.
@@ -868,15 +868,7 @@ static int nf_nat_proto_clean(struct nf_conn *ct, void *data)return 0 ; } -/* No one using conntrack by the time this called. */ -static void nf_nat_cleanup_conntrack (struct nf_conn *ct) -{ -if (ct->status &IPS_SRC_NAT_DONE ) -__nf_nat_cleanup_conntrack (ct); -} -static struct nf_ct_ext_type nat_extend__read_mostly = { - .destroy = nf_nat_cleanup_conntrack, .id =NF_CT_EXT_NAT , };
@@ -1171,6 +1163,7 @@ static const struct nf_nat_hook nat_hook = { .decode_session = __nf_nat_decode_session, #endif .manip_pkt = nf_nat_manip_pkt, + .remove_nat_bysrc = nf_nat_cleanup_conntrack, };static int __init nf_nat_init (void )
Signature · 1 line
2.34.1
Florian Westphal
maintainerPATCH 4/4 netfilter: conntrack: remove extension register api
In reply to Florian WestphalThese no longer register/unregister a meaningful structure so remove it.
--- include/net/netfilter/nf_conntrack_acct.h | 1 - include/net/netfilter/nf_conntrack_ecache.h | 13 ------ include/net/netfilter/nf_conntrack_extend.h | 9 ---- include/net/netfilter/nf_conntrack_labels.h | 3 -- include/net/netfilter/nf_conntrack_seqadj.h | 3 -- include/net/netfilter/nf_conntrack_timeout.h | 12 ------ .../net/netfilter/nf_conntrack_timestamp.h | 13 ------ net/netfilter/nf_conntrack_acct.c | 17 -------- net/netfilter/nf_conntrack_core.c | 43 ------------------- net/netfilter/nf_conntrack_ecache.c | 22 +--------- net/netfilter/nf_conntrack_extend.c | 35 +-------------- net/netfilter/nf_conntrack_helper.c | 15 ------- net/netfilter/nf_conntrack_labels.c | 18 +------- net/netfilter/nf_conntrack_seqadj.c | 14 ------ net/netfilter/nf_conntrack_timeout.c | 17 -------- net/netfilter/nf_conntrack_timestamp.c | 18 -------- net/netfilter/nf_nat_core.c | 13 ------ net/netfilter/nf_synproxy_core.c | 22 +--------- net/sched/act_ct.c | 11 ----- 19 files changed, 7 insertions(+), 292 deletions(-)
include/net/netfilter/nf_conntrack_acct.h +0 -1
@@ -78,7 +78,6 @@ static inline void nf_ct_acct_update(struct nf_conn *ct, u32 dir,void nf_conntrack_acct_pernet_init (struct net *net); -int nf_conntrack_acct_init (void );void nf_conntrack_acct_fini (void );#endif /* _NF_CONNTRACK_ACCT_H */
include/net/netfilter/nf_conntrack_ecache.h +0 -13
@@ -166,9 +166,6 @@ void nf_conntrack_ecache_work(struct net *net, enum nf_ct_ecache_state state);void nf_conntrack_ecache_pernet_init (struct net *net);void nf_conntrack_ecache_pernet_fini (struct net *net); -int nf_conntrack_ecache_init (void ); -void nf_conntrack_ecache_fini (void ); -static inline bool nf_conntrack_ecache_dwork_pending (const struct net *net) {return net->ct.ecache_dwork_pending;
@@ -194,16 +191,6 @@ static inline void nf_conntrack_ecache_pernet_init(struct net *net)static inline void nf_conntrack_ecache_pernet_fini (struct net *net) { } - -static inline int nf_conntrack_ecache_init (void ) -{ -return 0 ; -} - -static inline void nf_conntrack_ecache_fini (void ) -{ -} -static inline bool nf_conntrack_ecache_dwork_pending (const struct net *net) {return false; }#endif /* CONFIG_NF_CONNTRACK_EVENTS */ #endif /*_NF_CONNTRACK_ECACHE_H*/
include/net/netfilter/nf_conntrack_extend.h +0 -9
@@ -72,16 +72,7 @@ static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id)#define nf_ct_ext_find (ext, id) \ ((id##_TYPE *)__nf_ct_ext_find((ext), (id))) -/* Destroy all relationships */ -void nf_ct_ext_destroy (struct nf_conn *ct); -/* Add this type, returns pointer to data or NULL. */ void *nf_ct_ext_add (struct nf_conn *ct,enum nf_ct_ext_id id,gfp_t gfp); -struct nf_ct_ext_type { -enum nf_ct_ext_id id; -}; - -int nf_ct_extend_register (const struct nf_ct_ext_type *type); -void nf_ct_extend_unregister (const struct nf_ct_ext_type *type);#endif /* _NF_CONNTRACK_EXTEND_H */
include/net/netfilter/nf_conntrack_labels.h +0 -3
@@ -45,12 +45,9 @@ int nf_connlabels_replace(struct nf_conn *ct,#ifdef CONFIG_NF_CONNTRACK_LABELS int nf_conntrack_labels_init (void ); -void nf_conntrack_labels_fini (void );int nf_connlabels_get (struct net *net,unsigned int bit);void nf_connlabels_put (struct net *net);#else -static inline int nf_conntrack_labels_init (void ) {return 0 ; } -static inline void nf_conntrack_labels_fini (void ) {}static inline int nf_connlabels_get (struct net *net,unsigned int bit) {return 0 ; }static inline void nf_connlabels_put (struct net *net) {}#endif
include/net/netfilter/nf_conntrack_seqadj.h +0 -3
@@ -42,7 +42,4 @@ int nf_ct_seq_adjust(struct sk_buff *skb, struct nf_conn *ct, enum ip_conntrack_info ctinfo, unsigned int protoff);s32 nf_ct_seq_offset (const struct nf_conn *ct,enum ip_conntrack_dir ,u32 seq); -int nf_conntrack_seqadj_init (void ); -void nf_conntrack_seqadj_fini (void ); -#endif /* _NF_CONNTRACK_SEQADJ_H */
include/net/netfilter/nf_conntrack_timeout.h +0 -12
@@ -89,23 +89,11 @@ static inline unsigned int *nf_ct_timeout_lookup(const struct nf_conn *ct) }#ifdef CONFIG_NF_CONNTRACK_TIMEOUT -int nf_conntrack_timeout_init (void ); -void nf_conntrack_timeout_fini (void );void nf_ct_untimeout (struct net *net,struct nf_ct_timeout *timeout);int nf_ct_set_timeout (struct net *net,struct nf_conn *ct,u8 l3num,u8 l4num,const char *timeout_name);void nf_ct_destroy_timeout (struct nf_conn *ct);#else -static inline int nf_conntrack_timeout_init (void ) -{ -return 0 ; -} - -static inline void nf_conntrack_timeout_fini (void ) -{ -return ; -} -static inline int nf_ct_set_timeout (struct net *net,struct nf_conn *ct,u8 l3num,u8 l4num,const char *timeout_name)
include/net/netfilter/nf_conntrack_timestamp.h +0 -13
@@ -40,21 +40,8 @@ struct nf_conn_tstamp *nf_ct_tstamp_ext_add(struct nf_conn *ct, gfp_t gfp)#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP void nf_conntrack_tstamp_pernet_init (struct net *net); - -int nf_conntrack_tstamp_init (void ); -void nf_conntrack_tstamp_fini (void );#else static inline void nf_conntrack_tstamp_pernet_init (struct net *net) {} - -static inline int nf_conntrack_tstamp_init (void ) -{ -return 0 ; -} - -static inline void nf_conntrack_tstamp_fini (void ) -{ -return ; -}#endif /* CONFIG_NF_CONNTRACK_TIMESTAMP */ #endif /* _NF_CONNTRACK_TSTAMP_H */
net/netfilter/nf_conntrack_acct.c +0 -17
@@ -22,24 +22,7 @@ static bool nf_ct_acct __read_mostly;module_param_named (acct, nf_ct_acct, bool,0644 );MODULE_PARM_DESC (acct,"Enable connection tracking flow accounting." ); -static const struct nf_ct_ext_type acct_extend = { - .id =NF_CT_EXT_ACCT , -}; -void nf_conntrack_acct_pernet_init (struct net *net) { net->ct.sysctl_acct = nf_ct_acct; } - -int nf_conntrack_acct_init (void ) -{ -int ret =nf_ct_extend_register (&acct_extend); -if (ret <0 ) -pr_err ("Unable to register extension\n" ); -return ret; -} - -void nf_conntrack_acct_fini (void ) -{ -nf_ct_extend_unregister (&acct_extend); -}
net/netfilter/nf_conntrack_core.c +0 -43
74 lines not on this page · raw message
net/netfilter/nf_conntrack_ecache.c +2 -20
@@ -304,10 +304,6 @@ void nf_conntrack_ecache_work(struct net *net, enum nf_ct_ecache_state state)#define NF_CT_EVENTS_DEFAULT 1static int nf_ct_events__read_mostly =NF_CT_EVENTS_DEFAULT ; -static const struct nf_ct_ext_type event_extend = { - .id =NF_CT_EXT_ECACHE , -}; -void nf_conntrack_ecache_pernet_init (struct net *net) {struct nf_conntrack_net *cnet =nf_ct_pernet (net);
@@ -315,6 +311,8 @@ void nf_conntrack_ecache_pernet_init(struct net *net) net->ct.sysctl_events = nf_ct_events; cnet->ct_net = &net->ct;INIT_DELAYED_WORK (&cnet->ecache_dwork, ecache_work); + +BUILD_BUG_ON (__IPCT_MAX >=16 );/* ctmask, missed use u16 */ }void nf_conntrack_ecache_pernet_fini (struct net *net)
@@ -323,19 +321,3 @@ void nf_conntrack_ecache_pernet_fini(struct net *net)cancel_delayed_work_sync (&cnet->ecache_dwork); } - -int nf_conntrack_ecache_init (void ) -{ -int ret =nf_ct_extend_register (&event_extend); -if (ret <0 ) -pr_err ("Unable to register event extension\n" ); - -BUILD_BUG_ON (__IPCT_MAX >=16 );/* ctmask, missed use u16 */ - -return ret; -} - -void nf_conntrack_ecache_fini (void ) -{ -nf_ct_extend_unregister (&event_extend); -}
net/netfilter/nf_conntrack_extend.c +2 -33
@@ -25,8 +25,6 @@#include <net/netfilter/nf_conntrack_act_ct.h> #include <net/netfilter/nf_nat.h> -static struct nf_ct_ext_type __rcu *nf_ct_ext_types[NF_CT_EXT_NUM ]; -static DEFINE_MUTEX (nf_ct_ext_type_mutex);#define NF_CT_EXT_PREALLOC 128u/* conntrack events are on by default */ static const u8 nf_ct_ext_type_len[NF_CT_EXT_NUM ] = {
@@ -97,6 +95,8 @@ void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)/* Conntrack must not be confirmed to avoid races on reallocation. */ WARN_ON (nf_ct_is_confirmed (ct)); +/* struct nf_ct_ext uses u8 to store offsets/size */ +BUILD_BUG_ON (total_extension_size () >255u );if (ct->ext) {const struct nf_ct_ext *old = ct->ext;
@@ -127,34 +127,3 @@ void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)return (void *)new + newoff; }EXPORT_SYMBOL (nf_ct_ext_add); - -/* This MUST be called in process context. */ -int nf_ct_extend_register (const struct nf_ct_ext_type *type) -{ -int ret =0 ; - -/* struct nf_ct_ext uses u8 to store offsets/size */ -BUILD_BUG_ON (total_extension_size () >255u ); - -mutex_lock (&nf_ct_ext_type_mutex); -if (nf_ct_ext_types[type->id]) { - ret = -EBUSY ; - goto out; - } - -rcu_assign_pointer (nf_ct_ext_types[type->id], type); -out: -mutex_unlock (&nf_ct_ext_type_mutex); -return ret; -} -EXPORT_SYMBOL_GPL (nf_ct_extend_register); - -/* This MUST be called in process context. */ -void nf_ct_extend_unregister (const struct nf_ct_ext_type *type) -{ -mutex_lock (&nf_ct_ext_type_mutex); -RCU_INIT_POINTER (nf_ct_ext_types[type->id],NULL ); -mutex_unlock (&nf_ct_ext_type_mutex); -synchronize_rcu (); -} -EXPORT_SYMBOL_GPL (nf_ct_extend_unregister);
net/netfilter/nf_conntrack_helper.c +0 -15
@@ -550,10 +550,6 @@ void nf_nat_helper_unregister(struct nf_conntrack_nat_helper *nat) }EXPORT_SYMBOL_GPL (nf_nat_helper_unregister); -static const struct nf_ct_ext_type helper_extend = { - .id =NF_CT_EXT_HELPER , -}; -void nf_conntrack_helper_pernet_init (struct net *net) {struct nf_conntrack_net *cnet =nf_ct_pernet (net);
@@ -563,28 +559,17 @@ void nf_conntrack_helper_pernet_init(struct net *net)int nf_conntrack_helper_init (void ) { -int ret; nf_ct_helper_hsize =1 ;/* gets rounded up to use one page */ nf_ct_helper_hash =nf_ct_alloc_hashtable (&nf_ct_helper_hsize,0 );if (!nf_ct_helper_hash)return -ENOMEM ; - ret =nf_ct_extend_register (&helper_extend); -if (ret <0 ) { -pr_err ("nf_ct_helper: Unable to register helper extension.\n" ); - goto out_extend; - } -INIT_LIST_HEAD (&nf_ct_nat_helpers);return 0 ; -out_extend: -kvfree (nf_ct_helper_hash); -return ret; }void nf_conntrack_helper_fini (void ) { -nf_ct_extend_unregister (&helper_extend);kvfree (nf_ct_helper_hash); }
net/netfilter/nf_conntrack_labels.c +2 -16
@@ -67,6 +67,8 @@ int nf_connlabels_get(struct net *net, unsigned int bits) net->ct.labels_used++;spin_unlock (&nf_connlabels_lock); +BUILD_BUG_ON (NF_CT_LABELS_MAX_SIZE /sizeof (long ) >=U8_MAX ); +return 0 ; }EXPORT_SYMBOL_GPL (nf_connlabels_get);
@@ -78,19 +80,3 @@ void nf_connlabels_put(struct net *net)spin_unlock (&nf_connlabels_lock); }EXPORT_SYMBOL_GPL (nf_connlabels_put); - -static const struct nf_ct_ext_type labels_extend = { - .id =NF_CT_EXT_LABELS , -}; - -int nf_conntrack_labels_init (void ) -{ -BUILD_BUG_ON (NF_CT_LABELS_MAX_SIZE /sizeof (long ) >=U8_MAX ); - -return nf_ct_extend_register (&labels_extend); -} - -void nf_conntrack_labels_fini (void ) -{ -nf_ct_extend_unregister (&labels_extend); -}
net/netfilter/nf_conntrack_seqadj.c +0 -14
@@ -232,17 +232,3 @@ s32 nf_ct_seq_offset(const struct nf_conn *ct, this_way->offset_after : this_way->offset_before; }EXPORT_SYMBOL_GPL (nf_ct_seq_offset); - -static const struct nf_ct_ext_type nf_ct_seqadj_extend = { - .id =NF_CT_EXT_SEQADJ , -}; - -int nf_conntrack_seqadj_init (void ) -{ -return nf_ct_extend_register (&nf_ct_seqadj_extend); -} - -void nf_conntrack_seqadj_fini (void ) -{ -nf_ct_extend_unregister (&nf_ct_seqadj_extend); -}
net/netfilter/nf_conntrack_timeout.c +0 -17
@@ -134,20 +134,3 @@ void nf_ct_destroy_timeout(struct nf_conn *ct)rcu_read_unlock (); }EXPORT_SYMBOL_GPL (nf_ct_destroy_timeout); - -static const struct nf_ct_ext_type timeout_extend = { - .id =NF_CT_EXT_TIMEOUT , -}; - -int nf_conntrack_timeout_init (void ) -{ -int ret =nf_ct_extend_register (&timeout_extend); -if (ret <0 ) -pr_err ("nf_ct_timeout: Unable to register timeout extension.\n" ); -return ret; -} - -void nf_conntrack_timeout_fini (void ) -{ -nf_ct_extend_unregister (&timeout_extend); -}
net/netfilter/nf_conntrack_timestamp.c +0 -18
@@ -19,25 +19,7 @@ static bool nf_ct_tstamp __read_mostly;module_param_named (tstamp, nf_ct_tstamp, bool,0644 );MODULE_PARM_DESC (tstamp,"Enable connection tracking flow timestamping." ); -static const struct nf_ct_ext_type tstamp_extend = { - .id =NF_CT_EXT_TSTAMP , -}; -void nf_conntrack_tstamp_pernet_init (struct net *net) { net->ct.sysctl_tstamp = nf_ct_tstamp; } - -int nf_conntrack_tstamp_init (void ) -{ -int ret; - ret =nf_ct_extend_register (&tstamp_extend); -if (ret <0 ) -pr_err ("Unable to register extension\n" ); -return ret; -} - -void nf_conntrack_tstamp_fini (void ) -{ -nf_ct_extend_unregister (&tstamp_extend); -}
net/netfilter/nf_nat_core.c +0 -13
@@ -868,10 +868,6 @@ static int nf_nat_proto_clean(struct nf_conn *ct, void *data)return 0 ; } -static struct nf_ct_ext_type nat_extend__read_mostly = { - .id =NF_CT_EXT_NAT , -}; -#if IS_ENABLED (CONFIG_NF_CT_NETLINK )#include <linux/netfilter/nfnetlink.h>
@@ -1179,19 +1175,11 @@ static int __init nf_nat_init(void)if (!nf_nat_bysource)return -ENOMEM ; - ret =nf_ct_extend_register (&nat_extend); -if (ret <0 ) { -kvfree (nf_nat_bysource); -pr_err ("Unable to register extension\n" ); -return ret; - } -for (i =0 ; i <CONNTRACK_LOCKS ; i++)spin_lock_init (&nf_nat_locks[i]); ret =register_pernet_subsys (&nat_net_ops);if (ret <0 ) { -nf_ct_extend_unregister (&nat_extend);kvfree (nf_nat_bysource);return ret; }
@@ -1210,7 +1198,6 @@ static void __exit nf_nat_cleanup(void)nf_ct_iterate_destroy (nf_nat_proto_clean, &clean); -nf_ct_extend_unregister (&nat_extend);nf_ct_helper_expectfn_unregister (&follow_master_nat);RCU_INIT_POINTER (nf_nat_hook,NULL );
net/netfilter/nf_synproxy_core.c +1 -21
@@ -236,10 +236,6 @@ synproxy_tstamp_adjust(struct sk_buff *skb, unsigned int protoff,return 1 ; } -static struct nf_ct_ext_type nf_ct_synproxy_extend__read_mostly = { - .id =NF_CT_EXT_SYNPROXY , -}; -#ifdef CONFIG_PROC_FS static void *synproxy_cpu_seq_start (struct seq_file *seq,loff_t *pos) {
@@ -385,28 +381,12 @@ static struct pernet_operations synproxy_net_ops = {static int __init synproxy_core_init (void ) { -int err; - - err =nf_ct_extend_register (&nf_ct_synproxy_extend); -if (err <0 ) - goto err1; - - err =register_pernet_subsys (&synproxy_net_ops); -if (err <0 ) - goto err2; - -return 0 ; - -err2: -nf_ct_extend_unregister (&nf_ct_synproxy_extend); -err1: -return err; +return register_pernet_subsys (&synproxy_net_ops); } static void __exit synproxy_core_exit(void) {unregister_pernet_subsys (&synproxy_net_ops); -nf_ct_extend_unregister (&nf_ct_synproxy_extend); }module_init (synproxy_core_init);
net/sched/act_ct.c +0 -11
@@ -57,10 +57,6 @@ static const struct rhashtable_params zones_params = { .automatic_shrinking = true, }; -static struct nf_ct_ext_type act_ct_extend__read_mostly = { - .id =NF_CT_EXT_ACT_CT , -}; -static struct flow_action_entry *tcf_ct_flow_table_flow_action_get_next (struct flow_action *flow_action) {
@@ -1606,16 +1602,10 @@ static int __init ct_init_module(void)if (err) goto err_register; - err =nf_ct_extend_register (&act_ct_extend); -if (err) - goto err_register_extend; -static_branch_inc (&tcf_frag_xmit_count);return 0 ; -err_register_extend: -tcf_unregister_action (&act_ct_ops, &ct_net_ops); err_register:tcf_ct_flow_tables_uninit (); err_tbl_init:
@@ -1626,7 +1616,6 @@ static int __init ct_init_module(void) static void __exit ct_cleanup_module(void) {static_branch_dec (&tcf_frag_xmit_count); -nf_ct_extend_unregister (&act_ct_extend);tcf_unregister_action (&act_ct_ops, &ct_net_ops);tcf_ct_flow_tables_uninit ();destroy_workqueue (act_ct_wq);
Signature · 1 line
2.34.1
Pablo Neira Ayuso
maintainerQuoted 9 lines · Florian Westphal
This starts to simplify the extension infra. Should have no impact on functionality.
Extension IDs already need compile-time allocation, the dynamic registration isn't necessary, just place the sizes in the extension core and handle the only instance of the ->destroy hook manually.
Also avoids the ->destroy hook invocation during ct destruction if the conntrack wasn't added to the bysource hash list.
Series applied.