From 3b0d76c30bf63332f494e8aae18dc2f1feed28dd Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Mon, 12 Aug 2024 17:01:12 +0000 Subject: [PATCH] Fix get_default_host_ip ipv6 address parsing This is another occurrence of the issue fixed in bug 1786259 with change I30bf655f which occurs when there are multiple IPv6 gateways present. Before this change: $ source openrc +++++functions-common:get_default_host_ip:776 ip -f inet6 addr show 100 Device "100" does not exist. This is because the ip route command returns: default proto ra metric 100 expires 1497sec pref medium nexthop via fe80::4e16:fc01:298c:98ed dev ens3 weight 1 nexthop via fe80::4e16:fc01:2983:88aa dev ens3 weight 1 Related-Bug: #1786259 Change-Id: I7729730df66a4dc7ee11df1d23b19b9c0794b575 --- functions-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-common b/functions-common index 84d281b21e..e265256ccf 100644 --- a/functions-common +++ b/functions-common @@ -771,7 +771,7 @@ function get_default_host_ip { if [ -z "$host_ip" -o "$host_ip" == "dhcp" ]; then host_ip="" # Find the interface used for the default route - host_ip_iface=${host_ip_iface:-$(ip -f $af route | awk '/default/ {print $5}' | head -1)} + host_ip_iface=${host_ip_iface:-$(ip -f $af route list match default table all | grep via | awk '/default/ {print $5}' | head -1)} local host_ips host_ips=$(LC_ALL=C ip -f $af addr show ${host_ip_iface} | sed /temporary/d |awk /$af'/ {split($2,parts,"/"); print parts[1]}') local ip