commit:     f9793bb67a40dc58c97772a9731a2b6dfcb1422f
Author:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 23 23:50:08 2016 +0000
Commit:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Sun Oct 23 23:50:08 2016 +0000
URL:        https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=f9793bb6

iproute2: treat EEXIST error on routes as non-fatal.

Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>

 net/iproute2.sh | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index d03548e..779d334 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -251,10 +251,33 @@ _add_route()
                cmd="${cmd} metric ${metric}"
        fi
 
+       # Check for route already existing:
+       ip ${family} route show ${cmd} dev "${IFACE}" 2>/dev/null | \
+               fgrep -sq "${cmd%% *}"
+       route_already_exists=$?
+
        veinfo ip ${family} route append ${cmd} dev "${IFACE}"
        ip ${family} route append ${cmd} dev "${IFACE}"
        rc=$?
-       # TODO: check return code in some cases
+       # Check return code in some cases
+       if [ $rc -ne 0 ]; then
+               # If the route already exists, our default behavior is to WARN 
but continue.
+               # You can completely silence this with: 
errh_IFVAR_route_EEXIST=continue
+               if [ $route_already_exists -eq 0 ]; then
+                       eh_behavior=$(_get_errorhandler_behavior "$IFVAR" 
"route" "EEXIST" "warn")
+                       abort=0
+                       case $eh_behavior in
+                               continue) msgfunc=true ;;
+                               info) msgfunc=einfo ;;
+                               warn) msgfunc=ewarn ;;
+                               error|fatal) msgfunc=eerror abort=1;;
+                       esac
+                       $msgfunc "Route '$cmd' already existed: $(ip $family 
route show $cmd dev "${IFACE}" 2>&1)"
+                       [ $abort -eq 1 ] && rc=1
+               else
+                       # TODO: Handle other errors
+               fi
+       fi
        eend $rc
 }
 

Reply via email to