Skip to content

Commit e727629

Browse files
authored
Merge pull request #2052 from oalbrigt/findif-avoid-duplicate-route-issue
findif.sh: fix to avoid duplicate route issues
2 parents c03cd97 + d0d2a0f commit e727629

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

heartbeat/findif.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,14 @@ 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+
# ignore matches from unrelated tables, and sort by metric to get the route with the lowest metric
226+
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)
227+
232228
set -- $routematch
233229
if [ $# = 0 ] ; then
234230
case $OCF_RESKEY_ip in

0 commit comments

Comments
 (0)