netfilter: conntrack: Fix CT offload timeout on heavily loaded systems
Subsystems (3)
v2 cover netfilter: conntrack: Fix CT offload timeout on heavily loaded systems
On heavily loaded systems the GC can take time to go over all existing conns and reset their timeout. At that time other calls like from nf_conntrack_in() can call of nf_ct_is_expired() and see the conn as expired. To fix this when we set the offload bit we should also reset the timeout instead of counting on GC to finish first iteration over all conns before the initial timeout.
First commit is to expose the function that updates the timeout. Second commit is to use it from flow_offload_add().
Roi Dayan (2):
netfilter: conntrack: Move nf_ct_offload_timeout to header file
netfilter: flowtable: Set offload timeout when adding flow
include/net/netfilter/nf_conntrack.h | 12 ++++++++++++ net/netfilter/nf_conntrack_core.c | 12 ------------ net/netfilter/nf_flow_table_core.c | 2 ++ 3 files changed, 14 insertions(+), 12 deletions(-)
Signature · 1 line
2.8.4
PATCH v2 1/2 netfilter: conntrack: Move nf_ct_offload_timeout to header file
To be used by callers from other modules.
--- include/net/netfilter/nf_conntrack.h | 12 ++++++++++++ net/netfilter/nf_conntrack_core.c | 12 ------------ 2 files changed, 12 insertions(+), 12 deletions(-)
include/net/netfilter/nf_conntrack.h +12 -0
@@ -279,6 +279,18 @@ static inline bool nf_ct_should_gc(const struct nf_conn *ct) !nf_ct_is_dying (ct); } +#define DAY (86400 * HZ) + +/* Set an arbitrary timeout large enough not to ever expire, this save +* us a check for the IPS_OFFLOAD_BIT from the packet path via +* nf_ct_is_expired(). +*/ +static inline void nf_ct_offload_timeout (struct nf_conn *ct) +{ +if (nf_ct_expires (ct) <DAY /2 ) + ct->timeout = nfct_time_stamp +DAY ; +} +struct kernel_param ;int nf_conntrack_set_hashsize (const char *val,const struct kernel_param *kp);
net/netfilter/nf_conntrack_core.c +0 -12
@@ -1344,18 +1344,6 @@ static bool gc_worker_can_early_drop(const struct nf_conn *ct)return false; } -#define DAY (86400 * HZ) - -/* Set an arbitrary timeout large enough not to ever expire, this save -* us a check for the IPS_OFFLOAD_BIT from the packet path via -* nf_ct_is_expired(). -*/ -static void nf_ct_offload_timeout (struct nf_conn *ct) -{ -if (nf_ct_expires (ct) <DAY /2 ) - ct->timeout = nfct_time_stamp +DAY ; -} -static void gc_worker (struct work_struct *work) {unsigned int min_interval =max (HZ /GC_MAX_BUCKETS_DIV ,1u );
Signature · 1 line
2.8.4
Pablo Neira Ayuso
maintainerRe: [PATCH net v2 1/2] netfilter: conntrack: Move nf_ct_offload_timeout to header file
Quoted 21 lines · Roi Dayan
To be used by callers from other modules.
Signed-off-by Roi Dayan <[email protected]>Reviewed-by Oz Shlomo <[email protected]>--- include/net/netfilter/nf_conntrack.h | 12 ++++++++++++ net/netfilter/nf_conntrack_core.c | 12 ------------ 2 files changed, 12 insertions(+), 12 deletions(-)include/net/netfilter/nf_conntrack.h +4
-0@@ -279,6 +279,18 @@ static inline bool nf_ct_should_gc(const struct nf_conn *ct) !nf_ct_is_dying (ct); } +#define DAY (86400 * HZ) + +/* Set an arbitrary timeout large enough not to ever expire, this save +* us a check for the IPS_OFFLOAD_BIT from the packet path via
include/net/netfilter/nf_conntrack.h static inline bool nf_ct_should_gc(const struct nf_conn *ct) · line 295
Quoted 10 lines
include/net/netfilter/nf_conntrack.h +8
-0+* nf_ct_is_expired(). +*/ +static inline void nf_ct_offload_timeout (struct nf_conn *ct) +{ +if (nf_ct_expires (ct) <DAY /2 ) + ct->timeout = nfct_time_stamp +DAY ; +} +struct kernel_param ;
For the record: I have renamed DAY to NF_CT_DAY to avoid a possible symbol name clash. No need to resend, I applied this small change before applying.
Re: [PATCH net v2 1/2] netfilter: conntrack: Move nf_ct_offload_timeout to header file
Quoted 28 lines · Pablo Neira Ayuso
Quoted 27 lines · Roi Dayan
To be used by callers from other modules.
Signed-off-by Roi Dayan <[email protected]>Reviewed-by Oz Shlomo <[email protected]>--- include/net/netfilter/nf_conntrack.h | 12 ++++++++++++ net/netfilter/nf_conntrack_core.c | 12 ------------ 2 files changed, 12 insertions(+), 12 deletions(-)include/net/netfilter/nf_conntrack.h +10
-0@@ -279,6 +279,18 @@ static inline bool nf_ct_should_gc(const struct nf_conn *ct) !nf_ct_is_dying (ct); } +#define DAY (86400 * HZ) + +/* Set an arbitrary timeout large enough not to ever expire, this save +* us a check for the IPS_OFFLOAD_BIT from the packet path via +* nf_ct_is_expired(). +*/ +static inline void nf_ct_offload_timeout (struct nf_conn *ct) +{ +if (nf_ct_expires (ct) <DAY /2 ) + ct->timeout = nfct_time_stamp +DAY ;
Quoted 9 lines
include/net/netfilter/nf_conntrack.h static inline bool nf_ct_should_gc(const struct nf_conn *ct) · line 295
Quoted 4 lines
include/net/netfilter/nf_conntrack.h +2
-0+} +struct kernel_param ;For the record: I have renamed DAY to
NF_CT_DAYto avoid a possible symbol name clash. No need to resend, I applied this small change before applying.
thanks
PATCH v2 2/2 netfilter: flowtable: Set offload timeout when adding flow
In reply to Roi DayanOn heavily loaded systems the GC can take time to go over all existing conns and reset their timeout. At that time other calls like from nf_conntrack_in() can call of nf_ct_is_expired() and see the conn as expired. To fix this when we set the offload bit we should also reset the timeout instead of counting on GC to finish first iteration over all conns before the initial timeout.
---
Notes:
v2
- timeout fix from flow_offload_add() instead of act_ct
net/netfilter/nf_flow_table_core.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/nf_flow_table_core.c +2 -0
@@ -243,6 +243,8 @@ int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow)return err; } +nf_ct_offload_timeout (flow->ct); +if (nf_flowtable_hw_offload (flow_table)) {__set_bit (NF_FLOW_HW , &flow->flags);nf_flow_offload_add (flow_table, flow);
Signature · 1 line
2.8.4
Pablo Neira Ayuso
maintainerQuoted 9 lines · Roi Dayan
On heavily loaded systems the GC can take time to go over all existing conns and reset their timeout. At that time other calls like from
nf_conntrack_in()can call ofnf_ct_is_expired()and see the conn as expired. To fix this when we set the offload bit we should also reset the timeout instead of counting on GC to finish first iteration over all conns before the initial timeout.First commit is to expose the function that updates the timeout. Second commit is to use it from
flow_offload_add().
Series applied to nf.git, thanks.