From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796020974; b=ceVonLo10QRZ69O8cUiYl0klljSY7IeIdkOBAikcC08OUKxp8tf8Vx+3uXgfMuGBREfS sDCEjBmPBx30qLNb88LIOmoQAxamWZtSOtpY+so2TGGh0Ch93cNSHXSUBj+WzTGg0Qfnr GY5yeeSSPUoUV0b/lIuWjQpvDT/BrDIZERz3fGUUP9cVfPPMbr5Gw51dJEAC3oyX0GH9Z DZ/HAbYR05AtWRdPSCS6FdQeYz+nbXOVCOqKAcL4MWhmr3I8oKCloO9u7lwfgwDEbfJXT j9lYFxOhxq/avde3WrF0BfWRmlTU9Q3B7NBBYKjfnSq464uplBSsUwINNVKqb963PmA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796020974; 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=DChxuWi1QfV4n8QP1UzjQQITjBXMyISv+4oZQzrmx/Y=; b=OEAvqgC/9FxgBizdLpsDiOSrCLVBdy8eASCQ5LmWPHSpEgArD5RJlUuF+AsZOWZh5zzw vagMnk1khuGM+AFVWJ29AGtKy6g/Yev4JFOQtgedorFx4GeUStjSzQlcbMzceTY9cn/xQ bYqjpg6VnbvcUyKDZ+raWtzPsIhYPpFSTMunGPp06y6lK5OjpXzgRHOfU/4LGAjkwPl1e wfNzq9sf/AR+B1ynzS63j8xOUcqjP+X3TVs6+/NRwy4NN4JIWf5j/AySGFPUNsVHPHu4v OAR97sQRSSSCkP63r4iurilgZxO1HSPFT83kxb+zyI/e7shS8A5nucvuUAq9k98fTHw== 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=j3c0mxwc; arc=none smtp.remote-ip=74.125.82.177 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (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 2920C606A32F for ; Mon, 30 Nov 2026 06:42:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2920C606A32F 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=j3c0mxwc Received: by mail-dy1-f177.google.com with SMTP id 5a478bee46e88-33bf40b0c8bso2843801eec.0 for ; Sun, 29 Nov 2026 22:42:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blockcast.net; s=google; t=1796020973; x=1796625773; 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=DChxuWi1QfV4n8QP1UzjQQITjBXMyISv+4oZQzrmx/Y=; b=j3c0mxwcggOJZs8S+DFvuhFg2eKfAauLhtbO4Ivh2gxVwOlqGtiyRKIKzCihILQz9m YTc5PeOqjz7BbF4TjkEWHFk2wH+JgwvaJDAeRQwBtuW5OFtF2T/dmPwyy6A6cc4Kg8xX YGDF3qIvkjW1rvCj5y0qBNL5XxoOixiPpF6GvLuJ7Jsu/lZioaxQnW0+BPLuM1Sp9fL7 2qD5YN9P5qNOgyKQSXfH/mFMk+MH+KTg8STP/iNKUo/Vg2JdSf+tJ14RxCuKyZgZg64P TeKCWVOUk8o7URcCcc+6f+z9ggv7x36ApnjwxK4wgxjQ+biyqnd6cFr6j4c6HF8M0eCX 84Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796020973; x=1796625773; 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=DChxuWi1QfV4n8QP1UzjQQITjBXMyISv+4oZQzrmx/Y=; b=ePhZIKPRCy8mWdndda+ACFUTTxUyFDXWt8vOW/+ZvonU2QkDpcQGAi8Cf7bvM7emY0 OSf1ZzrP96kgtJ01GMXQiqOsyPip0po5NDMBPM7fRqNU0cuS29q1yam7SR/tEgLOTV/5 XLwH10GJg2NGZzKbFuaV6dAysC9iDajy+4awX1aYNVaN1/zO2fwRLImdaVzXhAhsBsIs oBuR5G02PnC7nlzlLyLTFZ+4zJ9Lv0wk5EwZ9Bx+w3tjkrHBTbedg+dvYFWOCyN2BMbR VYhH7F1tAdf3LziYyjqV8Y8CFbYTaKm8iOhexA/pYeWHDjvoQy2XzutY3CtbklrTs8kd e0eg== X-Forwarded-Encrypted: i=1; AL+hErHb0rnGOZc+hPoV9CP/+pO/q3C7dUbiVVu4NrPS8aCjVlp8oPDHoCacvYjSMEmTgyo6cUs69Rw=@vger.kernel.org X-Gm-Message-State: APuU4Z9JP4JQwQcmT9Kob99WWqiZNRL5Cr/DAOPT2BXYlBRMQ2mKzwiy +719NtR7B4NNjFSJqkP966n8e3U9q6Qvvz6QE+P44Icxn26ou/w5qmB47VWdEQnIL6c= X-Gm-Gg: AZFdTZev03ORHIKglyW0E7XrBvJxp1mbflwSlXxMXT8GcnJ3APYexvyPShSFo7sc4sT oSRpOxkUegCHvwAUW6NmCVgIg5ldER6oMNVW79gUL1VcV7W1y/+HMJK9oenniEtW4/ThPdbY3Je fYUoVrG1kBhcYxTdPdgQlP7oQE9fk/X61ue5+cxgSAU9SSjfaJCxiL8C4RdLxqARrAT9ISZx/6a G5Ata6BlYVQLk0Bn6/W8afbvjdQSjyyPgvOwBRCo8a+TB58fB6uxnzVevMo8YlIBNNBWk6lNupW KascYEdCW4zZaiPJBZvzZiudHbFUtZ3yR1KdgzIkHY6prHULQ6v1sGOgZVvnBReGX/GMpPzP782 HcOq2W9ZFLKRlcD53njYnapPoPWs9RWiLG7HtR95CxWnhpaRdVDUpS9fiSLhLQT3jwmGize+HOs vmBQVCH4uK9XGFS8hhSlniPhBo/kztb6+ANIWjZcfNyTEFuPhsQftpfVE9dqvxa2LVfzlKKonaU rTr1WWkKctDKQ5XI3CiblFyQYwBJXi+SUN3fFop2K/SIGO2ZiZW7JX9p5wdLSY80cFDWDSG2G4p Osld0iJFBx4dn7CfeSe9TZqZnKpcq5GajFlPRnKRUQBdbOTm+q2eA5azvoeO4vl9INiV3HD1z7B bzumoOs4iz2MfS/l9SncCqCYn1MM= X-Received: by 2002:a05:7301:152f:b0:381:c532:3d88 with SMTP id 5a478bee46e88-3857093c38bmr36126991eec.23.1796020973225; Sun, 29 Nov 2026 22:42:53 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 22:42:52 -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 01/12] amt: create an AF_INET6 encapsulation socket for an IPv6 outer address Date: Mon, 30 Nov 2026 06:42:38 +0000 Message-ID: <20261130064249.1874523-2-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: netdev@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 The amt device binds one AF_INET UDP socket on the relay port, so a relay and its gateways can only talk AMT over IPv4. RFC 7450 defines the protocol over either IP version: the Relay Advertisement carries an IPv4 or an IPv6 relay address, and s5.2 selects the form from the IP version of the outer header, so an IPv6-only access network needs an IPv6 outer transport to reach the relay at all. Add the outer IPv6 local address to struct amt_dev, and amt_v6(), which reports the device's outer family from it. amt_create_sock() binds an AF_INET6 socket for an IPv6 device. The socket sends and verifies the UDP checksum, which RFC 8200 s8.1 makes mandatory over IPv6, and it is V6ONLY, so that it does not also claim the IPv4 wildcard port, which an IPv4 amt device in the same netns may hold. The socket is also bound to the underlying link, IFLA_AMT_LINK. The IPv4 paths pass that link as the output interface, and an IPv4 route lookup then only uses routes through it. An IPv6 lookup that has a source address, as every AMT send does, treats the output interface as a preference unless the socket is bound to a device, so without the binding the outer IPv6 traffic could leave through another link while the device's MTU and headroom are derived from this one. The binding also keeps packets that arrive on other links away from the socket. A link-local address is unique only on its link, and relay tunnels are keyed on the gateway's address, so two gateways on different links with the same link-local address would otherwise share a tunnel, and the replies would go out the wrong link. The new socket also hands ICMPv6 errors to amt_err_lookup(). This relies on amt_parse_type() pulling the AMT header behind the transport header, as "amt: pull the AMT header behind the transport header in amt_parse_type()" in net makes it do, since on the error path skb->data points at the quoted IPv6 header. Nothing sets local_ipv6 yet. The netlink attribute that does is added at the end of this series, once every path can use it, so there is no functional change here. Assisted-by: LLM Signed-off-by: Omar Ramadan --- drivers/net/amt.c | 36 ++++++++++++++++++++++++++++++------ include/net/amt.h | 2 ++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index b145ed3ca..3f3205d2d 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -90,6 +90,14 @@ static struct in6_addr mld2_all_node = MLD2_ALL_NODE_INIT; static struct mld2_grec mldv2_zero_grec; #endif +/* The outer transport family is fixed when the link is created: an IPv6 + * local address selects IPv6, otherwise the device runs over IPv4. + */ +static bool amt_v6(const struct amt_dev *amt) +{ + return IS_ENABLED(CONFIG_IPV6) && !ipv6_addr_any(&amt->local_ipv6); +} + static void __amt_source_gc_work(void) { struct amt_source_node *snode; @@ -3310,19 +3318,35 @@ 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 :: by the memset, and to the underlying link: a + * bound socket makes every IPv6 route lookup strict about + * the output interface, as the IPv4 lookup is, and receives + * from that link only, where a link-local peer is unique. + * V6ONLY keeps the socket off the IPv4 wildcard, so an IPv4 + * amt device can use the same port in the netns. The UDP + * checksum is mandatory over IPv6. + */ + udp_conf.family = AF_INET6; + udp_conf.bind_ifindex = amt->stream_dev->ifindex; + udp_conf.use_udp6_tx_checksums = true; + udp_conf.use_udp6_rx_checksums = true; + udp_conf.ipv6_v6only = true; + } else { + udp_conf.family = AF_INET; + udp_conf.local_ip.s_addr = htonl(INADDR_ANY); + } - udp_conf.local_udp_port = port; + udp_conf.local_udp_port = amt->relay_port; - err = udp_sock_create(net, &udp_conf, &sock); + err = udp_sock_create(amt->net, &udp_conf, &sock); if (err < 0) return ERR_PTR(err); @@ -3334,7 +3358,7 @@ static int amt_socket_create(struct amt_dev *amt) struct udp_tunnel_sock_cfg tunnel_cfg; struct sock *sk; - sk = amt_create_sock(amt->net, amt->relay_port); + sk = amt_create_sock(amt); if (IS_ERR(sk)) return PTR_ERR(sk); diff --git a/include/net/amt.h b/include/net/amt.h index 9ba097127..ca35782f8 100644 --- a/include/net/amt.h +++ b/include/net/amt.h @@ -361,6 +361,8 @@ struct amt_dev { __be16 gw_port; /* Outer local ip */ __be32 local_ip; + /* Outer local IPv6 address, :: unless the outer transport is IPv6 */ + struct in6_addr local_ipv6; /* Outer remote ip */ __be32 remote_ip; /* Outer discovery ip */