diff options
author | 2016-10-23 16:43:35 -0700 | |
---|---|---|
committer | 2016-10-23 16:43:35 -0700 | |
commit | 5be82041cf23b0359190c148e9d356d8aa85e18b (patch) | |
tree | 210a78bc5825628928cd1cc57a2caf8730176a5c | |
parent | net.lo: framework for error handling customization. (diff) | |
download | netifrc-5be82041cf23b0359190c148e9d356d8aa85e18b.tar.gz netifrc-5be82041cf23b0359190c148e9d356d8aa85e18b.tar.bz2 netifrc-5be82041cf23b0359190c148e9d356d8aa85e18b.zip |
iproute2: treat EEXIST error on addresses as non-fatal.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rw-r--r-- | net/iproute2.sh | 25 |
1 files changed, 24 insertions, 1 deletions
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 } |