* [PATCH net-next v6 01/12] amt: create an AF_INET6 encapsulation socket for an IPv6 outer address
2026-12-02 4:31 [PATCH net-next v6 00/12] amt: add an IPv6 outer transport Omar Ramadan
@ 2026-12-02 4:31 ` Omar Ramadan
2026-12-02 4:31 ` [PATCH net-next v6 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-12-02 4:31 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,
Willem de Bruijn, David Ahern, Ido Schimmel
The amt device binds one AF_INET UDP socket, so a relay and its gateways
can only talk AMT over IPv4. RFC 7450 allows either: the Relay
Advertisement carries an IPv4 or an IPv6 relay address (s5.1.2.5), and a
relay must answer a Discovery received over IPv6 with the IPv6 form
(s5.3.3.2).
Add the outer IPv6 local address to struct amt_dev, and amt_v6(), which
reports the outer family from it. For an IPv6 device amt_create_sock()
binds an AF_INET6 socket that is V6ONLY, so that it does not claim the
IPv4 wildcard port, and that sends and verifies the UDP checksum (RFC
8200 s8.1).
The socket is also bound to IFLA_AMT_LINK. An IPv6 route lookup with a
source address treats the output interface only as a preference, so
without the binding the outer traffic could leave through another link,
and two gateways with the same link-local address on different links
would share a tunnel.
ICMPv6 errors go to amt_err_lookup(), which 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 does.
Nothing sets local_ipv6 yet, so there is no functional change.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 34 ++++++++++++++++++++++++++++------
include/net/amt.h | 2 ++
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index b145ed3ca..2f1b9cd04 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -90,6 +90,12 @@ static struct in6_addr mld2_all_node = MLD2_ALL_NODE_INIT;
static struct mld2_grec mldv2_zero_grec;
#endif
+/* An IPv6 local address selects an IPv6 outer transport. */
+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 +3316,35 @@ drop:
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 :: and to the underlying link: that makes route
+ * lookups strict about the output interface and receives from
+ * that link only, where a link-local peer is unique. V6ONLY
+ * leaves the IPv4 wildcard port to an IPv4 amt device. The UDP
+ * checksum is always sent (RFC 8200 s8.1); a gateway also
+ * accepts a zero one on Multicast Data (RFC 7450 s5.2.3.3), and
+ * amt_rcv() drops it on other messages.
+ */
+ 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 +3356,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 */
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH net-next v6 02/12] amt: send the Relay Advertisement over IPv6
2026-12-02 4:31 [PATCH net-next v6 00/12] amt: add an IPv6 outer transport Omar Ramadan
2026-12-02 4:31 ` [PATCH net-next v6 01/12] amt: create an AF_INET6 encapsulation socket for an IPv6 outer address Omar Ramadan
@ 2026-12-02 4:31 ` Omar Ramadan
2026-12-02 4:31 ` [PATCH net-next v6 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-12-02 4:31 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,
Willem de Bruijn, David Ahern, Ido Schimmel
A relay on an IPv6 outer transport must answer a Discovery with the
24-byte IPv6 form of the Relay Advertisement: a gateway tells the two
forms apart by the datagram length (RFC 7450 s5.1.2.5), and the relay
must use the family of the Discovery (s5.3.3.2).
Add struct amt_header_advertisement_v6 and amt_send_advertisement_v6(),
which sends it with a new amt_send_ctrl_v6(). The helper routes with
amt_route6(), which the later IPv6 senders share, and sends with
udp_tunnel6_xmit_skb(), which fills in the UDP checksum RFC 8200 s8.1
makes mandatory. Like the IPv4 senders it uses TC_PRIO_CONTROL and
AMT_TOS and passes no netdev, so control traffic stays out of the tunnel
stats. A drop after the hand-off to IPv6 output is therefore not counted
in tx_errors, which the IPv4 senders do for an ip_local_out() error.
The Advertisement is sent to the Discovery's source from its destination
(s5.1.2, s5.3.3.2), which may be an anycast or secondary address: a
gateway accepts only an Advertisement from the address it sent the
Discovery to. The relay address in the message stays local_ipv6. A
Discovery sent to a multicast group the socket receives, such as
ff02::1, or from ::, is not answered, as a multicast address cannot be a
source (RFC 4291 s2.7).
The IPv4 Advertisement is still sent from local_ip; changing that is a
fix of its own for net.
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 | 102 ++++++++++++++++++++++++++++++++++++++++++++++
include/net/amt.h | 20 +++++++++
2 files changed, 122 insertions(+)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 2f1b9cd04..e3c69ebf7 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -706,6 +706,74 @@ 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;
+ /* Route on AMT_TOS too, for a policy rule that matches the DSCP. */
+ fl6.flowlabel = ip6_make_flowinfo(AMT_TOS, 0);
+
+ return ip6_dst_lookup_flow(amt->net, sk, &fl6, NULL);
+}
+
+/* Send a control message from @saddr; returns 0 once handed to IPv6. */
+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;
@@ -3008,6 +3076,21 @@ out:
rcu_read_unlock();
}
+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;
@@ -3024,6 +3107,25 @@ static bool amt_discovery_handler(struct amt_dev *amt, struct sk_buff *skb)
if (amtd->reserved || amtd->version)
return true;
+ /* The form follows the Discovery's family (RFC 7450 s5.3.3.2), and the
+ * source is the address it was sent to, perhaps an anycast one.
+ */
+ if (amt_v6(amt)) {
+ struct in6_addr saddr = ipv6_hdr(skb)->saddr;
+ struct in6_addr daddr = ipv6_hdr(skb)->daddr;
+
+ /* No answer to a Discovery sent to a group, as a multicast
+ * address cannot be a source (RFC 4291 s2.7), or from ::.
+ */
+ 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..4c096590d 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -133,6 +133,26 @@ struct amt_header_advertisement {
__be32 ip4;
} __packed;
+/* The IPv6 form of the Relay Advertisement: the same header and nonce, then
+ * a 16-byte relay address. A gateway tells the forms apart by the datagram
+ * length (RFC 7450 s5.1.2.5).
+ */
+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,
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH net-next v6 03/12] amt: key relay tunnels on a union amt_addr endpoint
2026-12-02 4:31 [PATCH net-next v6 00/12] amt: add an IPv6 outer transport Omar Ramadan
2026-12-02 4:31 ` [PATCH net-next v6 01/12] amt: create an AF_INET6 encapsulation socket for an IPv6 outer address Omar Ramadan
2026-12-02 4:31 ` [PATCH net-next v6 02/12] amt: send the Relay Advertisement over IPv6 Omar Ramadan
@ 2026-12-02 4:31 ` Omar Ramadan
2026-12-02 4:31 ` [PATCH net-next v6 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-12-02 4:31 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,
Willem de Bruijn, David Ahern, Ido Schimmel
A relay finds a tunnel by the gateway's IPv4 address, a __be32 taken
from ip_hdr(skb)->saddr, and its UDP port. On an IPv6 outer transport
that would read four bytes from the middle of the source address.
Store the endpoint as a union amt_addr, moved above struct
amt_tunnel_list. Its ip6 member is not under CONFIG_IPV6, so code that
only copies or compares an endpoint needs no #if, and the tunnel needs
no family of its own, as the socket fixes it. amt_outer_saddr() copies
the outer source by value before a pull can move the header, and
amt_update_handler() and amt_request_handler() use it. The Update MAC
becomes amt_relay_mac(), one siphash() over {address, port, nonce}; only
the relay checks it, so the IPv4 value is not visible on the wire.
The per-source tunnel cap counts an IPv6 /64, not an address
(amt_same_source()): one host normally owns a /64 and could otherwise
hold the cap from each of its addresses. Gateways in one /64 share the
cap but keep their own tunnel, found by full endpoint, so a full table
refuses new gateways and evicts none. A party delegated a shorter prefix
still gets one source per /64 it routes: with the default max_tunnels
the cap is 16, so eight /64s fill the table, as eight addresses do for
IPv4. The relay cannot see the delegation size; the cap bounds one
source's share, not the number of sources.
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 | 113 +++++++++++++++++++++++++++++++---------------
include/net/amt.h | 18 ++++----
2 files changed, 86 insertions(+), 45 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index e3c69ebf7..bfdce6897 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -96,6 +96,29 @@ static bool amt_v6(const struct amt_dev *amt)
return IS_ENABLED(CONFIG_IPV6) && !ipv6_addr_any(&amt->local_ipv6);
}
+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;
+}
+
+/* One siphash() over the 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;
@@ -187,6 +210,19 @@ static bool amt_addr_equal(union amt_addr *a, union amt_addr *b)
return !memcmp(a, b, sizeof(union amt_addr));
}
+#define AMT_SRC_PREFIX6_LEN 8
+
+/* One source for the per-source tunnel cap: an IPv4 address or an IPv6
+ * /64, so that one host cannot reach the cap from each of its addresses.
+ */
+static bool amt_same_source(const struct amt_dev *amt,
+ const union amt_addr *a, const union amt_addr *b)
+{
+ if (amt_v6(amt))
+ return !memcmp(&a->ip6, &b->ip6, AMT_SRC_PREFIX6_LEN);
+ return a->ip4 == b->ip4;
+}
+
static u32 amt_source_hash(struct amt_tunnel_list *tunnel, union amt_addr *src)
{
u32 hash = jhash(src, sizeof(*src), tunnel->amt->hash_seed);
@@ -699,10 +735,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;
}
@@ -1284,12 +1326,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;
}
@@ -2720,21 +2762,21 @@ 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;
}
return NULL;
}
-/* Most tunnels one source address may hold: an eighth of the table, at
- * least one and at most AMT_MAX_TUNNELS_PER_SRC.
- */
+/* An eighth of the table per source, within 1..AMT_MAX_TUNNELS_PER_SRC. */
static u32 amt_max_tunnels_per_src(const struct amt_dev *amt)
{
return clamp_t(u32, amt->max_tunnels / 8, 1,
@@ -2748,10 +2790,10 @@ static u32 amt_max_tunnels_per_src(const struct amt_dev *amt)
* bounds the number of *verified* gateways rather than the number of
* unverified Requests anyone can send. A per-source cap derived from the
* table, amt_max_tunnels_per_src(), additionally limits the tunnels one
- * verified source address may hold.
+ * verified source (an IPv4 address or an IPv6 /64) 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;
@@ -2768,12 +2810,14 @@ static struct amt_tunnel_list *amt_tunnel_get_or_create(struct amt_dev *amt,
* count how many tunnels this source already holds on the same walk.
* Skip dead tunnels, as amt_tunnel_lookup() and the Request path do, so
* a tunnel being freed neither stands in for its endpoint nor counts
- * against its address.
+ * against its source.
*/
list_for_each_entry(tunnel, &amt->tunnel_list, list) {
- if (tunnel->ip4 != saddr || READ_ONCE(tunnel->dead))
+ if (!amt_same_source(amt, &tunnel->addr, saddr) ||
+ READ_ONCE(tunnel->dead))
continue;
- if (tunnel->source_port == sport) {
+ if (amt_addr_equal(&tunnel->addr, saddr) &&
+ tunnel->source_port == sport) {
spin_unlock_bh(&amt->lock);
return tunnel;
}
@@ -2800,7 +2844,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++)
@@ -2830,7 +2874,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;
@@ -2870,12 +2914,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))
@@ -2902,10 +2947,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;
@@ -2939,7 +2981,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));
@@ -2958,7 +3000,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));
@@ -3150,8 +3192,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;
@@ -3159,7 +3201,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);
@@ -3183,10 +3225,12 @@ 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_same_source(amt, &tunnel->addr, &saddr) ||
+ READ_ONCE(tunnel->dead))
continue;
per_src++;
- if (tunnel->source_port == udph->source)
+ if (amt_addr_equal(&tunnel->addr, &saddr) &&
+ tunnel->source_port == udph->source)
have = true;
}
rcu_read_unlock();
@@ -3195,15 +3239,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 4c096590d..82ab63876 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -251,6 +251,12 @@ struct amt_relay_headers {
};
} __packed;
+/* ip6 exists without CONFIG_IPV6, so copy and compare code needs no #if. */
+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 */
@@ -272,18 +278,12 @@ struct amt_tunnel_list {
*/
bool dead;
__be16 source_port;
- __be32 ip4;
+ /* Outer address of the gateway endpoint, in the outer family */
+ 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
@@ -423,7 +423,7 @@ struct amt_dev {
#define AMT_SECRET_TIMEOUT 60000
#define IANA_AMT_UDP_PORT 2268
#define AMT_MAX_TUNNELS 128
-/* Upper bound of amt_max_tunnels_per_src(), the per-address tunnel cap */
+/* Upper bound of amt_max_tunnels_per_src(), the per-source tunnel cap */
#define AMT_MAX_TUNNELS_PER_SRC 16
#define AMT_MAX_REQS 128
#define AMT_GW_HLEN (sizeof(struct iphdr) + \
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH net-next v6 04/12] amt: send the Membership Query over IPv6
2026-12-02 4:31 [PATCH net-next v6 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (2 preceding siblings ...)
2026-12-02 4:31 ` [PATCH net-next v6 03/12] amt: key relay tunnels on a union amt_addr endpoint Omar Ramadan
@ 2026-12-02 4:31 ` Omar Ramadan
2026-12-02 4:31 ` [PATCH net-next v6 05/12] amt: forward multicast data " Omar Ramadan
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Omar Ramadan @ 2026-12-02 4:31 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,
Willem de Bruijn, David Ahern, Ido Schimmel
amt_send_membership_query() routes and sends only over IPv4. Move that
step into amt_udp_xmit(), which takes an skb that carries the AMT
message, a union amt_addr destination and the ports, and sends over the
device's family: ip_route_output_key() and udp_tunnel_xmit_skb() for
IPv4, amt_route6() and udp_tunnel6_xmit_skb() for IPv6, both with
AMT_TOS.
iptunnel_xmit() scrubs the skb but udp_tunnel6_xmit_skb() does not, so
the IPv6 path calls skb_scrub_packet(); otherwise the inner packet's
conntrack entry would stay on the outer one. The Query has none, the
Multicast Data and Membership Update sent through this helper later do.
amt_send_membership_query() sizes its headroom with amt_ip_hlen(), and
the IPv4 route lookup now runs after the header push; on a route failure
the caller still frees the skb. amt_send_igmp_gq() and amt_send_mld_gq()
take the gateway's endpoint as a union amt_addr. The v6 argument still
selects the inner protocol, independent of the outer family.
amt_v6() is still false for every device, so the only effect is the
order of the IPv4 route lookup.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 122 ++++++++++++++++++++++++++++++----------------
1 file changed, 81 insertions(+), 41 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index bfdce6897..1f4914a63 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -96,6 +96,11 @@ static bool amt_v6(const struct amt_dev *amt)
return IS_ENABLED(CONFIG_IPV6) && !ipv6_addr_any(&amt->local_ipv6);
}
+static unsigned int amt_ip_hlen(const struct amt_dev *amt)
+{
+ return amt_v6(amt) ? sizeof(struct ipv6hdr) : sizeof(struct iphdr);
+}
+
static void amt_outer_saddr(const struct amt_dev *amt,
const struct sk_buff *skb, union amt_addr *addr)
{
@@ -999,16 +1004,16 @@ out:
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);
-/* The destination is passed by value rather than as a tunnel: a Request is
- * unauthenticated, so no tunnel state is created or changed for it - see
- * amt_request_handler().
+/* A Request is unauthenticated, so @daddr is the caller's copy of the
+ * endpoint and no tunnel state is touched; 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;
@@ -1097,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;
@@ -1114,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
@@ -1232,6 +1237,63 @@ static void amt_req_work(struct work_struct *work)
msecs_to_jiffies(100));
}
+/* Route and send an AMT message to @daddr over the device's family. Over
+ * IPv6 @dst may hold the route already looked up; it is consumed.
+ */
+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);
+ }
+ /* Unlike iptunnel_xmit(), udp_tunnel6_xmit_skb() does not scrub
+ * the skb.
+ */
+ 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)
@@ -1362,17 +1424,17 @@ static void amt_send_multicast_data(struct amt_dev *amt,
*
* No per-source state is read or created: the gateway echoes the nonce and
* the keyed MAC in its Membership Update, where the MAC is recomputed, so
- * everything this needs is passed by value.
+ * everything this needs is passed in: the nonce and the MAC by value, the
+ * endpoint as a pointer to the caller's copy.
*/
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;
@@ -1381,23 +1443,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;
@@ -1411,18 +1461,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)
@@ -3241,10 +3281,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;
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH net-next v6 05/12] amt: forward multicast data over IPv6
2026-12-02 4:31 [PATCH net-next v6 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (3 preceding siblings ...)
2026-12-02 4:31 ` [PATCH net-next v6 04/12] amt: send the Membership Query over IPv6 Omar Ramadan
@ 2026-12-02 4:31 ` Omar Ramadan
2026-12-02 4:31 ` [PATCH net-next v6 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-12-02 4:31 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,
Willem de Bruijn, David Ahern, Ido Schimmel
amt_send_multicast_data() routes and sends the relay's copy of a
multicast packet only over IPv4. Size its headroom for the outer family
and send it through amt_udp_xmit(). A copy that cannot be sent is now
counted in tx_dropped, and one with no route is freed with
SKB_DROP_REASON_IP_OUTNOROUTES. The inner protocol stays independent of
the outer family.
RFC 7450 s5.3.3.6.3.2 forbids a Fragment header on Multicast Data over
IPv6, and s5.3.3.6.2.2 has a payload above the tunnel MTU dropped and,
if it came from an SSM source, a Packet Too Big sent to it. The scrub in
amt_udp_xmit() clears ignore_df, so ip6_fragment() would drop such a
packet and send 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,
per segment with skb_gso_validate_network_len() for a GSO skb. A route
MTU below the outer headers gives a tunnel MTU of zero, not a wrapped
one.
A packet can match every tunnel, and an attacker can create tunnels, so
amt_dev_xmit() sends one Packet Too Big through icmpv6_ndo_send() after
walking all of them, with the smallest failing tunnel MTU. It is sent
only for an SSM group, ff3x::/32 (RFC 4607 s1); the source of an ASM
group is not told. A tunnel MTU below IPV6_MIN_MTU is left out, as a
smaller Packet Too Big is ignored. An IPv4 payload is dropped without an
ICMP error, as icmp_send() does not answer multicast, and is not
fragmented first (s5.3.3.6.2.1), as the IPv4 tunnel does not either.
ipv6_mc_check_mld() leaves the transport header just past the fixed IPv6
header, also for a packet it rejects as not MLD. amt_dev_xmit() puts it
back to the offset it had on entry, or the per-segment length of a GSO
skb would miss extension headers; the forwarding path counts them no
better, as in ip6_forward() and ip6_finish_output_gso().
The tunnel MTU follows the route's path MTU, as on every IPv6 UDP
tunnel. RFC 7450 s5.3.3.6.1 and s6.1 ask for a way to turn that off. The
IPv6 stack gives a tunnel none: udpv6_err() records the lowered MTU
before it looks up a socket, and "mtu lock" does not stop it. This
series adds none. A forged Packet Too Big, which anyone who can send
ICMPv6 to the relay can aim at a gateway's address, lowers the tunnel
MTU toward that gateway, down to 1230 (1280 less the 50 bytes of IPv6,
UDP and AMT headers), until the route exception expires, 10 minutes by
default, and every payload above it is dropped toward that gateway. A
forged value M with 1330 <= M < 1490 on a 1500 byte link, where the
device MTU is 1440, gives a tunnel MTU of M - 50, which the source of an
SSM group is sent if its payload exceeds it, and may apply to the group
for every receiver. Sending the Packet Too Big only for SSM narrows who
learns of it; it does not authenticate it.
amt_v6() is still false for every device, so on an IPv4 relay only the
tx_dropped accounting, the drop reason and the transport header restore
take effect.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 134 ++++++++++++++++++++++++++++++++--------------
1 file changed, 94 insertions(+), 40 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 1f4914a63..1780d3dca 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -1237,25 +1237,53 @@ static void amt_req_work(struct work_struct *work)
msecs_to_jiffies(100));
}
+/* A payload above the tunnel MTU is dropped, as RFC 7450 s5.3.3.6 forbids a
+ * Fragment header. Its source is sent a Packet Too Big only for an SSM group
+ * (s5.3.3.6.2.2) and not below IPV6_MIN_MTU, which a source would ignore.
+ * The tunnel MTU follows the route's path MTU, as on any IPv6 UDP tunnel.
+ */
+static u32 amt_tmtu(const struct dst_entry *dst)
+{
+ u32 hlen = sizeof(struct ipv6hdr) + sizeof(struct udphdr) +
+ sizeof(struct amt_header_mcast_data);
+ u32 mtu = dst_mtu(dst);
+
+ return mtu > hlen ? mtu - hlen : 0;
+}
+
+/* FF3x::/32 is SSM for any scope x (RFC 4607 s1). */
+static bool amt_group6_is_ssm(const struct in6_addr *group)
+{
+ return (group->s6_addr32[0] & htonl(0xfff0ffff)) == htonl(0xff300000);
+}
+
+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 and send an AMT message to @daddr over the device's family. Over
* IPv6 @dst may hold the route already looked up; it is consumed.
*/
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);
+ }
}
/* Unlike iptunnel_xmit(), udp_tunnel6_xmit_skb() does not scrub
* the skb.
@@ -1354,26 +1382,55 @@ static bool amt_send_membership_update(struct amt_dev *amt,
return false;
}
+/* Send the relay's copy to one gateway. Over IPv6 a payload that does not
+ * fit the tunnel MTU is dropped and *@ptb lowered to that MTU, for
+ * amt_dev_xmit() to send one Packet Too Big after walking 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 Packet Too Big below IPV6_MIN_MTU is ignored. */
+ 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);
+ DEV_STATS_INC(amt->dev, tx_dropped);
return;
+ }
/* amt_dev_xmit() pulled the Ethernet header without moving the mac
* header. The tunnelled payload has no link-layer header, so the
@@ -1382,18 +1439,8 @@ 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);
+ DEV_STATS_INC(amt->dev, tx_dropped);
kfree_skb(skb);
return;
}
@@ -1407,17 +1454,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.
@@ -1462,7 +1504,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)
@@ -1480,6 +1522,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);
@@ -1504,6 +1547,9 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)
group.ip4 = ip_hdr(skb)->daddr;
#if IS_ENABLED(CONFIG_IPV6)
} else if (iph->version == 6) {
+ bool th_set = skb_transport_header_was_set(skb);
+ int th_off = th_set ? skb_transport_offset(skb) : 0;
+
ip6h = ipv6_hdr(skb);
if (!ipv6_addr_is_multicast(&ip6h->daddr))
goto free;
@@ -1520,6 +1566,12 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)
}
} else {
data = true;
+ /* ipv6_mc_check_mld() moved the transport header just
+ * past the fixed header; restore it, or a GSO skb's
+ * segments look shorter than they are.
+ */
+ if (th_set)
+ skb_set_transport_header(skb, th_off);
}
v6 = true;
group.ip6 = ipv6_hdr(skb)->daddr;
@@ -1573,8 +1625,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 && amt_group6_is_ssm(&group.ip6))
+ icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, ptb);
}
dev_kfree_skb(skb);
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH net-next v6 06/12] amt: size the encapsulation headroom by the outer IP version
2026-12-02 4:31 [PATCH net-next v6 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (4 preceding siblings ...)
2026-12-02 4:31 ` [PATCH net-next v6 05/12] amt: forward multicast data " Omar Ramadan
@ 2026-12-02 4:31 ` Omar Ramadan
2026-12-02 4:31 ` [PATCH net-next v6 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-12-02 4:31 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,
Willem de Bruijn, David Ahern, Ido Schimmel
AMT_RELAY_HLEN and AMT_GW_HLEN, which size the device's headroom and its
MTU below the stream device's, assume a 20-byte IPv4 outer header, 20
bytes short of an IPv6 one. A payload near the device MTU would then
exceed the tunnel MTU that amt_send_multicast_data() computes from the
route and be dropped there.
Add AMT_RELAY_HLEN6 and AMT_GW_HLEN6, pick between them in amt_hlen(),
and use amt_hlen() at newlink and on NETDEV_CHANGEMTU of the stream
device, so that the stack refuses such a payload first.
amt_v6() is still false for every device, so there is no functional
change.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 25 ++++++++++++++-----------
include/net/amt.h | 6 ++++++
2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 1780d3dca..79702b002 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -101,6 +101,13 @@ static unsigned int amt_ip_hlen(const struct amt_dev *amt)
return amt_v6(amt) ? sizeof(struct ipv6hdr) : sizeof(struct iphdr);
}
+static unsigned int amt_hlen(const struct amt_dev *amt)
+{
+ if (amt->mode == AMT_MODE_RELAY)
+ return amt_v6(amt) ? AMT_RELAY_HLEN6 : AMT_RELAY_HLEN;
+ return amt_v6(amt) ? AMT_GW_HLEN6 : AMT_GW_HLEN;
+}
+
static void amt_outer_saddr(const struct amt_dev *amt,
const struct sk_buff *skb, union amt_addr *addr)
{
@@ -3904,10 +3911,10 @@ static int amt_newlink(struct net_device *dev,
amt->qrv = READ_ONCE(amt->net->ipv4.sysctl_igmp_qrv);
amt->qri = 10;
dev->needed_headroom = amt->stream_dev->needed_headroom +
- AMT_RELAY_HLEN;
- dev->mtu = amt->stream_dev->mtu - AMT_RELAY_HLEN;
+ amt_hlen(amt);
+ dev->mtu = amt->stream_dev->mtu - amt_hlen(amt);
dev->max_mtu = dev->mtu;
- dev->min_mtu = ETH_MIN_MTU + AMT_RELAY_HLEN;
+ dev->min_mtu = ETH_MIN_MTU + amt_hlen(amt);
} else {
if (!data[IFLA_AMT_DISCOVERY_IP]) {
NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_AMT_DISCOVERY_IP],
@@ -3930,10 +3937,10 @@ static int amt_newlink(struct net_device *dev,
}
dev->needed_headroom = amt->stream_dev->needed_headroom +
- AMT_GW_HLEN;
- dev->mtu = amt->stream_dev->mtu - AMT_GW_HLEN;
+ amt_hlen(amt);
+ dev->mtu = amt->stream_dev->mtu - amt_hlen(amt);
dev->max_mtu = dev->mtu;
- dev->min_mtu = ETH_MIN_MTU + AMT_GW_HLEN;
+ dev->min_mtu = ETH_MIN_MTU + amt_hlen(amt);
}
amt->qi = AMT_INIT_QUERY_INTERVAL;
@@ -4054,11 +4061,7 @@ static int amt_device_event(struct notifier_block *unused,
amt_dellink(amt->dev, &list);
break;
case NETDEV_CHANGEMTU:
- if (amt->mode == AMT_MODE_RELAY)
- new_mtu = dev->mtu - AMT_RELAY_HLEN;
- else
- new_mtu = dev->mtu - AMT_GW_HLEN;
-
+ new_mtu = dev->mtu - amt_hlen(amt);
dev_set_mtu(amt->dev, new_mtu);
break;
}
diff --git a/include/net/amt.h b/include/net/amt.h
index 82ab63876..726026259 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -429,9 +429,15 @@ struct amt_dev {
#define AMT_GW_HLEN (sizeof(struct iphdr) + \
sizeof(struct udphdr) + \
sizeof(struct amt_gw_headers))
+#define AMT_GW_HLEN6 (sizeof(struct ipv6hdr) + \
+ sizeof(struct udphdr) + \
+ sizeof(struct amt_gw_headers))
#define AMT_RELAY_HLEN (sizeof(struct iphdr) + \
sizeof(struct udphdr) + \
sizeof(struct amt_relay_headers))
+#define AMT_RELAY_HLEN6 (sizeof(struct ipv6hdr) + \
+ sizeof(struct udphdr) + \
+ sizeof(struct amt_relay_headers))
static inline bool netif_is_amt(const struct net_device *dev)
{
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH net-next v6 07/12] amt: send the AMT gateway control plane over IPv6
2026-12-02 4:31 [PATCH net-next v6 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (5 preceding siblings ...)
2026-12-02 4:31 ` [PATCH net-next v6 06/12] amt: size the encapsulation headroom by the outer IP version Omar Ramadan
@ 2026-12-02 4:31 ` Omar Ramadan
2026-12-02 4:31 ` [PATCH net-next v6 08/12] amt: receive " Omar Ramadan
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Omar Ramadan @ 2026-12-02 4:31 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,
Willem de Bruijn, David Ahern, Ido Schimmel
A gateway builds its Discovery, Request and Membership Updates for an
IPv4 outer header only, so on an IPv6-only access network it cannot
reach a relay.
Send the Discovery and the Request from amt_send_discovery_v6() and
amt_send_request_v6(). They are a few bytes, so they are built on the
stack and sent with amt_send_ctrl_v6(). The Membership Update carries
the IGMP or MLD report, so amt_send_membership_update() keeps its skb,
sizes the headroom with amt_ip_hlen() and sends through amt_udp_xmit().
struct amt_dev gains the IPv6 discovery address and the IPv6 relay
address a gateway learns; nothing writes the latter until the next
patch.
amt_send_ctrl_v6() holds rcu_read_lock_bh(): a gateway sends from its
event worker, and udp_tunnel6_xmit_skb() reaches ip6tunnel_xmit(), which
increments and decrements a per-CPU xmit recursion counter that a
migration in between would unbalance. IPv4 never touches it, and the
relay sends from softirq.
The P bit of the Request and the inner protocol of the Update follow the
inner family, as for IPv4. amt_v6() is still false for every device, so
none of the IPv6 code runs yet and IPv4 behaviour is unchanged.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 79 +++++++++++++++++++++++++++++------------------
include/net/amt.h | 4 +++
2 files changed, 53 insertions(+), 30 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 79702b002..40481b0f9 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -791,8 +791,9 @@ 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);
+ /* ip6tunnel_xmit() counts xmit recursion per CPU: BH must be off. */
+ 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 +825,36 @@ 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;
}
+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);
+}
+
+/* The inner family @v6 sets the P bit, independent of the outer one. */
+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 +868,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 +963,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);
@@ -1335,9 +1372,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;
@@ -1346,23 +1381,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;
@@ -1374,17 +1397,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 726026259..967acaf38 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -385,8 +385,12 @@ struct amt_dev {
struct in6_addr local_ipv6;
/* Outer remote ip */
__be32 remote_ip;
+ /* Outer remote ipv6 (learned from the Advertisement; :: in v4 mode) */
+ struct in6_addr remote_ipv6;
/* Outer discovery ip */
__be32 discovery_ip;
+ /* Outer discovery ipv6 (v6 gateway only; :: in v4 mode) */
+ struct in6_addr discovery_ipv6;
/* Only used in gateway mode */
__be32 nonce;
/* Gateway sent request and received query */
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH net-next v6 08/12] amt: receive the AMT gateway control plane over IPv6
2026-12-02 4:31 [PATCH net-next v6 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (6 preceding siblings ...)
2026-12-02 4:31 ` [PATCH net-next v6 07/12] amt: send the AMT gateway control plane over IPv6 Omar Ramadan
@ 2026-12-02 4:31 ` Omar Ramadan
2026-12-02 4:31 ` [PATCH net-next v6 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-12-02 4:31 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,
Willem de Bruijn, David Ahern, Ido Schimmel
The previous patch added the IPv6 senders of a gateway, but amt_rcv()
could not take the replies: it checks the outer source with
ip_hdr(skb)->saddr, which on an IPv6 header is four bytes from the
middle of the address, and amt_advertisement_handler() parses only the
IPv4 form.
amt_rcv() takes the outer source by value with amt_outer_saddr() before
amt_parse_type() pulls, and checks it with amt_from_relay(): the
discovery address for an Advertisement, the learned relay address
otherwise, in the device's family, and nothing matches while the relay
is not known. amt_membership_query_handler() repeats the check for a
queued Query. The IPv4 half is "amt: reject a gateway Query or Data from
0.0.0.0" in net. IPv6 input delivers a packet from ::, which would match
a cleared relay address and, with a zero nonce, inject a Query or have a
relay create a tunnel, so amt_rcv() drops it in either mode.
amt_advertisement_handler() pulls the 24-byte form on an IPv6 gateway
and refuses an unspecified, loopback, multicast or IPv4-mapped relay
address; the V6ONLY socket could not reach the last. An IPv6 gateway
takes only the exact 24-byte form, which is this driver's policy:
s5.1.2.5 only has a gateway tell the forms apart by length. An IPv4
gateway keeps its minimum-length check.
The learned relay address is written from the event worker (the
Advertisement handler, and amt_clear_remote() when called from
amt_event_send_request()) and in process context (amt_dev_open() and
amt_dev_stop() call amt_clear_remote()), and read in softirq and, from
the next patch on, by amt_fill_info(), which no longer relies on RTNL. A
struct in6_addr is not copied in one access, so a reader could see half
of an old and half of a new address. It is published with
amt_set_remote_ipv6() under a seqlock, remote_ipv6_lock, and read with
amt_get_remote_ipv6(), one snapshot per packet, without a lock.
amt_clear_remote() forgets the relay in both families in the three
places that reset it, so a gateway taken down and up neither accepts
traffic from its previous relay nor, once amt_fill_info() reports it,
keeps reporting it.
IPv4 input refuses a source that is one of the host's own addresses as a
martian when it comes from the wire; IPv6 input delivers it, an anycast
address too. A relay answers a Discovery and a Request to their source,
so a forged one from the relay's own address would make it send to
itself over lo, where a rule such as "-i lo -j ACCEPT" lets it in. A
relay's amt_rcv() therefore drops such a packet. amt_saddr_is_local()
looks a unicast address up with ipv6_chk_addr() in the L3 domain of the
stream device, so an address on a slave of its VRF is found, a
link-local one only on the stream device itself and a tentative one not,
and an anycast address with ipv6_chk_acast_addr() in the whole
namespace. That function is not exported, so this patch exports it from
net/ipv6/anycast.c, as ipv6_chk_addr() is. A packet that arrives over lo
comes from the host itself and is not dropped, as for IPv4, so a gateway
on the relay's host still works. In a VRF every packet arrives on the
VRF device, so that exception cannot apply there.
A gateway must accept a zero UDP checksum on Multicast Data (RFC 7450
s5.2.3.3; a relay may use the RFC 6936 exception to RFC 8200 s8.1), so
an IPv6 gateway's socket does, and still verifies a non-zero one.
amt_rcv() drops a zero checksum on every other message (RFC 6936 s5). A
relay's socket keeps requiring it.
The Query and Multicast Data handlers dispatch on the inner family and
need no change. amt_v6() is still false for every device, because
nothing sets local_ipv6 until the netlink attributes of the next patch,
so none of this runs yet and the receive path of an IPv4 gateway is
unchanged.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 161 ++++++++++++++++++++++++++++++++++++++-------
include/net/amt.h | 2 +
net/ipv6/anycast.c | 1 +
3 files changed, 140 insertions(+), 24 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 40481b0f9..c2126c7ba 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -767,6 +767,10 @@ static struct dst_entry *amt_route6(struct amt_dev *amt, struct sock *sk,
{
struct flowi6 fl6;
+ /* A gateway that just forgot its relay publishes ::. */
+ if (ipv6_addr_any(daddr))
+ return ERR_PTR(-EINVAL);
+
memset(&fl6, 0, sizeof(fl6));
fl6.flowi6_oif = amt->stream_dev->ifindex;
fl6.flowi6_proto = IPPROTO_UDP;
@@ -829,6 +833,69 @@ out:
return err;
}
+/* Written from the event worker and process context, read in softirq. A
+ * struct in6_addr is not stored in one access, so it goes under a seqlock
+ * and each 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));
+}
+
+static void amt_clear_remote(struct amt_dev *amt)
+{
+ WRITE_ONCE(amt->remote_ip, 0);
+ amt_set_remote_ipv6(amt, &in6addr_any);
+}
+
+/* Whether a gateway's message came from its relay: the discovery address
+ * for an Advertisement, the learned relay address otherwise. An unknown
+ * relay (::) 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;
+}
+
+/* A unicast address is looked up in the stream device's L3 domain (a
+ * link-local one only on the device itself), an anycast address in the
+ * whole namespace. A gateway has no reason to send from either.
+ */
+static bool amt_saddr_is_local(const struct amt_dev *amt,
+ const struct in6_addr *a)
+{
+ return ipv6_chk_addr(amt->net, a, amt->stream_dev, 0) ||
+ ipv6_chk_acast_addr(amt->net, NULL, a);
+}
+
static void amt_send_discovery_v6(struct amt_dev *amt)
{
struct amt_header_discovery amtd = {
@@ -850,9 +917,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)
@@ -1248,7 +1317,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;
@@ -1398,7 +1467,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,
@@ -2664,27 +2733,45 @@ 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);
+ 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 forms differ only in length. An IPv6 gateway accepts only its
+ * own: driver policy, not the RFC's.
+ */
+ if (amt_v6(amt) && 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);
@@ -2769,6 +2856,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;
@@ -2782,7 +2870,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)
@@ -3404,9 +3493,8 @@ drop:
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;
@@ -3417,10 +3505,28 @@ 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);
+ /* IPv6 input delivers a packet from ::. */
+ if (amt_v6(amt) && ipv6_addr_any(&saddr.ip6)) {
+ err = true;
+ goto drop;
+ }
+ /* IPv4 input refuses a source that is one of this host's own addresses
+ * as a martian, IPv6 input does not. Answering a forged one would send
+ * to ourselves over lo. A packet over lo is from this host, as for
+ * IPv4, so a gateway on the relay's host still works; in a VRF the
+ * incoming interface is the VRF device, so that exception cannot apply
+ * there.
+ */
+ if (amt_v6(amt) && amt->mode == AMT_MODE_RELAY &&
+ skb->skb_iif != amt->net->loopback_dev->ifindex &&
+ amt_saddr_is_local(amt, &saddr.ip6)) {
+ err = true;
+ goto drop;
+ }
type = amt_parse_type(skb);
if (type == -1) {
err = true;
@@ -3428,9 +3534,15 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb)
}
if (amt->mode == AMT_MODE_GATEWAY) {
+ /* RFC 6936 s5: a zero checksum only on Multicast Data. */
+ 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;
@@ -3442,7 +3554,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;
@@ -3453,7 +3565,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;
@@ -3598,7 +3710,7 @@ static struct sock *amt_create_sock(const struct amt_dev *amt)
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;
@@ -3667,7 +3779,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;
@@ -3716,7 +3828,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
@@ -3886,6 +3998,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 967acaf38..823623b99 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -387,6 +387,8 @@ struct amt_dev {
__be32 remote_ip;
/* Outer remote ipv6 (learned from the Advertisement; :: in v4 mode) */
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; :: in v4 mode) */
diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
index be6dac8a8..4adc6f316 100644
--- a/net/ipv6/anycast.c
+++ b/net/ipv6/anycast.c
@@ -513,6 +513,7 @@ bool ipv6_chk_acast_addr(struct net *net, struct net_device *dev,
rcu_read_unlock();
return found;
}
+EXPORT_SYMBOL(ipv6_chk_acast_addr);
/* check if this anycast address is link-local on given interface or
* is global
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH net-next v6 09/12] amt: add netlink attributes for an IPv6 outer transport
2026-12-02 4:31 [PATCH net-next v6 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (7 preceding siblings ...)
2026-12-02 4:31 ` [PATCH net-next v6 08/12] amt: receive " Omar Ramadan
@ 2026-12-02 4:31 ` Omar Ramadan
2026-12-02 4:31 ` [PATCH net-next v6 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-12-02 4:31 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,
Willem de Bruijn, David Ahern, Ido Schimmel
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 excludes IFLA_AMT_LOCAL_IP.
- IFLA_AMT_DISCOVERY_IP6, the address a gateway sends its Relay
Discovery to, in the family of its local address, as both ends use
one outer transport.
- IFLA_AMT_REMOTE_IP6, the relay address the gateway learned. Like
IFLA_AMT_REMOTE_IP it is only reported; the policy rejects it on
input.
amt_fill_info() reports the addresses of the device's outer family.
IFLA_AMT_LOCAL_IP6 is refused with -EAFNOSUPPORT without CONFIG_IPV6,
rather than creating an IPv4 device with no local address. An IPv6 local
or discovery address is refused when unspecified, loopback, multicast or
IPv4-mapped, the last because the V6ONLY socket could never send from or
to it.
IFLA_AMT_LOCAL_IP and IFLA_AMT_DISCOVERY_IP cannot carry 16 bytes: net
requires exactly four ("amt: require an exact IPv4-sized
IFLA_AMT_{LOCAL,DISCOVERY}_IP"), so the IPv6 addresses get attributes of
their own, as in vxlan and geneve. A kernel that does not know them
ignores them and fails for lack of a local address, so userspace can
tell. They are appended to the enum, so existing values do not change;
strict_start_type makes the policy validate them and later attributes
strictly, with an exact 16-byte length.
A relay has always ignored IFLA_AMT_DISCOVERY_IP, so an IPv4 relay still
accepts it. An IPv6 relay has no existing users and 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 | 157 ++++++++++++++++++++++++++++++---------
include/uapi/linux/amt.h | 13 ++++
2 files changed, 134 insertions(+), 36 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index c2126c7ba..14c544d80 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -3925,6 +3925,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 },
@@ -3933,6 +3934,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[],
@@ -3959,16 +3964,49 @@ 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; an
+ * IPv6 one has no such users and rejects both families.
+ */
+ 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;
+ }
+
+ 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;
}
@@ -4019,13 +4057,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],
@@ -4048,24 +4098,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 +
@@ -4119,7 +4180,25 @@ 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 */
+ /* {LOCAL,DISCOVERY,REMOTE}_IP6: sized for both families. */
+ 3 * nla_total_size(sizeof(struct in6_addr));
+}
+
+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)
@@ -4136,15 +4215,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,
};
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH net-next v6 10/12] MAINTAINERS: amt: cover the amt headers and selftests
2026-12-02 4:31 [PATCH net-next v6 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (8 preceding siblings ...)
2026-12-02 4:31 ` [PATCH net-next v6 09/12] amt: add netlink attributes for an IPv6 outer transport Omar Ramadan
@ 2026-12-02 4:31 ` Omar Ramadan
2026-12-02 4:31 ` [PATCH net-next v6 11/12] selftests: net: add amt_v6.sh for an IPv6 outer transport Omar Ramadan
2026-12-02 4:32 ` [PATCH net-next v6 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-12-02 4:31 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,
Willem de Bruijn, David Ahern, Ido Schimmel
The AMT entry lists only drivers/net/amt.c, so get_maintainer.pl finds
no AMT maintainer for include/net/amt.h, include/uapi/linux/amt.h or
tools/testing/selftests/net/amt.sh. Add the headers, and a glob for
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 05b2d9e36..067271943 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>
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH net-next v6 11/12] selftests: net: add amt_v6.sh for an IPv6 outer transport
2026-12-02 4:31 [PATCH net-next v6 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (9 preceding siblings ...)
2026-12-02 4:31 ` [PATCH net-next v6 10/12] MAINTAINERS: amt: cover the amt headers and selftests Omar Ramadan
@ 2026-12-02 4:31 ` Omar Ramadan
2026-12-02 4:32 ` [PATCH net-next v6 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-12-02 4:31 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,
Willem de Bruijn, David Ahern, Ido Schimmel
Nothing covers the IPv6 outer transport. amt_v6.sh is amt.sh with the
gateway<->relay link moved to IPv6, and a second gateway on it:
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, smcroute routes and tools are those of
amt.sh, plus tcpdump for the Discovery checks, which skip without it.
The forwarding checks cover the whole handshake, as the relay forwards
only after the gateway's Update. It checks that:
- amtg learns 2001:db8:a::2 from an Advertisement requested through the
relay's second address, so the Advertisement comes from the address
the Discovery was sent to;
- IPv4 and IPv6 multicast reach the listener through the tunnel, and
IPv4 multicast reaches a listener on the second gateway, which shares
the first one's /64 and port;
- with max_tunnels 16 the relay allows two tunnels per /64 source: a
third gateway in it gets no tunnel and no multicast, one in another
/64 does;
- the relay's General Queries do not leave through amtr;
- with the route MTU to the gateway lowered, an IPv6 payload above the
tunnel MTU is dropped and counted in tx_dropped, neither fragmented
nor sent to IPv6 output, where it would count in Ip6FragFails;
- its source is sent a Packet Too Big if the group is SSM, ff3e::5:6,
and none if it is ASM, ff0e::5:6 (RFC 7450 s5.3.3.6.2.2);
- a Discovery to ff02::1 draws no reply, while one to the discovery
address, the positive control, does;
- a Discovery from the wire with the relay's own address, unicast or
the subnet-router anycast one, as its source is dropped, counted in
rx_dropped and not answered on lo, while the same Discovery over lo,
as from a gateway on the relay's host, is answered;
- taking amtg down clears the learned relay address, and bringing it up
discovers the relay again.
A probe creates a throwaway IPv6 relay first and skips when iproute2
does not know amt, when the kernel ignores IFLA_AMT_LOCAL_IP6 ("Local
attribute is required") or has no amt link type ("Unknown device type"),
and when iproute2 cannot pass the address: it rejects the literal
("expected rather than"), or packs it into the 4-byte IFLA_AMT_LOCAL_IP,
which this kernel refuses with "binary attribute size out of range" and
an older one creates as an IPv4 relay, read back as an address without a
colon. Any other failure is a FAIL. The script skips without CONFIG_IPV6
before it creates a link.
A listener that must get nothing has to be alive at the end, so one that
never started cannot pass. disc_answer() and local_src_answers() fail
with a reason, and tcpdump's own text, when tcpdump does not start or
ends early, or a send fails, so a harness failure is not read as "no
reply". gw_l is up before it joins the gateway's bridge, and amtg comes up
only once its bridge port forwards, so that the relay's first Query
reaches the listener. br_gw's MAC is set, as a bridge takes its lowest
port's and a port added later would leave the gateway a stale neighbour
entry for the relay.
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 | 716 ++++++++++++++++++++++++++
2 files changed, 717 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 fb0a64662..a31f19e9f 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..c5447ffea
--- /dev/null
+++ b/tools/testing/selftests/net/amt_v6.sh
@@ -0,0 +1,716 @@
+#!/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 carry IPv4 and IPv6 multicast inside. The gateway<->relay link
+# differs from amt.sh, 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 gateways discover the relay (::2) through 2001:db8:a::3, so the Relay
+# Advertisement has to come from the address the Discovery was sent to.
+
+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"
+# A third gateway in the first /64, and one in a /64 of its own.
+readonly GW4_6="2001:db8:a::5"
+readonly GW3_6="2001:db8:b::5"
+readonly DISC6B="2001:db8:b::3"
+# An SSM group (RFC 4607, ff3x::/32), next to the ASM group ff0e::5:6.
+readonly SSM6="ff3e::5:6"
+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" ]
+}
+
+gw_l_forwarding()
+{
+ [ "$(ip netns exec "$GATEWAY" bridge -j link show dev gw_l |
+ jq -r '.[0].state')" = forwarding ]
+}
+
+snmp6()
+{
+ ip netns exec "$1" awk -v k="$2" '$1 == k { print $2 }' /proc/net/snmp6
+}
+
+setup_links()
+{
+ local ns
+
+ # No DAD: the gateway and relay addresses must not be tentative.
+ 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
+ # A bridge takes its lowest port MAC; a later port must not change it.
+ ip -n "$RELAY" link set br_gw address 02:00:00:00:0a:03
+ 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
+}
+
+# Skip only when iproute2 or the kernel lacks IPv6 AMT support: an iproute2
+# without it rejects the literal or packs it into the 4-byte
+# IFLA_AMT_LOCAL_IP (refused here, read back as IPv4 on an older kernel); a
+# kernel without it ignores IFLA_AMT_LOCAL_IP6 or does not know amt.
+probe_v6_relay()
+{
+ local err got
+
+ if ! ip link help 2>&1 | grep -q amt; then
+ echo "SKIP: missing amt support in iproute2"
+ exit "$ksft_skip"
+ fi
+
+ 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"*|\
+ *"binary attribute size out of range"*|*"Unknown device type"*)
+ 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 "$LISTENER" addr add "$SSM6/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 up
+ ip -n "$GATEWAY" link set gw_l master br0
+ # The relay's first Query must not be flooded past the listener.
+ slowwait 5 gw_l_forwarding
+ 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 with no route.
+ 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 16
+ # max_tunnels 16 allows two tunnels per /64 source (max_tunnels / 8).
+ # Count the IGMP packets and MLD queries leaving through amtr, expected
+ # none.
+ ip netns exec "$RELAY" tc qdisc add dev amtr clsact
+ ip netns exec "$RELAY" tc filter add dev amtr egress pref 1 \
+ protocol ip flower ip_proto 0x2 action pass
+ ip netns exec "$RELAY" tc filter add dev amtr egress pref 2 \
+ protocol ipv6 flower ip_proto icmpv6 type 130 action pass
+ 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: a hop limit rewrite would break Neighbour Discovery.
+ ip netns exec "$RELAY" ip6tables -t mangle -I PREROUTING \
+ -d ff0e::5:6 -j HL --hl-set 2
+ ip netns exec "$RELAY" ip6tables -t mangle -I PREROUTING \
+ -d "$SSM6" -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
+ ip netns exec "$RELAY" smcroutectl -u "$SMCDIR/sock" \
+ a relay_src 2001:db8:3::2 "$SSM6" 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>
+# [none]
+# The listener gets the data, or, with "none", nothing.
+test_forward()
+{
+ local ns=$1 addr=$2 port=$3 grp=$4 src=$5 desc=$6 want=${7:-data}
+ local out pid i rc
+
+ RET=0
+ out=$(mktemp)
+ ip netns exec "$ns" timeout 20 \
+ socat -u "$addr,readbytes=128" - > "$out" &
+ pid=$!
+ wait_local_port_listen "$ns" "$port" udp
+ # Paced to outlast a Request/Query refresh of the gateway.
+ for i in $(seq 40); do
+ ip netns exec "$SOURCE" bash -c \
+ "printf '%s %128s' $src | nc -w 1 -u $grp $port"
+ [ "$want" = data ] && grep -q "$src" "$out" && break
+ sleep 0.25
+ done
+ wait "$pid"
+ rc=$?
+ if [ "$want" = data ]; then
+ grep -q "$src" "$out"
+ check_err $? "nothing from $src reached the listener"
+ else
+ ! grep -q "$src" "$out"
+ check_err $? "$src reached a listener that should get no tunnel"
+ # Only the timeout ends a live listener; anything else means it
+ # never ran.
+ [ "$rc" -eq 124 ]
+ check_err $? "listener ended early, status $rc"
+ fi
+ rm -f "$out"
+ log_test "$desc"
+}
+
+tx_dropped()
+{
+ ip -n "$RELAY" -s -j link show amtr | jq -r '.[0].stats64.tx.dropped'
+}
+
+# With the route MTU to the gateway below the payload, the relay must drop the
+# payload without fragmenting it, and send its source a Packet Too Big only
+# for an SSM group (RFC 7450 s5.3.3.6.2.2).
+# test_tmtu <group> <ptb|none> <description>
+test_tmtu()
+{
+ local grp=$1 want=$2 desc=$3
+ local ptb frag fragfail drop 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)
+ drop=$(tx_dropped)
+ for i in 1 2 3; do
+ ip netns exec "$SOURCE" bash -c \
+ "printf '%1352s' x | nc -w 1 -u $grp 6000"
+ done
+ # The drops show that the payload reached the tunnel, so that "none" is
+ # not a send that never ran. -gt: the first Packet Too Big caches a path
+ # MTU in the source, so later datagrams may be fragmented, not dropped.
+ [ "$(tx_dropped)" -gt "$drop" ]
+ check_err $? "the relay did not drop the payload"
+ if [ "$want" = ptb ]; then
+ [ "$(snmp6 "$SOURCE" Icmp6InPktTooBigs)" -gt "$ptb" ]
+ check_err $? "the source got no Packet Too Big"
+ else
+ [ "$(snmp6 "$SOURCE" Icmp6InPktTooBigs)" -eq "$ptb" ]
+ check_err $? "the source of an ASM group got a Packet Too Big"
+ fi
+ [ "$(snmp6 "$RELAY" Ip6FragCreates)" -eq "$frag" ]
+ check_err $? "the relay fragmented an AMT datagram"
+ # amt_udp_xmit() clears ignore_df: an oversized datagram past the tunnel
+ # MTU check would count as a FragFail, not 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 "$desc"
+}
+
+# A second gateway in the same /64 and with the same port needs its own
+# Membership Query: one sent to the wrong gateway fails the nonce check.
+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"
+}
+
+# amtg and amtg2 hold the two tunnels the relay allows per /64 source. A
+# third gateway in that /64 must get no Query, so no tunnel and no multicast,
+# while one in another /64 does.
+test_source_cap()
+{
+ RET=0
+ # Each extra gateway gets a link of its own, as a gateway binds to its
+ # link.
+ ip -n "$RELAY" addr add "$DISC6B/64" dev br_gw
+ ip -n "$GATEWAY2" link add gw3_relay type veth peer name relay_gw3 \
+ netns "$RELAY"
+ ip -n "$GATEWAY2" link add gw4_relay type veth peer name relay_gw4 \
+ netns "$RELAY"
+ ip -n "$RELAY" link set relay_gw3 master br_gw up
+ ip -n "$RELAY" link set relay_gw4 master br_gw up
+ ip -n "$GATEWAY2" addr add "$GW3_6/64" dev gw3_relay
+ ip -n "$GATEWAY2" addr add "$GW4_6/64" dev gw4_relay
+ ip -n "$GATEWAY2" link set gw3_relay up
+ # The relay answers from its own address in the first /64: reach it here
+ # too.
+ ip -n "$GATEWAY2" route add 2001:db8:a::/64 dev gw3_relay metric 2048
+ ip -n "$GATEWAY2" link set gw4_relay up
+ ip -n "$GATEWAY2" link add amtg3 type amt mode gateway \
+ local "$GW3_6" discovery "$DISC6B" dev gw3_relay \
+ gateway_port 2268 relay_port 2268
+ ip -n "$GATEWAY2" link add amtg4 type amt mode gateway \
+ local "$GW4_6" discovery "$DISC6" dev gw4_relay \
+ gateway_port 2268 relay_port 2268
+ ip -n "$GATEWAY2" link set amtg3 up
+ ip -n "$GATEWAY2" link set amtg4 up
+ slowwait 10 remote_is "$RELAY6" "$GATEWAY2" amtg3
+ check_err $? "amtg3 remote is '$(amt_field "$GATEWAY2" amtg3 remote)'"
+ slowwait 10 remote_is "$RELAY6" "$GATEWAY2" amtg4
+ check_err $? "amtg4 remote is '$(amt_field "$GATEWAY2" amtg4 remote)'"
+ log_test "gateways in the same /64 and in another discover the relay"
+
+ test_forward "$GATEWAY2" \
+ UDP4-RECV:4000,ip-add-membership=239.0.0.1:amtg3 \
+ 4000 239.0.0.1 172.17.0.2 \
+ "IPv4 multicast to a gateway in another /64"
+ test_forward "$GATEWAY2" \
+ UDP4-RECV:4000,ip-add-membership=239.0.0.1:amtg4 \
+ 4000 239.0.0.1 172.17.0.2 \
+ "a third gateway in a /64 at its cap gets no tunnel" none
+ # amtg4 is refused every time it asks, and each refusal counts in
+ # rx_dropped, which test_local_source() reads.
+ ip -n "$GATEWAY2" link del amtg4
+}
+
+# The relay's General Queries leave through the stream device, not amtr.
+test_query_egress()
+{
+ local jqf='[.[].options.actions[0].stats.packets // empty] | add // 0'
+ local n4 n6
+
+ RET=0
+ n4=$(ip netns exec "$RELAY" tc -s -j filter show dev amtr egress \
+ pref 1 | jq "$jqf")
+ n6=$(ip netns exec "$RELAY" tc -s -j filter show dev amtr egress \
+ pref 2 | jq "$jqf")
+ [ "$n4" -eq 0 ]
+ check_err $? "$n4 IGMP packets left through amtr"
+ [ "$n6" -eq 0 ]
+ check_err $? "$n6 MLD queries left through amtr"
+ log_test "relay queries bypass the amt device"
+}
+
+# Why the last disc_answer() or local_src_answers() failed: DISC_WHY starts
+# with "relay:" or "harness:", DISC_ERR is tcpdump's own text.
+DISC_WHY=
+DISC_ERR=
+
+cap_text()
+{
+ tr '\n' ' ' < "$1" | cut -c1-300
+}
+
+cap_note()
+{
+ echo "${DISC_ERR:+ [tcpdump: $DISC_ERR]}"
+}
+
+# relay_state: the relay's neighbour entry for the gateway, its rx_dropped,
+# br_gw's MAC and the gateway's entry for the discovery address.
+relay_state()
+{
+ echo "relay: neigh $(ip -n "$RELAY" -6 neigh show "$GW6" dev br_gw |
+ tr '\n' ' ')rx_dropped $(rx_dropped)" \
+ "br_gw $(ip -n "$RELAY" -j link show br_gw |
+ jq -r '.[0].address')" \
+ "gateway: neigh $(ip -n "$GATEWAY" -6 neigh show "$DISC6" \
+ dev gw_relay | tr '\n' ' ')"
+}
+
+disc_msg()
+{
+ echo "$1${DISC_WHY:+ ($DISC_WHY)}$(cap_note)"
+}
+
+why()
+{
+ DISC_WHY="${DISC_WHY:+$DISC_WHY; }$*"
+}
+
+# disc_answer <dst> <filter>: send a Relay Discovery from the gateway to
+# [<dst>]:2268 and wait for gw_relay to see a packet matching <filter>. Returns
+# 0 if it did, 1 if none came, 2 if the harness failed (see DISC_WHY).
+disc_answer()
+{
+ local dst=$1 filter=$2 pid i rc st out cap
+ local to="UDP6-SENDTO:[$dst]:2268,sourceport=40000"
+
+ DISC_WHY=
+ DISC_ERR=
+ cap=$(mktemp)
+ ip netns exec "$GATEWAY" timeout 30 \
+ tcpdump -nni gw_relay -c 1 "$filter" > /dev/null 2> "$cap" &
+ pid=$!
+ # Nothing tcpdump reports means anything until it is listening.
+ for i in $(seq 50); do
+ grep -q "listening on" "$cap" && break
+ kill -0 "$pid" 2> /dev/null || break
+ sleep 0.1
+ done
+ if ! grep -q "listening on" "$cap"; then
+ if kill -0 "$pid" 2> /dev/null; then
+ kill "$pid" 2> /dev/null
+ wait "$pid" 2> /dev/null
+ why "harness: tcpdump never listened within 5s"
+ else
+ wait "$pid"
+ why "harness: tcpdump exited with status $?" \
+ "before listening"
+ fi
+ DISC_ERR=$(cap_text "$cap")
+ rm -f "$cap"
+ return 2
+ fi
+ # Type 1 (Relay Discovery), version 0, then a nonce.
+ for i in 1 2 3; do
+ if ! out=$(printf '\x01\x00\x00\x00\x12\x34\x56\x78' |
+ ip netns exec "$GATEWAY" socat -u - \
+ "$to,so-bindtodevice=gw_relay" 2>&1); then
+ rc=2
+ why "harness: socat failed to send to $dst:" \
+ "${out//$'\n'/ }"
+ fi
+ sleep 0.5
+ done
+ # Five seconds after the sends, whatever tcpdump's start-up took;
+ # timeout is only a backstop.
+ for i in $(seq 50); do
+ kill -0 "$pid" 2> /dev/null || break
+ sleep 0.1
+ done
+ if kill -0 "$pid" 2> /dev/null; then
+ kill "$pid" 2> /dev/null
+ wait "$pid" 2> /dev/null
+ why "relay: no Advertisement within 5s after the sends"
+ DISC_ERR=$(cap_text "$cap")
+ rm -f "$cap"
+ return "${rc:-1}"
+ fi
+ wait "$pid"
+ st=$?
+ DISC_ERR=$(cap_text "$cap")
+ rm -f "$cap"
+ case $st in
+ 0) return "${rc:-0}" ;;
+ *)
+ why "harness: tcpdump exited with status $st"
+ return 2
+ ;;
+ esac
+}
+
+# The relay's socket also receives a Discovery sent to ff02::1, which must not
+# be answered: a multicast address cannot be a source (RFC 4291 s2.7). The
+# unicast Discovery is the positive control.
+test_mcast_discovery()
+{
+ local rc
+
+ 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's status: 0 answered, 1 no reply, 2 the harness failed.
+ disc_answer "$DISC6" "udp and src port 2268 and dst port 40000"
+ rc=$?
+ [ $rc -eq 0 ] || why "$(relay_state)"
+ check_err $rc "$(disc_msg "no Advertisement for a unicast Discovery")"
+ disc_answer ff02::1 "udp and src port 2268 and dst port 40000"
+ rc=$?
+ [ $rc -eq 1 ]
+ check_err $? "$(disc_msg "ff02::1 status $rc, want 1")"
+ log_test "Discovery to ff02::1 is not answered"
+}
+
+# A namespace on the relay's bridge, holding the relay's address on its lo.
+setup_spoof()
+{
+ setup_ns SPOOF
+ # No DAD, as in setup_links(): a tentative fe80:: stalls ND.
+ ip netns exec "$SPOOF" sysctl -wq net.ipv6.conf.all.accept_dad=0 \
+ net.ipv6.conf.default.accept_dad=0
+ ip -n "$SPOOF" link add spoof_relay type veth peer name relay_spoof \
+ netns "$RELAY"
+ ip -n "$RELAY" link set relay_spoof master br_gw up
+ ip -n "$SPOOF" addr add 2001:db8:a::7/64 dev spoof_relay nodad
+ ip -n "$SPOOF" link set spoof_relay up
+ ip -n "$SPOOF" addr add "$RELAY6/128" dev lo nodad
+}
+
+rx_dropped()
+{
+ ip -n "$RELAY" -s -j link show amtr | jq -r '.[0].stats64.rx.dropped'
+}
+
+# local_src_answers <ns> <source> <socat options>: send three Relay Discoveries
+# from <ns>, with <source> as their source, to the relay's second address, and
+# set ANSWERS to the Advertisements seen on the relay's lo. Status 2: the
+# harness failed (see DISC_WHY).
+local_src_answers()
+{
+ local ns=$1 src=$2 opts=$3 pid i cap err rc=0 out
+ local to="UDP6-SENDTO:[$DISC6]:2268,bind=[$src]:40000$opts"
+
+ ANSWERS=0
+ DISC_WHY=
+ DISC_ERR=
+ cap=$(mktemp)
+ err=$(mktemp)
+ ip netns exec "$RELAY" timeout 30 tcpdump -nnl -i lo \
+ "udp and src port 2268 and dst port 40000" > "$cap" 2> "$err" &
+ pid=$!
+ for i in $(seq 50); do
+ grep -q "listening on" "$err" && break
+ kill -0 "$pid" 2> /dev/null || break
+ sleep 0.1
+ done
+ if ! grep -q "listening on" "$err"; then
+ if kill -0 "$pid" 2> /dev/null; then
+ kill "$pid" 2> /dev/null
+ wait "$pid" 2> /dev/null
+ why "harness: tcpdump never listened within 5s"
+ else
+ wait "$pid"
+ why "harness: tcpdump exited with status $?" \
+ "before listening"
+ fi
+ DISC_ERR=$(cap_text "$err")
+ rm -f "$cap" "$err"
+ return 2
+ fi
+ # Type 1 (Relay Discovery), version 0, then a nonce.
+ for i in 1 2 3; do
+ if ! out=$(printf '\x01\x00\x00\x00\x12\x34\x56\x78' |
+ ip netns exec "$ns" socat -u - "$to" 2>&1); then
+ rc=2
+ why "harness: socat failed to send from $src:" \
+ "${out//$'\n'/ }"
+ fi
+ sleep 0.3
+ done
+ sleep 1
+ # A capture that ended before the sends saw nothing.
+ if ! kill -0 "$pid" 2> /dev/null; then
+ rc=2
+ why "harness: tcpdump ended before the sends were done"
+ fi
+ kill "$pid" 2> /dev/null
+ wait "$pid" 2> /dev/null
+ ANSWERS=$(grep -c "UDP" "$cap")
+ DISC_ERR=$(cap_text "$err")
+ rm -f "$cap" "$err"
+ return "$rc"
+}
+
+# A Discovery from the wire with one of the relay's own addresses as its source
+# is not answered, or the Advertisement would go to this host over lo, which
+# IPv4 input prevents as a martian. SPOOF holds the address on its lo only and
+# sends from its veth; each drop counts in rx_dropped, which shows that the
+# Discovery arrived.
+# test_local_source <source> <description>
+test_local_source()
+{
+ local src=$1 desc=$2
+ local d0 d1 rc
+
+ RET=0
+ if ! command -v tcpdump > /dev/null; then
+ log_test_skip "$desc" "tcpdump not installed"
+ return
+ fi
+ d0=$(rx_dropped)
+ local_src_answers "$SPOOF" "$src" ",so-bindtodevice=spoof_relay"
+ rc=$?
+ check_err $rc "$(disc_msg "capture on lo failed")"
+ d1=$(rx_dropped)
+ [ "$ANSWERS" -eq 0 ]
+ check_err $? "the relay answered $ANSWERS times$(cap_note)"
+ [ $((d1 - d0)) -ge 3 ]
+ check_err $? "dropped $((d1 - d0)) of 3 Discoveries$(cap_note)"
+ log_test "$desc"
+}
+
+# The same address over lo is a gateway on the relay's host, and is answered.
+test_local_source_lo()
+{
+ local desc="Discovery over lo from the relay's own address is answered"
+ local rc
+
+ RET=0
+ if ! command -v tcpdump > /dev/null; then
+ log_test_skip "$desc" "tcpdump not installed"
+ return
+ fi
+ local_src_answers "$RELAY" "$RELAY6" ""
+ rc=$?
+ check_err $rc "$(disc_msg "capture on lo failed")"
+ [ "$ANSWERS" -ge 1 ]
+ check_err $? "a Discovery over lo was not answered$(cap_note)"
+ log_test "$desc"
+}
+
+# The subnet-router anycast address of the stream device's prefix, which the
+# relay holds once forwarding is on, is the relay's too.
+test_local_source_anycast()
+{
+ local desc="Discovery from the relay's anycast address is not answered"
+ local anycast=2001:db8:a:: key=20010db8000a00000000000000000000
+
+ RET=0
+ ip netns exec "$RELAY" sysctl -wq net.ipv6.conf.br_gw.forwarding=1
+ # Fails, not skips, if the relay does not hold the address.
+ ip netns exec "$RELAY" grep -q "$key" /proc/net/anycast6
+ check_err $? "the relay does not hold $anycast as an anycast address"
+ ip -n "$SPOOF" addr add "$anycast/128" dev lo nodad
+ if [ "$RET" -eq 0 ]; then
+ test_local_source "$anycast" "$desc"
+ else
+ log_test "$desc"
+ fi
+ ip netns exec "$RELAY" sysctl -wq net.ipv6.conf.br_gw.forwarding=0
+}
+
+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 tc smcrouted smcroutectl iptables ip6tables bridge; 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_source_cap
+test_tmtu "$SSM6" ptb "IPv6 payload above the tunnel MTU, SSM group"
+test_tmtu ff0e::5:6 none "IPv6 payload above the tunnel MTU, ASM group"
+test_mcast_discovery
+setup_spoof
+test_local_source "$RELAY6" \
+ "Discovery from the relay's own address is not answered"
+test_local_source_lo
+test_local_source_anycast
+test_down_up
+test_query_egress
+
+exit "$EXIT_STATUS"
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH net-next v6 12/12] selftests: net: add amt_gw_v6.sh for the IPv6 netlink attributes
2026-12-02 4:31 [PATCH net-next v6 00/12] amt: add an IPv6 outer transport Omar Ramadan
` (10 preceding siblings ...)
2026-12-02 4:31 ` [PATCH net-next v6 11/12] selftests: net: add amt_v6.sh for an IPv6 outer transport Omar Ramadan
@ 2026-12-02 4:32 ` Omar Ramadan
11 siblings, 0 replies; 13+ messages in thread
From: Omar Ramadan @ 2026-12-02 4:32 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,
Willem de Bruijn, David Ahern, Ido Schimmel
amt_v6.sh checks the data plane with valid attributes only. The
link-creation rules for IFLA_AMT_LOCAL_IP6 and IFLA_AMT_DISCOVERY_IP6
are not exercised.
This adds a companion without a data plane: one netns and one dummy
device. 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,
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 is matched on its
extack message, so a rule that fails for the wrong reason is not a pass.
The unspecified and multicast cases need iproute2 to pass those
addresses on as given, which it does: ip/iplink_amt.c tests
is_addrtype_inet(), true for "::" and multicast, and the IPv6 branch of
the iproute2 patch adds its attribute without a test.
Not covered, as iproute2 cannot express them: both `discovery <v4>` and
`discovery <v6>`, or both `local` forms, in one command, and a 16-byte
IFLA_AMT_LOCAL_IP or IFLA_AMT_DISCOVERY_IP.
The probe skips on an iproute2 without IPv6 AMT support: one that
rejects the literal or does not know amt, or that packs the 16-byte
literal into the IPv4 attribute. This kernel refuses that with "binary
attribute size out of range", logged as a passing test before the skip;
a kernel without that rule truncates it to an IPv4 address (`discovery
2001:db8:a::2` reads back as 32.1.13.184), and the probe skips on that
readback only. It also skips on a kernel that ignores the attributes
("Local attribute is required"), has no amt ("Unknown device type") or
no IPv6. Any other failure to create the probe link, and any other
readback without a colon, is a FAIL.
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 | 205 +++++++++++++++++++++++
2 files changed, 206 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 a31f19e9f..bd6c08d11 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..8f18df024
--- /dev/null
+++ b/tools/testing/selftests/net/amt_gw_v6.sh
@@ -0,0 +1,205 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Netlink coverage for IFLA_AMT_LOCAL_IP6 and IFLA_AMT_DISCOVERY_IP6 and the
+# rules that validate them; amt_v6.sh covers the data plane. Not covered, as
+# iproute2 cannot express them: `discovery` or `local` in both families in one
+# command, and a 16-byte IFLA_AMT_LOCAL_IP or IFLA_AMT_DISCOVERY_IP.
+
+source lib.sh
+
+readonly V6_LOCAL="2001:db8:a::1"
+readonly V6_DISC="2001:db8:a::2"
+# What an iproute2 that packs the literal into a 4-byte attribute reads back.
+readonly TRUNC_DISC="32.1.13.184"
+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"
+}
+
+# Probe on the readback, not only the exit code: an iproute2 without the IPv6
+# attributes may pack the literal into the 4-byte attribute, which this kernel
+# refuses and an older one truncates. Skip only for missing IPv6 AMT support.
+probe_v6_gateway()
+{
+ local got
+
+ if ! ip link help 2>&1 | grep -q amt; then
+ echo "SKIP: missing amt support in iproute2"
+ exit "$ksft_skip"
+ fi
+
+ if ! add_amt amtprobe mode gateway local "$V6_LOCAL" \
+ discovery "$V6_DISC"; then
+ case "$ADD_ERR" in
+ *"binary attribute size out of range"*)
+ # An older iproute2: the exact attribute length refused
+ # the 16 bytes.
+ 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"*|*"Unknown device type"*)
+ 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
+ # Only a truncated literal is a skip; any other readback is a
+ # FAIL.
+ if [ "$got" != "$TRUNC_DISC" ]; then
+ echo "FAIL: discovery 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: only read back, never used to send.
+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"
+# iproute2 sends :: and multicast as given, so these reach amt_newlink(); the
+# extack match in expect_reject() is what pins the kernel rule as the cause.
+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"
^ permalink raw reply related [flat|nested] 13+ messages in thread