The current regex only matches host interface names that consits
of "word characters" (regex \w). Intefaces having other special
chars like "-" or "." are not parsed. Examples that are not yet
matched are br-ex (ovs bridge) or enccw0.0.1234 (s390 eth device
name).
In addition it's hard to understand the the regex.
This fix is replacing the regex by a simple awk statement also
matching those names.
In addition the determination of the host_ip_iface was moved
down into the if clause, as it is only used inside.
Change-Id: I3d1b1afa32956e4e8c55c7e68cbafaf8e03e7da2
Closes-Bug: #1429903
... | ... |
@@ -542,11 +542,11 @@ function get_default_host_ip { |
542 | 542 |
local host_ip_iface=$3 |
543 | 543 |
local host_ip=$4 |
544 | 544 |
|
545 |
- # Find the interface used for the default route |
|
546 |
- host_ip_iface=${host_ip_iface:-$(ip route | sed -n '/^default/{ s/.*dev \(\w\+\)\s\+.*/\1/; p; }' | head -1)} |
|
547 | 545 |
# Search for an IP unless an explicit is set by ``HOST_IP`` environment variable |
548 | 546 |
if [ -z "$host_ip" -o "$host_ip" == "dhcp" ]; then |
549 | 547 |
host_ip="" |
548 |
+ # Find the interface used for the default route |
|
549 |
+ host_ip_iface=${host_ip_iface:-$(ip route | awk '/default/ {print $5}' | head -1)} |
|
550 | 550 |
local host_ips=$(LC_ALL=C ip -f inet addr show ${host_ip_iface} | awk '/inet/ {split($2,parts,"/"); print parts[1]}') |
551 | 551 |
local ip |
552 | 552 |
for ip in $host_ips; do |