Netfilter-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH nf-next] netfilter: flowtable: refresh flow if hardware offload fails
@ 2020-01-06 12:03 Pablo Neira Ayuso
  2020-01-07  0:33 ` wenxu
  0 siblings, 1 reply; 2+ messages in thread
From: Pablo Neira Ayuso @ 2020-01-06 12:03 UTC (permalink / raw)
  To: netfilter-devel

If nf_flow_offload_add() fails to add the flow to hardware, then the
NF_FLOW_HW flag bit is unset and the flow remains in the flowtable
software path.

If flowtable hardware offload is enabled, this patch enqueues a new
request to offload this flow to hardware.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_flow_table_core.c    |  4 +++-
 net/netfilter/nf_flow_table_ip.c      | 10 ++++++++++
 net/netfilter/nf_flow_table_offload.c |  3 +--
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index 9f134f44d139..388e87b06a00 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -243,8 +243,10 @@ int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow)
 		return err;
 	}
 
-	if (flow_table->flags & NF_FLOWTABLE_HW_OFFLOAD)
+	if (flow_table->flags & NF_FLOWTABLE_HW_OFFLOAD) {
+		__set_bit(NF_FLOW_HW, &flow->flags);
 		nf_flow_offload_add(flow_table, flow);
+	}
 
 	return 0;
 }
diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c
index f4ccb5f5008b..6e0a5bacfe2e 100644
--- a/net/netfilter/nf_flow_table_ip.c
+++ b/net/netfilter/nf_flow_table_ip.c
@@ -259,6 +259,11 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
 
 	dir = tuplehash->tuple.dir;
 	flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
+
+	if (unlikely((flow_table->flags & NF_FLOWTABLE_HW_OFFLOAD) &&
+		     !test_and_set_bit(NF_FLOW_HW, &flow->flags)))
+		nf_flow_offload_add(flow_table, flow);
+
 	rt = (struct rtable *)flow->tuplehash[dir].tuple.dst_cache;
 	outdev = rt->dst.dev;
 
@@ -488,6 +493,11 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
 
 	dir = tuplehash->tuple.dir;
 	flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
+
+	if (unlikely((flow_table->flags & NF_FLOWTABLE_HW_OFFLOAD) &&
+		     !test_and_set_bit(NF_FLOW_HW, &flow->flags)))
+		nf_flow_offload_add(flow_table, flow);
+
 	rt = (struct rt6_info *)flow->tuplehash[dir].tuple.dst_cache;
 	outdev = rt->dst.dev;
 
diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
index 8a1fe391666e..e7b766b3f731 100644
--- a/net/netfilter/nf_flow_table_offload.c
+++ b/net/netfilter/nf_flow_table_offload.c
@@ -723,7 +723,7 @@ static void flow_offload_work_handler(struct work_struct *work)
 		case FLOW_CLS_REPLACE:
 			ret = flow_offload_work_add(offload);
 			if (ret < 0)
-				__clear_bit(NF_FLOW_HW, &offload->flow->flags);
+				clear_bit(NF_FLOW_HW, &offload->flow->flags);
 			break;
 		case FLOW_CLS_DESTROY:
 			flow_offload_work_del(offload);
@@ -776,7 +776,6 @@ void nf_flow_offload_add(struct nf_flowtable *flowtable,
 	if (!offload)
 		return;
 
-	__set_bit(NF_FLOW_HW, &flow->flags);
 	flow_offload_queue_work(offload);
 }
 
-- 
2.11.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH nf-next] netfilter: flowtable: refresh flow if hardware offload fails
  2020-01-06 12:03 [PATCH nf-next] netfilter: flowtable: refresh flow if hardware offload fails Pablo Neira Ayuso
@ 2020-01-07  0:33 ` wenxu
  0 siblings, 0 replies; 2+ messages in thread
From: wenxu @ 2020-01-07  0:33 UTC (permalink / raw)
  To: Pablo Neira Ayuso, netfilter-devel


