Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796020976; b=i6L60lJ+BrVT1YT4NWByyXLh6yz0QYIr6uthOGewyu21uGWQt+FtC2x/GUoyaWl4CUap 1xVPa9UWHGnRIqYESG9NEwQfVlca4t6n5ZEGu0zOCSkBPLDkkpqFmAGLIO6dzSQS459G5 qVnun4BVQ3lHKQ6ubFbAUU+dwnHU9wtm0hSwnhEe5ZLH9Yl6XM3tDUOD6Ke3gliXkusjJ SyjF8VkUUBozt7apmnfejB3BtSqKFcCpL2wIYzaZj5dzyP+jDObJzJ23sb37I68Nb62YL xwLpXEjvNfWLbnz9shEF0gXrjMPeVvij/HGBk+1YPy4RM7/7YCPq97jtLvlyMGGQQig== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796020976; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=rLsQ/GlDzGOb8CaVAi+lRi51pZAWGSStX7fuTRtzazk=; b=fcwp0qVmR9jTi5J8nd/k4bOv++K4rpTcmXTEJX1z0eJ2LMKcf+rzqcAGAvXu4WGwrYdZ ysU0sNIvBFLOBV8XscIQPL+57ClP3A3xHCd6zbFh/+Hmoan+UbCCaOzYoigeOi+FujwMB jZP+MEOGIXaD7/MSA1Tby0EZmxf6r8zuZ1KoUOmh/yvPVwjpvdTMH/ulZA5/EMlh56mLH Jz2YFYvOQH3Czw205t0ThC2ikMO2ae+VTNa9bIWOf2ngGso7xQaSrAI73WR0n4T5U3S1+ QsIZ2FQZ8q5yqTM/MvPKUBrT9z8SHzWg6MP6ckhU6qJT4EqtFRvJZOCdpOsb0KN1tXA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=blockcast.net; spf=pass smtp.mailfrom=blockcast.net; dkim=pass header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b=jCQfCNtp; arc=none smtp.remote-ip=74.125.82.180 Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2D83606A33C for ; Mon, 30 Nov 2026 06:42:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E2D83606A33C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=blockcast.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=blockcast.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b=jCQfCNtp Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-38699cf08dfso13634142eec.1 for ; Sun, 29 Nov 2026 22:42:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blockcast.net; s=google; t=1796020975; x=1796625775; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=rLsQ/GlDzGOb8CaVAi+lRi51pZAWGSStX7fuTRtzazk=; b=jCQfCNtpAvkh+m/7PuJlF2cA4GBzYq48/craCksHCSfjVaUH/KNg/F80eYTMMCReiC NibbdG2pbfG5vYmttr7LKgGWAKvEV4VdW5JSNoYNXB/xJfaFhM8a/r8k/7OQqgNkVOpU SAK0h2R9BN8MPB3DclOyEPN44eS/ctsX2FajwzWT6DvkZkXkKJAf28ouxpPuDbFY4xy8 YvYfmzuUlsYqdrxuEcKyVNwuvJNwPw09/Y2fMrsiiJWP5iDsXL89mTg2uh7eCVzV2uhA 8eEemE2hwOQhLdUNDRv1s6N41SWD/n3qdB1b/JpsuMnbAnBbiQ1jY1yP7l+k9I5Pn5Mn R4jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796020975; x=1796625775; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=rLsQ/GlDzGOb8CaVAi+lRi51pZAWGSStX7fuTRtzazk=; b=RvIPkWOAYenQke/OYsrqhxoz0z6CFPopeSPS/umo8UqiabId0JQQgkE7jMMWVhwTvx PRmnIcUSAMzfcBjFH/rcir42LIbJ9YVejAZjlR37mv2O07VJoPy51HvwMvvTb0osE/Ju OmuzBCnSK3o4uqgy0YvCNzzF4kqEZS0EXUDKENLy78F26fOns02hi+hxIkWY6CuHvYcl 2Rrr9U18Y/DRuUEToVFcNbpsootqtB64KtTwKpJIDazSYe9+d3f/b0OlsexCfEpZVKuu CMp7MU54WC3WXl+Q9LjuKSoSSqlspvDb7Lt+96srGnLg5Ca9i658Zy8ArF2bmEouc9YH k7/Q== X-Forwarded-Encrypted: i=1; AL+hErHtYXPqxDTyQtVbjBzwexg4RCNMs2v1Y3RNw0LT98QRRPKKFCcn5GSSiuR5NM1vtLMF2gKu/Yd2I6sMzdjgkVY=@vger.kernel.org X-Gm-Message-State: APuU4Z9F/sGK1IMCq4WtVjBRxe3cj0eC8EHVYax9BkKexmTImoUwGnto 13W6e25MWBQ0ynROZbAhMgmO0DPRukwGeP7qSZhc0SgLHlf9Z58aeePdTORT4dTGooo= X-Gm-Gg: AZFdTZfR02haCKA3r8XlloIoff+LQQ6AOmtRldkNodx7TG7/E2pPGGT43SxSEnEOPYq 0B7m8/iILlGGWmNN22l7WiUy3yYqAsNXVnPNeZnXdVC2IjZWGLeyOYPegqvVnpAWlF5fxy8JrnI qJ35kgwHxV+N8TrNJS+ERuJ0ywmoLkQ02T872a5OYHws2Eo38YW8Rs7B7kIle4nHkeLewWLERQy QXsayrdrthgYcW7rKF/Ow0jcF1omPgYrLjiBSQJcWrCIEQ1hONc5I+NjGE+kaSkOHDyR0z2OGEi eZDb2p2p6bzo5OTU1ZZFRM6ljAIgqBI/g48cxoPi9m3n2mkwCr/FgRIUyJ3Hgx2u3z62VcacyyB B7X3wQon2KnMP/Uqzyfd6C1NcmKhQ1jbQtQVTVMPRn3cdM4ql8f/EPDqCNNnoq20Cpf0ZKWd7Z9 2MZ2FCyoMEZ1p4lpfhFmOMU2mihpZ/nFwAmVc/xVU4BFw0QY7TQNQcA4JMCi9a5FRZaC23PfR62 8LfwhDcCTkvOW1fhY6vW9AqNoZHk03LGDQxJ3KmtwiubLx2Xf+NyC4cEmH5eGelaLNzqUMDzT+t oE5wBJzOQvyKqi4YubLj+oKt/xRQaC7Yimo5ru61IBednp2rCSm52QgOC+4pn4y8poF8IM2ZgHh 9W7uZQeNGHMGwwpjTSnGQCqcePgY= X-Received: by 2002:a05:693c:8843:b0:386:b526:251e with SMTP id 5a478bee46e88-386b52637c1mr20853173eec.10.1796020974922; Sun, 29 Nov 2026 22:42:54 -0800 (PST) Received: from devbox.ts.blockcast.net ([2602:f74d:1::32]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385672c6f31sm94744995eec.15.2026.11.29.22.42.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 22:42:54 -0800 (PST) From: Omar Ramadan To: Taehee Yoo , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: Simon Horman , netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Willem de Bruijn Subject: [PATCH net-next v5 02/12] amt: send the Relay Advertisement over IPv6 Date: Mon, 30 Nov 2026 06:42:39 +0000 Message-ID: <20261130064249.1874523-3-omar@blockcast.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130064249.1874523-1-omar@blockcast.net> References: <20261130064249.1874523-1-omar@blockcast.net> X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A gateway finds its relay with a Relay Discovery, and the relay answers with a Relay Advertisement carrying the address the gateway should use from then on. RFC 7450 s5.1.2 defines two forms of the Advertisement: the same fixed header and nonce followed by either a 4-byte IPv4 or a 16-byte IPv6 relay address, and s5.2 selects the form from the IP version of the outer header rather than from a field in the message. An amt relay on an IPv6 outer transport therefore has to answer with the 24-byte IPv6 form. Add struct amt_header_advertisement_v6 for that form and amt_send_advertisement_v6(), which fills it on the stack and sends it with a new amt_send_ctrl_v6() helper. The helper routes with ip6_dst_lookup_flow() through amt_route6(), which the later IPv6 senders share, and sends with udp_tunnel6_xmit_skb(), which builds the UDP and IPv6 headers and fills in the UDP checksum that RFC 8200 s8.1 makes mandatory over IPv6. Like the IPv4 control messages, it marks the skb TC_PRIO_CONTROL, uses AMT_TOS as the traffic class and passes no netdev, so control traffic stays out of the amt device's tunnel stats. Passing no netdev also means that a drop after the hand-off to IPv6 output, in netfilter, in neighbour resolution or by the qdisc, is not counted in tx_errors, whereas the IPv4 senders count an ip_local_out() error; only a failed route lookup or allocation is counted. amt_discovery_handler() answers an IPv6 device's Discovery with the IPv6 form, sent back to the outer source of the Discovery. RFC 7450 s5.1.2 makes the source of the Advertisement the destination of the Discovery, the Relay Discovery Address, so amt_send_ctrl_v6() and amt_route6() take the source address from their caller. The socket is bound to ::, so a Discovery sent to an anycast or secondary address reaches the relay, and a gateway accepts only an Advertisement whose source is the address it sent the Discovery to; answering from local_ipv6 would leave such a gateway stuck in discovery. The relay address carried in the message stays local_ipv6. The same socket also receives a Discovery sent to a multicast group the host has joined, such as ff02::1, and a multicast address may not be a source (RFC 4291 s2.7), so a Discovery with a multicast destination is dropped rather than answered by every relay on the link with an invalid packet. The handler copies both outer addresses by value after its last pskb_may_pull(), and sending does not pull the received skb. The IPv4 Advertisement has always been sent from local_ip, so an IPv4 gateway that discovers the relay through another of its addresses drops the reply. That is left as it is: changing the source of an existing IPv4 relay's replies is a fix of its own for net, and nothing in this series depends on it. amt_v6() is still false for every device, so there is no functional change yet. Assisted-by: LLM Signed-off-by: Omar Ramadan --- drivers/net/amt.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++ include/net/amt.h | 21 +++++++++ 2 files changed, 136 insertions(+) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 3f3205d2d..52ccaca08 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -708,6 +708,80 @@ static void __amt_update_relay_status(struct amt_tunnel_list *tunnel, tunnel->status = status; } +static struct dst_entry *amt_route6(struct amt_dev *amt, struct sock *sk, + const struct in6_addr *saddr, + const struct in6_addr *daddr, + __be16 sport, __be16 dport) +{ + struct flowi6 fl6; + + memset(&fl6, 0, sizeof(fl6)); + fl6.flowi6_oif = amt->stream_dev->ifindex; + fl6.flowi6_proto = IPPROTO_UDP; + fl6.daddr = *daddr; + fl6.saddr = *saddr; + fl6.fl6_dport = dport; + fl6.fl6_sport = sport; + /* The packet carries AMT_TOS, so route on it too: a policy rule + * that matches the DSCP must see the same value. + */ + fl6.flowlabel = ip6_make_flowinfo(AMT_TOS, 0); + + return ip6_dst_lookup_flow(amt->net, sk, &fl6, NULL); +} + +/* Send an AMT control message over the IPv6 outer transport from @saddr. + * udp_tunnel6_xmit_skb() adds the UDP and IPv6 headers, including the UDP + * checksum that IPv6 requires. Returns 0 once the message is handed to the + * IPv6 stack. + */ +static int amt_send_ctrl_v6(struct amt_dev *amt, const struct in6_addr *saddr, + const struct in6_addr *daddr, + __be16 sport, __be16 dport, + const void *msg, unsigned int len) +{ + struct dst_entry *dst; + struct sk_buff *skb; + struct sock *sk; + int hlen, err; + + rcu_read_lock(); + sk = rcu_dereference(amt->sk); + if (!sk || !netif_running(amt->stream_dev) || + !netif_running(amt->dev)) { + err = -ENETDOWN; + goto out; + } + + dst = amt_route6(amt, sk, saddr, daddr, sport, dport); + if (IS_ERR(dst)) { + DEV_STATS_INC(amt->dev, tx_errors); + err = PTR_ERR(dst); + goto out; + } + + hlen = LL_RESERVED_SPACE(amt->dev) + sizeof(struct ipv6hdr) + + sizeof(struct udphdr); + skb = netdev_alloc_skb_ip_align(amt->dev, hlen + len + + amt->dev->needed_tailroom); + if (!skb) { + dst_release(dst); + DEV_STATS_INC(amt->dev, tx_errors); + err = -ENOMEM; + goto out; + } + + skb_reserve(skb, hlen); + skb_put_data(skb, msg, len); + skb->priority = TC_PRIO_CONTROL; + udp_tunnel6_xmit_skb(dst, sk, skb, NULL, saddr, daddr, AMT_TOS, + ip6_dst_hoplimit(dst), 0, sport, dport, false, 0); + err = 0; +out: + rcu_read_unlock(); + return err; +} + static void amt_send_discovery(struct amt_dev *amt) { struct amt_header_discovery *amtd; @@ -3010,6 +3084,24 @@ out: rcu_read_unlock(); } +/* The IPv6 form of amt_send_advertisement(), carrying the relay's IPv6 + * address. It is sent from @saddr, the address the Discovery was sent to. + */ +static void amt_send_advertisement_v6(struct amt_dev *amt, __be32 nonce, + const struct in6_addr *saddr, + const struct in6_addr *daddr, + __be16 dport) +{ + struct amt_header_advertisement_v6 amta = { + .type = AMT_MSG_ADVERTISEMENT, + .nonce = nonce, + .ip6 = amt->local_ipv6, + }; + + amt_send_ctrl_v6(amt, saddr, daddr, amt->relay_port, dport, + &amta, sizeof(amta)); +} + static bool amt_discovery_handler(struct amt_dev *amt, struct sk_buff *skb) { struct amt_header_discovery *amtd; @@ -3026,6 +3118,29 @@ static bool amt_discovery_handler(struct amt_dev *amt, struct sk_buff *skb) if (amtd->reserved || amtd->version) return true; + /* The Advertisement takes the form of the outer IP version, and + * RFC 7450 s5.1.2 sources it from the address the Discovery was + * sent to, which may be an anycast Relay Discovery Address rather + * than local_ipv6. + */ + if (amt_v6(amt)) { + struct in6_addr saddr = ipv6_hdr(skb)->saddr; + struct in6_addr daddr = ipv6_hdr(skb)->daddr; + + /* The socket bound to :: also receives a Discovery sent to + * a group, and a multicast address can never be a source + * (RFC 4291 s2.7), so such a Discovery is not answered. Nor + * is one from ::, which has nowhere to be sent. + */ + if (ipv6_addr_is_multicast(&daddr) || + ipv6_addr_any(&saddr)) + return true; + + amt_send_advertisement_v6(amt, amtd->nonce, &daddr, &saddr, + udph->source); + return false; + } + amt_send_advertisement(amt, amtd->nonce, iph->saddr, udph->source); return false; diff --git a/include/net/amt.h b/include/net/amt.h index ca35782f8..52d77bc6b 100644 --- a/include/net/amt.h +++ b/include/net/amt.h @@ -133,6 +133,27 @@ struct amt_header_advertisement { __be32 ip4; } __packed; +/* The IPv6 form of the Relay Advertisement (RFC 7450 s5.1.2): the same + * header and nonce, followed by a 16-byte relay address. s5.2 selects the + * form from the IP version of the outer header, not from a field in the + * message, so it is a type of its own. + */ +struct amt_header_advertisement_v6 { +#if defined(__LITTLE_ENDIAN_BITFIELD) + u32 type:4, + version:4, + reserved:24; +#elif defined(__BIG_ENDIAN_BITFIELD) + u32 version:4, + type:4, + reserved:24; +#else +#error "Please fix " +#endif + __be32 nonce; + struct in6_addr ip6; +} __packed; + struct amt_header_request { #if defined(__LITTLE_ENDIAN_BITFIELD) u32 type:4,