From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <gentoo-commits+bounces-907748-garchives=archives.gentoo.org@lists.gentoo.org> Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 3B7B5138B07 for <garchives@archives.gentoo.org>; Sun, 23 Oct 2016 23:50:23 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id CDC94E080A; Sun, 23 Oct 2016 23:50:18 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B1056E080A for <gentoo-commits@lists.gentoo.org>; Sun, 23 Oct 2016 23:50:18 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 4BDFE34165D for <gentoo-commits@lists.gentoo.org>; Sun, 23 Oct 2016 23:50:17 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 843BE2497 for <gentoo-commits@lists.gentoo.org>; Sun, 23 Oct 2016 23:50:15 +0000 (UTC) From: "Robin H. Johnson" <robbat2@gentoo.org> To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Robin H. Johnson" <robbat2@gentoo.org> Message-ID: <1477266215.5be82041cf23b0359190c148e9d356d8aa85e18b.robbat2@OpenRC> Subject: [gentoo-commits] proj/netifrc:master commit in: net/ X-VCS-Repository: proj/netifrc X-VCS-Files: net/iproute2.sh X-VCS-Directories: net/ X-VCS-Committer: robbat2 X-VCS-Committer-Name: Robin H. Johnson X-VCS-Revision: 5be82041cf23b0359190c148e9d356d8aa85e18b X-VCS-Branch: master Date: Sun, 23 Oct 2016 23:50:15 +0000 (UTC) Precedence: bulk List-Post: <mailto:gentoo-commits@lists.gentoo.org> List-Help: <mailto:gentoo-commits+help@lists.gentoo.org> List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org> List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org> List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org> X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 57ce13ee-ab4b-45ec-a3c6-4e516a96c5fe X-Archives-Hash: 2b408417f541025e7601ccdb02409e97 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 }