Netdev List
 help / color / mirror / Atom feed
From: Omar Ramadan <omar@blockcast.net>
To: netdev@vger.kernel.org
Cc: David Ahern <dsahern@kernel.org>,
	Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute2-next v2] iplink: amt: support an IPv6 outer transport
Date: Thu, 26 Nov 2026 00:43:29 +0000	[thread overview]
Message-ID: <20261126004258.2133805-iproute2-omar@blockcast.net> (raw)

The amt driver can now run AMT over IPv6 (net-next, "amt: add netlink
attributes for an IPv6 outer transport"). IFLA_AMT_LOCAL_IP6 selects
IPv6 as the outer transport, IFLA_AMT_DISCOVERY_IP6 is the IPv6 address
a gateway discovers its relay through, and IFLA_AMT_REMOTE_IP6 reports
the relay address the gateway learned.

Put an IPv6 local or discovery address in the new attributes, and print
all three under the same keys as their IPv4 counterparts; a device has
one family, so only one of each pair is present. Until now an IPv6
literal was put in the 4-byte IPv4 attribute: older kernels quietly
used its first four bytes as an IPv4 address, and kernels whose policy
sets the attribute's exact length reject it.

  ip link add amtg type amt mode gateway local 2001:db8:a::1 \
          discovery 2001:db8:a::2 dev eth0

This needs include/uapi/linux/amt.h synced with the kernel change.

Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
v2: print each IPv6 address with print_color_string() and
format_host_r(), and the keyword outside the color, as ip6tunnel.c
does (Stephen Hemminger).
v1: https://lore.kernel.org/netdev/20261125170100.3054010-iproute2-omar@blockcast.net/

 ip/iplink_amt.c       | 39 +++++++++++++++++++++++++++++++++++++--
 man/man8/ip-link.8.in |  6 +++++-
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/ip/iplink_amt.c b/ip/iplink_amt.c
index 3a35bd9..2370bc5 100644
--- a/ip/iplink_amt.c
+++ b/ip/iplink_amt.c
@@ -107,7 +107,10 @@ static int amt_parse_opt(struct link_util *lu, int argc, char **argv,
 			check_duparg(&attrs, IFLA_AMT_LOCAL_IP, "local", *argv);
 			get_addr(&saddr, *argv, daddr.family);
 
-			if (is_addrtype_inet(&saddr))
+			if (saddr.family == AF_INET6)
+				addattr_l(n, 1024, IFLA_AMT_LOCAL_IP6,
+					  saddr.data, saddr.bytelen);
+			else if (is_addrtype_inet(&saddr))
 				addattr_l(n, 1024, IFLA_AMT_LOCAL_IP,
 					  saddr.data, saddr.bytelen);
 		} else if (strcmp(*argv, "discovery") == 0) {
@@ -115,7 +118,10 @@ static int amt_parse_opt(struct link_util *lu, int argc, char **argv,
 			check_duparg(&attrs, IFLA_AMT_DISCOVERY_IP,
 				     "discovery", *argv);
 			get_addr(&daddr, *argv, daddr.family);
-			if (is_addrtype_inet(&daddr))
+			if (daddr.family == AF_INET6)
+				addattr_l(n, 1024, IFLA_AMT_DISCOVERY_IP6,
+					  daddr.data, daddr.bytelen);
+			else if (is_addrtype_inet(&daddr))
 				addattr_l(n, 1024, IFLA_AMT_DISCOVERY_IP,
 					  daddr.data, daddr.bytelen);
 		} else if (strcmp(*argv, "help") == 0) {
@@ -134,6 +140,8 @@ static int amt_parse_opt(struct link_util *lu, int argc, char **argv,
 
 static void amt_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
+	SPRINT_BUF(b1);
+
 	if (!tb)
 		return;
 
@@ -156,6 +164,15 @@ static void amt_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 			     format_host(AF_INET, 4, &addr));
 	}
 
+	if (tb[IFLA_AMT_LOCAL_IP6]) {
+		const void *addr = RTA_DATA(tb[IFLA_AMT_LOCAL_IP6]);
+
+		print_string(PRINT_FP, NULL, "%s", "local ");
+		print_color_string(PRINT_ANY, COLOR_INET6, "local", "%s ",
+				   format_host_r(AF_INET6, 16, addr,
+						 b1, sizeof(b1)));
+	}
+
 	if (tb[IFLA_AMT_REMOTE_IP]) {
 		__be32 addr = rta_getattr_u32(tb[IFLA_AMT_REMOTE_IP]);
 
@@ -163,6 +180,15 @@ static void amt_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 			     format_host(AF_INET, 4, &addr));
 	}
 
+	if (tb[IFLA_AMT_REMOTE_IP6]) {
+		const void *addr = RTA_DATA(tb[IFLA_AMT_REMOTE_IP6]);
+
+		print_string(PRINT_FP, NULL, "%s", "remote ");
+		print_color_string(PRINT_ANY, COLOR_INET6, "remote", "%s ",
+				   format_host_r(AF_INET6, 16, addr,
+						 b1, sizeof(b1)));
+	}
+
 	if (tb[IFLA_AMT_DISCOVERY_IP]) {
 		__be32 addr = rta_getattr_u32(tb[IFLA_AMT_DISCOVERY_IP]);
 
@@ -170,6 +196,15 @@ static void amt_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 			     format_host(AF_INET, 4, &addr));
 	}
 
+	if (tb[IFLA_AMT_DISCOVERY_IP6]) {
+		const void *addr = RTA_DATA(tb[IFLA_AMT_DISCOVERY_IP6]);
+
+		print_string(PRINT_FP, NULL, "%s", "discovery ");
+		print_color_string(PRINT_ANY, COLOR_INET6, "discovery", "%s ",
+				   format_host_r(AF_INET6, 16, addr,
+						 b1, sizeof(b1)));
+	}
+
 	if (tb[IFLA_AMT_LINK]) {
 		unsigned int link = rta_getattr_u32(tb[IFLA_AMT_LINK]);
 
diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
index 8fd900e..48d2ca9 100644
--- a/man/man8/ip-link.8.in
+++ b/man/man8/ip-link.8.in
@@ -1616,12 +1616,16 @@ the following additional arguments are supported:
 .sp
 .BI discovery " IPADDR"
 - specifies the unicast discovery IP address to use to find remote IP address.
+It must be of the same family as the
+.B local
+address.
 
 .BR mode " { " gateway " | " relay " } "
 - specifies the role of AMT, Gateway or Relay
 
 .BI local " IPADDR "
-- specifies the source IP address to use in outgoing packets.
+- specifies the source IP address to use in outgoing packets. An IPv6
+address makes the device use IPv6 as the outer transport of the tunnel.
 
 .BI dev " PHYS_DEV "
 - specifies the underlying physical interface from which transform traffic

                 reply	other threads:[~2026-11-26  0:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261126004258.2133805-iproute2-omar@blockcast.net \
    --to=omar@blockcast.net \
    --cc=dsahern@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /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