[PATCH net-next v6 06/12] amt: size the encapsulation headroom by the outer IP version
From: Omar Ramadan
Date: Tue Dec 01 2026 - 23:33:17 EST
AMT_RELAY_HLEN and AMT_GW_HLEN, which size the device's headroom and its
MTU below the stream device's, assume a 20-byte IPv4 outer header, 20
bytes short of an IPv6 one. A payload near the device MTU would then
exceed the tunnel MTU that amt_send_multicast_data() computes from the
route and be dropped there.
Add AMT_RELAY_HLEN6 and AMT_GW_HLEN6, pick between them in amt_hlen(),
and use amt_hlen() at newlink and on NETDEV_CHANGEMTU of the stream
device, so that the stack refuses such a payload first.
amt_v6() is still false for every device, so there is no functional
change.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@xxxxxxxxxxxxx>
---
drivers/net/amt.c | 25 ++++++++++++++-----------
include/net/amt.h | 6 ++++++
2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 1780d3dca..79702b002 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -101,6 +101,13 @@ static unsigned int amt_ip_hlen(const struct amt_dev *amt)
return amt_v6(amt) ? sizeof(struct ipv6hdr) : sizeof(struct iphdr);
}
+static unsigned int amt_hlen(const struct amt_dev *amt)
+{
+ if (amt->mode == AMT_MODE_RELAY)
+ return amt_v6(amt) ? AMT_RELAY_HLEN6 : AMT_RELAY_HLEN;
+ return amt_v6(amt) ? AMT_GW_HLEN6 : AMT_GW_HLEN;
+}
+
static void amt_outer_saddr(const struct amt_dev *amt,
const struct sk_buff *skb, union amt_addr *addr)
{
@@ -3904,10 +3911,10 @@ static int amt_newlink(struct net_device *dev,
amt->qrv = READ_ONCE(amt->net->ipv4.sysctl_igmp_qrv);
amt->qri = 10;
dev->needed_headroom = amt->stream_dev->needed_headroom +
- AMT_RELAY_HLEN;
- dev->mtu = amt->stream_dev->mtu - AMT_RELAY_HLEN;
+ amt_hlen(amt);
+ dev->mtu = amt->stream_dev->mtu - amt_hlen(amt);
dev->max_mtu = dev->mtu;
- dev->min_mtu = ETH_MIN_MTU + AMT_RELAY_HLEN;
+ dev->min_mtu = ETH_MIN_MTU + amt_hlen(amt);
} else {
if (!data[IFLA_AMT_DISCOVERY_IP]) {
NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_AMT_DISCOVERY_IP],
@@ -3930,10 +3937,10 @@ static int amt_newlink(struct net_device *dev,
}
dev->needed_headroom = amt->stream_dev->needed_headroom +
- AMT_GW_HLEN;
- dev->mtu = amt->stream_dev->mtu - AMT_GW_HLEN;
+ amt_hlen(amt);
+ dev->mtu = amt->stream_dev->mtu - amt_hlen(amt);
dev->max_mtu = dev->mtu;
- dev->min_mtu = ETH_MIN_MTU + AMT_GW_HLEN;
+ dev->min_mtu = ETH_MIN_MTU + amt_hlen(amt);
}
amt->qi = AMT_INIT_QUERY_INTERVAL;
@@ -4054,11 +4061,7 @@ static int amt_device_event(struct notifier_block *unused,
amt_dellink(amt->dev, &list);
break;
case NETDEV_CHANGEMTU:
- if (amt->mode == AMT_MODE_RELAY)
- new_mtu = dev->mtu - AMT_RELAY_HLEN;
- else
- new_mtu = dev->mtu - AMT_GW_HLEN;
-
+ new_mtu = dev->mtu - amt_hlen(amt);
dev_set_mtu(amt->dev, new_mtu);
break;
}
diff --git a/include/net/amt.h b/include/net/amt.h
index 82ab63876..726026259 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -429,9 +429,15 @@ struct amt_dev {
#define AMT_GW_HLEN (sizeof(struct iphdr) + \
sizeof(struct udphdr) + \
sizeof(struct amt_gw_headers))
+#define AMT_GW_HLEN6 (sizeof(struct ipv6hdr) + \
+ sizeof(struct udphdr) + \
+ sizeof(struct amt_gw_headers))
#define AMT_RELAY_HLEN (sizeof(struct iphdr) + \
sizeof(struct udphdr) + \
sizeof(struct amt_relay_headers))
+#define AMT_RELAY_HLEN6 (sizeof(struct ipv6hdr) + \
+ sizeof(struct udphdr) + \
+ sizeof(struct amt_relay_headers))
static inline bool netif_is_amt(const struct net_device *dev)
{