xfrm: Add pre-encap fragmentation for packet offload
Subsystems (3)
PATCH 1/1 xfrm: Add pre-encap fragmentation for packet offload
In packet offload mode the raw packets will be sent to the NiC, and will not return to the Network Stack. In event of crossing the MTU size after the encapsulation, the NiC HW may not be able to fragment the final packet.
Adding mandatory pre-encapsulation fragmentation for both IPv4 and IPv6, if tunnel mode with packet offload is configured on the state.
--- net/ipv4/xfrm4_output.c | 31 +++++++++++++++++++++++++++++-- net/ipv6/xfrm6_output.c | 8 ++++++-- 2 files changed, 35 insertions(+), 4 deletions(-)
net/ipv4/xfrm4_output.c +29 -2
@@ -14,17 +14,44 @@#include <net/xfrm.h> #include <net/icmp.h> +static int __xfrm4_output_finish (struct net *net,struct sock *sk,struct sk_buff *skb) +{ +return xfrm_output (sk, skb); +} +static int __xfrm4_output (struct net *net,struct sock *sk,struct sk_buff *skb) { -#ifdef CONFIG_NETFILTER -struct xfrm_state *x =skb_dst (skb)->xfrm; +struct dst_entry *dst =skb_dst (skb); +struct xfrm_state *x = dst->xfrm; +unsigned int mtu; +bool toobig; +#ifdef CONFIG_NETFILTER if (!x) {IPCB (skb)->flags |=IPSKB_REROUTED ;return dst_output (net, sk, skb); }#endif +if (x->props.mode !=XFRM_MODE_TUNNEL || x->xso.type !=XFRM_DEV_OFFLOAD_PACKET ) + goto skip_frag; + + mtu =xfrm_state_mtu (x,dst_mtu (skb_dst (skb))); + + toobig = skb->len > mtu && !skb_is_gso (skb); + +if (!skb->ignore_df && toobig && skb->sk) { +xfrm_local_error (skb, mtu); +kfree_skb (skb); +return -EMSGSIZE ; + } + +if (toobig) { +IPCB (skb)->frag_max_size = mtu; +return ip_do_fragment (net, sk, skb, __xfrm4_output_finish); + } + +skip_frag:return xfrm_output (sk, skb); }
net/ipv6/xfrm6_output.c +6 -2
@@ -75,10 +75,14 @@ static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)if (x->props.mode !=XFRM_MODE_TUNNEL ) goto skip_frag; -if (skb->protocol ==htons (ETH_P_IPV6 )) +if (x->xso.type ==XFRM_DEV_OFFLOAD_PACKET ) { + mtu =xfrm_state_mtu (x,dst_mtu (skb_dst (skb))); +IP6CB (skb)->frag_max_size = mtu; + }else if (skb->protocol ==htons (ETH_P_IPV6 )) { mtu =ip6_skb_dst_mtu (skb); -else + }else { mtu =dst_mtu (skb_dst (skb)); + } toobig = skb->len > mtu && !skb_is_gso (skb);
Signature · 1 line
2.25.1
Quoted 4 lines · Ilia Lin
In packet offload mode the raw packets will be sent to the NiC, and will not return to the Network Stack. In event of crossing the MTU size after the encapsulation, the NiC HW may not be able to fragment the final packet.
Yes, HW doesn't know how to handle these packets.
Quoted 3 lines
Adding mandatory pre-encapsulation fragmentation for both IPv4 and IPv6, if tunnel mode with packet offload is configured on the state.
I was under impression is that xfrm_dev_offload_ok() is responsible to prevent fragmentation.
https://elixir.bootlin.com/linux/v6.12/source/net/xfrm/xfrm_device.c#L410
Thanks
Quoted 9 lines · Leon Romanovsky
Quoted 4 lines · Ilia Lin
In packet offload mode the raw packets will be sent to the NiC, and will not return to the Network Stack. In event of crossing the MTU size after the encapsulation, the NiC HW may not be able to fragment the final packet.
Yes, HW doesn't know how to handle these packets.
Quoted 7 lines
Quoted 3 lines
Adding mandatory pre-encapsulation fragmentation for both IPv4 and IPv6, if tunnel mode with packet offload is configured on the state.
I was under impression is that
xfrm_dev_offload_ok()is responsible to prevent fragmentation.
https://elixir.bootlin.com/linux/v6.12/source/net/xfrm/xfrm_device.c#L410
With my change we can both support inner fragmentation or prevent it, depending on the network device driver implementation.
Quoted 2 lines
Thanks
Quoted 14 lines · Ilia Lin
Quoted 13 lines · Leon Romanovsky
Quoted 4 lines · Ilia Lin
In packet offload mode the raw packets will be sent to the NiC, and will not return to the Network Stack. In event of crossing the MTU size after the encapsulation, the NiC HW may not be able to fragment the final packet.
Yes, HW doesn't know how to handle these packets.
Quoted 3 lines
Adding mandatory pre-encapsulation fragmentation for both IPv4 and IPv6, if tunnel mode with packet offload is configured on the state.
Quoted 6 lines
Quoted 3 lines
I was under impression is that
xfrm_dev_offload_ok()is responsible to prevent fragmentation.
https://elixir.bootlin.com/linux/v6.12/source/net/xfrm/xfrm_device.c#L410With my change we can both support inner fragmentation or prevent it, depending on the network device driver implementation.
The thing is that fragmentation isn't desirable thing. Why didn't PMTU take into account headers so we can rely on existing code and do not add extra logic for packet offload?
Thanks
Quoted 3 lines
Quoted 3 lines
Thanks
PATCH 1/1 xfrm: Add pre-encap fragmentation for packet offload
Quoted 20 lines · Leon Romanovsky
Quoted 18 lines · Ilia Lin
Quoted 16 lines · Leon Romanovsky
Quoted 4 lines · Ilia Lin
In packet offload mode the raw packets will be sent to the NiC, and will not return to the Network Stack. In event of crossing the MTU size after the encapsulation, the NiC HW may not be able to fragment the final packet.
Yes, HW doesn't know how to handle these packets.
Quoted 3 lines
Adding mandatory pre-encapsulation fragmentation for both IPv4 and IPv6, if tunnel mode with packet offload is configured on the state.
I was under impression is that
xfrm_dev_offload_ok()is responsible to prevent fragmentation.
https://elixir.bootlin.com/linux/v6.12/source/net/xfrm/xfrm_device.c#L410
Quoted 6 lines
Quoted 2 lines
With my change we can both support inner fragmentation or prevent it, depending on the network device driver implementation.
The thing is that fragmentation isn't desirable thing. Why didn't PMTU take into account headers so we can rely on existing code and do not add extra logic for packet offload?
I agree that PMTU is a preferred option, but the packets may be routed from a host behind the VPN, which is unaware that it transmits into an IPsec tunnel, and therefore will not count on the extra headers.
Quoted 6 lines
Thanks
Quoted 3 lines
Quoted 3 lines
Thanks
A message that is not in the archive (sent off-list or not yet received): CA+5LGR0e677wm5zEx9yYZDtsCUL6etMoRB2yF9o5msqdVOWU8w@mail.gmail.com
Quoted 25 lines · Ilia Lin
Quoted 12 lines · Leon Romanovsky
Quoted 10 lines · Ilia Lin
Quoted 9 lines · Leon Romanovsky
Quoted 4 lines · Ilia Lin
In packet offload mode the raw packets will be sent to the NiC, and will not return to the Network Stack. In event of crossing the MTU size after the encapsulation, the NiC HW may not be able to fragment the final packet.
Yes, HW doesn't know how to handle these packets.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Adding mandatory pre-encapsulation fragmentation for both IPv4 and IPv6, if tunnel mode with packet offload is configured on the state.
I was under impression is that
xfrm_dev_offload_ok()is responsible to prevent fragmentation.https://elixir.bootlin.com/linux/v6.12/source/net/xfrm/xfrm_device.c#L410
Quoted 4 lines
Quoted 3 lines
With my change we can both support inner fragmentation or prevent it, depending on the network device driver implementation.
Quoted 8 lines
Quoted 3 lines
The thing is that fragmentation isn't desirable thing. Why didn't PMTU take into account headers so we can rely on existing code and do not add extra logic for packet offload?
I agree that PMTU is preferred option, but the packets may be routed from a host behind the VPN, which is unaware that it transmits into an IPsec tunnel,
and therefore will not count on the extra headers.
My basic web search shows that PMTU works correctly for IPsec tunnels too.
Steffen, do we need special case for packet offload here? My preference is to make sure that we will have as less possible special cases for packet offload.
Thanks
Quoted 6 lines
Quoted 6 lines
Thanks
Quoted 3 lines
Quoted 3 lines
Thanks
Steffen Klassert
maintainerQuoted 30 lines · Leon Romanovsky
Quoted 29 lines · Ilia Lin
Quoted 12 lines · Leon Romanovsky
Quoted 10 lines · Ilia Lin
Quoted 9 lines · Leon Romanovsky
Quoted 4 lines · Ilia Lin
In packet offload mode the raw packets will be sent to the NiC, and will not return to the Network Stack. In event of crossing the MTU size after the encapsulation, the NiC HW may not be able to fragment the final packet.
Yes, HW doesn't know how to handle these packets.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Adding mandatory pre-encapsulation fragmentation for both IPv4 and IPv6, if tunnel mode with packet offload is configured on the state.
I was under impression is that
xfrm_dev_offload_ok()is responsible to prevent fragmentation.https://elixir.bootlin.com/linux/v6.12/source/net/xfrm/xfrm_device.c#L410
Quoted 7 lines
Quoted 3 lines
With my change we can both support inner fragmentation or prevent it, depending on the network device driver implementation.
The thing is that fragmentation isn't desirable thing. Why didn't PMTU take into account headers so we can rely on existing code and do not add extra logic for packet offload?
Quoted 6 lines
Quoted 4 lines
I agree that PMTU is preferred option, but the packets may be routed from a host behind the VPN, which is unaware that it transmits into an IPsec tunnel,
and therefore will not count on the extra headers.My basic web search shows that PMTU works correctly for IPsec tunnels too.
Yes, at least SW and crypto offload IPsec PMTU works correctly.
Quoted 4 lines
Steffen, do we need special case for packet offload here? My preference is to make sure that we will have as less possible special cases for packet offload.
Looks like the problem on packet offload is that packets bigger than MTU size are dropped before the PMTU signaling is handled.
Quoted 41 lines · Steffen Klassert
Quoted 30 lines · Leon Romanovsky
Quoted 29 lines · Ilia Lin
Quoted 12 lines · Leon Romanovsky
Quoted 10 lines · Ilia Lin
Quoted 9 lines · Leon Romanovsky
Quoted 4 lines · Ilia Lin
In packet offload mode the raw packets will be sent to the NiC, and will not return to the Network Stack. In event of crossing the MTU size after the encapsulation, the NiC HW may not be able to fragment the final packet.
Yes, HW doesn't know how to handle these packets.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Adding mandatory pre-encapsulation fragmentation for both IPv4 and IPv6, if tunnel mode with packet offload is configured on the state.
I was under impression is that
xfrm_dev_offload_ok()is responsible to prevent fragmentation.https://elixir.bootlin.com/linux/v6.12/source/net/xfrm/xfrm_device.c#L410
Quoted 7 lines
Quoted 3 lines
With my change we can both support inner fragmentation or prevent it, depending on the network device driver implementation.
The thing is that fragmentation isn't desirable thing. Why didn't PMTU take into account headers so we can rely on existing code and do not add extra logic for packet offload?
Quoted 6 lines
Quoted 4 lines
I agree that PMTU is preferred option, but the packets may be routed from a host behind the VPN, which is unaware that it transmits into an IPsec tunnel,
and therefore will not count on the extra headers.My basic web search shows that PMTU works correctly for IPsec tunnels too.
Yes, at least SW and crypto offload IPsec PMTU works correctly.
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
Steffen, do we need special case for packet offload here? My preference is to make sure that we will have as less possible special cases for packet offload.
Looks like the problem on packet offload is that packets bigger than MTU size are dropped before the PMTU signaling is handled.
But PMTU should be less or equal to MTU, even before first packet was sent. Otherwise already first packet will be fragmented.
Thanks
Steffen Klassert
maintainerQuoted 7 lines · Leon Romanovsky
Quoted 6 lines · Steffen Klassert
Quoted 4 lines · Leon Romanovsky
Steffen, do we need special case for packet offload here? My preference is to make sure that we will have as less possible special cases for packet offload.
Quoted 6 lines
Quoted 3 lines
Looks like the problem on packet offload is that packets bigger than MTU size are dropped before the PMTU signaling is handled.
But PMTU should be less or equal to MTU, even before first packet was sent. Otherwise already first packet will be fragmented.
Atually I ment PMTU. On packet offload, we just drop packets bigger than PMTU. We need to make sure that xfrm{4,6}_tunnel_check_size is called. This will either fragment or do PMTU signaling.
Quoted 12 lines · Steffen Klassert
Quoted 11 lines · Leon Romanovsky
Quoted 9 lines · Steffen Klassert
Quoted 4 lines · Leon Romanovsky
Steffen, do we need special case for packet offload here? My preference is to make sure that we will have as less possible special cases for packet offload.
Looks like the problem on packet offload is that packets bigger than MTU size are dropped before the PMTU signaling is handled.
Quoted 6 lines
Quoted 2 lines
But PMTU should be less or equal to MTU, even before first packet was sent. Otherwise already first packet will be fragmented.
Atually I ment PMTU. On packet offload, we just drop packets bigger than PMTU. We need to make sure that xfrm{4,6}_tunnel_check_size is called. This will either fragment or do PMTU signaling.
Right, I'll check it next week (change is clear, need some time to set testing setup).
Thanks
Steffen Klassert
maintainerQuoted 50 lines · Ilia Lin
In packet offload mode the raw packets will be sent to the NiC, and will not return to the Network Stack. In event of crossing the MTU size after the encapsulation, the NiC HW may not be able to fragment the final packet.
Adding mandatory pre-encapsulation fragmentation for both IPv4 and IPv6, if tunnel mode with packet offload is configured on the state.Signed-off-by Ilia Lin <[email protected]>--- net/ipv4/xfrm4_output.c | 31 +++++++++++++++++++++++++++++-- net/ipv6/xfrm6_output.c | 8 ++++++-- 2 files changed, 35 insertions(+), 4 deletions(-)net/ipv4/xfrm4_output.c +17
-2@@ -14,17 +14,44 @@#include <net/xfrm.h> #include <net/icmp.h> +static int __xfrm4_output_finish (struct net *net,struct sock *sk,struct sk_buff *skb) +{ +return xfrm_output (sk, skb); +} +static int __xfrm4_output (struct net *net,struct sock *sk,struct sk_buff *skb) { -#ifdef CONFIG_NETFILTER -struct xfrm_state *x =skb_dst (skb)->xfrm; +struct dst_entry *dst =skb_dst (skb); +struct xfrm_state *x = dst->xfrm; +unsigned int mtu; +bool toobig; +#ifdef CONFIG_NETFILTER if (!x) {IPCB (skb)->flags |=IPSKB_REROUTED ;return dst_output (net, sk, skb); }#endif +if (x->props.mode !=XFRM_MODE_TUNNEL || x->xso.type !=XFRM_DEV_OFFLOAD_PACKET ) + goto skip_frag; + + mtu =xfrm_state_mtu (x,dst_mtu (skb_dst (skb))); + + toobig = skb->len > mtu && !skb_is_gso (skb); +
net/ipv4/xfrm4_output.c line 52
Quoted 10 lines
net/ipv4/xfrm4_output.c +10
-0+if (!skb->ignore_df && toobig && skb->sk) { +xfrm_local_error (skb, mtu); +kfree_skb (skb); +return -EMSGSIZE ; + } + +if (toobig) { +IPCB (skb)->frag_max_size = mtu; +return ip_do_fragment (net, sk, skb, __xfrm4_output_finish); + }
This would fragment the packet even if the DF bit is set.
Please no further packet offload stuff in generic code.
Quoted 64 lines · Steffen Klassert
Quoted 50 lines · Ilia Lin
In packet offload mode the raw packets will be sent to the NiC, and will not return to the Network Stack. In event of crossing the MTU size after the encapsulation, the NiC HW may not be able to fragment the final packet.
Adding mandatory pre-encapsulation fragmentation for both IPv4 and IPv6, if tunnel mode with packet offload is configured on the state.Signed-off-by Ilia Lin <[email protected]>--- net/ipv4/xfrm4_output.c | 31 +++++++++++++++++++++++++++++-- net/ipv6/xfrm6_output.c | 8 ++++++-- 2 files changed, 35 insertions(+), 4 deletions(-)net/ipv4/xfrm4_output.c +17
-2@@ -14,17 +14,44 @@#include <net/xfrm.h> #include <net/icmp.h> +static int __xfrm4_output_finish (struct net *net,struct sock *sk,struct sk_buff *skb) +{ +return xfrm_output (sk, skb); +} +static int __xfrm4_output (struct net *net,struct sock *sk,struct sk_buff *skb) { -#ifdef CONFIG_NETFILTER -struct xfrm_state *x =skb_dst (skb)->xfrm; +struct dst_entry *dst =skb_dst (skb); +struct xfrm_state *x = dst->xfrm; +unsigned int mtu; +bool toobig; +#ifdef CONFIG_NETFILTER if (!x) {IPCB (skb)->flags |=IPSKB_REROUTED ;return dst_output (net, sk, skb); }#endif +if (x->props.mode !=XFRM_MODE_TUNNEL || x->xso.type !=XFRM_DEV_OFFLOAD_PACKET ) + goto skip_frag; + + mtu =xfrm_state_mtu (x,dst_mtu (skb_dst (skb))); + + toobig = skb->len > mtu && !skb_is_gso (skb); +net/ipv4/xfrm4_output.c line 52
Quoted 10 lines
net/ipv4/xfrm4_output.c +10
-0+if (!skb->ignore_df && toobig && skb->sk) { +xfrm_local_error (skb, mtu); +kfree_skb (skb); +return -EMSGSIZE ; + } + +if (toobig) { +IPCB (skb)->frag_max_size = mtu; +return ip_do_fragment (net, sk, skb, __xfrm4_output_finish); + }This would fragment the packet even if the DF bit is set.
Quoted 1 line
Please no further packet offload stuff in generic code.
+ 100000
Thanks