commit:     5be82041cf23b0359190c148e9d356d8aa85e18b
Author:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 23 23:43:35 2016 +0000
Commit:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Sun Oct 23 23:43:35 2016 +0000
URL:        https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=5be82041

iproute2: treat EEXIST error on addresses 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 f15f3af..d03548e 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -177,12 +177,35 @@ _add_address()
        # Always have a netmask
        [ -z "$netmask" ] && netmask=$family_maxnetmask
 
+       # Check for address already existing:
+       ip addr show to "${address}/${family_maxnetmask}" dev "${IFACE}" 
2>/dev/null | \
+               fgrep -sq "${address}"
+       address_already_exists=$?
+
        # This must appear on a single line, continuations cannot be used
        set -- "${address}${netmask:+/}${netmask}" ${peer:+peer} ${peer} 
${broadcast:+broadcast} ${broadcast} ${anycast:+anycast} ${anycast} 
${label:+label} ${label} ${scope:+scope} ${scope} dev "${IFACE}" 
${valid_lft:+valid_lft} $valid_lft ${preferred_lft:+preferred_lft} 
$preferred_lft $confflaglist
        veinfo ip addr add "$@"
        ip addr add "$@"
        rc=$?
-       # TODO: check return code in some cases
+       # Check return code in some cases
+       if [ $rc -ne 0 ]; then
+               # If the address already exists, our default behavior is to 
WARN but continue.
+               # You can completely silence this with: 
errh_IFVAR_address_EEXIST=continue
+               if [ $address_already_exists -eq 0 ]; then
+                       eh_behavior=$(_get_errorhandler_behavior "$IFVAR" 
"address" "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 "Address ${address}${netmask:+/}${netmask} 
already existed: $(ip addr show to "${address}/${family_maxnetmask}" dev 
"${IFACE}" 2>&1)"
+                       [ $abort -eq 1 ] && rc=1
+               else
+                       # TODO: Handle other errors
+               fi
+       fi
        return $rc
 }
 

Reply via email to