Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796185939; b=ONjaB5FG5Mleb7A3WPWjAz5HphqyWouiBJW3P6mFqTP5mLcFvKnZxi/WLOpU1B0TX68u 26KCDFTbWEQnIJRS3T2DUMWJdQYp4EmjxcjdWTIb4tQsWFkOxvYBU3OY8QJ7zfjjfgcbM iiFWHwePtcVUIQSsN/exrDey+s1TouLTQLiuNtSiEJrhE1JKNuXsDrUSNYCXOvoVBsk7e yhSuk6NKMRn0Yml+dlmVOaPJ789LBz8nIXF4erPbV9ghFK2ZsrfFB9ie6tor6aqR+fvU1 J/vZffl+jbecD1zKX2forJiviJnGFUEieXhwNXpfZwfI+1l+Zmec6ZV9+EEyLRSFrfQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796185939; 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=fbTC0W/sT9uJOupkBQJxZV+XiZ2dL+NX85EJNWq4Ra4=; b=DiBwWqxIIZgbNYqbjEEqYa4g2PMU/EWZJcIuNH64uI6QUM1B/zFSGagSA/6ymm0lCO59 IeaOTIRtjhuPUMyiznkNeI3kwlUURUfFtdfXTGTAXgHBoO+r94v5UXFDFJOhvsNjKV7LO EBna8+ukzLC1Ieot4edTDKYTVANa8WSaalTrmfK9Pcq3IBX62Nu0d32WJvKaCI5rSM4gV EXVNTzXALch839noRUEw14X3WzZGKyAS0k04lC4D/Cg2B3wLmjm6GEQG3vtOtKS3JtxQ1 fIYAZ0QelePkI4E5vLIPk28KLNJHEkynHBR2Uuw+OGxUgUZeEKh0ZFDX0fvAMv0OrBg== 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=TU22Q88P; arc=none smtp.remote-ip=74.125.82.178 Received: from mail-dy1-f178.google.com (mail-dy1-f178.google.com [74.125.82.178]) (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 695C3606A6B0 for ; Wed, 2 Dec 2026 04:32:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 695C3606A6B0 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=TU22Q88P Received: by mail-dy1-f178.google.com with SMTP id 5a478bee46e88-3866a784546so17532564eec.0 for ; Tue, 01 Dec 2026 20:32:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blockcast.net; s=google; t=1796185939; x=1796790739; 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=fbTC0W/sT9uJOupkBQJxZV+XiZ2dL+NX85EJNWq4Ra4=; b=TU22Q88P+QhfaOXbqzHpIpEIG+8CScr9OznXs6T/7Fj72uN8bsjMNf3AIHEbzviNrV D48jeud3lNpkZy0ByYnz2wb/V+LxMEjFLRrijG5lXuuA/ISrCGqQXvHAXfdHddiRWbpN xRvOjQrvFa11CCN/3QTOd7v3TtUze+/9RAOrugWeozA8pyVQFAkivK8lvhWgCTICMLIt 0RDfIEmTiLLnr9ZSNDoQ2iL96xax5bL1BkWZTUptKKLB+0TqZl6A9ysV17gekGAwC0uO loU6Jly6XTG2qvXC5ywnMowsBXABhE0e9+IDcVTArFCF8GKyMUuvv7QqOsPFK8dyWxNI hWGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796185939; x=1796790739; 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=fbTC0W/sT9uJOupkBQJxZV+XiZ2dL+NX85EJNWq4Ra4=; b=mcdcfzxIJcQcDwjofNxSAh/ig0ScDEAMM4XqifCMdJIXwXU/XIvA8Hq23nm1McUbMg ik+ZlgwQ9BU/Jh6rgB8sxJNJxLVUPrxdp2EfXvSVOld7CNrLoe46zJSn2QuknkOH7V+w CxiXhGHDhKxKrB+hZCujbowCGAF9312uwqG4dAdWHgZ5yv0WvT2a4zIMg7rJiQI9t0AY OgCYgDXHWHan8JK2MO47ytWTDCo7PSqYfwF+W0WcyFsj7zMFsC2lw/Rsv9sIiVfCKbxg xYtzGB2BM1vGiqobt7Et09fsfS+wqv8QXBgvb01RJZitHF5mdWx0G1fA7Eaxcp03wCDZ pYKQ== X-Forwarded-Encrypted: i=1; AL+hErEIerLkUcbdAP2n7IUKwrmP9CkObQpinq3PjaV6KfnUMMyWH4pLtPTY41E74/6I9mlXLpc8Tzki8W0t51d/wKk=@vger.kernel.org X-Gm-Message-State: APuU4Z8e2RaxcDraRumVQHMCwLCifBPmjhFQWr26Lb3yqDHBr7xfo0Jd oSPgDOrbo7E/nuh+hpuZ9phPl6+pihgBPjM5rM6HlzkHYJpx4p5gC7z+oz4X/f6WEg8= X-Gm-Gg: AZFdTZcy7jV4mSLpjlONyI38zLkNXVSWb4b315OTFEgJNRCoJZLG7f5fj7eMpfontYC TD5+AB/giMBnos2GVYvrjdoF7f6r/X+hQyo5SmBGtzgXSKSXZ4ZV1e7072b4Bn+4mh1bvmUzC9U 3OlzDvSTDf+KB5bjqC+a2861fV/GSnVJ7r74DPZ94gZ6Lls7Dg5sFVjc2iC41ncjtlMX7M6p5DD drVj1dOJ6utPyFyeAkuRozZWIU62WBibE21CBmd8PTZUy2ye2wAlVhkoDNN9GKTKc/LHsNvyJOb IZfyPx3vt09xX8T14pXlR0Fyi1bwBfnYSQ8NeedHf2r9A30EhvvnNw7rn0dhG+/f8ctLxN1Ki5F SdqE/wu3N23jre0zK+yFUx7e4sfnGM1NB03DfOmm7AonW294kjKeotkRLltSo836JriPQP6h33T iq/cr437I3E/nDOtgu910i82v7yCZuZrC6c9BHEnNz/jb+rQ7KjJQOcpdz5+jeomb1BFn9853vy 988E4xOTDJF6VNgyUASSVYUx6RBvknDzJ0nOIQzvNrduimJ4UoYjFZCBLjXma2+uu96jiYc0FPG Dz/YkvXhsZcol7Q4QcJdLfN+Nk9Gy/ZtuCaq0oZHaBeHTlVEvidd36E+uxgY4BAEWgXT0gz29vQ hBvZU1n6u1w1qp970ZsQb/Tmb3aU= X-Received: by 2002:a05:7300:881a:b0:385:8aea:11bf with SMTP id 5a478bee46e88-3858aea13eamr44589628eec.41.1796185938626; Tue, 01 Dec 2026 20:32:18 -0800 (PST) Received: from devbox.ts.blockcast.net ([2602:f74d:1::32]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-386d605c894sm54632028eec.2.2026.12.01.20.32.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 20:32:17 -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 , David Ahern , Ido Schimmel Subject: [PATCH net-next v6 09/12] amt: add netlink attributes for an IPv6 outer transport Date: Wed, 2 Dec 2026 04:31:57 +0000 Message-ID: <20261202043200.286260-10-omar@blockcast.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261202043200.286260-1-omar@blockcast.net> References: <20261202043200.286260-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 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 --- 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, };