Skip to content

Commit ef6ce8d

Browse files
committed
findif.sh: fix to avoid duplicate route issues
1 parent fefb54b commit ef6ce8d

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

heartbeat/findif.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,13 @@ findif()
217217
fi
218218
if [ -n "$nic" ] ; then
219219
# NIC supports more than two.
220-
routematch=$(ip -o -f $family route list match $match $proto $scope | grep -v "^\(unreachable\|prohibit\|blackhole\)" | grep "dev $nic " | sed -e 's,^\([0-9.]\+\) ,\1/32 ,;s,^\([0-9a-f:]\+\) ,\1/128 ,' | sort -t/ -k2,2nr)
220+
routematch=$(ip -o -f $family route list match $match $proto $scope | grep "dev $nic " | sed -e 's,^\([0-9.]\+\) ,\1/32 ,;s,^\([0-9a-f:]\+\) ,\1/128 ,' | sort -t/ -k2,2nr)
221221
else
222-
routematch=$(ip -o -f $family route list match $match $proto $scope | grep -v "^\(unreachable\|prohibit\|blackhole\)" | sed -e 's,^\([0-9.]\+\) ,\1/32 ,;s,^\([0-9a-f:]\+\) ,\1/128 ,' | sort -t/ -k2,2nr)
223-
fi
224-
if [ "$family" = "inet6" ]; then
225-
routematch=$(echo "$routematch" | grep -v "^default")
222+
routematch=$(ip -o -f $family route list match $match $proto $scope | sed -e 's,^\([0-9.]\+\) ,\1/32 ,;s,^\([0-9a-f:]\+\) ,\1/128 ,' | sort -t/ -k2,2nr)
226223
fi
227224

228-
if [ $(echo "$routematch" | wc -l) -gt 1 ]; then
229-
ocf_exit_reason "More than 1 routes match $match. Unable to decide which route to use."
230-
return $OCF_ERR_GENERIC
231-
fi
225+
routematch=$(echo "$routematch" | awk '!/^(default|unreachable|prohibit|blackhole)/{match($0, /metric ([^ ]+)/, arr); print arr[1], $0}' | sort -k 1n -u | cut -d" " -f 2- | head -1)
226+
232227
set -- $routematch
233228
if [ $# = 0 ] ; then
234229
case $OCF_RESKEY_ip in

0 commit comments

Comments
 (0)