From: David Bauer <mail@david-bauer.net>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next 2/2] l2tp: unify headroom calculation
Date: Fri, 27 Feb 2026 23:07:38 +0100 [thread overview]
Message-ID: <20260227220740.11928-2-mail@david-bauer.net> (raw)
In-Reply-To: <20260227220740.11928-1-mail@david-bauer.net>
Unify the calculation to determine the required headroom for each skb.
This was previously done inconsistently, resulting requesting more space
in the skb headroom when crafting the L2TP header than indicated with
needed_headroom.
Signed-off-by: David Bauer <mail@david-bauer.net>
---
net/l2tp/l2tp_core.c | 8 +++-----
net/l2tp/l2tp_core.h | 17 +++++++++++++++++
net/l2tp/l2tp_eth.c | 14 +++-----------
3 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
index bb19c11b0af8e..a726bdc0d6204 100644
--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -1226,18 +1226,16 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, uns
struct l2tp_tunnel *tunnel = session->tunnel;
unsigned int data_len = skb->len;
struct sock *sk = tunnel->sock;
- int headroom, uhlen, udp_len;
int ret = NET_XMIT_SUCCESS;
struct inet_sock *inet;
struct udphdr *uh;
+ int udp_len;
/* Check that there's enough headroom in the skb to insert IP,
* UDP and L2TP headers. If not enough, expand it to
* make room. Adjust truesize.
*/
- uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(*uh) : 0;
- headroom = NET_SKB_PAD + tunnel->l3_overhead + uhlen + session->hdr_len;
- if (skb_cow_head(skb, headroom)) {
+ if (skb_cow_head(skb, l2tp_session_skb_headroom(session))) {
kfree_skb(skb);
return NET_XMIT_DROP;
}
@@ -1289,7 +1287,7 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, uns
uh = udp_hdr(skb);
uh->source = inet->inet_sport;
uh->dest = inet->inet_dport;
- udp_len = uhlen + session->hdr_len + data_len;
+ udp_len = l2tp_session_udp_hdrlen(session) + session->hdr_len + data_len;
uh->len = htons(udp_len);
/* Calculate UDP checksum if configured to do so */
diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h
index aab574376d95f..635a6e01f417a 100644
--- a/net/l2tp/l2tp_core.h
+++ b/net/l2tp/l2tp_core.h
@@ -335,6 +335,23 @@ static inline int l2tp_v3_ensure_opt_in_linear(struct l2tp_session *session, str
return 0;
}
+static inline int l2tp_session_udp_hdrlen(struct l2tp_session *session)
+{
+ return session->tunnel->encap == L2TP_ENCAPTYPE_UDP ?
+ sizeof(struct udphdr) : 0;
+}
+
+static inline int l2tp_session_overhead(struct l2tp_session *session)
+{
+ return l2tp_session_udp_hdrlen(session) + session->hdr_len +
+ session->tunnel->l3_overhead;
+}
+
+static inline int l2tp_session_skb_headroom(struct l2tp_session *session)
+{
+ return NET_SKB_PAD + l2tp_session_overhead(session);
+}
+
#define MODULE_ALIAS_L2TP_PWTYPE(type) \
MODULE_ALIAS("net-l2tp-type-" __stringify(type))
diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
index 9e5f9deac08cf..29380fae02475 100644
--- a/net/l2tp/l2tp_eth.c
+++ b/net/l2tp/l2tp_eth.c
@@ -190,12 +190,6 @@ static void l2tp_eth_adjust_mtu(struct l2tp_tunnel *tunnel,
unsigned int overhead = 0;
u32 mtu;
- /* if the encap is UDP, account for UDP header size */
- if (tunnel->encap == L2TP_ENCAPTYPE_UDP) {
- overhead += sizeof(struct udphdr);
- dev->needed_headroom += sizeof(struct udphdr);
- }
-
if (tunnel->l3_overhead == 0) {
/* L3 Overhead couldn't be identified, this could be
* because tunnel->sock was NULL or the socket's
@@ -204,10 +198,8 @@ static void l2tp_eth_adjust_mtu(struct l2tp_tunnel *tunnel,
*/
return;
}
- /* Adjust MTU, factor overhead - underlay L3, overlay L2 hdr
- * UDP overhead, if any, was already factored in above.
- */
- overhead += session->hdr_len + ETH_HLEN + tunnel->l3_overhead;
+ /* Calculate required overhead */
+ overhead = ETH_HLEN + l2tp_session_overhead(session);
mtu = l2tp_tunnel_dst_mtu(tunnel) - overhead;
if (mtu < dev->min_mtu || mtu > dev->max_mtu)
@@ -215,7 +207,7 @@ static void l2tp_eth_adjust_mtu(struct l2tp_tunnel *tunnel,
else
dev->mtu = mtu;
- dev->needed_headroom += session->hdr_len;
+ dev->needed_headroom = l2tp_session_skb_headroom(session);
}
static int l2tp_eth_create(struct net *net, struct l2tp_tunnel *tunnel,
--
2.51.0
next prev parent reply other threads:[~2026-02-27 22:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-27 22:07 [PATCH net-next 1/2] l2tp: account for IP version in SKB headroom David Bauer
2026-02-27 22:07 ` David Bauer [this message]
2026-02-28 15:35 ` Jakub Kicinski
2026-02-28 22:12 ` [syzbot ci] " syzbot ci
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=20260227220740.11928-2-mail@david-bauer.net \
--to=mail@david-bauer.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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