l2tp: account for IP version in SKB headroom
Subsystems (2)
PATCH 1/1 l2tp: account for IP version in SKB headroom
Account for the IP version of the tunnel when accounting skb headroom on xmit. This avoids having to potentially copy the skb a second time down the stack due to allocating not enough space for IPv6 headers in case the tunnel uses IPv6.
--- net/l2tp/l2tp_core.c | 3 ++- net/l2tp/l2tp_core.h | 1 + net/l2tp/l2tp_eth.c | 9 ++------- 3 files changed, 5 insertions(+), 8 deletions(-)
net/l2tp/l2tp_core.c +2 -1
@@ -1234,7 +1234,7 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, uns* make room. Adjust truesize. */ uhlen = (tunnel->encap ==L2TP_ENCAPTYPE_UDP ) ?sizeof (*uh) :0 ; - headroom =NET_SKB_PAD +sizeof (struct iphdr ) + uhlen + session->hdr_len; + headroom =NET_SKB_PAD + tunnel->l3_overhead + uhlen + session->hdr_len;if (skb_cow_head (skb, headroom)) {kfree_skb (skb);return NET_XMIT_DROP ;
@@ -1680,6 +1680,7 @@ int l2tp_tunnel_register(struct l2tp_tunnel *tunnel, struct net *net, } sk->sk_allocation =GFP_ATOMIC ; + tunnel->l3_overhead =kernel_sock_ip_overhead (sk);release_sock (sk);sock_hold (sk);
net/l2tp/l2tp_core.h +1 -0
@@ -167,6 +167,7 @@ struct l2tp_tunnel {u32 tunnel_id;u32 peer_tunnel_id;int version;/* 2=>L2TPv2, 3=>L2TPv3 */ +int l3_overhead;/* IP header overhead */ char name[L2TP_TUNNEL_NAME_MAX ];/* for logging */ enum l2tp_encap_type encap;
net/l2tp/l2tp_eth.c +2 -7
@@ -187,7 +187,6 @@ static void l2tp_eth_adjust_mtu(struct l2tp_tunnel *tunnel, struct net_device *dev) {unsigned int overhead =0 ; -u32 l3_overhead =0 ;u32 mtu;/* if the encap is UDP, account for UDP header size */
@@ -196,11 +195,7 @@ static void l2tp_eth_adjust_mtu(struct l2tp_tunnel *tunnel, dev->needed_headroom +=sizeof (struct udphdr ); } -lock_sock (tunnel->sock); - l3_overhead =kernel_sock_ip_overhead (tunnel->sock); -release_sock (tunnel->sock); - -if (l3_overhead ==0 ) { +if (tunnel->l3_overhead ==0 ) {/* L3 Overhead couldn't be identified, this could be * because tunnel->sock was NULL or the socket's * address family was not IPv4 or IPv6,
@@ -211,7 +206,7 @@ static void l2tp_eth_adjust_mtu(struct l2tp_tunnel *tunnel,/* Adjust MTU, factor overhead - underlay L3, overlay L2 hdr * UDP overhead, if any, was already factored in above. */ - overhead += session->hdr_len +ETH_HLEN + l3_overhead; + overhead += session->hdr_len +ETH_HLEN + tunnel->l3_overhead; mtu =l2tp_tunnel_dst_mtu (tunnel) - overhead;if (mtu < dev->min_mtu || mtu > dev->max_mtu)
Signature · 1 line
2.51.0
Simon Horman
reviewerQuoted 7 lines · David Bauer
Account for the IP version of the tunnel when accounting skb headroom on xmit. This avoids having to potentially copy the skb a second time down the stack due to allocating not enough space for IPv6 headers in case the tunnel uses IPv6.
Fixes b784e7ebfce8 ("L2TP:Adjust intf MTU, add underlay L3, L2 hdrs.")Signed-off-by David Bauer <[email protected]>
Hi David,
This feels more like an enhancement for net-next than a fix for net.
If so, please resubmit for net-next once it reopens, after 2nd January.
In that case the fixes tag should be dropped.
But you can cite a commit in free-form text in the commit message - above the tags - something like this.
...
Introduced by commit b784e7ebfce8 ("L2TP:Adjust intf MTU, add underlay L3, L2 hdrs.").