mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Omar Ramadan <omar@blockcast.net>
To: Taehee Yoo <ap420073@gmail.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Shuah Khan <shuah@kernel.org>
Cc: Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Willem de Bruijn <willemb@google.com>,
	David Ahern <dsahern@kernel.org>,
	Ido Schimmel <idosch@nvidia.com>
Subject: [PATCH net-next v6 02/12] amt: send the Relay Advertisement over IPv6
Date: Wed,  2 Dec 2026 04:31:50 +0000	[thread overview]
Message-ID: <20261202043200.286260-3-omar@blockcast.net> (raw)
In-Reply-To: <20261202043200.286260-1-omar@blockcast.net>

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,

  parent reply	other threads:[~2026-12-02  4:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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 ` [PATCH net-next v6 04/12] amt: send the Membership Query over IPv6 Omar Ramadan
2026-12-02  4:31 ` [PATCH net-next v6 05/12] amt: forward multicast data " 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
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 ` [PATCH net-next v6 08/12] amt: receive " Omar Ramadan
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 ` [PATCH net-next v6 10/12] MAINTAINERS: amt: cover the amt headers and selftests 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202043200.286260-3-omar@blockcast.net \
    --to=omar@blockcast.net \
    --cc=andrew+netdev@lunn.ch \
    --cc=ap420073@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®