在 2020/1/6 20:03, Pablo Neira Ayuso 写道:
> If nf_flow_offload_add() fails to add the flow to hardware, then the
> NF_FLOW_HW flag bit is unset and the flow remains in the flowtable
> software path.
>
> If flowtable hardware offload is enabled, this patch enqueues a new
> request to offload this flow to hardware.
>
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> ---
>   net/netfilter/nf_flow_table_core.c    |  4 +++-
>   net/netfilter/nf_flow_table_ip.c      | 10 ++++++++++
>   net/netfilter/nf_flow_table_offload.c |  3 +--
>   3 files changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
> index 9f134f44d139..388e87b06a00 100644
> --- a/net/netfilter/nf_flow_table_core.c
> +++ b/net/netfilter/nf_flow_table_core.c
> @@ -243,8 +243,10 @@ int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow)
>   		return err;
>   	}
>   
> -	if (flow_table->flags & NF_FLOWTABLE_HW_OFFLOAD)
> +	if (flow_table->flags & NF_FLOWTABLE_HW_OFFLOAD) {
> +		__set_bit(NF_FLOW_HW, &flow->flags);
>   		nf_flow_offload_add(flow_table, flow);
> +	}
>   
>   	return 0;
>   }
> diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c
> index f4ccb5f5008b..6e0a5bacfe2e 100644
> --- a/net/netfilter/nf_flow_table_ip.c
> +++ b/net/netfilter/nf_flow_table_ip.c
> @@ -259,6 +259,11 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
>   
>   	dir = tuplehash->tuple.dir;
>   	flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
> +
> +	if (unlikely((flow_table->flags & NF_FLOWTABLE_HW_OFFLOAD) &&
> +		     !test_and_set_bit(NF_FLOW_HW, &flow->flags)))
> +		nf_flow_offload_add(flow_table, flow);
> +

Maybe put the refresh operation ather the nf_flow_state_check to aviod

the RST/FIN packets do the this?

>   	rt = (struct rtable *)flow->tuplehash[dir].tuple.dst_cache;
>   	outdev = rt->dst.dev;
>   
> @@ -488,6 +493,11 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
>   
>   	dir = tuplehash->tuple.dir;
>   	flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
> +
> +	if (unlikely((flow_table->flags & NF_FLOWTABLE_HW_OFFLOAD) &&
> +		     !test_and_set_bit(NF_FLOW_HW, &flow->flags)))
> +		nf_flow_offload_add(flow_table, flow);
> +
>   	rt = (struct rt6_info *)flow->tuplehash[dir].tuple.dst_cache;
>   	outdev = rt->dst.dev;
>   
> diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
> index 8a1fe391666e..e7b766b3f731 100644
> --- a/net/netfilter/nf_flow_table_offload.c
> +++ b/net/netfilter/nf_flow_table_offload.c
> @@ -723,7 +723,7 @@ static void flow_offload_work_handler(struct work_struct *work)
>   		case FLOW_CLS_REPLACE:
>   			ret = flow_offload_work_add(offload);
>   			if (ret < 0)
> -				__clear_bit(NF_FLOW_HW, &offload->flow->flags);
> +				clear_bit(NF_FLOW_HW, &offload->flow->flags);
>   			break;
>   		case FLOW_CLS_DESTROY:
>   			flow_offload_work_del(offload);
> @@ -776,7 +776,6 @@ void nf_flow_offload_add(struct nf_flowtable *flowtable,
>   	if (!offload)
>   		return;
>   
> -	__set_bit(NF_FLOW_HW, &flow->flags);
>   	flow_offload_queue_work(offload);
>   }
>   

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-06 12:03 [PATCH nf-next] netfilter: flowtable: refresh flow if hardware offload fails Pablo Neira Ayuso
2020-01-07  0:33 ` wenxu

Netfilter-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netfilter-devel/0 netfilter-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netfilter-devel netfilter-devel/ https://lore.kernel.org/netfilter-devel \
		netfilter-devel@vger.kernel.org
	public-inbox-index netfilter-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netfilter-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git