iplink: amt: support an IPv6 outer transport
Subsystems (2)
PATCH 1/1 iplink: amt: support an IPv6 outer transport
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 eth0This needs include/uapi/linux/amt.h synced with the kernel change.
--- ip/iplink_amt.c | 31 +++++++++++++++++++++++++++++-- man/man8/ip-link.8.in | 6 +++++- 2 files changed, 34 insertions(+), 3 deletions(-)
ip/iplink_amt.c +29 -2
@@ -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 ) {
@@ -156,6 +162,13 @@ 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_ANY ,"local" ,"local %s " , +format_host (AF_INET6 ,16 , addr)); + } +if (tb[IFLA_AMT_REMOTE_IP ]) {__be32 addr =rta_getattr_u32 (tb[IFLA_AMT_REMOTE_IP ]);
@@ -163,6 +176,13 @@ 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_ANY ,"remote" ,"remote %s " , +format_host (AF_INET6 ,16 , addr)); + } +if (tb[IFLA_AMT_DISCOVERY_IP ]) {__be32 addr =rta_getattr_u32 (tb[IFLA_AMT_DISCOVERY_IP ]);
@@ -170,6 +190,13 @@ 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_ANY ,"discovery" ,"discovery %s " , +format_host (AF_INET6 ,16 , addr)); + } +if (tb[IFLA_AMT_LINK ]) {unsigned int link =rta_getattr_u32 (tb[IFLA_AMT_LINK ]);
man/man8/ip-link.8.in +5 -1
@@ -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
Signature · 1 line
2.50.1 (Apple Git-155)
ip/iplink_amt.c static void amt_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) · line 170
Quoted 6 lines · On Wed, 25 Nov 2026 19:14:47 +0000 Omar Ramadan <[email protected]> wrote:
ip/iplink_amt.c +6
-0+if (tb[IFLA_AMT_LOCAL_IP6 ]) { +const void *addr =RTA_DATA (tb[IFLA_AMT_LOCAL_IP6 ]); + +print_string (PRINT_ANY ,"local" ,"local %s " , +format_host (AF_INET6 ,16 , addr)); + }
Should be something like:
print_string(PRINT_FP, NULL, "%s", "local "); print_color_string(PRINT_ANY, "local", "%s", format_host_r(AF_INET6, 16, addr, b1, sizeof(b1));
key point:
color output
only for address not the "local "
prefer format_host_r on new code
See ip/ip6tunnel.c for examples