Commit 41f2c7c3 authored by Paul Blakey's avatar Paul Blakey Committed by Paolo Abeni

net/sched: act_ct: Fix promotion of offloaded unreplied tuple

Currently UNREPLIED and UNASSURED connections are added to the nf flow
table. This causes the following connection packets to be processed
by the flow table which then skips conntrack_in(), and thus such the
connections will remain UNREPLIED and UNASSURED even if reply traffic
is then seen. Even still, the unoffloaded reply packets are the ones
triggering hardware update from new to established state, and if
there aren't any to triger an update and/or previous update was
missed, hardware can get out of sync with sw and still mark
packets as new.

Fix the above by:
1) Not skipping conntrack_in() for UNASSURED packets, but still
   refresh for hardware, as before the cited patch.
2) Try and force a refresh by reply-direction packets that update
   the hardware rules from new to established state.
3) Remove any bidirectional flows that didn't failed to update in
   hardware for re-insertion as bidrectional once any new packet
   arrives.

Fixes: 6a9bad00 ("net/sched: act_ct: offload UDP NEW connections")
Co-developed-by: default avatarVlad Buslov <vladbu@nvidia.com>
Signed-off-by: default avatarVlad Buslov <vladbu@nvidia.com>
Signed-off-by: default avatarPaul Blakey <paulb@nvidia.com>
Reviewed-by: default avatarFlorian Westphal <fw@strlen.de>
Link: https://lore.kernel.org/r/1686313379-117663-1-git-send-email-paulb@nvidia.comSigned-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 07b1cc84
...@@ -268,7 +268,7 @@ int flow_offload_route_init(struct flow_offload *flow, ...@@ -268,7 +268,7 @@ int flow_offload_route_init(struct flow_offload *flow,
int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow); int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow);
void flow_offload_refresh(struct nf_flowtable *flow_table, void flow_offload_refresh(struct nf_flowtable *flow_table,
struct flow_offload *flow); struct flow_offload *flow, bool force);
struct flow_offload_tuple_rhash *flow_offload_lookup(struct nf_flowtable *flow_table, struct flow_offload_tuple_rhash *flow_offload_lookup(struct nf_flowtable *flow_table,
struct flow_offload_tuple *tuple); struct flow_offload_tuple *tuple);
......
...@@ -317,12 +317,12 @@ int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow) ...@@ -317,12 +317,12 @@ int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow)
EXPORT_SYMBOL_GPL(flow_offload_add); EXPORT_SYMBOL_GPL(flow_offload_add);
void flow_offload_refresh(struct nf_flowtable *flow_table, void flow_offload_refresh(struct nf_flowtable *flow_table,
struct flow_offload *flow) struct flow_offload *flow, bool force)
{ {
u32 timeout; u32 timeout;
timeout = nf_flowtable_time_stamp + flow_offload_get_timeout(flow); timeout = nf_flowtable_time_stamp + flow_offload_get_timeout(flow);
if (timeout - READ_ONCE(flow->timeout) > HZ) if (force || timeout - READ_ONCE(flow->timeout) > HZ)
WRITE_ONCE(flow->timeout, timeout); WRITE_ONCE(flow->timeout, timeout);
else else
return; return;
...@@ -334,6 +334,12 @@ void flow_offload_refresh(struct nf_flowtable *flow_table, ...@@ -334,6 +334,12 @@ void flow_offload_refresh(struct nf_flowtable *flow_table,
} }
EXPORT_SYMBOL_GPL(flow_offload_refresh); EXPORT_SYMBOL_GPL(flow_offload_refresh);
static bool nf_flow_is_outdated(const struct flow_offload *flow)
{
return test_bit(IPS_SEEN_REPLY_BIT, &flow->ct->status) &&
!test_bit(NF_FLOW_HW_ESTABLISHED, &flow->flags);
}
static inline bool nf_flow_has_expired(const struct flow_offload *flow) static inline bool nf_flow_has_expired(const struct flow_offload *flow)
{ {
return nf_flow_timeout_delta(flow->timeout) <= 0; return nf_flow_timeout_delta(flow->timeout) <= 0;
...@@ -423,7 +429,8 @@ static void nf_flow_offload_gc_step(struct nf_flowtable *flow_table, ...@@ -423,7 +429,8 @@ static void nf_flow_offload_gc_step(struct nf_flowtable *flow_table,
struct flow_offload *flow, void *data) struct flow_offload *flow, void *data)
{ {
if (nf_flow_has_expired(flow) || if (nf_flow_has_expired(flow) ||
nf_ct_is_dying(flow->ct)) nf_ct_is_dying(flow->ct) ||
nf_flow_is_outdated(flow))
flow_offload_teardown(flow); flow_offload_teardown(flow);
if (test_bit(NF_FLOW_TEARDOWN, &flow->flags)) { if (test_bit(NF_FLOW_TEARDOWN, &flow->flags)) {
......
...@@ -384,7 +384,7 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, ...@@ -384,7 +384,7 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
if (skb_try_make_writable(skb, thoff + hdrsize)) if (skb_try_make_writable(skb, thoff + hdrsize))
return NF_DROP; return NF_DROP;
flow_offload_refresh(flow_table, flow); flow_offload_refresh(flow_table, flow, false);
nf_flow_encap_pop(skb, tuplehash); nf_flow_encap_pop(skb, tuplehash);
thoff -= offset; thoff -= offset;
...@@ -650,7 +650,7 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb, ...@@ -650,7 +650,7 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
if (skb_try_make_writable(skb, thoff + hdrsize)) if (skb_try_make_writable(skb, thoff + hdrsize))
return NF_DROP; return NF_DROP;
flow_offload_refresh(flow_table, flow); flow_offload_refresh(flow_table, flow, false);
nf_flow_encap_pop(skb, tuplehash); nf_flow_encap_pop(skb, tuplehash);
......
...@@ -610,6 +610,7 @@ static bool tcf_ct_flow_table_lookup(struct tcf_ct_params *p, ...@@ -610,6 +610,7 @@ static bool tcf_ct_flow_table_lookup(struct tcf_ct_params *p,
struct flow_offload_tuple tuple = {}; struct flow_offload_tuple tuple = {};
enum ip_conntrack_info ctinfo; enum ip_conntrack_info ctinfo;
struct tcphdr *tcph = NULL; struct tcphdr *tcph = NULL;
bool force_refresh = false;
struct flow_offload *flow; struct flow_offload *flow;
struct nf_conn *ct; struct nf_conn *ct;
u8 dir; u8 dir;
...@@ -647,6 +648,7 @@ static bool tcf_ct_flow_table_lookup(struct tcf_ct_params *p, ...@@ -647,6 +648,7 @@ static bool tcf_ct_flow_table_lookup(struct tcf_ct_params *p,
* established state, then don't refresh. * established state, then don't refresh.
*/ */
return false; return false;
force_refresh = true;
} }
if (tcph && (unlikely(tcph->fin || tcph->rst))) { if (tcph && (unlikely(tcph->fin || tcph->rst))) {
...@@ -660,7 +662,12 @@ static bool tcf_ct_flow_table_lookup(struct tcf_ct_params *p, ...@@ -660,7 +662,12 @@ static bool tcf_ct_flow_table_lookup(struct tcf_ct_params *p,
else else
ctinfo = IP_CT_ESTABLISHED_REPLY; ctinfo = IP_CT_ESTABLISHED_REPLY;
flow_offload_refresh(nf_ft, flow); flow_offload_refresh(nf_ft, flow, force_refresh);
if (!test_bit(IPS_ASSURED_BIT, &ct->status)) {
/* Process this flow in SW to allow promoting to ASSURED */
return false;
}
nf_conntrack_get(&ct->ct_general); nf_conntrack_get(&ct->ct_general);
nf_ct_set(skb, ct, ctinfo); nf_ct_set(skb, ct, ctinfo);
if (nf_ft->flags & NF_FLOWTABLE_COUNTER) if (nf_ft->flags & NF_FLOWTABLE_COUNTER)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment