* [PATCH net-next v2 01/12] amt: create an AF_INET6 encapsulation socket for an IPv6 outer address
2026-11-25 19:14 [PATCH net-next v2 00/12] amt: add an IPv6 outer transport Omar Ramadan
@ 2026-11-25 19:14 ` Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 02/12] amt: send the Relay Advertisement over IPv6 Omar Ramadan
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Omar Ramadan @ 2026-11-25 19:14 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Shuah Khan
Cc: Simon Horman, netdev, linux-kselftest, linux-kernel
The amt device binds one AF_INET UDP socket on the relay port, so a
relay and its gateways can only talk AMT over IPv4. RFC 7450 defines
the protocol over either IP version: the Relay Advertisement carries
an IPv4 or an IPv6 relay address, and s5.2 selects the form from the
IP version of the outer header, so an IPv6-only access network needs
an IPv6 outer transport to reach the relay at all.
Add the outer IPv6 local address to struct amt_dev, and amt_v6(),
which reports the device's outer family from it. amt_create_sock()
binds an AF_INET6 socket for an IPv6 device. The socket sends and
verifies the UDP checksum, which RFC 8200 s8.1 makes mandatory over
IPv6, and it is V6ONLY, so that it does not also claim the IPv4
wildcard port, which an IPv4 amt device in the same netns may hold.
The socket is also bound to the underlying link, IFLA_AMT_LINK. The
IPv4 paths pass that link as the output interface, and an IPv4 route
lookup then only uses routes through it. An IPv6 lookup that has a
source address, as every AMT send does, treats the output interface as
a preference unless the socket is bound to a device, so without the
binding the outer IPv6 traffic could leave through another link while
the device's MTU and headroom are derived from this one. The binding
also keeps packets that arrive on other links away from the socket. A
link-local address is unique only on its link, and relay tunnels are
keyed on the gateway's address, so two gateways on different links
with the same link-local address would otherwise share a tunnel, and
the replies would go out the wrong link.
The new socket also hands ICMPv6 errors to amt_err_lookup(). This relies
on amt_parse_type() pulling the AMT header behind the transport header,
as "amt: pull the AMT header behind the transport header in
amt_parse_type()" in net makes it do, since on the error path skb->data
points at the quoted IPv6 header.
Nothing sets local_ipv6 yet. The netlink attribute that does is added
at the end of this series, once every path can use it, so there is no
functional change here.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 36 ++++++++++++++++++++++++++++++------
include/net/amt.h | 2 ++
2 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index b145ed3ca..3f3205d2d 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -90,6 +90,14 @@ static struct in6_addr mld2_all_node = MLD2_ALL_NODE_INIT;
static struct mld2_grec mldv2_zero_grec;
#endif
+/* The outer transport family is fixed when the link is created: an IPv6
+ * local address selects IPv6, otherwise the device runs over IPv4.
+ */
+static bool amt_v6(const struct amt_dev *amt)
+{
+ return IS_ENABLED(CONFIG_IPV6) && !ipv6_addr_any(&amt->local_ipv6);
+}
+
static void __amt_source_gc_work(void)
{
struct amt_source_node *snode;
@@ -3310,19 +3318,35 @@ static int amt_err_lookup(struct sock *sk, struct sk_buff *skb)
return 0;
}
-static struct sock *amt_create_sock(struct net *net, __be16 port)
+static struct sock *amt_create_sock(const struct amt_dev *amt)
{
struct udp_port_cfg udp_conf;
struct socket *sock;
int err;
memset(&udp_conf, 0, sizeof(udp_conf));
- udp_conf.family = AF_INET;
- udp_conf.local_ip.s_addr = htonl(INADDR_ANY);
+ if (amt_v6(amt)) {
+ /* Bound to :: by the memset, and to the underlying link: a
+ * bound socket makes every IPv6 route lookup strict about
+ * the output interface, as the IPv4 lookup is, and receives
+ * from that link only, where a link-local peer is unique.
+ * V6ONLY keeps the socket off the IPv4 wildcard, so an IPv4
+ * amt device can use the same port in the netns. The UDP
+ * checksum is mandatory over IPv6.
+ */
+ udp_conf.family = AF_INET6;
+ udp_conf.bind_ifindex = amt->stream_dev->ifindex;
+ udp_conf.use_udp6_tx_checksums = true;
+ udp_conf.use_udp6_rx_checksums = true;
+ udp_conf.ipv6_v6only = true;
+ } else {
+ udp_conf.family = AF_INET;
+ udp_conf.local_ip.s_addr = htonl(INADDR_ANY);
+ }
- udp_conf.local_udp_port = port;
+ udp_conf.local_udp_port = amt->relay_port;
- err = udp_sock_create(net, &udp_conf, &sock);
+ err = udp_sock_create(amt->net, &udp_conf, &sock);
if (err < 0)
return ERR_PTR(err);
@@ -3334,7 +3358,7 @@ static int amt_socket_create(struct amt_dev *amt)
struct udp_tunnel_sock_cfg tunnel_cfg;
struct sock *sk;
- sk = amt_create_sock(amt->net, amt->relay_port);
+ sk = amt_create_sock(amt);
if (IS_ERR(sk))
return PTR_ERR(sk);
diff --git a/include/net/amt.h b/include/net/amt.h
index 9ba097127..ca35782f8 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -361,6 +361,8 @@ struct amt_dev {
__be16 gw_port;
/* Outer local ip */
__be32 local_ip;
+ /* Outer local IPv6 address, :: unless the outer transport is IPv6 */
+ struct in6_addr local_ipv6;
/* Outer remote ip */
__be32 remote_ip;
/* Outer discovery ip */
--
2.47.3
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH net-next v2 02/12] amt: send the Relay Advertisement over IPv6
2026-11-25 19:14 [PATCH net-next v2 00/12] amt: add an IPv6 outer transport Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 01/12] amt: create an AF_INET6 encapsulation socket for an IPv6 outer address Omar Ramadan
@ 2026-11-25 19:14 ` Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 03/12] amt: key relay tunnels on a union amt_addr endpoint Omar Ramadan
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Omar Ramadan @ 2026-11-25 19:14 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Shuah Khan
Cc: Simon Horman, netdev, linux-kselftest, linux-kernel
A gateway finds its relay with a Relay Discovery, and the relay answers
with a Relay Advertisement carrying the address the gateway should use
from then on. RFC 7450 s5.1.2 defines two forms of the Advertisement:
the same fixed header and nonce followed by either a 4-byte IPv4 or a
16-byte IPv6 relay address, and s5.2 selects the form from the IP
version of the outer header rather than from a field in the message.
An amt relay on an IPv6 outer transport therefore has to answer with
the 24-byte IPv6 form.
Add struct amt_header_advertisement_v6 for that form and
amt_send_advertisement_v6(), which fills it on the stack and sends it
with a new amt_send_ctrl_v6() helper. The helper routes with
ip6_dst_lookup_flow() through amt_route6(), which the later IPv6
senders share, and sends with udp_tunnel6_xmit_skb(), which builds the
UDP and IPv6 headers and fills in the UDP checksum that RFC 8200 s8.1
makes mandatory over IPv6. Like the IPv4 control messages, it marks the
skb TC_PRIO_CONTROL, uses AMT_TOS as the traffic class and passes no
netdev, so control traffic stays out of the amt device's tunnel stats.
amt_discovery_handler() answers an IPv6 device's Discovery with the
IPv6 form, sent back to the outer source of the Discovery. RFC 7450
s5.1.2 makes the source of the Advertisement the destination of the
Discovery, the Relay Discovery Address, so amt_send_ctrl_v6() and
amt_route6() take the source address from their caller. The socket is
bound to ::, so a Discovery sent to an anycast or secondary address
reaches the relay, and a gateway accepts only an Advertisement whose
source is the address it sent the Discovery to; answering from
local_ipv6 would leave such a gateway stuck in discovery. The relay
address carried in the message stays local_ipv6. The same socket also
receives a Discovery sent to a multicast group the host has joined,
such as ff02::1, and a multicast address may not be a source (RFC 4291
s2.7), so a Discovery with a multicast destination is dropped rather
than answered by every relay on the link with an invalid packet. The
handler copies both outer addresses by value after its last
pskb_may_pull(), and sending does not pull the received skb.
The IPv4 Advertisement has always been sent from local_ip, so an IPv4
gateway that discovers the relay through another of its addresses drops
the reply. That is left as it is: changing the source of an existing
IPv4 relay's replies is a fix of its own for net, and nothing in this
series depends on it.
amt_v6() is still false for every device, so there is no functional
change yet.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++
include/net/amt.h | 21 +++++++++
2 files changed, 136 insertions(+)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 3f3205d2d..52ccaca08 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -708,6 +708,80 @@ static void __amt_update_relay_status(struct amt_tunnel_list *tunnel,
tunnel->status = status;
}
+static struct dst_entry *amt_route6(struct amt_dev *amt, struct sock *sk,
+ const struct in6_addr *saddr,
+ const struct in6_addr *daddr,
+ __be16 sport, __be16 dport)
+{
+ struct flowi6 fl6;
+
+ memset(&fl6, 0, sizeof(fl6));
+ fl6.flowi6_oif = amt->stream_dev->ifindex;
+ fl6.flowi6_proto = IPPROTO_UDP;
+ fl6.daddr = *daddr;
+ fl6.saddr = *saddr;
+ fl6.fl6_dport = dport;
+ fl6.fl6_sport = sport;
+ /* The packet carries AMT_TOS, so route on it too: a policy rule
+ * that matches the DSCP must see the same value.
+ */
+ fl6.flowlabel = ip6_make_flowinfo(AMT_TOS, 0);
+
+ return ip6_dst_lookup_flow(amt->net, sk, &fl6, NULL);
+}
+
+/* Send an AMT control message over the IPv6 outer transport from @saddr.
+ * udp_tunnel6_xmit_skb() adds the UDP and IPv6 headers, including the UDP
+ * checksum that IPv6 requires. Returns 0 once the message is handed to the
+ * IPv6 stack.
+ */
+static int amt_send_ctrl_v6(struct amt_dev *amt, const struct in6_addr *saddr,
+ const struct in6_addr *daddr,
+ __be16 sport, __be16 dport,
+ const void *msg, unsigned int len)
+{
+ struct dst_entry *dst;
+ struct sk_buff *skb;
+ struct sock *sk;
+ int hlen, err;
+
+ rcu_read_lock();
+ sk = rcu_dereference(amt->sk);
+ if (!sk || !netif_running(amt->stream_dev) ||
+ !netif_running(amt->dev)) {
+ err = -ENETDOWN;
+ goto out;
+ }
+
+ dst = amt_route6(amt, sk, saddr, daddr, sport, dport);
+ if (IS_ERR(dst)) {
+ DEV_STATS_INC(amt->dev, tx_errors);
+ err = PTR_ERR(dst);
+ goto out;
+ }
+
+ hlen = LL_RESERVED_SPACE(amt->dev) + sizeof(struct ipv6hdr) +
+ sizeof(struct udphdr);
+ skb = netdev_alloc_skb_ip_align(amt->dev, hlen + len +
+ amt->dev->needed_tailroom);
+ if (!skb) {
+ dst_release(dst);
+ DEV_STATS_INC(amt->dev, tx_errors);
+ err = -ENOMEM;
+ goto out;
+ }
+
+ skb_reserve(skb, hlen);
+ skb_put_data(skb, msg, len);
+ skb->priority = TC_PRIO_CONTROL;
+ udp_tunnel6_xmit_skb(dst, sk, skb, NULL, saddr, daddr, AMT_TOS,
+ ip6_dst_hoplimit(dst), 0, sport, dport, false, 0);
+ err = 0;
+out:
+ rcu_read_unlock();
+ return err;
+}
+
static void amt_send_discovery(struct amt_dev *amt)
{
struct amt_header_discovery *amtd;
@@ -3010,6 +3084,24 @@ static void amt_send_advertisement(struct amt_dev *amt, __be32 nonce,
rcu_read_unlock();
}
+/* The IPv6 form of amt_send_advertisement(), carrying the relay's IPv6
+ * address. It is sent from @saddr, the address the Discovery was sent to.
+ */
+static void amt_send_advertisement_v6(struct amt_dev *amt, __be32 nonce,
+ const struct in6_addr *saddr,
+ const struct in6_addr *daddr,
+ __be16 dport)
+{
+ struct amt_header_advertisement_v6 amta = {
+ .type = AMT_MSG_ADVERTISEMENT,
+ .nonce = nonce,
+ .ip6 = amt->local_ipv6,
+ };
+
+ amt_send_ctrl_v6(amt, saddr, daddr, amt->relay_port, dport,
+ &amta, sizeof(amta));
+}
+
static bool amt_discovery_handler(struct amt_dev *amt, struct sk_buff *skb)
{
struct amt_header_discovery *amtd;
@@ -3026,6 +3118,29 @@ static bool amt_discovery_handler(struct amt_dev *amt, struct sk_buff *skb)
if (amtd->reserved || amtd->version)
return true;
+ /* The Advertisement takes the form of the outer IP version, and
+ * RFC 7450 s5.1.2 sources it from the address the Discovery was
+ * sent to, which may be an anycast Relay Discovery Address rather
+ * than local_ipv6.
+ */
+ if (amt_v6(amt)) {
+ struct in6_addr saddr = ipv6_hdr(skb)->saddr;
+ struct in6_addr daddr = ipv6_hdr(skb)->daddr;
+
+ /* The socket bound to :: also receives a Discovery sent to
+ * a group, and a multicast address can never be a source
+ * (RFC 4291 s2.7), so such a Discovery is not answered. Nor
+ * is one from ::, which has nowhere to be sent.
+ */
+ if (ipv6_addr_is_multicast(&daddr) ||
+ ipv6_addr_any(&saddr))
+ return true;
+
+ amt_send_advertisement_v6(amt, amtd->nonce, &daddr, &saddr,
+ udph->source);
+ return false;
+ }
+
amt_send_advertisement(amt, amtd->nonce, iph->saddr, udph->source);
return false;
diff --git a/include/net/amt.h b/include/net/amt.h
index ca35782f8..52d77bc6b 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -133,6 +133,27 @@ struct amt_header_advertisement {
__be32 ip4;
} __packed;
+/* The IPv6 form of the Relay Advertisement (RFC 7450 s5.1.2): the same
+ * header and nonce, followed by a 16-byte relay address. s5.2 selects the
+ * form from the IP version of the outer header, not from a field in the
+ * message, so it is a type of its own.
+ */
+struct amt_header_advertisement_v6 {
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+ u32 type:4,
+ version:4,
+ reserved:24;
+#elif defined(__BIG_ENDIAN_BITFIELD)
+ u32 version:4,
+ type:4,
+ reserved:24;
+#else
+#error "Please fix <asm/byteorder.h>"
+#endif
+ __be32 nonce;
+ struct in6_addr ip6;
+} __packed;
+
struct amt_header_request {
#if defined(__LITTLE_ENDIAN_BITFIELD)
u32 type:4,
--
2.47.3
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH net-next v2 03/12] amt: key relay tunnels on a union amt_addr endpoint
2026-11-25 19:14 [PATCH net-next v2 00/12] amt: add an IPv6 outer transport Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 01/12] amt: create an AF_INET6 encapsulation socket for an IPv6 outer address Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 02/12] amt: send the Relay Advertisement over IPv6 Omar Ramadan
@ 2026-11-25 19:14 ` Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 04/12] amt: send the Membership Query over IPv6 Omar Ramadan
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Omar Ramadan @ 2026-11-25 19:14 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Shuah Khan
Cc: Simon Horman, netdev, linux-kselftest, linux-kernel
A relay keeps one struct amt_tunnel_list per gateway endpoint and finds
it by the gateway's IPv4 address, stored as __be32 ip4 and taken from
ip_hdr(skb)->saddr, together with its UDP source port. On an IPv6 outer
transport that reads the traffic class and flow label of the IPv6
header as an address, and the field cannot hold the gateway's address
anyway.
Store the endpoint as a union amt_addr, which group and source nodes
already use, and move the union above struct amt_tunnel_list so the
tunnel can embed it. Its ip6 member is no longer under CONFIG_IPV6, so
code that only copies, compares or prints an endpoint compiles without
an #if and relies on amt_v6() being false. A kernel without IPv6 pays 12
bytes per group and source node, which it already zeroes. The tunnel
needs no family of its own: the relay's socket is bound to one family,
so every tunnel has the device's family, which amt_v6() reports.
amt_outer_saddr() copies the outer source address of a received message
by value into a zeroed union amt_addr. amt_request_handler() and
amt_update_handler() take that snapshot on entry, before
pskb_may_pull() and iptunnel_pull_header() can reallocate the header,
and pass it to amt_tunnel_lookup(), amt_tunnel_get_or_create() and
amt_update_tunnel(). They match endpoints with the existing
amt_addr_equal(); the union is zero-padded for IPv4, so one memcmp()
serves both families. The per-source tunnel count in
amt_request_handler() and amt_tunnel_get_or_create() compares the same
way.
The Membership Update MAC becomes amt_relay_mac(), one siphash() over the
packed {address, port, nonce} tuple instead of siphash_3u32() over the
IPv4 address. The Request and Update handlers both compute it with the
helper. Only the relay computes and checks the MAC; the gateway echoes it
verbatim, so the different IPv4 value is not visible on the wire.
The IPv4 senders and the relay status debug message are converted to
tunnel->addr.ip4, and the debug message prints an IPv6 endpoint with
%pI6c. amt_v6() is still false for every device, so there is no
functional change.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 89 ++++++++++++++++++++++++++++++++---------------
include/net/amt.h | 20 ++++++-----
2 files changed, 72 insertions(+), 37 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 52ccaca08..38740e0ac 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -98,6 +98,32 @@ static bool amt_v6(const struct amt_dev *amt)
return IS_ENABLED(CONFIG_IPV6) && !ipv6_addr_any(&amt->local_ipv6);
}
+/* Snapshot the outer source address of a received AMT message. */
+static void amt_outer_saddr(const struct amt_dev *amt,
+ const struct sk_buff *skb, union amt_addr *addr)
+{
+ memset(addr, 0, sizeof(*addr));
+ if (amt_v6(amt))
+ addr->ip6 = ipv6_hdr(skb)->saddr;
+ else
+ addr->ip4 = ip_hdr(skb)->saddr;
+}
+
+/* The Membership Update MAC for a gateway endpoint. The gateway only echoes
+ * it, so one siphash() over the zero-padded endpoint serves both families.
+ */
+static u64 amt_relay_mac(const union amt_addr *addr, __be16 port, __be32 nonce,
+ const siphash_key_t *key)
+{
+ struct {
+ union amt_addr addr;
+ __be16 port;
+ __be32 nonce;
+ } __packed in = { .addr = *addr, .port = port, .nonce = nonce };
+
+ return siphash(&in, sizeof(in), key) >> 16;
+}
+
static void __amt_source_gc_work(void)
{
struct amt_source_node *snode;
@@ -701,10 +727,16 @@ static void __amt_update_relay_status(struct amt_tunnel_list *tunnel,
{
if (validate && tunnel->status >= status)
return;
- netdev_dbg(tunnel->amt->dev,
- "Update Tunnel(IP = %pI4, PORT = %u) status %s -> %s",
- &tunnel->ip4, ntohs(tunnel->source_port),
- status_str[tunnel->status], status_str[status]);
+ if (amt_v6(tunnel->amt))
+ netdev_dbg(tunnel->amt->dev,
+ "Update Tunnel(IP = %pI6c, PORT = %u) status %s -> %s",
+ &tunnel->addr.ip6, ntohs(tunnel->source_port),
+ status_str[tunnel->status], status_str[status]);
+ else
+ netdev_dbg(tunnel->amt->dev,
+ "Update Tunnel(IP = %pI4, PORT = %u) status %s -> %s",
+ &tunnel->addr.ip4, ntohs(tunnel->source_port),
+ status_str[tunnel->status], status_str[status]);
tunnel->status = status;
}
@@ -1292,12 +1324,12 @@ static void amt_send_multicast_data(struct amt_dev *amt,
memset(&fl4, 0, sizeof(struct flowi4));
fl4.flowi4_oif = amt->stream_dev->ifindex;
- fl4.daddr = tunnel->ip4;
+ fl4.daddr = tunnel->addr.ip4;
fl4.saddr = amt->local_ip;
fl4.flowi4_proto = IPPROTO_UDP;
rt = ip_route_output_key(amt->net, &fl4);
if (IS_ERR(rt)) {
- netdev_dbg(amt->dev, "no route to %pI4\n", &tunnel->ip4);
+ netdev_dbg(amt->dev, "no route to %pI4\n", &tunnel->addr.ip4);
kfree_skb(skb);
return;
}
@@ -2728,12 +2760,14 @@ static bool amt_membership_query_handler(struct amt_dev *amt,
* race with amt_tunnel_expire() creates the replacement.
*/
static struct amt_tunnel_list *amt_tunnel_lookup(struct amt_dev *amt,
- __be32 saddr, __be16 sport)
+ union amt_addr *saddr,
+ __be16 sport)
{
struct amt_tunnel_list *tunnel;
list_for_each_entry_rcu(tunnel, &amt->tunnel_list, list) {
- if (tunnel->ip4 == saddr && tunnel->source_port == sport &&
+ if (amt_addr_equal(&tunnel->addr, saddr) &&
+ tunnel->source_port == sport &&
!READ_ONCE(tunnel->dead))
return tunnel;
}
@@ -2759,7 +2793,7 @@ static u32 amt_max_tunnels_per_src(const struct amt_dev *amt)
* verified source address may hold.
*/
static struct amt_tunnel_list *amt_tunnel_get_or_create(struct amt_dev *amt,
- __be32 saddr,
+ union amt_addr *saddr,
__be16 sport)
{
struct amt_tunnel_list *tunnel;
@@ -2779,7 +2813,8 @@ static struct amt_tunnel_list *amt_tunnel_get_or_create(struct amt_dev *amt,
* against its address.
*/
list_for_each_entry(tunnel, &amt->tunnel_list, list) {
- if (tunnel->ip4 != saddr || READ_ONCE(tunnel->dead))
+ if (!amt_addr_equal(&tunnel->addr, saddr) ||
+ READ_ONCE(tunnel->dead))
continue;
if (tunnel->source_port == sport) {
spin_unlock_bh(&amt->lock);
@@ -2808,7 +2843,7 @@ static struct amt_tunnel_list *amt_tunnel_get_or_create(struct amt_dev *amt,
}
tunnel->source_port = sport;
- tunnel->ip4 = saddr;
+ tunnel->addr = *saddr;
tunnel->amt = amt;
spin_lock_init(&tunnel->lock);
for (i = 0; i < amt->hash_buckets; i++)
@@ -2838,7 +2873,7 @@ static struct amt_tunnel_list *amt_tunnel_get_or_create(struct amt_dev *amt,
* second amt_tunnel_get_or_create() call, which creates its replacement.
*/
static bool amt_update_tunnel(struct amt_dev *amt, struct sk_buff *skb,
- __be32 saddr, __be16 sport, bool v6)
+ union amt_addr *saddr, __be16 sport, bool v6)
{
struct amt_tunnel_list *tunnel;
int i;
@@ -2878,12 +2913,13 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)
struct ethhdr *eth;
struct iphdr *iph;
unsigned int seq;
+ union amt_addr saddr;
u64 response_mac;
- __be32 saddr;
__be32 nonce;
__be16 sport;
- saddr = ip_hdr(skb)->saddr;
+ /* Snapshot the outer source before any pull can move the header. */
+ amt_outer_saddr(amt, skb, &saddr);
hdr_size = sizeof(*amtmu) + sizeof(struct udphdr);
if (!pskb_may_pull(skb, hdr_size))
@@ -2910,10 +2946,7 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)
} while (read_seqcount_retry(&amt->key_seq, seq));
for (i = 0; i < ARRAY_SIZE(key); i++) {
- u64 mac = siphash_3u32((__force u32)saddr,
- (__force u32)sport,
- (__force u32)nonce,
- &key[i]) >> 16;
+ u64 mac = amt_relay_mac(&saddr, sport, nonce, &key[i]);
if (response_mac == mac) {
verified = true;
@@ -2947,7 +2980,7 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)
return true;
}
- if (!amt_update_tunnel(amt, skb, saddr, sport, false))
+ if (!amt_update_tunnel(amt, skb, &saddr, sport, false))
return true;
skb_push(skb, sizeof(struct ethhdr));
@@ -2966,7 +2999,7 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)
return true;
}
- if (!amt_update_tunnel(amt, skb, saddr, sport, true))
+ if (!amt_update_tunnel(amt, skb, &saddr, sport, true))
return true;
skb_push(skb, sizeof(struct ethhdr));
@@ -3165,8 +3198,8 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)
struct amt_header_request *amtrh;
struct amt_tunnel_list *tunnel;
bool full, have = false;
+ union amt_addr saddr;
struct udphdr *udph;
- struct iphdr *iph;
siphash_key_t key;
u32 per_src = 0;
u64 mac;
@@ -3174,7 +3207,7 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)
if (!pskb_may_pull(skb, sizeof(*udph) + sizeof(*amtrh)))
return true;
- iph = ip_hdr(skb);
+ amt_outer_saddr(amt, skb, &saddr);
udph = udp_hdr(skb);
amtrh = (struct amt_header_request *)(udp_hdr(skb) + 1);
@@ -3198,7 +3231,8 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)
*/
rcu_read_lock();
list_for_each_entry_rcu(tunnel, &amt->tunnel_list, list) {
- if (tunnel->ip4 != iph->saddr || READ_ONCE(tunnel->dead))
+ if (!amt_addr_equal(&tunnel->addr, &saddr) ||
+ READ_ONCE(tunnel->dead))
continue;
per_src++;
if (tunnel->source_port == udph->source)
@@ -3210,15 +3244,12 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)
if (!have && (full || per_src >= amt_max_tunnels_per_src(amt)))
return true;
- mac = siphash_3u32((__force u32)iph->saddr,
- (__force u32)udph->source,
- (__force u32)amtrh->nonce,
- &key) >> 16;
+ mac = amt_relay_mac(&saddr, udph->source, amtrh->nonce, &key);
if (!amtrh->p)
- amt_send_igmp_gq(amt, iph->saddr, udph->source, amtrh->nonce,
+ amt_send_igmp_gq(amt, saddr.ip4, udph->source, amtrh->nonce,
mac);
else
- amt_send_mld_gq(amt, iph->saddr, udph->source, amtrh->nonce,
+ amt_send_mld_gq(amt, saddr.ip4, udph->source, amtrh->nonce,
mac);
return false;
diff --git a/include/net/amt.h b/include/net/amt.h
index 52d77bc6b..245947113 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -252,6 +252,14 @@ struct amt_relay_headers {
};
} __packed;
+/* ip6 is present without CONFIG_IPV6 too, so that code which only copies
+ * or compares addresses needs no #if; amt_v6() is then false.
+ */
+union amt_addr {
+ __be32 ip4;
+ struct in6_addr ip6;
+};
+
struct amt_tunnel_list {
struct list_head list;
/* Protect All resources under an amt_tunne_list */
@@ -273,18 +281,14 @@ struct amt_tunnel_list {
*/
bool dead;
__be16 source_port;
- __be32 ip4;
+ /* Outer source address of the gateway endpoint, in the device's
+ * outer family (amt_v6()).
+ */
+ union amt_addr addr;
struct rcu_head rcu;
struct hlist_head groups[];
};
-union amt_addr {
- __be32 ip4;
-#if IS_ENABLED(CONFIG_IPV6)
- struct in6_addr ip6;
-#endif
-};
-
/* RFC 3810
*
* When the router is in EXCLUDE mode, the router state is represented
--
2.47.3
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH net-next v2 04/12] amt: send the Membership Query over IPv6
2026-11-25 19:14 [PATCH net-next v2 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (2 preceding siblings ...)
2026-11-25 19:14 ` [PATCH net-next v2 03/12] amt: key relay tunnels on a union amt_addr endpoint Omar Ramadan
@ 2026-11-25 19:14 ` Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 05/12] amt: forward multicast data " Omar Ramadan
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Omar Ramadan @ 2026-11-25 19:14 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Shuah Khan
Cc: Simon Horman, netdev, linux-kselftest, linux-kernel
After the Request, a relay answers each gateway with a Membership Query
through amt_send_membership_query(), which routes and transmits only
over IPv4.
Rather than adding an IPv6 twin of the function, move its routing and
transmit step into amt_udp_xmit(). Given an skb that already carries
the AMT message, a union amt_addr destination and the port pair, it
sends over the device's family: ip_route_output_key() and
udp_tunnel_xmit_skb() for IPv4, as before, and amt_route6() and
udp_tunnel6_xmit_skb(), which fills in the mandatory IPv6 UDP checksum,
for IPv6. Both use AMT_TOS, as the IPv4 path and the IPv6 control
messages do. udp_tunnel_xmit_skb() scrubs the skb in iptunnel_xmit(),
but udp_tunnel6_xmit_skb() does not, so the IPv6 path calls
skb_scrub_packet() itself. Otherwise the conntrack entry and extensions
of the inner packet would stay on the outer one, which conntrack would
then pass as an already tracked flow.
amt_send_membership_query() sizes its headroom for the outer family
with amt_ip_hlen(), builds the AMT header and hands the skb to
amt_udp_xmit(). The route lookup now runs after the header push; on a
route failure the caller still frees the skb.
The v6 argument keeps its meaning: it selects the inner protocol, IGMP
or MLD, which is independent of the outer family, so an IPv6 relay
queries for both. The relay's General Query, which amt_send_igmp_gq()
and amt_send_mld_gq() now send directly through
amt_send_membership_query(), takes the IPv6 path. Both now take the
gateway's endpoint as a union amt_addr, as amt_send_membership_query()
does.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 118 +++++++++++++++++++++++++++++++---------------
1 file changed, 81 insertions(+), 37 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 38740e0ac..7e8219a0c 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -98,6 +98,12 @@ static bool amt_v6(const struct amt_dev *amt)
return IS_ENABLED(CONFIG_IPV6) && !ipv6_addr_any(&amt->local_ipv6);
}
+/* Length of the outer IP header for the device's family. */
+static unsigned int amt_ip_hlen(const struct amt_dev *amt)
+{
+ return amt_v6(amt) ? sizeof(struct ipv6hdr) : sizeof(struct iphdr);
+}
+
/* Snapshot the outer source address of a received AMT message. */
static void amt_outer_saddr(const struct amt_dev *amt,
const struct sk_buff *skb, union amt_addr *addr)
@@ -997,7 +1003,8 @@ static void amt_send_request(struct amt_dev *amt, bool v6)
static bool amt_send_membership_query(struct amt_dev *amt,
struct sk_buff *skb,
- __be32 daddr, __be16 dport,
+ const union amt_addr *daddr,
+ __be16 dport,
__be32 nonce, u64 mac,
bool v6);
@@ -1005,8 +1012,8 @@ static bool amt_send_membership_query(struct amt_dev *amt,
* unauthenticated, so no tunnel state is created or changed for it - see
* amt_request_handler().
*/
-static void amt_send_igmp_gq(struct amt_dev *amt, __be32 daddr, __be16 dport,
- __be32 nonce, u64 mac)
+static void amt_send_igmp_gq(struct amt_dev *amt, const union amt_addr *daddr,
+ __be16 dport, __be32 nonce, u64 mac)
{
struct sk_buff *skb;
@@ -1095,8 +1102,8 @@ static struct sk_buff *amt_build_mld_gq(struct amt_dev *amt)
return skb;
}
-static void amt_send_mld_gq(struct amt_dev *amt, __be32 daddr, __be16 dport,
- __be32 nonce, u64 mac)
+static void amt_send_mld_gq(struct amt_dev *amt, const union amt_addr *daddr,
+ __be16 dport, __be32 nonce, u64 mac)
{
struct sk_buff *skb;
@@ -1112,8 +1119,8 @@ static void amt_send_mld_gq(struct amt_dev *amt, __be32 daddr, __be16 dport,
}
}
#else
-static void amt_send_mld_gq(struct amt_dev *amt, __be32 daddr, __be16 dport,
- __be32 nonce, u64 mac)
+static void amt_send_mld_gq(struct amt_dev *amt, const union amt_addr *daddr,
+ __be16 dport, __be32 nonce, u64 mac)
{
}
#endif
@@ -1230,6 +1237,66 @@ static void amt_req_work(struct work_struct *work)
msecs_to_jiffies(100));
}
+/* Route an AMT-encapsulated skb to @daddr and send it over the device's
+ * outer family. The caller has already pushed the AMT header; @dscp only
+ * steers the IPv4 route lookup.
+ */
+static int amt_udp_xmit(struct amt_dev *amt, struct sock *sk,
+ struct sk_buff *skb, const union amt_addr *daddr,
+ __be16 sport, __be16 dport, dscp_t dscp)
+{
+ struct rtable *rt;
+ struct flowi4 fl4;
+
+ if (amt_v6(amt)) {
+ struct dst_entry *dst;
+
+ dst = amt_route6(amt, sk, &amt->local_ipv6, &daddr->ip6,
+ sport, dport);
+ if (IS_ERR(dst)) {
+ netdev_dbg(amt->dev, "no route to %pI6c\n",
+ &daddr->ip6);
+ return PTR_ERR(dst);
+ }
+ /* iptunnel_xmit() scrubs the IPv4 tunnel skb, but
+ * udp_tunnel6_xmit_skb() does not, so drop the inner
+ * packet's conntrack and extensions here. Links cannot
+ * cross netns, so this is never xnet.
+ */
+ skb_scrub_packet(skb, false);
+ udp_tunnel6_xmit_skb(dst, sk, skb, amt->dev, &amt->local_ipv6,
+ &daddr->ip6, AMT_TOS,
+ ip6_dst_hoplimit(dst), 0, sport, dport,
+ false, 0);
+ return 0;
+ }
+
+ memset(&fl4, 0, sizeof(struct flowi4));
+ fl4.flowi4_oif = amt->stream_dev->ifindex;
+ fl4.daddr = daddr->ip4;
+ fl4.saddr = amt->local_ip;
+ fl4.flowi4_dscp = dscp;
+ fl4.flowi4_proto = IPPROTO_UDP;
+ rt = ip_route_output_key(amt->net, &fl4);
+ if (IS_ERR(rt)) {
+ netdev_dbg(amt->dev, "no route to %pI4\n", &daddr->ip4);
+ return PTR_ERR(rt);
+ }
+
+ udp_tunnel_xmit_skb(rt, sk, skb,
+ fl4.saddr,
+ fl4.daddr,
+ AMT_TOS,
+ ip4_dst_hoplimit(&rt->dst),
+ 0,
+ sport,
+ dport,
+ false,
+ false,
+ 0);
+ return 0;
+}
+
static bool amt_send_membership_update(struct amt_dev *amt,
struct sk_buff *skb,
bool v6)
@@ -1364,13 +1431,12 @@ static void amt_send_multicast_data(struct amt_dev *amt,
*/
static bool amt_send_membership_query(struct amt_dev *amt,
struct sk_buff *skb,
- __be32 daddr, __be16 dport,
+ const union amt_addr *daddr,
+ __be16 dport,
__be32 nonce, u64 mac,
bool v6)
{
struct amt_header_membership_query *amtmq;
- struct rtable *rt;
- struct flowi4 fl4;
struct sock *sk;
int err;
@@ -1379,23 +1445,11 @@ static bool amt_send_membership_query(struct amt_dev *amt,
return true;
err = skb_cow_head(skb, LL_RESERVED_SPACE(amt->dev) + sizeof(*amtmq) +
- sizeof(struct iphdr) + sizeof(struct udphdr));
+ amt_ip_hlen(amt) + sizeof(struct udphdr));
if (err)
return true;
skb_reset_inner_headers(skb);
- memset(&fl4, 0, sizeof(struct flowi4));
- fl4.flowi4_oif = amt->stream_dev->ifindex;
- fl4.daddr = daddr;
- fl4.saddr = amt->local_ip;
- fl4.flowi4_dscp = inet_dsfield_to_dscp(AMT_TOS);
- fl4.flowi4_proto = IPPROTO_UDP;
- rt = ip_route_output_key(amt->net, &fl4);
- if (IS_ERR(rt)) {
- netdev_dbg(amt->dev, "no route to %pI4\n", &daddr);
- return true;
- }
-
amtmq = skb_push(skb, sizeof(*amtmq));
amtmq->version = 0;
amtmq->type = AMT_MSG_MEMBERSHIP_QUERY;
@@ -1409,18 +1463,8 @@ static bool amt_send_membership_query(struct amt_dev *amt,
skb_set_inner_protocol(skb, htons(ETH_P_IP));
else
skb_set_inner_protocol(skb, htons(ETH_P_IPV6));
- udp_tunnel_xmit_skb(rt, sk, skb,
- fl4.saddr,
- fl4.daddr,
- AMT_TOS,
- ip4_dst_hoplimit(&rt->dst),
- 0,
- amt->relay_port,
- dport,
- false,
- false,
- 0);
- return false;
+ return amt_udp_xmit(amt, sk, skb, daddr, amt->relay_port, dport,
+ inet_dsfield_to_dscp(AMT_TOS));
}
static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)
@@ -3246,10 +3290,10 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)
mac = amt_relay_mac(&saddr, udph->source, amtrh->nonce, &key);
if (!amtrh->p)
- amt_send_igmp_gq(amt, saddr.ip4, udph->source, amtrh->nonce,
+ amt_send_igmp_gq(amt, &saddr, udph->source, amtrh->nonce,
mac);
else
- amt_send_mld_gq(amt, saddr.ip4, udph->source, amtrh->nonce,
+ amt_send_mld_gq(amt, &saddr, udph->source, amtrh->nonce,
mac);
return false;
--
2.47.3
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH net-next v2 05/12] amt: forward multicast data over IPv6
2026-11-25 19:14 [PATCH net-next v2 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (3 preceding siblings ...)
2026-11-25 19:14 ` [PATCH net-next v2 04/12] amt: send the Membership Query over IPv6 Omar Ramadan
@ 2026-11-25 19:14 ` Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 06/12] amt: size the encapsulation headroom by the outer IP version Omar Ramadan
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Omar Ramadan @ 2026-11-25 19:14 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Shuah Khan
Cc: Simon Horman, netdev, linux-kselftest, linux-kernel
amt_send_multicast_data() routes and transmits the relay's copy of a
multicast packet only over IPv4, so an IPv6 relay could establish
tunnels but not deliver traffic through them.
Size the copy's headroom for the outer family and send it through
amt_udp_xmit(), which already carries the Membership Query over either
family. The IPv4 route lookup still sets no DSCP. A copy that cannot be
sent is still freed, but it is now counted in tx_dropped and freed with
a drop reason; before, nothing recorded the drop, as amt_dev_xmit()
returns NETDEV_TX_OK for the packet. The inner protocol stays
independent of the outer family, so an IPv6 tunnel carries both IPv4 and
IPv6 multicast.
RFC 7450 s5.3.3.6.3.2 forbids a Fragment header on a Multicast Data
message sent over IPv6, and s5.3.3.6.2.2 wants an IPv6 payload that
exceeds the tunnel MTU dropped with a Packet Too Big to its source.
The device MTU is derived from the link MTU only, so a smaller path MTU
to a gateway is found at the route. The scrub in amt_udp_xmit() clears
ignore_df, so ip6_fragment() never adds a Fragment header, but on its
own it drops such a packet and sends the Packet Too Big to the relay
itself. amt_send_multicast_data() therefore routes first and compares
the inner packet with the route's MTU less the outer headers and the
AMT header. The device offers software GSO, so a GSO skb is checked
per segment with skb_gso_validate_network_len(), before the tunnel
offloads are set up. A payload that does not fit is dropped.
A multicast packet can match every tunnel, and an attacker can create
tunnels, so the Packet Too Big is not sent per tunnel. Each failing
tunnel only lowers a value, and amt_dev_xmit() sends one Packet Too Big
through icmpv6_ndo_send(), as ip6_tunnel does, after it has walked all
tunnels, reporting the smallest failing tunnel MTU. A tunnel MTU below
IPV6_MIN_MTU is left out, as a source ignores a smaller Packet Too Big,
so such a tunnel only drops the payload. The inner version is the v6
flag the caller already computed, not skb->protocol.
The tunnel MTU follows the route's path MTU, which ICMPv6 Packet Too
Big messages lower, as it does on every IPv6 UDP tunnel in the tree.
RFC 7450 s5.3.3.6.1 and s6.1 ask a relay that adjusts the tunnel MTU
dynamically to offer a way to turn that off. The IPv6 stack gives a
tunnel no such way: udpv6_err() records the lowered MTU in a route
exception before it looks up a socket, "mtu lock" does not stop it
(IPv6 path MTU discovery is not optional, see __ip6_rt_update_pmtu()),
and ip6_skb_dst_mtu() ignores the socket's pmtudisc inside a tunnel's
transmit. This series does not add one. The route MTU never drops
below IPV6_MIN_MTU, as a smaller Packet Too Big is ignored, so a forged
Packet Too Big can at most lower the tunnel MTU to 1280 bytes less the
outer headers; an IPv6 payload between that and 1280 bytes is then
undeliverable.
skb_tunnel_check_pmtu() is not used: with reply false it only updates
the route's PMTU and sends nothing. An IPv4 payload is dropped without
an ICMP error, since icmp_send() does not answer multicast datagrams,
and it is not fragmented before encapsulation as s5.3.3.6.2.1 asks for
DF=0. The IPv4 tunnel does not do that either; it clears DF on the
outer header instead.
With this, every relay message has an IPv6 path: Discovery and
Advertisement, Request and Membership Query, Membership Update and
Multicast Data.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 126 +++++++++++++++++++++++++++++++---------------
1 file changed, 85 insertions(+), 41 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 7e8219a0c..823367e82 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -1237,26 +1237,51 @@ static void amt_req_work(struct work_struct *work)
msecs_to_jiffies(100));
}
+/* RFC 7450 s5.3.3.6: a Multicast Data message sent over IPv6 must not
+ * carry a Fragment header, so a payload larger than the tunnel MTU is
+ * dropped, and an IPv6 source is sent a Packet Too Big. An IPv4 source is
+ * not told, as icmp_send() never answers a multicast datagram. The tunnel
+ * MTU follows the route's path MTU, as on every IPv6 UDP tunnel.
+ */
+static u32 amt_tmtu(const struct dst_entry *dst)
+{
+ return dst_mtu(dst) - sizeof(struct ipv6hdr) - sizeof(struct udphdr) -
+ sizeof(struct amt_header_mcast_data);
+}
+
+/* True if @skb, the inner packet before encapsulation, or any segment of
+ * it, is larger than @tmtu.
+ */
+static bool amt_tmtu_exceeded(const struct sk_buff *skb, u32 tmtu)
+{
+ if (skb_is_gso(skb))
+ return !skb_gso_validate_network_len(skb, tmtu);
+ return skb->len > tmtu;
+}
+
/* Route an AMT-encapsulated skb to @daddr and send it over the device's
* outer family. The caller has already pushed the AMT header; @dscp only
- * steers the IPv4 route lookup.
+ * steers the IPv4 route lookup. Over IPv6 the caller may pass the route it
+ * already looked up in @dst, which is consumed; otherwise it is looked up
+ * here.
*/
static int amt_udp_xmit(struct amt_dev *amt, struct sock *sk,
struct sk_buff *skb, const union amt_addr *daddr,
- __be16 sport, __be16 dport, dscp_t dscp)
+ __be16 sport, __be16 dport, dscp_t dscp,
+ struct dst_entry *dst)
{
struct rtable *rt;
struct flowi4 fl4;
if (amt_v6(amt)) {
- struct dst_entry *dst;
-
- dst = amt_route6(amt, sk, &amt->local_ipv6, &daddr->ip6,
- sport, dport);
- if (IS_ERR(dst)) {
- netdev_dbg(amt->dev, "no route to %pI6c\n",
- &daddr->ip6);
- return PTR_ERR(dst);
+ if (!dst) {
+ dst = amt_route6(amt, sk, &amt->local_ipv6,
+ &daddr->ip6, sport, dport);
+ if (IS_ERR(dst)) {
+ netdev_dbg(amt->dev, "no route to %pI6c\n",
+ &daddr->ip6);
+ return PTR_ERR(dst);
+ }
}
/* iptunnel_xmit() scrubs the IPv4 tunnel skb, but
* udp_tunnel6_xmit_skb() does not, so drop the inner
@@ -1357,26 +1382,58 @@ static bool amt_send_membership_update(struct amt_dev *amt,
return false;
}
+/* Send the relay's copy of a multicast packet to one gateway. Over IPv6 a
+ * payload that does not fit the tunnel MTU is dropped, and *@ptb is lowered
+ * to that MTU so that amt_dev_xmit() can send a single Packet Too Big to
+ * the source once it has walked every tunnel.
+ */
static void amt_send_multicast_data(struct amt_dev *amt,
const struct sk_buff *oskb,
struct amt_tunnel_list *tunnel,
- bool v6)
+ bool v6, u32 *ptb)
{
struct amt_header_mcast_data *amtmd;
+ struct dst_entry *dst = NULL;
struct sk_buff *skb;
- struct iphdr *iph;
- struct flowi4 fl4;
- struct rtable *rt;
struct sock *sk;
+ int err;
sk = rcu_dereference_bh(amt->sk);
if (!sk)
return;
- skb = skb_copy_expand(oskb, sizeof(*amtmd) + sizeof(*iph) +
+ if (amt_v6(amt)) {
+ u32 tmtu;
+
+ dst = amt_route6(amt, sk, &amt->local_ipv6, &tunnel->addr.ip6,
+ amt->relay_port, tunnel->source_port);
+ if (IS_ERR(dst)) {
+ netdev_dbg(amt->dev, "no route to %pI6c\n",
+ &tunnel->addr.ip6);
+ DEV_STATS_INC(amt->dev, tx_dropped);
+ return;
+ }
+
+ tmtu = amt_tmtu(dst);
+ if (amt_tmtu_exceeded(oskb, tmtu)) {
+ dst_release(dst);
+ /* A source ignores a Packet Too Big below
+ * IPV6_MIN_MTU, so a tunnel that small is only
+ * dropped for.
+ */
+ if (tmtu >= IPV6_MIN_MTU && (!*ptb || tmtu < *ptb))
+ *ptb = tmtu;
+ DEV_STATS_INC(amt->dev, tx_dropped);
+ return;
+ }
+ }
+
+ skb = skb_copy_expand(oskb, sizeof(*amtmd) + amt_ip_hlen(amt) +
sizeof(struct udphdr), 0, GFP_ATOMIC);
- if (!skb)
+ if (!skb) {
+ dst_release(dst);
return;
+ }
/* amt_dev_xmit() pulled the Ethernet header without moving the mac
* header. The tunnelled payload has no link-layer header, so the
@@ -1385,18 +1442,7 @@ static void amt_send_multicast_data(struct amt_dev *amt,
skb_reset_mac_header(skb);
skb_reset_inner_headers(skb);
if (udp_tunnel_handle_offloads(skb, true)) {
- kfree_skb(skb);
- return;
- }
-
- memset(&fl4, 0, sizeof(struct flowi4));
- fl4.flowi4_oif = amt->stream_dev->ifindex;
- fl4.daddr = tunnel->addr.ip4;
- fl4.saddr = amt->local_ip;
- fl4.flowi4_proto = IPPROTO_UDP;
- rt = ip_route_output_key(amt->net, &fl4);
- if (IS_ERR(rt)) {
- netdev_dbg(amt->dev, "no route to %pI4\n", &tunnel->addr.ip4);
+ dst_release(dst);
kfree_skb(skb);
return;
}
@@ -1410,17 +1456,12 @@ static void amt_send_multicast_data(struct amt_dev *amt,
skb_set_inner_protocol(skb, htons(ETH_P_IP));
else
skb_set_inner_protocol(skb, htons(ETH_P_IPV6));
- udp_tunnel_xmit_skb(rt, sk, skb,
- fl4.saddr,
- fl4.daddr,
- AMT_TOS,
- ip4_dst_hoplimit(&rt->dst),
- 0,
- amt->relay_port,
- tunnel->source_port,
- false,
- false,
- 0);
+ err = amt_udp_xmit(amt, sk, skb, &tunnel->addr, amt->relay_port,
+ tunnel->source_port, 0, dst);
+ if (err) {
+ DEV_STATS_INC(amt->dev, tx_dropped);
+ kfree_skb_reason(skb, SKB_DROP_REASON_IP_OUTNOROUTES);
+ }
}
/* Send a Membership Query in reply to an unauthenticated Request.
@@ -1464,7 +1505,7 @@ static bool amt_send_membership_query(struct amt_dev *amt,
else
skb_set_inner_protocol(skb, htons(ETH_P_IPV6));
return amt_udp_xmit(amt, sk, skb, daddr, amt->relay_port, dport,
- inet_dsfield_to_dscp(AMT_TOS));
+ inet_dsfield_to_dscp(AMT_TOS), NULL);
}
static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)
@@ -1482,6 +1523,7 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)
struct iphdr *iph;
bool data = false;
bool v6 = false;
+ u32 ptb = 0;
u32 hash;
iph = ip_hdr(skb);
@@ -1575,8 +1617,10 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)
}
continue;
found:
- amt_send_multicast_data(amt, skb, tunnel, v6);
+ amt_send_multicast_data(amt, skb, tunnel, v6, &ptb);
}
+ if (ptb && v6)
+ icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, ptb);
}
dev_kfree_skb(skb);
--
2.47.3
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH net-next v2 06/12] amt: size the encapsulation headroom by the outer IP version
2026-11-25 19:14 [PATCH net-next v2 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (4 preceding siblings ...)
2026-11-25 19:14 ` [PATCH net-next v2 05/12] amt: forward multicast data " Omar Ramadan
@ 2026-11-25 19:14 ` Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 07/12] amt: send the AMT gateway control plane over IPv6 Omar Ramadan
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Omar Ramadan @ 2026-11-25 19:14 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Shuah Khan
Cc: Simon Horman, netdev, linux-kselftest, linux-kernel
The amt device reserves AMT_RELAY_HLEN or AMT_GW_HLEN of headroom and
subtracts the same amount from the stream device's MTU. Both assume a
20-byte IPv4 outer header. An IPv6 outer header is 40 bytes, so on an
IPv6 device an inner packet in the last 20 bytes below the MTU would
not fit the stream device once encapsulated, and ip6_fragment() drops
it: nothing sets ignore_df on the tunnel skb.
Add AMT_RELAY_HLEN6 and AMT_GW_HLEN6, pick between the IPv4 and IPv6
sizes in amt_hlen(), and use amt_hlen() wherever the device sizes its
headroom and MTU: at newlink and on NETDEV_CHANGEMTU of the stream
device.
amt_v6() is still false for every device, so there is no functional
change.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 26 +++++++++++++++-----------
include/net/amt.h | 7 +++++++
2 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 823367e82..cb2ce552b 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -104,6 +104,14 @@ static unsigned int amt_ip_hlen(const struct amt_dev *amt)
return amt_v6(amt) ? sizeof(struct ipv6hdr) : sizeof(struct iphdr);
}
+/* Headroom the device reserves for its outer encapsulation. */
+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;
+}
+
/* Snapshot the outer source address of a received AMT message. */
static void amt_outer_saddr(const struct amt_dev *amt,
const struct sk_buff *skb, union amt_addr *addr)
@@ -3903,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],
@@ -3929,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;
@@ -4053,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 245947113..eabe6fa7a 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -434,9 +434,16 @@ struct amt_dev {
#define AMT_GW_HLEN (sizeof(struct iphdr) + \
sizeof(struct udphdr) + \
sizeof(struct amt_gw_headers))
+/* IPv6-outer gateway headroom: the outer header is a struct ipv6hdr. */
+#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)
{
--
2.47.3
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH net-next v2 07/12] amt: send the AMT gateway control plane over IPv6
2026-11-25 19:14 [PATCH net-next v2 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (5 preceding siblings ...)
2026-11-25 19:14 ` [PATCH net-next v2 06/12] amt: size the encapsulation headroom by the outer IP version Omar Ramadan
@ 2026-11-25 19:14 ` Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 08/12] amt: receive " Omar Ramadan
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Omar Ramadan @ 2026-11-25 19:14 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Shuah Khan
Cc: Simon Horman, netdev, linux-kselftest, linux-kernel
A gateway sends three control messages: the Relay Discovery to its
discovery address, then the Request and the Membership Updates to the
relay it learned. All three are built for an IPv4 outer header only, so
a gateway on an IPv6-only access network cannot reach any relay.
Send the Discovery and the Request of a gateway with an IPv6 local
address from amt_send_discovery_v6() and amt_send_request_v6(). Both
messages are a few bytes with no payload, so they are built on the stack
and sent with amt_send_ctrl_v6(), the helper that already sends the
relay's IPv6 Advertisement, rather than with a copy of the IPv4 skb
construction. The Membership Update carries the gateway's IGMP or MLD
report, so amt_send_membership_update() keeps building on that skb: it
sizes the headroom for the outer family and sends through
amt_udp_xmit(), like the relay's Membership Query and Multicast Data,
which avoids an IPv6 copy of the function.
struct amt_dev gains the gateway's IPv6 discovery address and the IPv6
relay address it learns and sends to. Nothing writes the latter until
the next patch, which also adds its synchronisation.
amt_send_ctrl_v6() now holds rcu_read_lock_bh() instead of
rcu_read_lock(). The gateway sends the Discovery and the Request from
its event worker in process context, and udp_tunnel6_xmit_skb() reaches
ip6tunnel_xmit(), which increments and later decrements the per-CPU xmit
recursion counter with __this_cpu_inc() and __this_cpu_dec(). With
preemption enabled the task could migrate in between and leave both
counters wrong. The IPv4 Discovery and Request go through ip_local_out()
and never touch the counter, and the relay's Advertisement is sent from
softirq, so neither is affected.
Nothing can set a local IPv6 address until the netlink attributes
arrive, so none of the IPv6 sender code added here runs yet, and the
conversion of amt_send_membership_update() to amt_ip_hlen() and
amt_udp_xmit() changes no IPv4 behaviour.
The P bit of the Request and the inner protocol of the Update still
follow the inner family, so an IPv6 gateway requests and reports both
IGMP and MLD, as an IPv4 one does.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 84 ++++++++++++++++++++++++++++++-----------------
include/net/amt.h | 8 +++++
2 files changed, 62 insertions(+), 30 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index cb2ce552b..6158e13f5 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -791,8 +791,11 @@ static int amt_send_ctrl_v6(struct amt_dev *amt, const struct in6_addr *saddr,
struct sock *sk;
int hlen, err;
- rcu_read_lock();
- sk = rcu_dereference(amt->sk);
+ /* The gateway sends from its event worker, but ip6tunnel_xmit()
+ * counts xmit recursion per CPU, which needs BH disabled.
+ */
+ rcu_read_lock_bh();
+ sk = rcu_dereference_bh(amt->sk);
if (!sk || !netif_running(amt->stream_dev) ||
!netif_running(amt->dev)) {
err = -ENETDOWN;
@@ -824,10 +827,39 @@ static int amt_send_ctrl_v6(struct amt_dev *amt, const struct in6_addr *saddr,
ip6_dst_hoplimit(dst), 0, sport, dport, false, 0);
err = 0;
out:
- rcu_read_unlock();
+ rcu_read_unlock_bh();
return err;
}
+/* IPv6-outer variant of amt_send_discovery(). */
+static void amt_send_discovery_v6(struct amt_dev *amt)
+{
+ struct amt_header_discovery amtd = {
+ .type = AMT_MSG_DISCOVERY,
+ .nonce = amt->nonce,
+ };
+
+ if (!amt_send_ctrl_v6(amt, &amt->local_ipv6, &amt->discovery_ipv6,
+ amt->gw_port, amt->relay_port,
+ &amtd, sizeof(amtd)))
+ amt_update_gw_status(amt, AMT_STATUS_SENT_DISCOVERY, true);
+}
+
+/* IPv6-outer variant of amt_send_request(). The inner-family @v6 sets the
+ * P bit (IGMP vs MLD) independently of the outer transport.
+ */
+static void amt_send_request_v6(struct amt_dev *amt, bool v6)
+{
+ struct amt_header_request amtrh = {
+ .type = AMT_MSG_REQUEST,
+ .p = v6,
+ .nonce = amt->nonce,
+ };
+
+ amt_send_ctrl_v6(amt, &amt->local_ipv6, &amt->remote_ipv6,
+ amt->gw_port, amt->relay_port, &amtrh, sizeof(amtrh));
+}
+
static void amt_send_discovery(struct amt_dev *amt)
{
struct amt_header_discovery *amtd;
@@ -841,6 +873,11 @@ static void amt_send_discovery(struct amt_dev *amt)
u32 len;
int err;
+ if (amt_v6(amt)) {
+ amt_send_discovery_v6(amt);
+ return;
+ }
+
rcu_read_lock();
sk = rcu_dereference(amt->sk);
if (!sk)
@@ -931,6 +968,11 @@ static void amt_send_request(struct amt_dev *amt, bool v6)
u32 len;
int err;
+ if (amt_v6(amt)) {
+ amt_send_request_v6(amt, v6);
+ return;
+ }
+
rcu_read_lock();
remote_ip = READ_ONCE(amt->remote_ip);
sk = rcu_dereference(amt->sk);
@@ -1336,9 +1378,7 @@ static bool amt_send_membership_update(struct amt_dev *amt,
{
__be32 remote_ip = READ_ONCE(amt->remote_ip);
struct amt_header_membership_update *amtmu;
- struct iphdr *iph;
- struct flowi4 fl4;
- struct rtable *rt;
+ union amt_addr remote = {};
struct sock *sk;
int err;
@@ -1347,23 +1387,11 @@ static bool amt_send_membership_update(struct amt_dev *amt,
return true;
err = skb_cow_head(skb, LL_RESERVED_SPACE(amt->dev) + sizeof(*amtmu) +
- sizeof(*iph) + sizeof(struct udphdr));
+ amt_ip_hlen(amt) + sizeof(struct udphdr));
if (err)
return true;
skb_reset_inner_headers(skb);
- memset(&fl4, 0, sizeof(struct flowi4));
- fl4.flowi4_oif = amt->stream_dev->ifindex;
- fl4.daddr = remote_ip;
- fl4.saddr = amt->local_ip;
- fl4.flowi4_dscp = inet_dsfield_to_dscp(AMT_TOS);
- fl4.flowi4_proto = IPPROTO_UDP;
- rt = ip_route_output_key(amt->net, &fl4);
- if (IS_ERR(rt)) {
- netdev_dbg(amt->dev, "no route to %pI4\n", &remote_ip);
- return true;
- }
-
amtmu = skb_push(skb, sizeof(*amtmu));
amtmu->version = 0;
amtmu->type = AMT_MSG_MEMBERSHIP_UPDATE;
@@ -1375,17 +1403,13 @@ static bool amt_send_membership_update(struct amt_dev *amt,
skb_set_inner_protocol(skb, htons(ETH_P_IP));
else
skb_set_inner_protocol(skb, htons(ETH_P_IPV6));
- udp_tunnel_xmit_skb(rt, sk, skb,
- fl4.saddr,
- fl4.daddr,
- AMT_TOS,
- ip4_dst_hoplimit(&rt->dst),
- 0,
- amt->gw_port,
- amt->relay_port,
- false,
- false,
- 0);
+ if (amt_v6(amt))
+ remote.ip6 = amt->remote_ipv6;
+ else
+ remote.ip4 = remote_ip;
+ if (amt_udp_xmit(amt, sk, skb, &remote, amt->gw_port,
+ amt->relay_port, inet_dsfield_to_dscp(AMT_TOS), NULL))
+ return true;
amt_update_gw_status(amt, AMT_STATUS_SENT_UPDATE, true);
return false;
}
diff --git a/include/net/amt.h b/include/net/amt.h
index eabe6fa7a..be564c710 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -390,8 +390,16 @@ struct amt_dev {
struct in6_addr local_ipv6;
/* Outer remote ip */
__be32 remote_ip;
+ /* Outer remote ipv6 (learned from the v6 Relay Advertisement;
+ * in6addr_any in v4 mode, mutually exclusive with remote_ip)
+ */
+ struct in6_addr remote_ipv6;
/* Outer discovery ip */
__be32 discovery_ip;
+ /* Outer discovery ipv6 (v6 gateway only; in6addr_any in v4 mode,
+ * mutually exclusive with discovery_ip)
+ */
+ struct in6_addr discovery_ipv6;
/* Only used in gateway mode */
__be32 nonce;
/* Gateway sent request and received query */
--
2.47.3
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH net-next v2 08/12] amt: receive the AMT gateway control plane over IPv6
2026-11-25 19:14 [PATCH net-next v2 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (6 preceding siblings ...)
2026-11-25 19:14 ` [PATCH net-next v2 07/12] amt: send the AMT gateway control plane over IPv6 Omar Ramadan
@ 2026-11-25 19:14 ` Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 09/12] amt: add netlink attributes for an IPv6 outer transport Omar Ramadan
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Omar Ramadan @ 2026-11-25 19:14 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Shuah Khan
Cc: Simon Horman, netdev, linux-kselftest, linux-kernel
An IPv6 gateway now sends its Discovery, Request and Updates over IPv6,
but it cannot take the replies. amt_rcv() checks the outer source of an
Advertisement against the discovery address, and that of Multicast Data
and a Membership Query against the learned relay address, by reading
ip_hdr(skb)->saddr, which on an IPv6 outer header is part of the flow
label and payload length. amt_advertisement_handler() parses only the
IPv4 form, so the gateway never learns an IPv6 relay address.
amt_rcv() now takes the outer source by value with amt_outer_saddr()
before amt_parse_type() pulls, and checks it through amt_from_relay(),
which compares it with the discovery address for an Advertisement and
with the learned relay address otherwise, in the device's family.
The IPv4 comparison it replaces is the one "amt: reject a gateway Query
or Data from 0.0.0.0" fixed in net for IPv4, so this patch carries only
the IPv6 half. amt_membership_query_handler() repeats the check for a
Query that waited in the event queue, now through amt_from_relay() too.
amt_advertisement_handler() pulls the 24-byte IPv6 form on an IPv6
gateway. Its fixed header and nonce are laid out as in the IPv4 form, so
the shared checks run once and only the relay address is checked and
recorded per family. An IPv6 relay address is refused when it is
unspecified, loopback, multicast or IPv4-mapped, the IPv6 counterparts
of the checks on the IPv4 address; the V6ONLY socket could not reach an
IPv4-mapped relay.
The IPv6 relay address needs more care than the IPv4 one. The
Advertisement handler, its only writer, runs from the event workqueue,
while it is read in softirq, on receive and on transmit, and from
amt_fill_info(), which no longer relies on RTNL. Nothing serialises
them. remote_ip is a single 32-bit word, but a struct in6_addr is copied
word by word, so with a plain assignment a reader could see half of an
old and half of a new address: a packet sent to a spliced destination,
or a valid relay's traffic dropped as "Invalid Relay IP". Publish it
with amt_set_remote_ipv6() under a seqlock, remote_ipv6_lock, and read
it with amt_get_remote_ipv6(), which retries until it has a consistent
copy. Readers take no lock, so the receive path does not contend with
the worker. Every consumer takes one snapshot per packet and uses it
throughout, and amt_rcv() takes it only for the message types that use
it. amt_newlink() initialises the seqlock before the device is
registered.
amt_clear_remote() forgets the learned relay in both families. It
replaces the IPv4-only reset in amt_event_send_request(), amt_dev_open()
and amt_dev_stop(), so a gateway that is taken down and up again neither
accepts traffic from its previous relay's IPv6 address nor keeps
reporting it.
IPv6 input does not drop a packet from the unspecified address, as
IPv4 input drops a 0.0.0.0 source as a martian. Such a packet would
match the cleared relay address of a gateway that has lost its relay,
and with a zero nonce in that window it could inject a Membership
Query; a relay would create a tunnel for it. amt_rcv() drops it, and
amt_from_relay() matches nothing against a relay address that is not
known, in either family.
RFC 7450 s5.2.3.3 says a gateway that processes Multicast Data itself,
as amt_rcv() does, must not discard it for a zero UDP checksum, and
s5.1.6 lets a relay send one, the RFC 6936 exception to RFC 8200 s8.1.
The socket of an IPv6 gateway therefore accepts a zero checksum; a
non-zero one is still verified. amt_rcv() drops a zero checksum on
every other message a gateway receives, as RFC 6936 s5 asks, and the
socket of a relay keeps requiring the checksum.
The Membership Query and Multicast Data handlers dispatch on the inner
family and work on the AMT payload behind the outer header, so they
need no change. With this an IPv6 gateway discovers an IPv6 relay,
completes the Request, Query and Update exchange and receives multicast,
as an IPv4 gateway does.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 151 ++++++++++++++++++++++++++++++++++++++--------
include/net/amt.h | 2 +
2 files changed, 127 insertions(+), 26 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 6158e13f5..7dd1d544f 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -831,6 +831,61 @@ static int amt_send_ctrl_v6(struct amt_dev *amt, const struct in6_addr *saddr,
return err;
}
+/* The learned relay address is written by the event worker and read by the
+ * softirq RX and TX paths. A struct in6_addr cannot be stored or loaded in
+ * one access, so it is published under a seqlock, and every consumer takes
+ * one snapshot per packet.
+ */
+static void amt_set_remote_ipv6(struct amt_dev *amt,
+ const struct in6_addr *addr)
+{
+ write_seqlock_bh(&amt->remote_ipv6_lock);
+ amt->remote_ipv6 = *addr;
+ write_sequnlock_bh(&amt->remote_ipv6_lock);
+}
+
+static void amt_get_remote_ipv6(const struct amt_dev *amt,
+ struct in6_addr *addr)
+{
+ unsigned int seq;
+
+ do {
+ seq = read_seqbegin(&amt->remote_ipv6_lock);
+ *addr = amt->remote_ipv6;
+ } while (read_seqretry(&amt->remote_ipv6_lock, seq));
+}
+
+/* Forget the relay a gateway learned, in both outer families. */
+static void amt_clear_remote(struct amt_dev *amt)
+{
+ WRITE_ONCE(amt->remote_ip, 0);
+ amt_set_remote_ipv6(amt, &in6addr_any);
+}
+
+/* Whether a message a gateway received came from its relay: the discovery
+ * address for an Advertisement, the learned relay address otherwise. A
+ * relay address that is not known, the unspecified address, matches
+ * nothing.
+ */
+static bool amt_from_relay(const struct amt_dev *amt,
+ const union amt_addr *saddr, bool discovery)
+{
+ __be32 relay4;
+
+ if (amt_v6(amt)) {
+ struct in6_addr relay;
+
+ if (discovery)
+ relay = amt->discovery_ipv6;
+ else
+ amt_get_remote_ipv6(amt, &relay);
+ return !ipv6_addr_any(&relay) &&
+ ipv6_addr_equal(&saddr->ip6, &relay);
+ }
+ relay4 = discovery ? amt->discovery_ip : READ_ONCE(amt->remote_ip);
+ return relay4 && saddr->ip4 == relay4;
+}
+
/* IPv6-outer variant of amt_send_discovery(). */
static void amt_send_discovery_v6(struct amt_dev *amt)
{
@@ -855,9 +910,11 @@ static void amt_send_request_v6(struct amt_dev *amt, bool v6)
.p = v6,
.nonce = amt->nonce,
};
+ struct in6_addr remote6;
- amt_send_ctrl_v6(amt, &amt->local_ipv6, &amt->remote_ipv6,
- amt->gw_port, amt->relay_port, &amtrh, sizeof(amtrh));
+ amt_get_remote_ipv6(amt, &remote6);
+ amt_send_ctrl_v6(amt, &amt->local_ipv6, &remote6, amt->gw_port,
+ amt->relay_port, &amtrh, sizeof(amtrh));
}
static void amt_send_discovery(struct amt_dev *amt)
@@ -1254,7 +1311,7 @@ static void amt_event_send_request(struct amt_dev *amt)
amt->qi = AMT_INIT_REQ_TIMEOUT;
WRITE_ONCE(amt->ready4, false);
WRITE_ONCE(amt->ready6, false);
- WRITE_ONCE(amt->remote_ip, 0);
+ amt_clear_remote(amt);
amt_update_gw_status(amt, AMT_STATUS_INIT, false);
amt->req_cnt = 0;
amt->nonce = 0;
@@ -1404,7 +1461,7 @@ static bool amt_send_membership_update(struct amt_dev *amt,
else
skb_set_inner_protocol(skb, htons(ETH_P_IPV6));
if (amt_v6(amt))
- remote.ip6 = amt->remote_ipv6;
+ amt_get_remote_ipv6(amt, &remote.ip6);
else
remote.ip4 = remote_ip;
if (amt_udp_xmit(amt, sk, skb, &remote, amt->gw_port,
@@ -2662,27 +2719,48 @@ static bool amt_advertisement_handler(struct amt_dev *amt, struct sk_buff *skb)
struct amt_header_advertisement *amta;
int hdr_size;
- hdr_size = sizeof(*amta) + sizeof(struct udphdr);
+ /* The IPv6 form (RFC 7450 s5.1.2) has the same header and nonce, with
+ * a 16-byte relay address in place of ip4.
+ */
+ hdr_size = sizeof(struct udphdr) +
+ (amt_v6(amt) ? sizeof(struct amt_header_advertisement_v6) :
+ sizeof(*amta));
if (!pskb_may_pull(skb, hdr_size))
return true;
- amta = (struct amt_header_advertisement *)(udp_hdr(skb) + 1);
- if (!amta->ip4)
+ /* The two forms differ only in their length, and the device's family
+ * picks one, so a message of the other form is not accepted.
+ */
+ if (ntohs(udp_hdr(skb)->len) != hdr_size)
return true;
+ amta = (struct amt_header_advertisement *)(udp_hdr(skb) + 1);
if (amta->reserved || amta->version)
return true;
- if (ipv4_is_loopback(amta->ip4) || ipv4_is_multicast(amta->ip4) ||
- ipv4_is_zeronet(amta->ip4))
- return true;
-
if (amt->status != AMT_STATUS_SENT_DISCOVERY ||
amt->nonce != amta->nonce)
return true;
- WRITE_ONCE(amt->remote_ip, amta->ip4);
- netdev_dbg(amt->dev, "advertised remote ip = %pI4\n", &amta->ip4);
+ if (amt_v6(amt)) {
+ const struct in6_addr *ip6;
+
+ ip6 = &((struct amt_header_advertisement_v6 *)amta)->ip6;
+ if (ipv6_addr_any(ip6) || ipv6_addr_loopback(ip6) ||
+ ipv6_addr_is_multicast(ip6) || ipv6_addr_v4mapped(ip6))
+ return true;
+
+ amt_set_remote_ipv6(amt, ip6);
+ netdev_dbg(amt->dev, "advertised remote ipv6 = %pI6c\n", ip6);
+ } else {
+ if (!amta->ip4 || ipv4_is_loopback(amta->ip4) ||
+ ipv4_is_multicast(amta->ip4) || ipv4_is_zeronet(amta->ip4))
+ return true;
+
+ WRITE_ONCE(amt->remote_ip, amta->ip4);
+ netdev_dbg(amt->dev, "advertised remote ip = %pI4\n",
+ &amta->ip4);
+ }
mod_delayed_work(amt_wq, &amt->req_wq, 0);
amt_update_gw_status(amt, AMT_STATUS_RECEIVED_ADVERTISEMENT, true);
@@ -2767,6 +2845,7 @@ static bool amt_membership_query_handler(struct amt_dev *amt,
struct ethhdr *eth, *oeth;
struct igmpv3_query *ihv3;
u8 h_source[ETH_ALEN];
+ union amt_addr saddr;
struct iphdr *iph;
int hdr_size, len;
u64 response_mac;
@@ -2780,7 +2859,8 @@ static bool amt_membership_query_handler(struct amt_dev *amt,
return true;
/* A deferred query may outlive a relay address change. */
- if (ip_hdr(skb)->saddr != READ_ONCE(amt->remote_ip))
+ amt_outer_saddr(amt, skb, &saddr);
+ if (!amt_from_relay(amt, &saddr, false))
return true;
if (amtmq->nonce != amt->nonce)
@@ -3409,9 +3489,8 @@ static void amt_gw_rcv(struct amt_dev *amt, struct sk_buff *skb)
static int amt_rcv(struct sock *sk, struct sk_buff *skb)
{
+ union amt_addr saddr;
struct amt_dev *amt;
- __be32 remote_ip;
- __be32 saddr;
int type;
bool err;
@@ -3422,10 +3501,17 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb)
kfree_skb(skb);
goto out;
}
- remote_ip = READ_ONCE(amt->remote_ip);
skb->dev = amt->dev;
- saddr = ip_hdr(skb)->saddr;
+ /* Snapshot the outer source before amt_parse_type() pulls. */
+ amt_outer_saddr(amt, skb, &saddr);
+ /* IPv4 input drops a 0.0.0.0 source as a martian, but IPv6 input
+ * delivers ::, which no relay or gateway can be.
+ */
+ if (amt_v6(amt) && ipv6_addr_any(&saddr.ip6)) {
+ err = true;
+ goto drop;
+ }
type = amt_parse_type(skb);
if (type == -1) {
err = true;
@@ -3433,9 +3519,17 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb)
}
if (amt->mode == AMT_MODE_GATEWAY) {
+ /* RFC 6936 s5: accept the zero checksum only on the message
+ * that needs it.
+ */
+ if (amt_v6(amt) && !udp_hdr(skb)->check &&
+ type != AMT_MSG_MULTICAST_DATA) {
+ err = true;
+ goto drop;
+ }
switch (type) {
case AMT_MSG_ADVERTISEMENT:
- if (saddr != amt->discovery_ip) {
+ if (!amt_from_relay(amt, &saddr, true)) {
netdev_dbg(amt->dev, "Invalid Relay IP\n");
err = true;
goto drop;
@@ -3447,7 +3541,7 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb)
}
goto out;
case AMT_MSG_MULTICAST_DATA:
- if (!remote_ip || saddr != remote_ip) {
+ if (!amt_from_relay(amt, &saddr, false)) {
netdev_dbg(amt->dev, "Invalid Relay IP\n");
err = true;
goto drop;
@@ -3458,7 +3552,7 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb)
else
goto out;
case AMT_MSG_MEMBERSHIP_QUERY:
- if (!remote_ip || saddr != remote_ip) {
+ if (!amt_from_relay(amt, &saddr, false)) {
netdev_dbg(amt->dev, "Invalid Relay IP\n");
err = true;
goto drop;
@@ -3597,13 +3691,17 @@ static struct sock *amt_create_sock(const struct amt_dev *amt)
* the output interface, as the IPv4 lookup is, and receives
* from that link only, where a link-local peer is unique.
* V6ONLY keeps the socket off the IPv4 wildcard, so an IPv4
- * amt device can use the same port in the netns. The UDP
- * checksum is mandatory over IPv6.
+ * amt device can use the same port in the netns.
+ *
+ * The UDP checksum is always sent (RFC 8200 s8.1). A gateway
+ * also accepts a zero checksum, as RFC 7450 s5.2.3.3 requires
+ * for Multicast Data, and amt_rcv() drops it on the other
+ * messages; a non-zero checksum is still verified.
*/
udp_conf.family = AF_INET6;
udp_conf.bind_ifindex = amt->stream_dev->ifindex;
udp_conf.use_udp6_tx_checksums = true;
- udp_conf.use_udp6_rx_checksums = true;
+ udp_conf.use_udp6_rx_checksums = amt->mode == AMT_MODE_RELAY;
udp_conf.ipv6_v6only = true;
} else {
udp_conf.family = AF_INET;
@@ -3672,7 +3770,7 @@ static int amt_dev_open(struct net_device *dev)
}
amt->req_cnt = 0;
- WRITE_ONCE(amt->remote_ip, 0);
+ amt_clear_remote(amt);
amt->nonce = 0;
amt->status = AMT_STATUS_INIT;
@@ -3721,7 +3819,7 @@ static int amt_dev_stop(struct net_device *dev)
amt->ready4 = false;
amt->ready6 = false;
amt->req_cnt = 0;
- WRITE_ONCE(amt->remote_ip, 0);
+ amt_clear_remote(amt);
/* Mark every tunnel dead first, so a concurrent amt_tunnel_expire()
* sees ->dead and bails instead of freeing a tunnel in parallel; this
@@ -3891,6 +3989,7 @@ static int amt_newlink(struct net_device *dev,
amt->max_tunnels = AMT_MAX_TUNNELS;
spin_lock_init(&amt->lock);
+ seqlock_init(&amt->remote_ipv6_lock);
seqcount_spinlock_init(&amt->key_seq, &amt->lock);
amt->max_groups = AMT_MAX_GROUP;
amt->max_sources = AMT_MAX_SOURCE;
diff --git a/include/net/amt.h b/include/net/amt.h
index be564c710..4fc1452e0 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -394,6 +394,8 @@ struct amt_dev {
* in6addr_any in v4 mode, mutually exclusive with remote_ip)
*/
struct in6_addr remote_ipv6;
+ /* Publishes remote_ipv6, which is too wide for a single access */
+ seqlock_t remote_ipv6_lock;
/* Outer discovery ip */
__be32 discovery_ip;
/* Outer discovery ipv6 (v6 gateway only; in6addr_any in v4 mode,
--
2.47.3
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH net-next v2 09/12] amt: add netlink attributes for an IPv6 outer transport
2026-11-25 19:14 [PATCH net-next v2 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (7 preceding siblings ...)
2026-11-25 19:14 ` [PATCH net-next v2 08/12] amt: receive " Omar Ramadan
@ 2026-11-25 19:14 ` Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 10/12] MAINTAINERS: amt: cover the amt headers and selftests Omar Ramadan
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Omar Ramadan @ 2026-11-25 19:14 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Shuah Khan
Cc: Simon Horman, netdev, linux-kselftest, linux-kernel
Every path of the relay and the gateway can now run over an IPv6 outer
transport, but nothing can create such a device. Add the attributes
that do:
- IFLA_AMT_LOCAL_IP6, the local IPv6 address. It selects IPv6 as the
outer transport and is mutually exclusive with IFLA_AMT_LOCAL_IP.
- IFLA_AMT_DISCOVERY_IP6, the IPv6 address a gateway sends its Relay
Discovery to. A gateway's discovery address has to be in the family
of its local address, as both ends of the tunnel use one outer
transport.
- IFLA_AMT_REMOTE_IP6, the relay address the gateway learned from the
IPv6 Relay Advertisement. Like IFLA_AMT_REMOTE_IP it is only
reported, and the policy rejects it on input.
amt_fill_info() reports the addresses in the device's outer family.
IFLA_AMT_LOCAL_IP6 is refused with -EAFNOSUPPORT on a kernel built
without IPv6, rather than creating an IPv4 device with no local
address. An IPv6 local or discovery address is refused when it is
unspecified, loopback or multicast, as the IPv4 ones are, and also when
it is IPv4-mapped: the V6ONLY socket could never send from or to such
an address, so the device would be created but silently fail every
send.
The existing IFLA_AMT_LOCAL_IP and IFLA_AMT_DISCOVERY_IP cannot simply
carry 16 bytes. Net requires exactly four bytes for them ("amt: require
an exact IPv4-sized IFLA_AMT_{LOCAL,DISCOVERY}_IP"), so the IPv6
addresses need attributes of their own. A kernel that does not know the
new attributes ignores them and fails the request for lack of a local
address, so userspace can tell whether IPv6 is supported. vxlan
(IFLA_VXLAN_LOCAL6, IFLA_VXLAN_GROUP6) and geneve (IFLA_GENEVE_REMOTE6)
add their IPv6 addresses the same way. The attributes are appended to
the enum, so the existing values do not change, and strict_start_type
makes the policy validate them, and any attribute added after them,
strictly. Their policy is an exact 16-byte length.
A relay has always ignored IFLA_AMT_DISCOVERY_IP, and existing users may
pass it, so an IPv4 relay still accepts it. An IPv6 relay has no
existing users, so it rejects a discovery address of either family, and
an IPv4 relay rejects IFLA_AMT_DISCOVERY_IP6.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 164 ++++++++++++++++++++++++++++++---------
include/uapi/linux/amt.h | 13 ++++
2 files changed, 141 insertions(+), 36 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 7dd1d544f..bd833a05a 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -3916,6 +3916,7 @@ static void amt_link_setup(struct net_device *dev)
}
static const struct nla_policy amt_policy[IFLA_AMT_MAX + 1] = {
+ [IFLA_AMT_UNSPEC] = { .strict_start_type = IFLA_AMT_LOCAL_IP6 },
[IFLA_AMT_MODE] = { .type = NLA_U32 },
[IFLA_AMT_RELAY_PORT] = { .type = NLA_U16 },
[IFLA_AMT_GATEWAY_PORT] = { .type = NLA_U16 },
@@ -3924,6 +3925,10 @@ static const struct nla_policy amt_policy[IFLA_AMT_MAX + 1] = {
[IFLA_AMT_REMOTE_IP] = { .len = sizeof_field(struct iphdr, daddr) },
[IFLA_AMT_DISCOVERY_IP] = NLA_POLICY_EXACT_LEN(sizeof(__be32)),
[IFLA_AMT_MAX_TUNNELS] = { .type = NLA_U32 },
+ [IFLA_AMT_LOCAL_IP6] = NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)),
+ [IFLA_AMT_DISCOVERY_IP6] =
+ NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)),
+ [IFLA_AMT_REMOTE_IP6] = { .type = NLA_REJECT },
};
static int amt_validate(struct nlattr *tb[], struct nlattr *data[],
@@ -3950,16 +3955,53 @@ static int amt_validate(struct nlattr *tb[], struct nlattr *data[],
return -EINVAL;
}
- if (!data[IFLA_AMT_LOCAL_IP]) {
- NL_SET_ERR_MSG_ATTR(extack, data[IFLA_AMT_DISCOVERY_IP],
- "Local attribute is required");
+ if (!data[IFLA_AMT_LOCAL_IP] && !data[IFLA_AMT_LOCAL_IP6]) {
+ NL_SET_ERR_MSG_MOD(extack, "Local attribute is required");
return -EINVAL;
}
- if (!data[IFLA_AMT_DISCOVERY_IP] &&
- nla_get_u32(data[IFLA_AMT_MODE]) == AMT_MODE_GATEWAY) {
- NL_SET_ERR_MSG_ATTR(extack, data[IFLA_AMT_LOCAL_IP],
- "Discovery attribute is required");
+ if (data[IFLA_AMT_LOCAL_IP] && data[IFLA_AMT_LOCAL_IP6]) {
+ NL_SET_ERR_MSG_ATTR(extack, data[IFLA_AMT_LOCAL_IP6],
+ "Local IPv4 and IPv6 are mutually exclusive");
+ return -EINVAL;
+ }
+
+ if (data[IFLA_AMT_LOCAL_IP6] && !IS_ENABLED(CONFIG_IPV6)) {
+ NL_SET_ERR_MSG_ATTR(extack, data[IFLA_AMT_LOCAL_IP6],
+ "IPv6 support is disabled");
+ return -EAFNOSUPPORT;
+ }
+
+ if (nla_get_u32(data[IFLA_AMT_MODE]) != AMT_MODE_GATEWAY) {
+ struct nlattr *disc = data[IFLA_AMT_DISCOVERY_IP6];
+
+ /* An IPv4 relay has always ignored IFLA_AMT_DISCOVERY_IP,
+ * and existing users may pass it. An IPv6 relay has no such
+ * users, so it rejects a discovery address of either family.
+ */
+ if (!disc && data[IFLA_AMT_LOCAL_IP6])
+ disc = data[IFLA_AMT_DISCOVERY_IP];
+ if (disc) {
+ NL_SET_ERR_MSG_ATTR(extack, disc,
+ "Discovery is only valid in gateway mode");
+ return -EINVAL;
+ }
+ return 0;
+ }
+
+ /* A gateway's discovery address is in the family of its local
+ * address, since both ends of the tunnel use one outer transport.
+ */
+ if (data[IFLA_AMT_LOCAL_IP6] ? !data[IFLA_AMT_DISCOVERY_IP6] :
+ !data[IFLA_AMT_DISCOVERY_IP]) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Discovery attribute of the local family is required");
+ return -EINVAL;
+ }
+
+ if (data[IFLA_AMT_DISCOVERY_IP] && data[IFLA_AMT_DISCOVERY_IP6]) {
+ NL_SET_ERR_MSG_ATTR(extack, data[IFLA_AMT_DISCOVERY_IP6],
+ "Discovery IPv4 and IPv6 are mutually exclusive");
return -EINVAL;
}
@@ -4010,13 +4052,25 @@ static int amt_newlink(struct net_device *dev,
goto err;
}
- amt->local_ip = nla_get_in_addr(data[IFLA_AMT_LOCAL_IP]);
- if (ipv4_is_loopback(amt->local_ip) ||
- ipv4_is_zeronet(amt->local_ip) ||
- ipv4_is_multicast(amt->local_ip)) {
- NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_AMT_LOCAL_IP],
- "Invalid Local address");
- goto err;
+ if (data[IFLA_AMT_LOCAL_IP6]) {
+ amt->local_ipv6 = nla_get_in6_addr(data[IFLA_AMT_LOCAL_IP6]);
+ if (ipv6_addr_loopback(&amt->local_ipv6) ||
+ ipv6_addr_any(&amt->local_ipv6) ||
+ ipv6_addr_is_multicast(&amt->local_ipv6) ||
+ ipv6_addr_v4mapped(&amt->local_ipv6)) {
+ NL_SET_ERR_MSG_ATTR(extack, data[IFLA_AMT_LOCAL_IP6],
+ "Invalid Local IPv6 address");
+ goto err;
+ }
+ } else {
+ amt->local_ip = nla_get_in_addr(data[IFLA_AMT_LOCAL_IP]);
+ if (ipv4_is_loopback(amt->local_ip) ||
+ ipv4_is_zeronet(amt->local_ip) ||
+ ipv4_is_multicast(amt->local_ip)) {
+ NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_AMT_LOCAL_IP],
+ "Invalid Local address");
+ goto err;
+ }
}
amt->relay_port = nla_get_be16_default(data[IFLA_AMT_RELAY_PORT],
@@ -4039,24 +4093,35 @@ static int amt_newlink(struct net_device *dev,
dev->max_mtu = dev->mtu;
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],
- "discovery must be set in gateway mode");
- goto err;
- }
if (!amt->gw_port) {
NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_AMT_DISCOVERY_IP],
"gateway port must not be 0");
goto err;
}
- WRITE_ONCE(amt->remote_ip, 0);
- amt->discovery_ip = nla_get_in_addr(data[IFLA_AMT_DISCOVERY_IP]);
- if (ipv4_is_loopback(amt->discovery_ip) ||
- ipv4_is_zeronet(amt->discovery_ip) ||
- ipv4_is_multicast(amt->discovery_ip)) {
- NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_AMT_DISCOVERY_IP],
- "discovery must be unicast");
- goto err;
+ if (data[IFLA_AMT_DISCOVERY_IP6]) {
+ struct nlattr *attr = data[IFLA_AMT_DISCOVERY_IP6];
+
+ amt->discovery_ipv6 = nla_get_in6_addr(attr);
+ if (ipv6_addr_loopback(&amt->discovery_ipv6) ||
+ ipv6_addr_any(&amt->discovery_ipv6) ||
+ ipv6_addr_is_multicast(&amt->discovery_ipv6) ||
+ ipv6_addr_v4mapped(&amt->discovery_ipv6)) {
+ NL_SET_ERR_MSG_ATTR(extack, attr,
+ "discovery must be unicast");
+ goto err;
+ }
+ } else {
+ WRITE_ONCE(amt->remote_ip, 0);
+ amt->discovery_ip =
+ nla_get_in_addr(data[IFLA_AMT_DISCOVERY_IP]);
+ if (ipv4_is_loopback(amt->discovery_ip) ||
+ ipv4_is_zeronet(amt->discovery_ip) ||
+ ipv4_is_multicast(amt->discovery_ip)) {
+ NL_SET_ERR_MSG_ATTR(extack,
+ tb[IFLA_AMT_DISCOVERY_IP],
+ "discovery must be unicast");
+ goto err;
+ }
}
dev->needed_headroom = amt->stream_dev->needed_headroom +
@@ -4110,7 +4175,28 @@ static size_t amt_get_size(const struct net_device *dev)
nla_total_size(sizeof(__u32)) + /* IFLA_MAX_TUNNELS */
nla_total_size(sizeof(__be32)) + /* IFLA_AMT_DISCOVERY_IP */
nla_total_size(sizeof(__be32)) + /* IFLA_AMT_REMOTE_IP */
- nla_total_size(sizeof(__be32)); /* IFLA_AMT_LOCAL_IP */
+ nla_total_size(sizeof(__be32)) + /* IFLA_AMT_LOCAL_IP */
+ /* IFLA_AMT_{LOCAL,DISCOVERY,REMOTE}_IP6. Only one address of
+ * each IPv4/IPv6 pair is emitted, but this sizes for both.
+ */
+ 3 * nla_total_size(sizeof(struct in6_addr));
+}
+
+/* The IPv6 addresses of an IPv6 device, one of each IPv4/IPv6 pair. */
+static int amt_fill_addr6(struct sk_buff *skb, const struct amt_dev *amt)
+{
+ struct in6_addr remote6;
+
+ if (nla_put_in6_addr(skb, IFLA_AMT_LOCAL_IP6, &amt->local_ipv6))
+ return -EMSGSIZE;
+ if (amt->mode == AMT_MODE_GATEWAY &&
+ nla_put_in6_addr(skb, IFLA_AMT_DISCOVERY_IP6, &amt->discovery_ipv6))
+ return -EMSGSIZE;
+ amt_get_remote_ipv6(amt, &remote6);
+ if (!ipv6_addr_any(&remote6) &&
+ nla_put_in6_addr(skb, IFLA_AMT_REMOTE_IP6, &remote6))
+ return -EMSGSIZE;
+ return 0;
}
static int amt_fill_info(struct sk_buff *skb, const struct net_device *dev)
@@ -4127,15 +4213,21 @@ static int amt_fill_info(struct sk_buff *skb, const struct net_device *dev)
goto nla_put_failure;
if (nla_put_u32(skb, IFLA_AMT_LINK, amt->stream_dev->ifindex))
goto nla_put_failure;
- if (nla_put_in_addr(skb, IFLA_AMT_LOCAL_IP, amt->local_ip))
- goto nla_put_failure;
- if (nla_put_in_addr(skb, IFLA_AMT_DISCOVERY_IP, amt->discovery_ip))
- goto nla_put_failure;
-
- remote_ip = READ_ONCE(amt->remote_ip);
- if (remote_ip)
- if (nla_put_in_addr(skb, IFLA_AMT_REMOTE_IP, remote_ip))
+ if (amt_v6(amt)) {
+ if (amt_fill_addr6(skb, amt))
goto nla_put_failure;
+ } else {
+ if (nla_put_in_addr(skb, IFLA_AMT_LOCAL_IP, amt->local_ip))
+ goto nla_put_failure;
+ if (nla_put_in_addr(skb, IFLA_AMT_DISCOVERY_IP,
+ amt->discovery_ip))
+ goto nla_put_failure;
+
+ remote_ip = READ_ONCE(amt->remote_ip);
+ if (remote_ip)
+ if (nla_put_in_addr(skb, IFLA_AMT_REMOTE_IP, remote_ip))
+ goto nla_put_failure;
+ }
if (nla_put_u32(skb, IFLA_AMT_MAX_TUNNELS, amt->max_tunnels))
goto nla_put_failure;
diff --git a/include/uapi/linux/amt.h b/include/uapi/linux/amt.h
index 2dccff417..5290ece75 100644
--- a/include/uapi/linux/amt.h
+++ b/include/uapi/linux/amt.h
@@ -54,6 +54,19 @@ enum {
IFLA_AMT_DISCOVERY_IP,
/* This attribute specify number of maximum tunnel. */
IFLA_AMT_MAX_TUNNELS,
+ /* This attribute specifies the local IPv6 address. It selects IPv6
+ * as the outer transport and excludes IFLA_AMT_LOCAL_IP.
+ */
+ IFLA_AMT_LOCAL_IP6,
+ /* This attribute specifies the IPv6 address of the relay a gateway
+ * sends its Discovery to. It is the IPv6 form of
+ * IFLA_AMT_DISCOVERY_IP and needs IFLA_AMT_LOCAL_IP6.
+ */
+ IFLA_AMT_DISCOVERY_IP6,
+ /* This attribute reports the IPv6 relay address a gateway learned
+ * from the Relay Advertisement. It is read-only.
+ */
+ IFLA_AMT_REMOTE_IP6,
__IFLA_AMT_MAX,
};
--
2.47.3
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH net-next v2 10/12] MAINTAINERS: amt: cover the amt headers and selftests
2026-11-25 19:14 [PATCH net-next v2 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (8 preceding siblings ...)
2026-11-25 19:14 ` [PATCH net-next v2 09/12] amt: add netlink attributes for an IPv6 outer transport Omar Ramadan
@ 2026-11-25 19:14 ` Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 11/12] selftests: net: add amt_v6.sh for an IPv6 outer transport Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 12/12] selftests: net: add amt_gw_v6.sh for the IPv6 netlink attributes Omar Ramadan
11 siblings, 0 replies; 13+ messages in thread
From: Omar Ramadan @ 2026-11-25 19:14 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Shuah Khan
Cc: Simon Horman, netdev, linux-kselftest, linux-kernel
The AMT entry lists only drivers/net/amt.c, so get_maintainer.pl does
not find the AMT maintainer for changes to include/net/amt.h,
include/uapi/linux/amt.h or tools/testing/selftests/net/amt.sh, and this
series touches the first two and adds selftests next to the third. Add
the two headers, and a glob that covers amt.sh and the new amt_*.sh
scripts.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
MAINTAINERS | 3 +++
1 file changed, 3 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 9f1a6024f..6a028cdba 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1506,6 +1506,9 @@ S: Maintained
T: git git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git
T: git git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git
F: drivers/net/amt.c
+F: include/net/amt.h
+F: include/uapi/linux/amt.h
+F: tools/testing/selftests/net/amt*.sh
ANALOG DEVICES INC AD3530R DRIVER
M: Kim Seer Paller <kimseer.paller@analog.com>
--
2.47.3
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH net-next v2 11/12] selftests: net: add amt_v6.sh for an IPv6 outer transport
2026-11-25 19:14 [PATCH net-next v2 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (9 preceding siblings ...)
2026-11-25 19:14 ` [PATCH net-next v2 10/12] MAINTAINERS: amt: cover the amt headers and selftests Omar Ramadan
@ 2026-11-25 19:14 ` Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 12/12] selftests: net: add amt_gw_v6.sh for the IPv6 netlink attributes Omar Ramadan
11 siblings, 0 replies; 13+ messages in thread
From: Omar Ramadan @ 2026-11-25 19:14 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Shuah Khan
Cc: Simon Horman, netdev, linux-kselftest, linux-kernel
amt.sh runs the gateway and the relay over IPv4; its 2001:db8:: addresses
are inner MLD carried in that IPv4 tunnel. Nothing covers the IPv6 outer
transport this series adds.
amt_v6.sh is amt.sh with the gateway<->relay link moved to IPv6, and a
second gateway on that link:
amtg: mode gateway local 2001:db8:a::1 discovery 2001:db8:a::3
amtg2: mode gateway local 2001:db8:a::4 discovery 2001:db8:a::3
amtr: mode relay local 2001:db8:a::2
The namespaces, inner addresses and smcroute (S,G) routes are those of
amt.sh, and the scripts use the same tools, plus jq. The relay forwards
to a tunnel only after the gateway's Membership Update, and the gateway
sends that only after the relay's Membership Query, so the forwarding
checks cover the whole handshake. The test checks that:
- the gateway learns 2001:db8:a::2 from an Advertisement it requested
through the relay's second address, 2001:db8:a::3, so the
Advertisement has to come from the address the Discovery was sent to;
- IPv4 and IPv6 multicast both reach the listener through the tunnel;
- IPv4 multicast also reaches a listener on the second gateway, which
shares the first one's /64 and gateway port, so the relay has to
deliver each gateway's Membership Query to that gateway and not to
one whose address merely begins the same way;
- with the relay's route MTU to the gateway lowered, an IPv6 payload
above the tunnel MTU earns its source a Packet Too Big, and neither
is the AMT datagram fragmented nor does it reach IPv6 output, where
it would be refused and counted in Ip6FragFails;
- a Relay Discovery sent to ff02::1 draws no reply at all, while the
same Discovery sent to the discovery address, the positive control
with the same capture filter, draws an Advertisement. This check
needs tcpdump and is skipped without it;
- taking amtg down clears the learned relay address, and bringing it
up discovers the relay again.
A probe creates a throwaway IPv6 relay first. It skips when the kernel
ignores IFLA_AMT_LOCAL_IP6 ("Local attribute is required") or iproute2
cannot pass it, which includes an iproute2 that packs the IPv6 literal
into the 4-byte IFLA_AMT_LOCAL_IP: this kernel refuses that, and an
older one creates an IPv4 relay, which the probe reads back. Any other
failure after the probe, including in setup, is a FAIL. DAD is off in
the namespaces: the relay sends its MLD General Query from amtr's
link-local address, which must not be tentative at that point.
The script skips when /proc/net/if_inet6 is missing, that is without
CONFIG_IPV6, before it creates any link. disc_answer() returns a distinct
status when tcpdump fails to start or a send fails, and the ff02::1 check
accepts only "no reply", so a broken capture cannot pass it.
The iproute2 side is posted to iproute2-next separately.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
tools/testing/selftests/net/Makefile | 1 +
tools/testing/selftests/net/amt_v6.sh | 355 ++++++++++++++++++++++++++
2 files changed, 356 insertions(+)
create mode 100755 tools/testing/selftests/net/amt_v6.sh
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index c80dabbcc..7f98f74f9 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -9,6 +9,7 @@ CFLAGS += -I../
TEST_PROGS := \
altnames.sh \
amt.sh \
+ amt_v6.sh \
arp_ndisc_evict_nocarrier.sh \
arp_ndisc_untracked_subnets.sh \
bareudp.sh \
diff --git a/tools/testing/selftests/net/amt_v6.sh b/tools/testing/selftests/net/amt_v6.sh
new file mode 100755
index 000000000..9d3e4a206
--- /dev/null
+++ b/tools/testing/selftests/net/amt_v6.sh
@@ -0,0 +1,355 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# amt.sh with an IPv6 outer transport. The gateways and the relay speak AMT
+# over IPv6, and IPv4 and IPv6 multicast are carried inside. The namespaces,
+# roles and inner addresses are those of amt.sh; the gateway<->relay link
+# differs, and a second gateway shares it:
+#
+# LISTENER l_gw -- gw_l [br0: gw_l, amtg] GATEWAY gw_relay 2001:db8:a::1
+# | IPv6 outer
+# [amtg2] GATEWAY2 gw2_relay 2001:db8:a::4
+# |
+# SOURCE src_relay -- relay_src [amtr] RELAY br_gw 2001:db8:a::2
+# [br_gw: relay_gw, relay_gw2] 2001:db8:a::3
+#
+# The relay's local address is 2001:db8:a::2. The gateways discover it
+# through 2001:db8:a::3, so the Relay Advertisement has to come from the
+# address the Discovery was sent to (RFC 7450 s5.1.2) and carry ::2.
+
+source lib.sh
+
+readonly GW6="2001:db8:a::1"
+readonly GW2_6="2001:db8:a::4"
+readonly RELAY6="2001:db8:a::2"
+readonly DISC6="2001:db8:a::3"
+SMCDIR=
+
+cleanup()
+{
+ cleanup_all_ns
+ [ -n "$SMCDIR" ] && rm -rf "$SMCDIR"
+}
+
+setup_fail()
+{
+ echo "FAIL: setup failed at line $1" >&2
+ exit "$ksft_fail"
+}
+
+amt_field()
+{
+ ip -n "$1" -d -j link show "$2" |
+ jq -r ".[0].linkinfo.info_data.$3 // empty"
+}
+
+# remote_is <addr> [<ns> <dev>]: the relay address a gateway learned.
+remote_is()
+{
+ [ "$(amt_field "${2:-$GATEWAY}" "${3:-amtg}" remote)" = "$1" ]
+}
+
+snmp6()
+{
+ ip netns exec "$1" awk -v k="$2" '$1 == k { print $2 }' /proc/net/snmp6
+}
+
+setup_links()
+{
+ local ns
+
+ # No DAD: the relay sources its MLD General Query from amtr's
+ # link-local address, which must not be tentative when it is sent.
+ for ns in "$LISTENER" "$GATEWAY" "$GATEWAY2" "$RELAY" "$SOURCE"; do
+ ip netns exec "$ns" sysctl -wq \
+ net.ipv6.conf.all.accept_dad=0 \
+ net.ipv6.conf.default.accept_dad=0
+ done
+
+ ip -n "$LISTENER" link add l_gw type veth peer name gw_l \
+ netns "$GATEWAY"
+ ip -n "$GATEWAY" link add gw_relay type veth peer name relay_gw \
+ netns "$RELAY"
+ ip -n "$GATEWAY2" link add gw2_relay type veth peer name relay_gw2 \
+ netns "$RELAY"
+ ip -n "$RELAY" link add relay_src type veth peer name src_relay \
+ netns "$SOURCE"
+
+ ip -n "$GATEWAY" addr add "$GW6/64" dev gw_relay
+ ip -n "$GATEWAY" link set gw_relay up
+ ip -n "$GATEWAY2" addr add "$GW2_6/64" dev gw2_relay
+ ip -n "$GATEWAY2" link set gw2_relay up
+ ip -n "$RELAY" link add br_gw type bridge
+ ip -n "$RELAY" link set relay_gw master br_gw up
+ ip -n "$RELAY" link set relay_gw2 master br_gw up
+ ip -n "$RELAY" addr add "$RELAY6/64" dev br_gw
+ ip -n "$RELAY" addr add "$DISC6/64" dev br_gw
+ ip -n "$RELAY" link set br_gw up
+}
+
+# An iproute2 without IPv6 AMT support either rejects the address or packs
+# it into the 4-byte IFLA_AMT_LOCAL_IP, which this kernel refuses and an
+# older one takes as an IPv4 address. A kernel without IPv6 AMT support
+# ignores IFLA_AMT_LOCAL_IP6 and asks for a local address. Skip in those
+# cases only.
+probe_v6_relay()
+{
+ local err got
+
+ if ! err=$(ip -n "$RELAY" link add amtprobe type amt mode relay \
+ local "$RELAY6" dev br_gw 2>&1); then
+ case "$err" in
+ *"Local attribute is required"*|*"expected rather than"*|\
+ *"IPv6 address in an IPv4 attribute"*)
+ echo "SKIP: no IPv6 AMT support: $err"
+ exit "$ksft_skip"
+ ;;
+ esac
+ echo "FAIL: cannot create an IPv6 relay: $err"
+ exit "$ksft_fail"
+ fi
+ got=$(amt_field "$RELAY" amtprobe local)
+ ip -n "$RELAY" link del amtprobe
+ if [[ "$got" != *:* ]]; then
+ echo "SKIP: iproute2 lacks IPv6 AMT support (read back '$got')"
+ exit "$ksft_skip"
+ fi
+}
+
+setup_topology()
+{
+ ip -n "$LISTENER" addr add 192.168.0.2/24 dev l_gw
+ ip -n "$LISTENER" addr add 2001:db8::2/64 dev l_gw
+ ip -n "$LISTENER" link set l_gw up
+ ip -n "$LISTENER" route add default via 192.168.0.1 dev l_gw
+ ip -n "$LISTENER" route add default via 2001:db8::1 dev l_gw
+ ip -n "$LISTENER" addr add 239.0.0.1/32 dev l_gw autojoin
+ ip -n "$LISTENER" addr add ff0e::5:6/128 dev l_gw autojoin
+
+ ip -n "$GATEWAY" addr add 192.168.0.1/24 dev gw_l
+ ip -n "$GATEWAY" addr add 2001:db8::1/64 dev gw_l
+ ip -n "$GATEWAY" link add br0 type bridge
+ ip -n "$GATEWAY" link set br0 up
+ ip -n "$GATEWAY" link set gw_l master br0 up
+ ip -n "$GATEWAY" link add amtg master br0 type amt mode gateway \
+ local "$GW6" discovery "$DISC6" dev gw_relay \
+ gateway_port 2268 relay_port 2268
+
+ # rp_filter off: amtg2's listener gets data from a source it has no
+ # route to.
+ ip netns exec "$GATEWAY2" sysctl -wq net.ipv4.conf.all.rp_filter=0 \
+ net.ipv4.conf.default.rp_filter=0
+ ip -n "$GATEWAY2" link add amtg2 type amt mode gateway \
+ local "$GW2_6" discovery "$DISC6" dev gw2_relay \
+ gateway_port 2268 relay_port 2268
+
+ ip -n "$RELAY" link add amtr type amt mode relay local "$RELAY6" \
+ dev br_gw relay_port 2268 max_tunnels 4
+ ip -n "$RELAY" addr add 172.17.0.1/24 dev relay_src
+ ip -n "$RELAY" addr add 2001:db8:3::1/64 dev relay_src
+ ip -n "$RELAY" link set relay_src up
+ ip netns exec "$RELAY" sysctl -wq net.ipv4.ip_forward=1
+ ip netns exec "$RELAY" iptables -t mangle -I PREROUTING \
+ -d 239.0.0.1 -j TTL --ttl-set 2
+ # Only the group: rewriting the hop limit of Neighbour Discovery on
+ # the IPv6 outer link would break it.
+ ip netns exec "$RELAY" ip6tables -t mangle -I PREROUTING \
+ -d ff0e::5:6 -j HL --hl-set 2
+
+ ip -n "$SOURCE" addr add 172.17.0.2/24 dev src_relay
+ ip -n "$SOURCE" addr add 2001:db8:3::2/64 dev src_relay
+ ip -n "$SOURCE" link set src_relay up
+ ip -n "$SOURCE" route add default via 172.17.0.1 dev src_relay
+ ip -n "$SOURCE" route add default via 2001:db8:3::1 dev src_relay
+
+ ip -n "$RELAY" link set amtr up
+ ip -n "$GATEWAY" link set amtg up
+ ip -n "$GATEWAY2" link set amtg2 up
+
+ SMCDIR=$(mktemp -d)
+ ip netns exec "$RELAY" smcrouted -P "$SMCDIR/pid" -u "$SMCDIR/sock"
+ slowwait 5 test -S "$SMCDIR/sock"
+ ip netns exec "$RELAY" smcroutectl -u "$SMCDIR/sock" \
+ a relay_src 172.17.0.2 239.0.0.1 amtr
+ ip netns exec "$RELAY" smcroutectl -u "$SMCDIR/sock" \
+ a relay_src 2001:db8:3::2 ff0e::5:6 amtr
+}
+
+test_discovery()
+{
+ RET=0
+ slowwait 10 remote_is "$RELAY6"
+ check_err $? "remote is '$(amt_field "$GATEWAY" amtg remote)'"
+ log_test "IPv6 discovery through a secondary relay address"
+}
+
+# test_forward <ns> <socat address> <port> <group> <source> <description>
+test_forward()
+{
+ local ns=$1 addr=$2 port=$3 grp=$4 src=$5 desc=$6
+ local out pid i
+
+ RET=0
+ out=$(mktemp)
+ ip netns exec "$ns" timeout 20 \
+ socat -u "$addr,readbytes=128" - > "$out" &
+ pid=$!
+ wait_local_port_listen "$ns" "$port" udp
+ for i in $(seq 15); do
+ ip netns exec "$SOURCE" bash -c \
+ "printf '%s %128s' $src | nc -w 1 -u $grp $port"
+ grep -q "$src" "$out" && break
+ done
+ wait "$pid"
+ grep -q "$src" "$out"
+ check_err $? "nothing from $src reached the listener"
+ rm -f "$out"
+ log_test "$desc"
+}
+
+# The tunnel MTU is the path MTU to the gateway less the outer headers.
+# Lower the relay's route MTU to the gateway below the payload: the relay
+# must not fragment the AMT datagram, and it must send the payload's
+# source a Packet Too Big (RFC 7450 s5.3.3.6).
+test_tmtu()
+{
+ local ptb frag fragfail i
+
+ RET=0
+ ip -n "$RELAY" -6 route add "$GW6/128" dev br_gw mtu 1400
+ ptb=$(snmp6 "$SOURCE" Icmp6InPktTooBigs)
+ frag=$(snmp6 "$RELAY" Ip6FragCreates)
+ fragfail=$(snmp6 "$RELAY" Ip6FragFails)
+ for i in 1 2 3; do
+ ip netns exec "$SOURCE" bash -c \
+ "printf '%1352s' x | nc -w 1 -u ff0e::5:6 6000"
+ done
+ [ "$(snmp6 "$SOURCE" Icmp6InPktTooBigs)" -gt "$ptb" ]
+ check_err $? "the source got no Packet Too Big"
+ [ "$(snmp6 "$RELAY" Ip6FragCreates)" -eq "$frag" ]
+ check_err $? "the relay fragmented an AMT datagram"
+ # amt_udp_xmit() clears ignore_df, so an oversized datagram that got
+ # past the tunnel MTU check would be refused by IPv6 output and
+ # counted as a FragFail rather than a FragCreate.
+ [ "$(snmp6 "$RELAY" Ip6FragFails)" -eq "$fragfail" ]
+ check_err $? "an oversized AMT datagram reached IPv6 output"
+ ip -n "$RELAY" -6 route del "$GW6/128" dev br_gw mtu 1400
+ log_test "IPv6 payload above the tunnel MTU"
+}
+
+# A second gateway in the same /64, with the same gateway port as the first.
+# The relay has to send each gateway its own Membership Query: a query sent
+# to the wrong one fails its nonce check, and the intended gateway never
+# reports, so the relay never forwards to it.
+test_second_gateway()
+{
+ RET=0
+ slowwait 10 remote_is "$RELAY6" "$GATEWAY2" amtg2
+ check_err $? "amtg2 remote is '$(amt_field "$GATEWAY2" amtg2 remote)'"
+ log_test "second IPv6 gateway on the link discovers the relay"
+
+ test_forward "$GATEWAY2" \
+ UDP4-RECV:4000,ip-add-membership=239.0.0.1:amtg2 \
+ 4000 239.0.0.1 172.17.0.2 \
+ "IPv4 multicast to a second gateway in the same /64"
+}
+
+# disc_answer <dst> <filter>: send a Relay Discovery from the gateway's
+# namespace to [<dst>]:2268 and wait for gw_relay to see a packet matching
+# the tcpdump <filter>. Returns 0 if it did, 1 if none came within a few
+# seconds, and 2 if the harness failed: tcpdump did not start or stopped
+# with an error, or a send failed. Callers must not read 2 as "no reply".
+disc_answer()
+{
+ local dst=$1 filter=$2 pid i rc
+ local to="UDP6-SENDTO:[$dst]:2268,sourceport=40000"
+
+ ip netns exec "$GATEWAY" timeout 6 \
+ tcpdump -nni gw_relay -c 1 "$filter" > /dev/null 2>&1 &
+ pid=$!
+ sleep 1
+ # tcpdump stays up until it matches or times out, so it is gone here
+ # only if it failed to start.
+ kill -0 "$pid" 2> /dev/null || { wait "$pid"; return 2; }
+ # Type 1 (Relay Discovery), version 0, then a nonce.
+ for i in 1 2 3; do
+ printf '\x01\x00\x00\x00\x12\x34\x56\x78' |
+ ip netns exec "$GATEWAY" socat -u - \
+ "$to,so-bindtodevice=gw_relay" || rc=2
+ sleep 0.5
+ done
+ wait "$pid"
+ case $? in
+ 0) return "${rc:-0}" ;;
+ 124) return "${rc:-1}" ;;
+ *) return 2 ;;
+ esac
+}
+
+# The relay's socket is bound to ::, so it also receives a Discovery sent
+# to ff02::1. Answering it from that destination would put a multicast
+# source address on the wire (RFC 4291 s2.7), so the relay must not answer
+# it at all. The unicast Discovery is the positive control: it shows that
+# the probe and the capture work, and it uses the same capture filter.
+test_mcast_discovery()
+{
+ RET=0
+ if ! command -v tcpdump > /dev/null; then
+ log_test_skip "Discovery to ff02::1 is not answered" \
+ "tcpdump not installed"
+ return
+ fi
+ disc_answer "$DISC6" "udp and src port 2268 and dst port 40000"
+ check_err $? "no Advertisement for a unicast Discovery"
+ disc_answer ff02::1 "udp and src port 2268 and dst port 40000"
+ [ $? -eq 1 ]
+ check_err $? "the relay answered ff02::1, or the capture failed"
+ log_test "Discovery to ff02::1 is not answered"
+}
+
+test_down_up()
+{
+ RET=0
+ ip -n "$GATEWAY" link set amtg down
+ remote_is ""
+ check_err $? "relay still reported while down"
+ ip -n "$GATEWAY" link set amtg up
+ slowwait 10 remote_is "$RELAY6"
+ check_err $? "relay not rediscovered after up"
+ log_test "gateway forgets its IPv6 relay on link down"
+}
+
+for cmd in jq socat nc smcrouted smcroutectl iptables ip6tables; do
+ require_command "$cmd"
+done
+
+# Without CONFIG_IPV6 setup_links() would fail first and report FAIL.
+if [ ! -e /proc/net/if_inet6 ]; then
+ echo "SKIP: IPv6 support is disabled"
+ exit "$ksft_skip"
+fi
+
+trap cleanup EXIT
+setup_ns LISTENER GATEWAY GATEWAY2 RELAY SOURCE || exit "$ksft_skip"
+
+set -E
+trap 'setup_fail $LINENO' ERR
+setup_links
+trap - ERR
+probe_v6_relay
+trap 'setup_fail $LINENO' ERR
+setup_topology
+trap - ERR
+set +E
+
+test_discovery
+test_forward "$LISTENER" UDP4-LISTEN:4000 4000 239.0.0.1 172.17.0.2 \
+ "IPv4 multicast over an IPv6 tunnel"
+test_forward "$LISTENER" UDP6-LISTEN:6000 6000 ff0e::5:6 2001:db8:3::2 \
+ "IPv6 multicast over an IPv6 tunnel"
+test_second_gateway
+test_tmtu
+test_mcast_discovery
+test_down_up
+
+exit "$EXIT_STATUS"
--
2.47.3
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH net-next v2 12/12] selftests: net: add amt_gw_v6.sh for the IPv6 netlink attributes
2026-11-25 19:14 [PATCH net-next v2 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (10 preceding siblings ...)
2026-11-25 19:14 ` [PATCH net-next v2 11/12] selftests: net: add amt_v6.sh for an IPv6 outer transport Omar Ramadan
@ 2026-11-25 19:14 ` Omar Ramadan
11 siblings, 0 replies; 13+ messages in thread
From: Omar Ramadan @ 2026-11-25 19:14 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Shuah Khan
Cc: Simon Horman, netdev, linux-kselftest, linux-kernel
amt_v6.sh builds a gateway and a relay over an IPv6 outer transport and
checks the data plane, but only with valid attributes. The link-creation
rules this series adds for IFLA_AMT_LOCAL_IP6 and IFLA_AMT_DISCOVERY_IP6
are not exercised.
This adds a small companion without a data plane: one netns and one
dummy device, no relay, socat or smcroute. It checks that the IPv6
local and discovery addresses of a gateway, and the local address of a
relay, read back through amt_fill_info(), that a relay reports no
discovery address, that an IPv4 gateway still creates and reports its
IPv4 discovery address, and that an IPv4 relay still accepts the IPv4
discovery address it has always ignored. It then checks each rejection:
a gateway without a discovery address, a gateway whose local and
discovery addresses differ in family (both ways), an IPv6 relay given a
discovery address of either family, an IPv4 relay given an IPv6 one,
and an unspecified, loopback, multicast or IPv4-mapped IPv6 local or
discovery address. Each rejection is matched on its extack message as
well as on the failure, so a rule that fails for the wrong reason is not
a pass.
Three cases are left out because iproute2 cannot express them: both
`discovery <v4>` and `discovery <v6>`, or both `local <v4>` and
`local <v6>`, in one command, and a 16-byte IFLA_AMT_LOCAL_IP or
IFLA_AMT_DISCOVERY_IP. iproute2 rejects the repeated argument before it
builds a message, and with IPv6 support it never sends 16 bytes in an
IPv4 attribute, so those checks are reachable only from a raw netlink
client or an older iproute2.
The probe checks the readback as well as the result. An iproute2 without
the IPv6 attributes may pack the first four bytes of the IPv6 literal
into the IPv4 attribute, so `discovery 2001:db8:a::2` becomes
32.1.13.184 and a kernel without this series builds a valid IPv4
gateway from it; this kernel refuses it ("IPv6 address in an IPv4
attribute"). That refusal is logged as a passing test before the
probe skips, since it is the rule an older iproute2 exercises. If such
an iproute2 gets an IPv4 device back from a kernel that has the IPv6
attributes, recognised by its "Discovery attribute of the local family
is required" message, the refusal is broken and the probe fails. The
probe skips on an iproute2 that rejects the literal, on a kernel that
ignores the attributes ("Local attribute is required"), and on a kernel
without IPv6 ("IPv6 support is disabled", or no /proc/net/if_inet6).
Any other failure to create the probe link is a FAIL.
The script uses lib.sh: setup_ns for the namespace, check_err and
log_test for reporting, and $ksft_skip when a prerequisite is missing.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
tools/testing/selftests/net/Makefile | 1 +
tools/testing/selftests/net/amt_gw_v6.sh | 207 +++++++++++++++++++++++
2 files changed, 208 insertions(+)
create mode 100755 tools/testing/selftests/net/amt_gw_v6.sh
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 7f98f74f9..eb82e120b 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -9,6 +9,7 @@ CFLAGS += -I../
TEST_PROGS := \
altnames.sh \
amt.sh \
+ amt_gw_v6.sh \
amt_v6.sh \
arp_ndisc_evict_nocarrier.sh \
arp_ndisc_untracked_subnets.sh \
diff --git a/tools/testing/selftests/net/amt_gw_v6.sh b/tools/testing/selftests/net/amt_gw_v6.sh
new file mode 100755
index 000000000..92e48d2f5
--- /dev/null
+++ b/tools/testing/selftests/net/amt_gw_v6.sh
@@ -0,0 +1,207 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Netlink coverage for the AMT IPv6 attributes, IFLA_AMT_LOCAL_IP6 and
+# IFLA_AMT_DISCOVERY_IP6, and the rules that validate them. amt_v6.sh covers
+# the data plane; this needs only one netns and one dummy device.
+#
+# Not covered: `discovery <v4>` together with `discovery <v6>`, or `local <v4>`
+# together with `local <v6>`, in one command. iproute2 rejects the duplicate
+# argument itself, so those checks are reachable only from a raw netlink
+# client.
+
+source lib.sh
+
+readonly V6_LOCAL="2001:db8:a::1"
+readonly V6_DISC="2001:db8:a::2"
+readonly V4_LOCAL="192.168.0.1"
+readonly V4_DISC="192.168.0.2"
+
+# add_amt <name> <args...>: create an amt link on gw_dev, stderr in $ADD_ERR.
+add_amt()
+{
+ local name=$1; shift
+
+ ADD_ERR=$(ip -n "$GW" link add "$name" type amt dev gw_dev "$@" 2>&1)
+}
+
+# amt_field <name> <key>: one attribute as amt_fill_info reports it.
+amt_field()
+{
+ ip -n "$GW" -d -j link show "$1" 2>/dev/null |
+ jq -r ".[0].linkinfo.info_data.$2 // empty"
+}
+
+# An iproute2 without IFLA_AMT_DISCOVERY_IP6 may not reject `discovery
+# <v6>`: it can pack the literal into IFLA_AMT_DISCOVERY_IP, which this
+# kernel refuses and an older one turns into a v4 gateway from the first
+# four bytes. So probe on the readback, not only on the exit code. A
+# kernel without the IPv6 attributes ignores them and asks for a local
+# address. Skip in those cases only; any other failure is a failure of the
+# code under test.
+probe_v6_gateway()
+{
+ local got
+
+ if ! add_amt amtprobe mode gateway local "$V6_LOCAL" \
+ discovery "$V6_DISC"; then
+ case "$ADD_ERR" in
+ *"IPv6 address in an IPv4 attribute"*)
+ # An older iproute2 on this kernel: the rule that
+ # refuses the 16-byte IPv4 attribute is what ran.
+ RET=0
+ log_test "16-byte IPv4 address attribute is refused"
+ echo "SKIP: iproute2 lacks IPv6 AMT support"
+ exit "$ksft_skip"
+ ;;
+ *"Local attribute is required"*|*"expected rather than"*|\
+ *"IPv6 support is disabled"*)
+ echo "SKIP: no IPv6 AMT support: $ADD_ERR"
+ exit "$ksft_skip"
+ ;;
+ esac
+ echo "FAIL: cannot create an IPv6 gateway: $ADD_ERR"
+ exit "$ksft_fail"
+ fi
+ got=$(amt_field amtprobe discovery)
+ ip -n "$GW" link del amtprobe
+ if [[ "$got" != *:* ]]; then
+ # A kernel with the IPv6 attributes names the missing
+ # discovery address this way, and must have refused the
+ # 16-byte IPv4 attribute that an older iproute2 sent.
+ add_amt amtprobe mode gateway local "$V4_LOCAL"
+ ip -n "$GW" link del amtprobe 2>/dev/null
+ if [[ "$ADD_ERR" == *"of the local family is required"* ]]; then
+ echo "FAIL: 16-byte IPv4 attribute read back as '$got'"
+ exit "$ksft_fail"
+ fi
+ echo "SKIP: iproute2 lacks IPv6 AMT support (read back '$got')"
+ exit "$ksft_skip"
+ fi
+}
+
+test_v6_gateway_roundtrip()
+{
+ RET=0
+ add_amt amtg6 mode gateway local "$V6_LOCAL" discovery "$V6_DISC"
+ check_err $? "create failed: $ADD_ERR"
+ [ "$(amt_field amtg6 discovery)" = "$V6_DISC" ]
+ check_err $? "discovery did not read back as $V6_DISC"
+ [ "$(amt_field amtg6 local)" = "$V6_LOCAL" ]
+ check_err $? "local did not read back as $V6_LOCAL"
+ ip -n "$GW" link del amtg6 2>/dev/null
+ log_test "v6 gateway: discovery round-trips through fill_info"
+}
+
+test_v6_relay_roundtrip()
+{
+ RET=0
+ add_amt amtr6 mode relay local "$V6_LOCAL"
+ check_err $? "create failed: $ADD_ERR"
+ [ "$(amt_field amtr6 local)" = "$V6_LOCAL" ]
+ check_err $? "local did not read back as $V6_LOCAL"
+ [ -z "$(amt_field amtr6 discovery)" ]
+ check_err $? "a relay reported a discovery address"
+ ip -n "$GW" link del amtr6 2>/dev/null
+ log_test "v6 relay: local round-trips, no discovery reported"
+}
+
+test_v4_gateway_unchanged()
+{
+ RET=0
+ add_amt amtg4 mode gateway local "$V4_LOCAL" discovery "$V4_DISC"
+ check_err $? "create failed: $ADD_ERR"
+ [ "$(amt_field amtg4 discovery)" = "$V4_DISC" ]
+ check_err $? "discovery did not read back as $V4_DISC"
+ ip -n "$GW" link del amtg4 2>/dev/null
+ log_test "v4 gateway still creates (no ABI change)"
+}
+
+# An IPv4 relay has always ignored IFLA_AMT_DISCOVERY_IP, and still must.
+test_v4_relay_unchanged()
+{
+ RET=0
+ add_amt amtr4 mode relay local "$V4_LOCAL" discovery "$V4_DISC"
+ check_err $? "create failed: $ADD_ERR"
+ ip -n "$GW" link del amtr4 2>/dev/null
+ log_test "v4 relay still accepts a v4 discovery (no ABI change)"
+}
+
+# expect_reject <description> <extack substring> <args...>: the create must
+# fail, and for the stated reason.
+expect_reject()
+{
+ local desc=$1 want=$2; shift 2
+
+ RET=0
+ add_amt amtbad "$@"
+ check_fail $? "link was created but should have been rejected"
+ ip -n "$GW" link del amtbad 2>/dev/null
+ grep -qi -- "$want" <<< "$ADD_ERR"
+ check_err $? "rejected for the wrong reason: $ADD_ERR"
+ log_test "$desc"
+}
+
+require_command jq
+if [ ! -e /proc/net/if_inet6 ]; then
+ echo "SKIP: the kernel has no IPv6"
+ exit "$ksft_skip"
+fi
+trap cleanup_all_ns EXIT
+setup_ns GW || exit "$ksft_skip"
+ip -n "$GW" link add gw_dev type dummy
+ip -n "$GW" link set gw_dev up
+ip -n "$GW" addr add "$V4_LOCAL/24" dev gw_dev
+# nodad: a tentative source address would race link creation.
+ip -n "$GW" addr add "$V6_LOCAL/64" dev gw_dev nodad
+
+probe_v6_gateway
+
+test_v6_gateway_roundtrip
+test_v6_relay_roundtrip
+test_v4_gateway_unchanged
+test_v4_relay_unchanged
+expect_reject "gateway without discovery is rejected" \
+ "Discovery attribute" \
+ mode gateway local "$V6_LOCAL"
+expect_reject "gateway v6 local + v4 discovery is rejected" \
+ "of the local family is required" \
+ mode gateway local "$V6_LOCAL" discovery "$V4_DISC"
+expect_reject "gateway v4 local + v6 discovery is rejected" \
+ "of the local family is required" \
+ mode gateway local "$V4_LOCAL" discovery "$V6_DISC"
+expect_reject "v6 discovery in relay mode is rejected" \
+ "only valid in gateway mode" \
+ mode relay local "$V6_LOCAL" discovery "$V6_DISC"
+expect_reject "v4 discovery on a v6 relay is rejected" \
+ "only valid in gateway mode" \
+ mode relay local "$V6_LOCAL" discovery "$V4_DISC"
+expect_reject "v6 discovery on a v4 relay is rejected" \
+ "only valid in gateway mode" \
+ mode relay local "$V4_LOCAL" discovery "$V6_DISC"
+expect_reject "unspecified v6 local is rejected" \
+ "Invalid Local IPv6" \
+ mode relay local ::
+expect_reject "v4-mapped v6 local is rejected" \
+ "Invalid Local IPv6" \
+ mode relay local ::ffff:192.168.0.1
+expect_reject "loopback v6 local is rejected" \
+ "Invalid Local IPv6" \
+ mode relay local ::1
+expect_reject "multicast v6 local is rejected" \
+ "Invalid Local IPv6" \
+ mode relay local ff02::1
+expect_reject "multicast v6 discovery is rejected" \
+ "must be unicast" \
+ mode gateway local "$V6_LOCAL" discovery ff02::1
+expect_reject "loopback v6 discovery is rejected" \
+ "must be unicast" \
+ mode gateway local "$V6_LOCAL" discovery ::1
+expect_reject "unspecified v6 discovery is rejected" \
+ "must be unicast" \
+ mode gateway local "$V6_LOCAL" discovery ::
+expect_reject "v4-mapped v6 discovery is rejected" \
+ "must be unicast" \
+ mode gateway local "$V6_LOCAL" discovery ::ffff:192.168.0.2
+
+exit "$EXIT_STATUS"
--
2.47.3
^ permalink raw reply [flat|nested] 13+ messages in thread