netfilter: conntrack: shrink size of netns_ct
Subsystems (2)
Florian Westphal
maintainerv2 cover netfilter: conntrack: shrink size of netns_ct
v2: fix linker error when PROCFS=n. This only affects patch 4/5, no other changes.
This reduces size of the netns_ct structure, which itself is embedded in struct net.
First two patches move two helper related settings to net_generic, these are only accessed when a new connection is added.
Patches 3 and 4 move the ct and expect counter to net_generic too. While these are used from packet path, they are not accessed when conntack finds an existing entry.
This also makes netns_ct a read-mostly structure, at this time each newly accepted conntrack dirties the first netns_ct cacheline for other cpus.
Last patch converts a few sysctls to u8. Most conntrack sysctls are timeouts, so these need to be kept as ints.
Florian Westphal (5):
netfilter: conntrack: move autoassign warning member to net_generic
data
netfilter: conntrack: move autoassign_helper sysctl to net_generic
data
netfilter: conntrack: move expect counter to net_generic data
netfilter: conntrack: move ct counter to net_generic data
netfilter: conntrack: convert sysctls to u8
include/net/netfilter/nf_conntrack.h | 8 +++ include/net/netns/conntrack.h | 23 ++++----- net/netfilter/nf_conntrack_core.c | 46 ++++++++++++----- net/netfilter/nf_conntrack_expect.c | 22 ++++++--- net/netfilter/nf_conntrack_helper.c | 15 ++++-- net/netfilter/nf_conntrack_netlink.c | 5 +- net/netfilter/nf_conntrack_proto_tcp.c | 34 ++++++------- net/netfilter/nf_conntrack_standalone.c | 66 +++++++++++++------------ 8 files changed, 132 insertions(+), 87 deletions(-)
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 1/5 netfilter: conntrack: move autoassign warning member to net_generic data
Not accessed in fast path, place this is generic_net data instead.
--- include/net/netfilter/nf_conntrack.h | 4 ++++ net/netfilter/nf_conntrack_helper.c | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)
include/net/netfilter/nf_conntrack.h +4 -0
@@ -44,6 +44,10 @@ union nf_conntrack_expect_proto { };struct nf_conntrack_net { +/* only used when new connection is allocated: */ +bool auto_assign_helper_warned; + +/* only used from work queues, configuration plane, and so on: */ unsigned int users4;unsigned int users6;unsigned int users_bridge;
net/netfilter/nf_conntrack_helper.c +6 -3
@@ -43,6 +43,8 @@ MODULE_PARM_DESC(nf_conntrack_helper,static DEFINE_MUTEX (nf_ct_nat_helpers_mutex);static struct list_head nf_ct_nat_helpers__read_mostly ; +extern unsigned int nf_conntrack_net_id; +/* Stupid hash, but collision free for the default registrations of the * helpers currently in the kernel. */ static unsigned int helper_hash (const struct nf_conntrack_tuple *tuple)
@@ -212,8 +214,10 @@ EXPORT_SYMBOL_GPL(nf_ct_helper_ext_add);static struct nf_conntrack_helper *nf_ct_lookup_helper (struct nf_conn *ct,struct net *net) { +struct nf_conntrack_net *cnet =net_generic (net, nf_conntrack_net_id); +if (!net->ct.sysctl_auto_assign_helper) { -if (net->ct.auto_assign_helper_warned) +if (cnet->auto_assign_helper_warned)return NULL ;if (!__nf_ct_helper_find (&ct->tuplehash[IP_CT_DIR_REPLY ].tuple))return NULL ;
@@ -221,7 +225,7 @@ nf_ct_lookup_helper(struct nf_conn *ct, struct net *net)"has been turned off for security reasons and CT-based " "firewall rule not found. Use the iptables CT target " "to attach helpers instead.\n"); - net->ct.auto_assign_helper_warned =1 ; + cnet->auto_assign_helper_warned = true;return NULL ; }
@@ -556,7 +560,6 @@ static const struct nf_ct_ext_type helper_extend = {void nf_conntrack_helper_pernet_init (struct net *net) { - net->ct.auto_assign_helper_warned = false; net->ct.sysctl_auto_assign_helper = nf_ct_auto_assign_helper; }
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 2/5 netfilter: conntrack: move autoassign_helper sysctl to net_generic data
In reply to Florian WestphalWhile at it, make it an u8, no need to use an integer for a boolean.
--- include/net/netfilter/nf_conntrack.h | 1 + net/netfilter/nf_conntrack_helper.c | 6 ++++-- net/netfilter/nf_conntrack_standalone.c | 7 +++---- 3 files changed, 8 insertions(+), 6 deletions(-)
include/net/netfilter/nf_conntrack.h +1 -0
@@ -45,6 +45,7 @@ union nf_conntrack_expect_proto {struct nf_conntrack_net {/* only used when new connection is allocated: */ +u8 sysctl_auto_assign_helper;bool auto_assign_helper_warned;/* only used from work queues, configuration plane, and so on: */
net/netfilter/nf_conntrack_helper.c +4 -2
@@ -216,7 +216,7 @@ nf_ct_lookup_helper(struct nf_conn *ct, struct net *net) {struct nf_conntrack_net *cnet =net_generic (net, nf_conntrack_net_id); -if (!net->ct.sysctl_auto_assign_helper) { +if (!cnet->sysctl_auto_assign_helper) {if (cnet->auto_assign_helper_warned)return NULL ;if (!__nf_ct_helper_find (&ct->tuplehash[IP_CT_DIR_REPLY ].tuple))
@@ -560,7 +560,9 @@ static const struct nf_ct_ext_type helper_extend = {void nf_conntrack_helper_pernet_init (struct net *net) { - net->ct.sysctl_auto_assign_helper = nf_ct_auto_assign_helper; +struct nf_conntrack_net *cnet =net_generic (net, nf_conntrack_net_id); + + cnet->sysctl_auto_assign_helper = nf_ct_auto_assign_helper; }int nf_conntrack_helper_init (void )
net/netfilter/nf_conntrack_standalone.c +3 -4
@@ -662,10 +662,9 @@ static struct ctl_table nf_ct_sysctl_table[] = { }, [NF_SYSCTL_CT_HELPER] = { .procname = "nf_conntrack_helper", - .data = &init_net.ct.sysctl_auto_assign_helper, - .maxlen = sizeof(int), + .maxlen = sizeof(u8), .mode = 0644, - .proc_handler = proc_dointvec_minmax, + .proc_handler = proc_dou8vec_minmax, .extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_ONE, },
@@ -1042,7 +1041,7 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net) table[NF_SYSCTL_CT_CHECKSUM ].data = &net->ct.sysctl_checksum; table[NF_SYSCTL_CT_LOG_INVALID ].data = &net->ct.sysctl_log_invalid; table[NF_SYSCTL_CT_ACCT ].data = &net->ct.sysctl_acct; - table[NF_SYSCTL_CT_HELPER ].data = &net->ct.sysctl_auto_assign_helper; + table[NF_SYSCTL_CT_HELPER ].data = &cnet->sysctl_auto_assign_helper;#ifdef CONFIG_NF_CONNTRACK_EVENTS table[NF_SYSCTL_CT_EVENTS ].data = &net->ct.sysctl_events;#endif
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 3/5 netfilter: conntrack: move expect counter to net_generic data
In reply to Florian WestphalCreation of a new conntrack entry isn't a frequent operation (compared to 'ct entry already exists'). Creation of a new entry that is also an expected (related) connection even less so.
Place this counter in net_generic data.
A followup patch will also move the conntrack count -- this will make netns_ct a read-mostly structure.
--- include/net/netfilter/nf_conntrack.h | 1 + net/netfilter/nf_conntrack_core.c | 6 +++++- net/netfilter/nf_conntrack_expect.c | 22 ++++++++++++++++------ 3 files changed, 22 insertions(+), 7 deletions(-)
include/net/netfilter/nf_conntrack.h +1 -0
@@ -45,6 +45,7 @@ union nf_conntrack_expect_proto {struct nf_conntrack_net {/* only used when new connection is allocated: */ +unsigned int expect_count;u8 sysctl_auto_assign_helper;bool auto_assign_helper_warned;
net/netfilter/nf_conntrack_core.c +5 -1
@@ -55,6 +55,8 @@#include "nf_internals.h" +extern unsigned int nf_conntrack_net_id; + __cacheline_aligned_in_smp spinlock_t nf_conntrack_locks[CONNTRACK_LOCKS];EXPORT_SYMBOL_GPL (nf_conntrack_locks);
@@ -1570,6 +1572,7 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,const struct nf_conntrack_zone *zone;struct nf_conn_timeout *timeout_ext;struct nf_conntrack_zone tmp; +struct nf_conntrack_net *cnet;if (!nf_ct_invert_tuple (&repl_tuple, tuple)) {pr_debug ("Can't invert tuple.\n" );
@@ -1603,7 +1606,8 @@ init_conntrack(struct net *net, struct nf_conn *tmpl, GFP_ATOMIC);local_bh_disable (); -if (net->ct.expect_count) { + cnet =net_generic (net, nf_conntrack_net_id); +if (cnet->expect_count) {spin_lock (&nf_conntrack_expect_lock); exp =nf_ct_find_expectation (net, zone, tuple);if (exp) {
net/netfilter/nf_conntrack_expect.c +16 -6
@@ -43,18 +43,23 @@ unsigned int nf_ct_expect_max __read_mostly;static struct kmem_cache *nf_ct_expect_cachep__read_mostly ;static unsigned int nf_ct_expect_hashrnd__read_mostly ; +extern unsigned int nf_conntrack_net_id; +/* nf_conntrack_expect helper functions */ void nf_ct_unlink_expect_report (struct nf_conntrack_expect *exp,u32 portid,int report) {struct nf_conn_help *master_help =nfct_help (exp->master);struct net *net =nf_ct_exp_net (exp); +struct nf_conntrack_net *cnet;WARN_ON (!master_help);WARN_ON (timer_pending (&exp->timeout));hlist_del_rcu (&exp->hnode); - net->ct.expect_count--; + + cnet =net_generic (net, nf_conntrack_net_id); + cnet->expect_count--;hlist_del_rcu (&exp->lnode); master_help->expecting[exp->class]--;
@@ -118,10 +123,11 @@ __nf_ct_expect_find(struct net *net,const struct nf_conntrack_zone *zone, const struct nf_conntrack_tuple *tuple) { + struct nf_conntrack_net *cnet = net_generic(net, nf_conntrack_net_id);struct nf_conntrack_expect *i;unsigned int h; -if (!net->ct.expect_count) +if (!cnet->expect_count)return NULL ; h =nf_ct_expect_dst_hash (net, tuple);
@@ -158,10 +164,11 @@ nf_ct_find_expectation(struct net *net,const struct nf_conntrack_zone *zone, const struct nf_conntrack_tuple *tuple) { + struct nf_conntrack_net *cnet = net_generic(net, nf_conntrack_net_id);struct nf_conntrack_expect *i, *exp =NULL ;unsigned int h; -if (!net->ct.expect_count) +if (!cnet->expect_count)return NULL ; h =nf_ct_expect_dst_hash (net, tuple);
@@ -368,6 +375,7 @@ EXPORT_SYMBOL_GPL(nf_ct_expect_put);static void nf_ct_expect_insert (struct nf_conntrack_expect *exp) { +struct nf_conntrack_net *cnet;struct nf_conn_help *master_help =nfct_help (exp->master);struct nf_conntrack_helper *helper;struct net *net =nf_ct_exp_net (exp);
@@ -389,7 +397,8 @@ static void nf_ct_expect_insert(struct nf_conntrack_expect *exp) master_help->expecting[exp->class]++;hlist_add_head_rcu (&exp->hnode, &nf_ct_expect_hash[h]); - net->ct.expect_count++; + cnet =net_generic (net, nf_conntrack_net_id); + cnet->expect_count++;NF_CT_STAT_INC (net, expect_create); }
@@ -415,6 +424,7 @@ static inline int __nf_ct_expect_check(struct nf_conntrack_expect *expect, {const struct nf_conntrack_expect_policy *p;struct nf_conntrack_expect *i; +struct nf_conntrack_net *cnet;struct nf_conn *master = expect->master;struct nf_conn_help *master_help =nfct_help (master);struct nf_conntrack_helper *helper;
@@ -458,7 +468,8 @@ static inline int __nf_ct_expect_check(struct nf_conntrack_expect *expect, } } -if (net->ct.expect_count >= nf_ct_expect_max) { + cnet =net_generic (net, nf_conntrack_net_id); +if (cnet->expect_count >= nf_ct_expect_max) {net_warn_ratelimited ("nf_conntrack: expectation table full\n" ); ret = -EMFILE ; }
@@ -686,7 +697,6 @@ module_param_named(expect_hashsize, nf_ct_expect_hsize, uint, 0400);int nf_conntrack_expect_pernet_init (struct net *net) { - net->ct.expect_count =0 ;return exp_proc_init (net); }
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 4/5 netfilter: conntrack: move ct counter to net_generic data
In reply to Florian WestphalIts only needed from slowpath (sysctl, ctnetlink, gc worker) and when a new conntrack object is allocated.
Furthermore, each write dirties the otherwise read-mostly pernet data in struct net.ct, which are accessed from packet path.
Move it to the net_generic data. This makes struct netns_ct read-mostly.
---
v2: don't place nf_conntrack_count() where it will be excluded in CONFIG_PROCFS=n builds.
include/net/netfilter/nf_conntrack.h | 2 ++ net/netfilter/nf_conntrack_core.c | 40 +++++++++++++++++-------- net/netfilter/nf_conntrack_netlink.c | 5 ++-- net/netfilter/nf_conntrack_standalone.c | 17 +++++++++-- 4 files changed, 47 insertions(+), 17 deletions(-)
include/net/netfilter/nf_conntrack.h +2 -0
@@ -45,6 +45,7 @@ union nf_conntrack_expect_proto {struct nf_conntrack_net {/* only used when new connection is allocated: */ +atomic_t count;unsigned int expect_count;u8 sysctl_auto_assign_helper;bool auto_assign_helper_warned;
@@ -337,6 +338,7 @@ struct nf_conn *nf_ct_tmpl_alloc(struct net *net,void nf_ct_tmpl_free (struct nf_conn *tmpl);u32 nf_ct_get_id (const struct nf_conn *ct); +u32 nf_conntrack_count (const struct net *net);static inline void nf_ct_set (struct sk_buff *skb,struct nf_conn *ct,enum ip_conntrack_info info)
net/netfilter/nf_conntrack_core.c +28 -12
@@ -87,6 +87,8 @@ static __read_mostly bool nf_conntrack_locks_all;static struct conntrack_gc_work conntrack_gc_work; +extern unsigned int nf_conntrack_net_id; +void nf_conntrack_lock (spinlock_t *lock)__acquires (lock) {/* 1) Acquire the lock */
@@ -1381,6 +1383,7 @@ static void gc_worker(struct work_struct *work) i =0 ;hlist_nulls_for_each_entry_rcu (h, n, &ct_hash[i], hnnode) { +struct nf_conntrack_net *cnet;struct net *net; tmp =nf_ct_tuplehash_to_ctrack (h);
@@ -1401,7 +1404,8 @@ static void gc_worker(struct work_struct *work)continue ; net =nf_ct_net (tmp); -if (atomic_read (&net->ct.count) < nf_conntrack_max95) + cnet =net_generic (net, nf_conntrack_net_id); +if (atomic_read (&cnet->count) < nf_conntrack_max95)continue ;/* need to take reference to avoid possible races */
@@ -1480,17 +1484,18 @@ __nf_conntrack_alloc(struct net *net,const struct nf_conntrack_tuple *repl, gfp_t gfp, u32 hash) { + struct nf_conntrack_net *cnet = net_generic(net, nf_conntrack_net_id); +unsigned int ct_count;struct nf_conn *ct;/* We don't want any race condition at early drop stage */ -atomic_inc (&net->ct.count); + ct_count =atomic_inc_return (&cnet->count); -if (nf_conntrack_max && -unlikely (atomic_read (&net->ct.count) > nf_conntrack_max)) { +if (nf_conntrack_max &&unlikely (ct_count > nf_conntrack_max)) {if (!early_drop (net, hash)) {if (!conntrack_gc_work.early_drop) conntrack_gc_work.early_drop = true; -atomic_dec (&net->ct.count); +atomic_dec (&cnet->count);net_warn_ratelimited ("nf_conntrack: table full, dropping packet\n" );return ERR_PTR (-ENOMEM ); }
@@ -1525,7 +1530,7 @@ __nf_conntrack_alloc(struct net *net,atomic_set (&ct->ct_general.use,0 );return ct; out: -atomic_dec (&net->ct.count); +atomic_dec (&cnet->count);return ERR_PTR (-ENOMEM ); }
@@ -1542,6 +1547,7 @@ EXPORT_SYMBOL_GPL(nf_conntrack_alloc);void nf_conntrack_free (struct nf_conn *ct) {struct net *net =nf_ct_net (ct); +struct nf_conntrack_net *cnet;/* A freed object has refcnt == 0, that's * the golden rule for SLAB_TYPESAFE_BY_RCU
@@ -1550,8 +1556,10 @@ void nf_conntrack_free(struct nf_conn *ct)nf_ct_ext_destroy (ct);kmem_cache_free (nf_conntrack_cachep, ct); + cnet =net_generic (net, nf_conntrack_net_id); +smp_mb__before_atomic (); -atomic_dec (&net->ct.count); +atomic_dec (&cnet->count); }EXPORT_SYMBOL_GPL (nf_conntrack_free);
@@ -2309,9 +2317,11 @@ __nf_ct_unconfirmed_destroy(struct net *net)void nf_ct_unconfirmed_destroy (struct net *net) { +struct nf_conntrack_net *cnet =net_generic (net, nf_conntrack_net_id); +might_sleep (); -if (atomic_read (&net->ct.count) >0 ) { +if (atomic_read (&cnet->count) >0 ) {__nf_ct_unconfirmed_destroy (net);nf_queue_nf_hook_drop (net);synchronize_net ();
@@ -2323,11 +2333,12 @@ void nf_ct_iterate_cleanup_net(struct net *net,int (*iter)(struct nf_conn *i,void *data), void *data, u32 portid, int report) { + struct nf_conntrack_net *cnet = net_generic(net, nf_conntrack_net_id);struct iter_data d;might_sleep (); -if (atomic_read (&net->ct.count) ==0 ) +if (atomic_read (&cnet->count) ==0 )return ; d.iter = iter;
@@ -2356,7 +2367,9 @@ nf_ct_iterate_destroy(int (*iter)(struct nf_conn *i, void *data), void *data)down_read (&net_rwsem);for_each_net (net) { -if (atomic_read (&net->ct.count) ==0 ) +struct nf_conntrack_net *cnet =net_generic (net, nf_conntrack_net_id); + +if (atomic_read (&cnet->count) ==0 )continue ;__nf_ct_unconfirmed_destroy (net);nf_queue_nf_hook_drop (net);
@@ -2436,8 +2449,10 @@ void nf_conntrack_cleanup_net_list(struct list_head *net_exit_list) i_see_dead_people: busy =0 ;list_for_each_entry (net, net_exit_list, exit_list) { +struct nf_conntrack_net *cnet =net_generic (net, nf_conntrack_net_id); +nf_ct_iterate_cleanup (kill_all, net,0 ,0 ); -if (atomic_read (&net->ct.count) !=0 ) +if (atomic_read (&cnet->count) !=0 ) busy =1 ; }if (busy) {
@@ -2718,12 +2733,13 @@ void nf_conntrack_init_end(void)int nf_conntrack_init_net (struct net *net) { +struct nf_conntrack_net *cnet =net_generic (net, nf_conntrack_net_id);int ret = -ENOMEM ;int cpu;BUILD_BUG_ON (IP_CT_UNTRACKED ==IP_CT_NUMBER );BUILD_BUG_ON_NOT_POWER_OF_2 (CONNTRACK_LOCKS ); -atomic_set (&net->ct.count,0 ); +atomic_set (&cnet->count,0 ); net->ct.pcpu_lists = alloc_percpu(struct ct_pcpu);if (!net->ct.pcpu_lists)
net/netfilter/nf_conntrack_netlink.c +3 -2
@@ -2559,9 +2559,9 @@ static int ctnetlink_stat_ct_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type, struct net *net) { - struct nlmsghdr *nlh; unsigned int flags = portid ? NLM_F_MULTI : 0, event; -unsigned int nr_conntracks =atomic_read (&net->ct.count); +unsigned int nr_conntracks; +struct nlmsghdr *nlh; event =nfnl_msg_type (NFNL_SUBSYS_CTNETLINK ,IPCTNL_MSG_CT_GET_STATS ); nlh = nfnl_msg_put(skb, portid, seq, event, flags, AF_UNSPEC,
@@ -2569,6 +2569,7 @@ ctnetlink_stat_ct_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type,if (!nlh) goto nlmsg_failure; + nr_conntracks =nf_conntrack_count (net);if (nla_put_be32 (skb,CTA_STATS_GLOBAL_ENTRIES ,htonl (nr_conntracks))) goto nla_put_failure;
net/netfilter/nf_conntrack_standalone.c +14 -3
@@ -424,14 +424,16 @@ static void ct_cpu_seq_stop(struct seq_file *seq, void *v)static int ct_cpu_seq_show (struct seq_file *seq,void *v) {struct net *net =seq_file_net (seq); -unsigned int nr_conntracks =atomic_read (&net->ct.count);const struct ip_conntrack_stat *st = v; +unsigned int nr_conntracks;if (v ==SEQ_START_TOKEN ) {seq_puts (seq,"entries clashres found new invalid ignore delete delete_list insert insert_failed drop early_drop icmp_error expect_new expect_create expect_delete search_restart\n" );return 0 ; } + nr_conntracks =nf_conntrack_count (net); + seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x " "%08x %08x %08x %08x %08x %08x %08x %08x %08x\n", nr_conntracks,
@@ -507,6 +509,16 @@ static void nf_conntrack_standalone_fini_proc(struct net *net) }#endif /* CONFIG_NF_CONNTRACK_PROCFS */ +u32 nf_conntrack_count (const struct net *net) +{ +const struct nf_conntrack_net *cnet; + + cnet =net_generic (net, nf_conntrack_net_id); + +return atomic_read (&cnet->count); +} +EXPORT_SYMBOL_GPL (nf_conntrack_count); +/* Sysctl support */ #ifdef CONFIG_SYSCTL
@@ -614,7 +626,6 @@ static struct ctl_table nf_ct_sysctl_table[] = { }, [NF_SYSCTL_CT_COUNT] = { .procname = "nf_conntrack_count", - .data = &init_net.ct.count, .maxlen = sizeof(int), .mode = 0444, .proc_handler = proc_dointvec,
@@ -1037,7 +1048,7 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net)if (!table)return -ENOMEM ; - table[NF_SYSCTL_CT_COUNT ].data = &net->ct.count; + table[NF_SYSCTL_CT_COUNT ].data = &cnet->count; table[NF_SYSCTL_CT_CHECKSUM ].data = &net->ct.sysctl_checksum; table[NF_SYSCTL_CT_LOG_INVALID ].data = &net->ct.sysctl_log_invalid; table[NF_SYSCTL_CT_ACCT ].data = &net->ct.sysctl_acct;
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH v2 5/5 netfilter: conntrack: convert sysctls to u8
In reply to Florian Westphallog_invalid sysctl allows values of 0 to 255 inclusive so we no longer need a range check: the min/max values can be removed.
This also removes all member variables that were moved to net_generic data in previous patches.
This reduces size of netns_ct struct by one cache line.
--- include/net/netns/conntrack.h | 23 ++++++-------- net/netfilter/nf_conntrack_proto_tcp.c | 34 ++++++++++---------- net/netfilter/nf_conntrack_standalone.c | 42 +++++++++++-------------- 3 files changed, 45 insertions(+), 54 deletions(-)
include/net/netns/conntrack.h +10 -13
@@ -24,9 +24,9 @@ struct nf_generic_net {struct nf_tcp_net {unsigned int timeouts[TCP_CONNTRACK_TIMEOUT_MAX ]; -int tcp_loose; -int tcp_be_liberal; -int tcp_max_retrans; +u8 tcp_loose; +u8 tcp_be_liberal; +u8 tcp_max_retrans; };enum udp_conntrack {
@@ -45,7 +45,7 @@ struct nf_icmp_net {#ifdef CONFIG_NF_CT_PROTO_DCCP struct nf_dccp_net { -int dccp_loose; +u8 dccp_loose;unsigned int dccp_timeout[CT_DCCP_MAX +1 ]; };#endif
@@ -93,18 +93,15 @@ struct ct_pcpu { };struct netns_ct { -atomic_t count; -unsigned int expect_count;#ifdef CONFIG_NF_CONNTRACK_EVENTS bool ecache_dwork_pending;#endif -bool auto_assign_helper_warned; -unsigned int sysctl_log_invalid;/* Log invalid packets */ -int sysctl_events; -int sysctl_acct; -int sysctl_auto_assign_helper; -int sysctl_tstamp; -int sysctl_checksum; +u8 sysctl_log_invalid;/* Log invalid packets */ +u8 sysctl_events; +u8 sysctl_acct; +u8 sysctl_auto_assign_helper; +u8 sysctl_tstamp; +u8 sysctl_checksum;struct ct_pcpu __percpu *pcpu_lists;struct ip_conntrack_stat __percpu *stat;
net/netfilter/nf_conntrack_proto_tcp.c +17 -17
@@ -31,20 +31,6 @@#include <net/netfilter/ipv4/nf_conntrack_ipv4.h> #include <net/netfilter/ipv6/nf_conntrack_ipv6.h> -/* "Be conservative in what you do, -be liberal in what you accept from others." -If it's non-zero, we mark only out of window RST segments as INVALID. */ -static int nf_ct_tcp_be_liberal__read_mostly =0 ; - -/* If it is set to zero, we disable picking up already established -connections. */ -static int nf_ct_tcp_loose__read_mostly =1 ; - -/* Max number of the retransmitted packets without receiving an (acceptable) -ACK from the destination. If this number is reached, a shorter timer -will be started. */ -static int nf_ct_tcp_max_retrans__read_mostly =3 ; -/* FIXME: Examine ipfilter's timeouts and conntrack transitions more closely. They're more complex. --RR */
@@ -1436,9 +1422,23 @@ void nf_conntrack_tcp_init_net(struct net *net)* ->timeouts[0] contains 'new' timeout, like udp or icmp. */ tn->timeouts[0 ] = tcp_timeouts[TCP_CONNTRACK_SYN_SENT ]; - tn->tcp_loose = nf_ct_tcp_loose; - tn->tcp_be_liberal = nf_ct_tcp_be_liberal; - tn->tcp_max_retrans = nf_ct_tcp_max_retrans; + +/* If it is set to zero, we disable picking up already established +* connections. +*/ + tn->tcp_loose =1 ; + +/* "Be conservative in what you do, +* be liberal in what you accept from others." +* If it's non-zero, we mark only out of window RST segments as INVALID. +*/ + tn->tcp_be_liberal =0 ; + +/* Max number of the retransmitted packets without receiving an (acceptable) +* ACK from the destination. If this number is reached, a shorter timer +* will be started. +*/ + tn->tcp_max_retrans =3 ; } const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp =
net/netfilter/nf_conntrack_standalone.c +18 -24
109 lines not on this page · raw message
Signature · 1 line
2.26.3
Pablo Neira Ayuso
maintainerQuoted 13 lines · Florian Westphal
v2: fix linker error when PROCFS=n. This only affects patch 4/5, no other changes.
This reduces size of the
netns_ctstructure, which itself is embedded in struct net.First two patches move two helper related settings to
net_generic, these are only accessed when a new connection is added.Patches 3 and 4 move the ct and expect counter to
net_generictoo. While these are used from packet path, they are not accessed when conntack finds an existing entry.
Quoted 6 lines
This also makes
netns_cta read-mostly structure, at this time each newly accepted conntrack dirties the firstnetns_ctcacheline for other cpus.Last patch converts a few sysctls to u8. Most conntrack sysctls are timeouts, so these need to be kept as ints.
Series applied, thanks.