Add IPv4 over IPv6 and SIT flowtable SW acceleration
Subsystems (5)
v2 cover Add IPv4 over IPv6 and SIT flowtable SW acceleration
Similar to IPIP and IP6I6 tunnels, introduce sw acceleration for IPv4 over IPv6 and SIT tunnels in the netfilter flowtable infrastructure.
---
Changes in v2:
- Fix skb dst configuration in nf_flow_queue_xmit{4,6}().
- Rely on tunnel->sit_parm pointer in ipip6_tunnel_fill_forward_path().
- Link to v1: https://lore.kernel.org/r/20261029-flowtable-sw-accel-ip6ip-sit-v1-0-6a17c54f9fb7@oss.qualcomm.com
---
Lorenzo Bianconi (8):
net: netfilter: nf_flow_table: recognize IPv4/IPv6 in tunnel proto matching
net: netfilter: nf_flow_table: refactor MTU check for tunnel offload
net: ip6_tunnel: add IPv4 over IPv6 flowtable tunnel offload
net: netfilter: nf_flow_table: use tunnel encap proto for route lookup
net: netfilter: add IPv4 over IPv6 tunnel flowtable acceleration
selftests: netfilter: nft_flowtable.sh: add IPv4 over IPv6 flowtable selftest
net: netfilter: add SIT tunnel flowtable acceleration
selftests: netfilter: nft_flowtable.sh: add SIT flowtable selftest
net/ipv6/ip6_tunnel.c | 19 ++- net/ipv6/sit.c | 72 +++++++++++ net/netfilter/nf_flow_table_core.c | 18 ++- net/netfilter/nf_flow_table_ip.c | 137 ++++++++++++++++----- tools/testing/selftests/net/netfilter/config | 1 + .../selftests/net/netfilter/nft_flowtable.sh | 86 ++++++++++++- 6 files changed, 290 insertions(+), 43 deletions(-)
---
base-commit: 734bef548a96e8774d6eef5dfa2026c6edc4e80b
change-id: 20261029-flowtable-sw-accel-ip6ip-sit-f3393772880e
Best regards,
Signature · 1 line
Lorenzo Bianconi <[email protected]>
PATCH v2 1/8 net: netfilter: nf_flow_table: recognize IPv4/IPv6 in tunnel proto matching
Allow the flowtable to parse IPv4-in-IPv6 and IPv6-in-IPv4 tunnels by accepting both IPPROTO_IPIP and IPPROTO_IPV6 as the inner protocol when walking the outer header in nf_flow_ip4_tunnel_proto() and nf_flow_ip6_tunnel_proto(). This is a preliminary patch to support IPv4 over IPv6 and SIT tunnel flowtable offload.
Please note IPv4 over IPv6 and SIT tunnel flowtable offloading is not enabled yet.
--- net/netfilter/nf_flow_table_ip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_flow_table_ip.c +2 -2
@@ -328,7 +328,7 @@ static bool nf_flow_ip4_tunnel_proto(struct nf_flowtable_ctx *ctx,if (iph->ttl <=1 )return false; -if (iph->protocol ==IPPROTO_IPIP ) { +if (iph->protocol ==IPPROTO_IPIP || iph->protocol ==IPPROTO_IPV6 ) { ctx->tun.inner_proto = iph->protocol; ctx->tun.hdr_size = size; ctx->offset += ctx->tun.hdr_size;
@@ -353,7 +353,7 @@ static bool nf_flow_ip6_tunnel_proto(struct nf_flowtable_ctx *ctx,if (ipv6_ext_hdr (ip6h->nexthdr))return false; -if (ip6h->nexthdr ==IPPROTO_IPV6 ) { +if (ip6h->nexthdr ==IPPROTO_IPIP || ip6h->nexthdr ==IPPROTO_IPV6 ) { ctx->tun.inner_proto = ip6h->nexthdr; ctx->tun.hdr_size =sizeof (*ip6h); ctx->offset += ctx->tun.hdr_size;
Signature · 1 line
2.56.0
PATCH v2 2/8 net: netfilter: nf_flow_table: refactor MTU check for tunnel offload
In reply to Lorenzo BianconiIntroduce nf_flow_offload_check_mtu() helper and use the encapsulated protocol (tun.encap_proto) to compute the tunnel overhead instead of relying on tun_num, so the correct inner header size (IPv4 vs IPv6) is accounted for. Use it in both the IPv4 and IPv6 forward paths. This is a preliminary patch to support IPv4 over IPv6 and SIT flowtable tunnel offload.
Please note IPv4 over IPv6 and SIT tunnel flowtable offloading is not enabled yet.
--- net/netfilter/nf_flow_table_ip.c | 41 ++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-)
net/netfilter/nf_flow_table_ip.c +29 -12
@@ -472,6 +472,31 @@ nf_flow_offload_lookup(struct nf_flowtable_ctx *ctx,return flow_offload_lookup (flow_table, &tuple); } +static int nf_flow_offload_check_mtu (struct nf_flowtable_ctx *ctx, +struct flow_offload *flow, +enum flow_offload_tuple_dir dir, +struct sk_buff *skb) +{ +unsigned int mtu; + + mtu = flow->tuplehash[dir].tuple.mtu + ctx->offset; +switch (flow->tuplehash[!dir].tuple.tun.encap_proto) { +case AF_INET : + mtu -=sizeof (struct iphdr ); +break ; +case AF_INET6 : + mtu -=sizeof (struct ipv6hdr ); +break ; +default : +break ; + } + +if (unlikely (nf_flow_exceeds_mtu (skb, mtu))) +return -EINVAL ; + +return 0 ; +} + static int nf_flow_offload_forward(struct nf_flowtable_ctx *ctx, struct nf_flowtable *flow_table, struct flow_offload_tuple_rhash *tuplehash,
@@ -479,17 +504,13 @@ static int nf_flow_offload_forward(struct nf_flowtable_ctx *ctx, {enum flow_offload_tuple_dir dir;struct flow_offload *flow; -unsigned int thoff, mtu; +unsigned int thoff;struct iphdr *iph; dir = tuplehash->tuple.dir; flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); - mtu = flow->tuplehash[dir].tuple.mtu + ctx->offset; -if (flow->tuplehash[!dir].tuple.tun_num) - mtu -=sizeof (*iph); - -if (unlikely (nf_flow_exceeds_mtu (skb, mtu))) +if (nf_flow_offload_check_mtu (ctx, flow, dir, skb))return 0 ; iph = (struct iphdr *)(skb_network_header (skb) + ctx->offset);
@@ -1108,17 +1129,13 @@ static int nf_flow_offload_ipv6_forward(struct nf_flowtable_ctx *ctx, {enum flow_offload_tuple_dir dir;struct flow_offload *flow; -unsigned int thoff, mtu;struct ipv6hdr *ip6h; +unsigned int thoff; dir = tuplehash->tuple.dir; flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); - mtu = flow->tuplehash[dir].tuple.mtu + ctx->offset; -if (flow->tuplehash[!dir].tuple.tun_num) - mtu -=sizeof (*ip6h); - -if (unlikely (nf_flow_exceeds_mtu (skb, mtu))) +if (nf_flow_offload_check_mtu (ctx, flow, dir, skb))return 0 ; ip6h = (struct ipv6hdr *)(skb_network_header (skb) + ctx->offset);
Signature · 1 line
2.56.0
PATCH v2 3/8 net: ip6_tunnel: add IPv4 over IPv6 flowtable tunnel offload
In reply to Lorenzo BianconiAllow ip6_tnl_fill_forward_path() to set the inner protocol for IPv4 packets (IPPROTO_IPIP) in addition to IPv6 (IPPROTO_IPV6), so that the flowtable can offload IPv4-in-IPv6 tunnels.
Return -EOPNOTSUPP for any other ethertype, and when the tunnel is configured for a specific inner protocol (t->parms.proto) that does not match the inner packet protocol, so the fast path does not bypass the check enforced by ipxip6_tnl_xmit() and ipxip6_rcv().
--- net/ipv6/ip6_tunnel.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
net/ipv6/ip6_tunnel.c +15 -4
@@ -1840,13 +1840,11 @@ static int ip6_tnl_fill_forward_path(struct net_device_path_ctx *ctx, struct net_device_path *path) {struct ip6_tnl *t =netdev_priv (ctx->dev); +u8 tproto =READ_ONCE (t->parms.proto);struct dst_entry *dst;struct flowi6 fl6;int err; -if (ctx->ether_type !=cpu_to_be16 (ETH_P_IPV6 )) -return -EOPNOTSUPP ; -if (t->parms.flags & (IP6_TNL_F_USE_ORIG_TCLASS |IP6_TNL_F_USE_ORIG_FLOWLABEL |IP6_TNL_F_USE_ORIG_FWMARK ))
@@ -1858,6 +1856,20 @@ static int ip6_tnl_fill_forward_path(struct net_device_path_ctx *ctx,if (!(t->parms.flags &IP6_TNL_F_IGN_ENCAP_LIMIT ))return -EOPNOTSUPP ; +switch (ctx->ether_type) { +case cpu_to_be16 (ETH_P_IP ): + path->tun.inner_proto =IPPROTO_IPIP ; +break ; +case cpu_to_be16 (ETH_P_IPV6 ): + path->tun.inner_proto =IPPROTO_IPV6 ; +break ; +default : +return -EOPNOTSUPP ; + } + +if (tproto && tproto != path->tun.inner_proto) +return -EOPNOTSUPP ; +memcpy (&fl6, &t->fl.u.ip6,sizeof (fl6)); fl6.flowi6_mark = t->parms.fwmark; fl6.flowi6_proto =0 ;
@@ -1867,7 +1879,6 @@ static int ip6_tnl_fill_forward_path(struct net_device_path_ctx *ctx, path->type =DEV_PATH_TUN ; path->tun.src_v6 = fl6.saddr; path->tun.dst_v6 = fl6.daddr; - path->tun.inner_proto =IPPROTO_IPV6 ; path->tun.encap_proto =AF_INET6 ; path->tun.dst = dst; path->dev = ctx->dev;
Signature · 1 line
2.56.0
PATCH v2 4/8 net: netfilter: nf_flow_table: use tunnel encap proto for route lookup
In reply to Lorenzo BianconiFor IP tunnels, resolve the MTU and the dst cookie against the tunnel's inner IP protocol (tun.encap_proto) instead of the flow's l3proto, so the correct header size and route cookie are used when the flow is carried over a tunnel.
This is a preliminary patch to support IPv4 over IPv6 and SIT tunnel flowtable offload.
--- net/netfilter/nf_flow_table_core.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
net/netfilter/nf_flow_table_core.c +13 -5
@@ -76,9 +76,10 @@ struct flow_offload *flow_offload_alloc(struct nf_conn *ct) }EXPORT_SYMBOL_GPL (flow_offload_alloc); -static u32 flow_offload_dst_cookie (struct flow_offload_tuple *flow_tuple) +static u32 flow_offload_dst_cookie (struct flow_offload_tuple *flow_tuple, +u8 l3_proto) { -if (flow_tuple->l3proto ==NFPROTO_IPV6 ) +if (l3_proto ==NFPROTO_IPV6 )return rt6_get_cookie (dst_rt6_info (flow_tuple->dst_cache));return 0 ;
@@ -100,9 +101,15 @@ static int flow_offload_fill_route(struct flow_offload *flow, {struct flow_offload_tuple *flow_tuple = &flow->tuplehash[dir].tuple;struct dst_entry *dst =nft_route_dst_fetch (route, dir); +u8 l3_proto = flow_tuple->l3proto;int i, j =0 ; -switch (flow_tuple->l3proto) { +if (route->tuple[!dir].in.tun.encap_proto) { +/* For IP tunnels we need to consider tunnel IP protocol. */ + l3_proto = route->tuple[!dir].in.tun.encap_proto; + } + +switch (l3_proto) {case NFPROTO_IPV4 : flow_tuple->mtu =ip_dst_mtu_maybe_forward (dst, true);break ;
@@ -130,7 +137,7 @@ static int flow_offload_fill_route(struct flow_offload *flow,if (route->tuple[!dir].in.num_tuns) { flow_tuple->dst_cache = dst; flow_tuple->dst_cookie = -flow_offload_dst_cookie (flow_tuple); +flow_offload_dst_cookie (flow_tuple, l3_proto); }else {dst_release (dst); }
@@ -144,7 +151,8 @@ static int flow_offload_fill_route(struct flow_offload *flow,case FLOW_OFFLOAD_XMIT_NEIGH : flow_tuple->ifidx = route->tuple[dir].out.ifindex; flow_tuple->dst_cache = dst; - flow_tuple->dst_cookie =flow_offload_dst_cookie (flow_tuple); + flow_tuple->dst_cookie =flow_offload_dst_cookie (flow_tuple, + l3_proto);break ;default :WARN_ON_ONCE (1 );
Signature · 1 line
2.56.0
PATCH v2 5/8 net: netfilter: add IPv4 over IPv6 tunnel flowtable acceleration
In reply to Lorenzo BianconiIntroduce sw flowtable acceleration for the TX/RX paths of IPv4 over IPv6 tunnels, relying on the netfilter flowtable infrastructure.
The feature can be tested with a forwarding scenario between two NICs (eth0 and eth1), where an IPv4 over IPv6 tunnel is used to reach a remote site via eth1 as the underlay device:
ETH0 -- TUN0 <==> ETH1 -- [IP network] -- TUN1 (2001:db8:2::2)
[IP configuration]
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
inet6 2001:db8:2::1/64 scope global nodad
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/tunnel6 2001:db8:2::1 peer 2001:db8:2::2 permaddr ce9c:2940:7dcc::
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.100.0/24 dev tun0 proto kernel scope link src 192.168.100.1
$ ip -6 route show 2001:db8:2::/64 dev eth1 proto kernel metric 256 pref medium
$ 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
}
}When reproducing this scenario using veth interfaces, the following results were observed:
- TCP stream received from IPv4 over IPv6 tunnel:
- net-next (baseline): ~126 Gbps
- net-next + IP4IP6 flowtable support: ~138 Gbps
- TCP stream transmitted to IPv4 over IPv6 tunnel:
- net-next (baseline): ~127 Gbps
- net-next + IP4IP6 flowtable support: ~140 Gbps
--- net/netfilter/nf_flow_table_ip.c | 70 ++++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 14 deletions(-)
net/netfilter/nf_flow_table_ip.c +56 -14
@@ -856,7 +856,8 @@ static unsigned int nf_flow_queue_xmit(struct net *net, struct sk_buff *skb,return NF_STOLEN ; } -static int nf_flow_queue_xmit4 (struct sk_buff *skb, +static int nf_flow_queue_xmit4 (struct nf_flowtable_ctx *ctx, +struct sk_buff *skb,struct flow_offload_tuple_rhash *tuplehash,const struct nf_hook_state *state) {
@@ -886,22 +887,38 @@ static int nf_flow_queue_xmit4(struct sk_buff *skb,return NF_DROP ;switch (tuplehash->tuple.xmit_type) { -case FLOW_OFFLOAD_XMIT_NEIGH : - rt =dst_rtable (tuplehash->tuple.dst_cache); +case FLOW_OFFLOAD_XMIT_NEIGH : { +struct dst_entry *dst; + xmit.outdev =dev_get_by_index_rcu (state->net, tuplehash->tuple.ifidx);if (!xmit.outdev) {flow_offload_teardown (flow);return NF_DROP ; } - neigh =ip_neigh_gw4 (rt->dst.dev,rt_nexthop (rt, ip_addr->ip)); +if (other_tuple->tun.encap_proto ? + other_tuple->tun.encap_proto ==AF_INET6 : + ctx->tun.inner_proto ==IPPROTO_IPV6 ) { +struct rt6_info *rt6; + + rt6 =dst_rt6_info (tuplehash->tuple.dst_cache); + neigh =ip_neigh_gw6 (rt6->dst.dev, +rt6_nexthop (rt6, &ip_addr->in6)); + dst = &rt6->dst; + }else { + rt =dst_rtable (tuplehash->tuple.dst_cache); + neigh =ip_neigh_gw4 (rt->dst.dev, +rt_nexthop (rt, ip_addr->ip)); + dst = &rt->dst; + }if (IS_ERR (neigh)) {flow_offload_teardown (flow);return NF_DROP ; } xmit.dest = neigh->ha;skb_dst_drop (skb); -skb_dst_set_noref (skb, &rt->dst); +skb_dst_set_noref (skb, dst);break ; + }case FLOW_OFFLOAD_XMIT_DIRECT : xmit.outdev =dev_get_by_index_rcu (state->net, tuplehash->tuple.out.ifidx);if (!xmit.outdev) {
@@ -948,7 +965,7 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,else if (ret ==0 )return NF_ACCEPT ; -return nf_flow_queue_xmit4 (skb, tuplehash, state); +return nf_flow_queue_xmit4 (&ctx, skb, tuplehash, state); }EXPORT_SYMBOL_GPL (nf_flow_offload_ip_hook);
@@ -1175,13 +1192,18 @@ nf_flow_offload_ipv6_lookup(struct nf_flowtable_ctx *ctx, {struct flow_offload_tuple tuple = {}; -if (nf_flow_tuple_ipv6 (ctx, skb, &tuple) <0 ) +if (ctx->tun.inner_proto ==IPPROTO_IPIP ) { +if (nf_flow_tuple_ip (ctx, skb, &tuple) <0 ) +return NULL ; + }else if (nf_flow_tuple_ipv6 (ctx, skb, &tuple) <0 ) {return NULL ; + }return flow_offload_lookup (flow_table, &tuple); } -static int nf_flow_queue_xmit6 (struct sk_buff *skb, +static int nf_flow_queue_xmit6 (struct nf_flowtable_ctx *ctx, +struct sk_buff *skb,struct flow_offload_tuple_rhash *tuplehash,const struct nf_hook_state *state) {
@@ -1211,22 +1233,38 @@ static int nf_flow_queue_xmit6(struct sk_buff *skb,return NF_DROP ;switch (tuplehash->tuple.xmit_type) { -case FLOW_OFFLOAD_XMIT_NEIGH : - rt =dst_rt6_info (tuplehash->tuple.dst_cache); +case FLOW_OFFLOAD_XMIT_NEIGH : { +struct dst_entry *dst; + xmit.outdev =dev_get_by_index_rcu (state->net, tuplehash->tuple.ifidx);if (!xmit.outdev) {flow_offload_teardown (flow);return NF_DROP ; } - neigh =ip_neigh_gw6 (rt->dst.dev,rt6_nexthop (rt, &ip_addr->in6)); +if (other_tuple->tun.encap_proto ? + other_tuple->tun.encap_proto ==AF_INET : + ctx->tun.inner_proto ==IPPROTO_IPIP ) { +struct rtable *rt4; + + rt4 =dst_rtable (tuplehash->tuple.dst_cache); + neigh =ip_neigh_gw4 (rt4->dst.dev, +rt_nexthop (rt4, ip_addr->ip)); + dst = &rt4->dst; + }else { + rt =dst_rt6_info (tuplehash->tuple.dst_cache); + neigh =ip_neigh_gw6 (rt->dst.dev, +rt6_nexthop (rt, &ip_addr->in6)); + dst = &rt->dst; + }if (IS_ERR (neigh)) {flow_offload_teardown (flow);return NF_DROP ; } xmit.dest = neigh->ha;skb_dst_drop (skb); -skb_dst_set_noref (skb, &rt->dst); +skb_dst_set_noref (skb, dst);break ; + }case FLOW_OFFLOAD_XMIT_DIRECT : xmit.outdev =dev_get_by_index_rcu (state->net, tuplehash->tuple.out.ifidx);if (!xmit.outdev) {
@@ -1267,12 +1305,16 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,if (!tuplehash)return NF_ACCEPT ; - ret =nf_flow_offload_ipv6_forward (&ctx, flow_table, tuplehash, skb); +if (ctx.tun.inner_proto ==IPPROTO_IPIP ) + ret =nf_flow_offload_forward (&ctx, flow_table, tuplehash, skb); +else + ret =nf_flow_offload_ipv6_forward (&ctx, flow_table, tuplehash, + skb);if (ret <0 )return NF_DROP ;else if (ret ==0 )return NF_ACCEPT ; -return nf_flow_queue_xmit6 (skb, tuplehash, state); +return nf_flow_queue_xmit6 (&ctx, skb, tuplehash, state); }EXPORT_SYMBOL_GPL (nf_flow_offload_ipv6_hook);
Signature · 1 line
2.56.0
PATCH v2 6/8 selftests: netfilter: nft_flowtable.sh: add IPv4 over IPv6 flowtable selftest
In reply to Lorenzo BianconiSimilar to IPIP and IP6IP6, introduce specific selftest for IPv4 over IPv6 flowtable sw acceleration in nft_flowtable.sh
--- .../selftests/net/netfilter/nft_flowtable.sh | 33 +++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-)
tools/testing/selftests/net/netfilter/nft_flowtable.sh +29 -4
@@ -579,9 +579,8 @@ if ! test_tcp_forwarding_nat "$ns1" "$ns2" 1 ""; then ip netns exec "$nsr1" nft list ruleset fi -# IPIP tunnel test: -# Add IPIP tunnel interfaces and check flowtable acceleration. -test_ipip() { +# IP tunnel tests: +test_ip_tnls() { if ! ip -net "$nsr1" link add name tun0 type ipip \ local 192.168.10.1 remote 192.168.10.2 >/dev/null;then echo "SKIP: could not add ipip tunnel"
@@ -594,7 +593,9 @@ ip netns exec "$nsr1" sysctl net.ipv4.conf.tun0.forwarding=1 > /dev/null ip -net "$nsr1" link add name tun6 type ip6tnl local fee1:2::1 remote fee1:2::2 encaplimit none ip -net "$nsr1" link set tun6 up +ip -net "$nsr1" addr add 192.168.210.1/24 dev tun6 ip -net "$nsr1" addr add fee1:3::1/64 dev tun6 nodad +ip netns exec "$nsr1" sysctl net.ipv4.conf.tun6.forwarding=1 > /dev/null ip -net "$nsr2" link add name tun0 type ipip local 192.168.10.2 remote 192.168.10.1 ip -net "$nsr2" link set tun0 up
@@ -603,7 +604,9 @@ ip netns exec "$nsr2" sysctl net.ipv4.conf.tun0.forwarding=1 > /dev/null ip -net "$nsr2" link add name tun6 type ip6tnl local fee1:2::2 remote fee1:2::1 encaplimit none || ret=1 ip -net "$nsr2" link set tun6 up +ip -net "$nsr2" addr add 192.168.210.2/24 dev tun6 ip -net "$nsr2" addr add fee1:3::2/64 dev tun6 nodad +ip netns exec "$nsr2" sysctl net.ipv4.conf.tun6.forwarding=1 > /dev/null ip -net "$nsr1" route change default via 192.168.100.2 ip -net "$nsr2" route change default via 192.168.100.1
@@ -640,6 +643,15 @@ else ret=1 fi +ip -net "$nsr1" route change default via 192.168.210.2 +ip -net "$nsr2" route change default via 192.168.210.1 + +if ! test_tcp_forwarding_nat "$ns1" "$ns2" 1 "IP4IP6 tunnel"; then + echo "FAIL: flow offload for ns1/ns2 with IP4IP6 tunnel" 1>&2 + ip netns exec "$nsr1" nft list ruleset + ret=1 +fi + # Create vlan tagged devices for IPIP traffic. ip -net "$nsr1" link add link veth1 name veth1.10 type vlan id 10 ip -net "$nsr1" link set veth1.10 up
@@ -661,7 +673,9 @@ ip netns exec "$nsr1" nft -a insert rule inet filter forward 'meta oif tun0.10 a ip -net "$nsr1" link add name tun6.10 type ip6tnl local fee1:4::1 remote fee1:4::2 encaplimit none ip -net "$nsr1" link set tun6.10 up +ip -net "$nsr1" addr add 192.168.220.1/24 dev tun6.10 ip -net "$nsr1" addr add fee1:5::1/64 dev tun6.10 nodad +ip netns exec "$nsr1" sysctl net.ipv4.conf.tun6/10.forwarding=1 > /dev/null ip -6 -net "$nsr1" route delete default ip -6 -net "$nsr1" route add default via fee1:5::2 ip netns exec "$nsr1" nft -a insert rule inet filter forward \
@@ -682,7 +696,9 @@ ip netns exec "$nsr2" sysctl net.ipv4.conf.tun0/10.forwarding=1 > /dev/null ip -net "$nsr2" link add name tun6.10 type ip6tnl local fee1:4::2 remote fee1:4::1 encaplimit none || ret=1 ip -net "$nsr2" link set tun6.10 up +ip -net "$nsr2" addr add 192.168.220.2/24 dev tun6.10 ip -net "$nsr2" addr add fee1:5::2/64 dev tun6.10 nodad +ip netns exec "$nsr2" sysctl net.ipv4.conf.tun6/10.forwarding=1 > /dev/null ip -6 -net "$nsr2" route delete default ip -6 -net "$nsr2" route add default via fee1:5::1
@@ -700,6 +716,15 @@ else ret=1 fi +ip -net "$nsr1" route change default via 192.168.220.2 +ip -net "$nsr2" route change default via 192.168.220.1 + +if ! test_tcp_forwarding_nat "$ns1" "$ns2" 1 "IP4IP6 tunnel over vlan"; then + echo "FAIL: flow offload for ns1/ns2 with IP4IP6 tunnel over vlan" 1>&2 + ip netns exec "$nsr1" nft list ruleset + ret=1 +fi + # Restore the previous configuration ip -net "$nsr1" route change default via 192.168.10.2 ip -net "$nsr2" route change default via 192.168.10.1
@@ -847,7 +872,7 @@ ip -net "$nsr1" addr add dead:1::1/64 dev veth0 nodad ip -net "$nsr1" link set up dev veth0 } -test_ipip +test_ip_tnls test_bridge
Signature · 1 line
2.56.0
PATCH v2 7/8 net: netfilter: add SIT tunnel flowtable acceleration
In reply to Lorenzo BianconiIntroduce sw flowtable acceleration for the TX/RX paths of SIT tunnels, relying on the netfilter flowtable infrastructure.
Only plain SIT tunnels are offloaded: NBMA tunnels (ISATAP, 6to4, 6rd), FOU/GUE encapsulation, inherited TOS, and packets whose inner protocol does not match the configured SIT mode are rejected. Tunnel parameters are read from the RCU-protected snapshot and the outer route is resolved in the tunnel netns using its fwmark, mirroring the slow path.
The feature can be tested with a forwarding scenario between two NICs (eth0 and eth1), where a SIT tunnel is used to reach a remote site via eth1 as the underlay device:
ETH0 -- TUN0 <==> ETH1 -- [IP network] -- TUN1 (192.168.2.2)
[IP configuration]
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
inet6 2001:db8:1::2/64 scope global nodad
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.2.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/sit 192.168.2.1 peer 192.168.2.2
inet6 2001:db8:200::1/64 scope global nodad
valid_lft forever preferred_lft forever$ ip route show 192.168.2.0/24 dev eth1 proto kernel scope link src 192.168.2.1
$ ip -6 route show 2001:db8:1::/64 dev eth0 proto kernel metric 256 pref medium 2001:db8:200::/64 dev tun0 proto kernel metric 256 pref medium default via 2001:db8:200::2 dev tun0 metric 1024 pref medium
$ 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
}
}When reproducing this scenario using veth interfaces, the following results were observed:
- TCP stream received from SIT tunnel:
- net-next (baseline): ~118 Gbps
- net-next + SIT flowtable support: ~148 Gbps
- TCP stream transmitted to SIT tunnel:
- net-next (baseline): ~131 Gbps
- net-next + SIT flowtable support: ~147 Gbps
--- net/ipv6/sit.c | 72 ++++++++++++++++++++++++++++++++++++++++ net/netfilter/nf_flow_table_ip.c | 22 ++++++++++-- 2 files changed, 92 insertions(+), 2 deletions(-)
net/ipv6/sit.c +72 -0
@@ -29,6 +29,7 @@#include <linux/icmp.h> #include <linux/slab.h> #include <linux/uaccess.h> +#include <linux/inetdevice.h> #include <linux/init.h> #include <linux/netfilter_ipv4.h> #include <linux/if_ether.h>
@@ -1483,6 +1484,76 @@ ipip6_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm_kern *p, } } +static int ipip6_tunnel_fill_forward_path (struct net_device_path_ctx *ctx, +struct net_device_path *path) +{ +struct ip_tunnel *tunnel =netdev_priv (ctx->dev); +const struct ip_tunnel_parm_kern *parms; +const struct iphdr *tiph; +struct flowi4 fl4; +struct rtable *rt; + +/* NBMA tunnels (ISATAP, 6to4, 6rd) resolve the outer destination +* per-packet from the inner IPv6 address; not offloadable. +*/ +if (ctx->dev->priv_flags &IFF_ISATAP ) +return -EOPNOTSUPP ; + + parms =rcu_dereference (tunnel->sit_parms); + tiph = &parms->iph; +if (!tiph->daddr) +return -EOPNOTSUPP ; + +if (tiph->tos &0x1 ) +return -EOPNOTSUPP ; + +/* FOU/GUE encapsulation is handled in the slow path by +* ip_tunnel_encap(); the fast path only pushes a plain +* IPv4 header and would skip the UDP encapsulation. +*/ +if (READ_ONCE (tunnel->encap.type) !=TUNNEL_ENCAP_NONE ) +return -EOPNOTSUPP ; + +switch (ctx->ether_type) { +case cpu_to_be16 (ETH_P_IP ): + path->tun.inner_proto =IPPROTO_IPIP ; +break ; +case cpu_to_be16 (ETH_P_IPV6 ): + path->tun.inner_proto =IPPROTO_IPV6 ; +break ; +default : +return -EOPNOTSUPP ; + } + +if (parms->iph.protocol && + parms->iph.protocol != path->tun.inner_proto) +return -EOPNOTSUPP ; + +flowi4_init_output (&fl4, parms->link,READ_ONCE (tunnel->fwmark), + tiph->tos &INET_DSCP_MASK ,RT_SCOPE_UNIVERSE , +0 ,0 , tiph->daddr, tiph->saddr,0 ,0 , +sock_net_uid (tunnel->net,NULL )); + rt =ip_route_output_key (tunnel->net, &fl4); +if (IS_ERR (rt)) +return PTR_ERR (rt); + + path->type =DEV_PATH_TUN ; +if (tiph->saddr) + path->tun.src_v4.s_addr = tiph->saddr; +else + path->tun.src_v4.s_addr =inet_select_addr (rt->dst.dev, + tiph->daddr, +RT_SCOPE_UNIVERSE ); + path->tun.dst_v4.s_addr = tiph->daddr; + path->tun.encap_proto =AF_INET ; + path->dev = ctx->dev; + path->tun.dst = &rt->dst; + + ctx->dev = rt->dst.dev; + +return 0 ; +} +static int ipip6_tunnel_siocdevprivate (struct net_device *dev,struct ifreq *ifr,void __user *data,int cmd)
@@ -1533,6 +1604,7 @@ static const struct net_device_ops ipip6_netdev_ops = { .ndo_siocdevprivate = ipip6_tunnel_siocdevprivate, .ndo_get_iflink = ipip6_get_iflink, .ndo_tunnel_ctl = ipip6_tunnel_ctl, + .ndo_fill_forward_path = ipip6_tunnel_fill_forward_path, };static void ipip6_dev_free (struct net_device *dev)
net/netfilter/nf_flow_table_ip.c +20 -2
@@ -158,6 +158,16 @@ struct nf_flowtable_ctx { } tun; }; +static int nf_flow_tuple_ipv6 (struct nf_flowtable_ctx *ctx, +struct sk_buff *skb, +struct flow_offload_tuple *tuple); + +static int +nf_flow_offload_ipv6_forward (struct nf_flowtable_ctx *ctx, +struct nf_flowtable *flow_table, +struct flow_offload_tuple_rhash *tuplehash, +struct sk_buff *skb); +static void nf_flow_tuple_encap (struct nf_flowtable_ctx *ctx,struct sk_buff *skb,struct flow_offload_tuple *tuple)
@@ -466,8 +476,12 @@ nf_flow_offload_lookup(struct nf_flowtable_ctx *ctx, {struct flow_offload_tuple tuple = {}; -if (nf_flow_tuple_ip (ctx, skb, &tuple) <0 ) +if (ctx->tun.inner_proto ==IPPROTO_IPV6 ) { +if (nf_flow_tuple_ipv6 (ctx, skb, &tuple) <0 ) +return NULL ; + }else if (nf_flow_tuple_ip (ctx, skb, &tuple) <0 ) {return NULL ; + }return flow_offload_lookup (flow_table, &tuple); }
@@ -959,7 +973,11 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,if (!tuplehash)return NF_ACCEPT ; - ret =nf_flow_offload_forward (&ctx, flow_table, tuplehash, skb); +if (ctx.tun.inner_proto ==IPPROTO_IPV6 ) + ret =nf_flow_offload_ipv6_forward (&ctx, flow_table, tuplehash, + skb); +else + ret =nf_flow_offload_forward (&ctx, flow_table, tuplehash, skb);if (ret <0 )return NF_DROP ;else if (ret ==0 )
Signature · 1 line
2.56.0
PATCH v2 8/8 selftests: netfilter: nft_flowtable.sh: add SIT flowtable selftest
In reply to Lorenzo BianconiSimilar to IPIP, IP6IP6 and IPv4 over IPv6, introduce specific selftest for SIT flowtable sw acceleration in nft_flowtable.sh.
Add sit1 and sit1.10 devices, route IPv6 over them, and add tunnel-specific flow-add rules so check_counters() verifies offload in the original direction. Append the unconditional accept rules after the ct-mark counter rule so packets that cannot be offloaded are still counted instead of bypassing the counters. Enable CONFIG_IPV6_SIT in the selftest config and restore the IPv6 default routes at cleanup to prevent tunnel routes leaking to subsequent tests (e.g. IPsec).
--- tools/testing/selftests/net/netfilter/config | 1 + .../selftests/net/netfilter/nft_flowtable.sh | 53 ++++++++++++++++++++++ 2 files changed, 54 insertions(+)
tools/testing/selftests/net/netfilter/config +1 -0
@@ -35,6 +35,7 @@ CONFIG_IP_SCTP=m CONFIG_IPV6=y CONFIG_IPV6_MULTIPLE_TABLES=y CONFIG_IPV6_TUNNEL=m +CONFIG_IPV6_SIT=m CONFIG_IP_VS=m CONFIG_IP_VS_PROTO_TCP=y CONFIG_IP_VS_RR=m
tools/testing/selftests/net/netfilter/nft_flowtable.sh +53 -0
100 lines not on this page · raw message
Signature · 1 line
2.56.0
PATCH 1/1 netfilter: flowtable: tunnel device poisons h_source of fast-path frames
In reply to Lorenzo BianconiWhen a flow enters an IP tunnel, the forward path discovered by dev_fill_forward_path() starts with a DEV_PATH_TUN entry for the tunnel device, followed by whatever carries the outer packet. nft_dev_path_info() handles DEV_PATH_TUN in the same switch case as the Ethernet-like path types and copies path->dev->dev_addr into info->h_source if it is still unset. For a tunnel device dev_addr is not an Ethernet address: ip6_tunnel stores the 16-byte local IPv6 there and ip_tunnel the 4-byte local IPv4. The tunnel entry is the first one on the path, so its "address" wins and poisons h_source: every fast-path frame is transmitted with the first bytes of the tunnel local IP address as the Ethernet source MAC.
Seen on a DS-Lite setup, LAN -> ip6tnl (IPv4 inside IPv6) -> PPPoE -> 802.1Q VLAN -> Ethernet, with conntrack flows offloaded through an nftables flowtable ('flow add @ft'). The first packets of a flow, still on the slow path, and the fast-path packets of the same flow differ only in the Ethernet source address:
slow path: d8:58:d7:00:2e:bd > 80:ac:ac:39:ef:c2, 802.1Q vlan 35,
PPPoE [ses 0x454] IP6 2a01:110f:4328:c400::1 >
2a01:1000:0:1::2216 next-header IPIP, 192.0.0.2.40010 >
1.1.1.1.53fast path: 2a:01:11:0f:43:28 > 80:ac:ac:39:ef:c2, same frame otherwise
As you can see 2a:01:11:0f:43:28 is the start of 2a01:110f:4328:c400::1, the tunnel local address. The PPPoE endpoint binds the session to the subscriber MAC and silently drops the frames, the effect is that every TCP/UDP flow dies the moment it is offloaded, while ICMP, which is never offloaded, keeps working. Received traffic is unaffected.
Do not let DEV_PATH_TUN poison h_source: skip the assignment for it. The real link-layer device appears later on the same path and provides the correct address; for a path with no Ethernet device the address stays zero as before.
---
Found while testing this series on a Turris Omnia (Debian, armhf) behind a DS-Lite ISP: with the series applied, IPv4 flows through the ip6tnl were offloaded but no fast-path frame ever got past the PPPoE concentrator. The problem is in the existing DEV_PATH_TUN handling, so it applies to net-next with or without this series; with the fix the series works here (tested: UDP flows with a fixed source port, TCP, bulk downloads through the tunnel). Without the series the same wrong MAC should affect ipip and ip6ip6 tunnels in front of PPPoE.
net/netfilter/nf_flow_table_path.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/netfilter/nf_flow_table_path.c +6 -1
@@ -121,7 +121,12 @@ static int nft_dev_path_info(struct net_device_path_stack *stack,case DEV_PATH_PPPOE :case DEV_PATH_TUN : info->dev = path->dev; -if (is_zero_ether_addr (info->h_source)) +/* A tunnel device has no Ethernet address: its dev_addr +* is the tunnel local IP address. Take h_source from the +* real link-layer device further down the path. +*/ +if (path->type !=DEV_PATH_TUN && +is_zero_ether_addr (info->h_source))memcpy (info->h_source, path->dev->dev_addr,ETH_ALEN ); if (path->type == DEV_PATH_ETHERNET ||
Signature · 1 line
2.39.5
Re: [PATCH nf-next] netfilter: flowtable: tunnel device poisons h_source of fast-path frames
Quoted 30 lines
When a flow enters an IP tunnel, the forward path discovered by
dev_fill_forward_path()starts with aDEV_PATH_TUNentry for the tunnel device, followed by whatever carries the outer packet.nft_dev_path_info()handlesDEV_PATH_TUNin the same switch case as the Ethernet-like path types and copiespath->dev->dev_addrintoinfo->h_sourceif it is still unset. For a tunnel devicedev_addris not an Ethernet address:ip6_tunnelstores the 16-byte local IPv6 there andip_tunnelthe 4-byte local IPv4. The tunnel entry is the first one on the path, so its "address" wins and poisonsh_source: every fast-path frame is transmitted with the first bytes of the tunnel local IP address as the Ethernet source MAC.Seen on a DS-Lite setup, LAN -> ip6tnl (IPv4 inside IPv6) -> PPPoE -> 802.1Q VLAN -> Ethernet, with conntrack flows offloaded through an nftables flowtable ('flow add @ft'). The first packets of a flow, still on the slow path, and the fast-path packets of the same flow differ only in the Ethernet source address:
slow path: d8:58:d7:00:2e:bd > 80:ac:ac:39:ef:c2, 802.1Q vlan 35,
PPPoE [ses 0x454] IP6 2a01:110f:4328:c400::1 > 2a01:1000:0:1::2216 next-header IPIP, 192.0.0.2.40010 > 1.1.1.1.53fast path: 2a:01:11:0f:43:28 > 80:ac:ac:39:ef:c2, same frame otherwise
As you can see 2a:01:11:0f:43:28 is the start of 2a01:110f:4328:c400::1, the tunnel local address. The PPPoE endpoint binds the session to the subscriber MAC and silently drops the frames, the effect is that every TCP/UDP flow dies the moment it is offloaded, while ICMP, which is never offloaded, keeps working. Received traffic is unaffected.
Quoted 7 lines
Do not let
DEV_PATH_TUNpoisonh_source: skip the assignment for it. The real link-layer device appears later on the same path and provides the correct address; for a path with no Ethernet device the address stays zero as before.Fixes ab427db17885 ("netfilter: flowtable: Add IPIP rx sw acceleration")Signed-off-by Marek Majkowski <[email protected]>
Hi Marek,
thx for testing the series and fixing this issue (I guess this is occurring since the PPPoE path forces the xmit_type to FLOW_OFFLOAD_XMIT_DIRECT). Since the issue is related even to IPIP or IP6IP6 tunnels, what about targeting nf branch instead?
Quoted 9 lines
---
Found while testing this series on a Turris Omnia (Debian, armhf) behind a DS-Lite ISP: with the series applied, IPv4 flows through the ip6tnl were offloaded but no fast-path frame ever got past the PPPoE concentrator. The problem is in the existingDEV_PATH_TUNhandling, so it applies to net-next with or without this series; with the fix the series works here (tested: UDP flows with a fixed source port, TCP, bulk downloads through the tunnel). Without the series the same wrong MAC should affect ipip and ip6ip6 tunnels in front of PPPoE.
Since you actually tested the series available in [0], can you please provide your tested-by tag? Thanks.
Regards,
Lorenzo
Quoted 25 lines
net/netfilter/nf_flow_table_path.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)net/netfilter/nf_flow_table_path.c +6
-1@@ -121,7 +121,12 @@ static int nft_dev_path_info(struct net_device_path_stack *stack,case DEV_PATH_PPPOE :case DEV_PATH_TUN : info->dev = path->dev; -if (is_zero_ether_addr (info->h_source)) +/* A tunnel device has no Ethernet address: its dev_addr +* is the tunnel local IP address. Take h_source from the +* real link-layer device further down the path. +*/ +if (path->type !=DEV_PATH_TUN && +is_zero_ether_addr (info->h_source))memcpy (info->h_source, path->dev->dev_addr,ETH_ALEN ); if (path->type == DEV_PATH_ETHERNET ||Signature · 1 line
2.39.5