linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Lorenzo Bianconi <lorenzo@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	David Ahern <dsahern@kernel.org>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Jozsef Kadlecsik <kadlec@netfilter.org>,
	Shuah Khan <shuah@kernel.org>,
	netdev@vger.kernel.org, netfilter-devel@vger.kernel.org,
	coreteam@netfilter.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net-next v2 1/2] net: netfilter: Add IPIP flowtable SW acceleration
Date: Sat, 28 Jun 2025 11:47:31 +0200	[thread overview]
Message-ID: <aF-6M-4SjQgRQw1j@lore-desk> (raw)
In-Reply-To: <aF6ygRse7xSy949F@calendula>

[-- Attachment #1: Type: text/plain, Size: 4700 bytes --]

> On Fri, Jun 27, 2025 at 02:45:28PM +0200, Lorenzo Bianconi wrote:
> > Introduce SW acceleration for IPIP tunnels in the netfilter flowtable
> > infrastructure.
> > IPIP SW acceleration can be tested running the following scenario where
> > the traffic is forwarded between two NICs (eth0 and eth1) and an IPIP
> > tunnel is used to access a remote site (using eth1 as the underlay device):
> > 
> > ETH0 -- TUN0 <==> ETH1 -- [IP network] -- TUN1 (192.168.100.2)
> > 
> > $ip addr show
> > 6: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
> >     link/ether 00:00:22:33:11:55 brd ff:ff:ff:ff:ff:ff
> >     inet 192.168.0.2/24 scope global eth0
> >        valid_lft forever preferred_lft forever
> > 7: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
> >     link/ether 00:11:22:33:11:55 brd ff:ff:ff:ff:ff:ff
> >     inet 192.168.1.1/24 scope global eth1
> >        valid_lft forever preferred_lft forever
> > 8: tun0@NONE: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1480 qdisc noqueue state UNKNOWN group default qlen 1000
> >     link/ipip 192.168.1.1 peer 192.168.1.2
> >     inet 192.168.100.1/24 scope global tun0
> >        valid_lft forever preferred_lft forever
> > 
> > $ip route show
> > default via 192.168.100.2 dev tun0
> > 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.2
> > 192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.1
> > 192.168.100.0/24 dev tun0 proto kernel scope link src 192.168.100.1
> > 
> > $nft list ruleset
> > table inet filter {
> >         flowtable ft {
> >                 hook ingress priority filter
> >                 devices = { eth0, eth1 }
> >         }
> > 
> >         chain forward {
> >                 type filter hook forward priority filter; policy accept;
> >                 meta l4proto { tcp, udp } flow add @ft
> >         }
> > }
> 
> Is there a proof that this accelerates forwarding?

I reproduced the scenario described above using veths (something similar to
what is done in nft_flowtable.sh) and I got the following results:

- flowtable configured as above between the two router interfaces
- TCP stream between client and server going via the IPIP tunnel
- TCP stream transmitted into the IPIP tunnel:
  - net-next:				~41Gbps
  - net-next + IPIP flowtbale support:	~40Gbps
- TCP stream received from the IPIP tunnel:
  - net-next:				~35Gbps
  - net-next + IPIP flowtbale support:	~49Gbps

> 
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > ---
> >  net/ipv4/ipip.c                  | 21 +++++++++++++++++++++
> >  net/netfilter/nf_flow_table_ip.c | 28 ++++++++++++++++++++++++++--
> >  2 files changed, 47 insertions(+), 2 deletions(-)
> > 

[...]

> >  static bool nf_flow_skb_encap_protocol(struct sk_buff *skb, __be16 proto,
> >  				       u32 *offset)
> >  {
> >  	struct vlan_ethhdr *veth;
> >  	__be16 inner_proto;
> > +	u16 size;
> >  
> >  	switch (skb->protocol) {
> > +	case htons(ETH_P_IP):
> > +		if (nf_flow_ip4_encap_proto(skb, &size))
> > +			*offset += size;
> 
> This is blindly skipping the outer IP header.

Do you mean we are supposed to validate the outer IP header performing the
sanity checks done in nf_flow_tuple_ip()?

Regards,
Lorenzo

> 
> > +		return true;
> >  	case htons(ETH_P_8021Q):
> >  		if (!pskb_may_pull(skb, skb_mac_offset(skb) + sizeof(*veth)))
> >  			return false;
> > @@ -310,6 +328,7 @@ static void nf_flow_encap_pop(struct sk_buff *skb,
> >  			      struct flow_offload_tuple_rhash *tuplehash)
> >  {
> >  	struct vlan_hdr *vlan_hdr;
> > +	u16 size;
> >  	int i;
> >  
> >  	for (i = 0; i < tuplehash->tuple.encap_num; i++) {
> > @@ -331,6 +350,12 @@ static void nf_flow_encap_pop(struct sk_buff *skb,
> >  			break;
> >  		}
> >  	}
> > +
> > +	if (skb->protocol == htons(ETH_P_IP) &&
> > +	    nf_flow_ip4_encap_proto(skb, &size)) {
> > +		skb_pull(skb, size);
> > +		skb_reset_network_header(skb);
> > +	}
> 
> I have a similar patch from 2023, I think I keep somewhere in my trees.
> 
> >  }
> >  
> >  static unsigned int nf_flow_queue_xmit(struct net *net, struct sk_buff *skb,
> > @@ -357,8 +382,7 @@ nf_flow_offload_lookup(struct nf_flowtable_ctx *ctx,
> >  {
> >  	struct flow_offload_tuple tuple = {};
> >  
> > -	if (skb->protocol != htons(ETH_P_IP) &&
> > -	    !nf_flow_skb_encap_protocol(skb, htons(ETH_P_IP), &ctx->offset))
> > +	if (!nf_flow_skb_encap_protocol(skb, htons(ETH_P_IP), &ctx->offset))
> >  		return NULL;
> >  
> >  	if (nf_flow_tuple_ip(ctx, skb, &tuple) < 0)
> > 
> > -- 
> > 2.50.0
> > 
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2025-06-28  9:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-27 12:45 [PATCH net-next v2 0/2] Add IPIP flowtable SW acceleratio Lorenzo Bianconi
2025-06-27 12:45 ` [PATCH net-next v2 1/2] net: netfilter: Add IPIP flowtable SW acceleration Lorenzo Bianconi
2025-06-27 15:02   ` Pablo Neira Ayuso
2025-06-28  9:47     ` Lorenzo Bianconi [this message]
2025-07-03  8:25       ` Paolo Abeni
2025-07-03 12:30         ` Lorenzo Bianconi
2025-06-27 12:45 ` [PATCH net-next v2 2/2] selftests: netfilter: nft_flowtable.sh: Add IPIP flowtable selftest Lorenzo Bianconi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aF-6M-4SjQgRQw1j@lore-desk \
    --to=lorenzo.bianconi@redhat.com \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kadlec@netfilter.org \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).