From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 4BA09138B08 for ; Sun, 23 Oct 2016 23:50:21 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C6769E0807; 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 9741EE0807 for ; 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 2A59534163E for ; 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 5EBCA2F9 for ; Sun, 23 Oct 2016 23:50:15 +0000 (UTC) From: "Robin H. Johnson" 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" Message-ID: <1477265711.c0e9d13165c53ee934b25883b03ff39ef04e2904.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: c0e9d13165c53ee934b25883b03ff39ef04e2904 X-VCS-Branch: master Date: Sun, 23 Oct 2016 23:50:15 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: cbc6dda9-b8b3-421c-9e0f-ad3fe6ff73b7 X-Archives-Hash: a8d4a5d37f3174914adaef5b9210814c commit: c0e9d13165c53ee934b25883b03ff39ef04e2904 Author: Robin H. Johnson gentoo org> AuthorDate: Sun Oct 23 23:35:11 2016 +0000 Commit: Robin H. Johnson gentoo org> CommitDate: Sun Oct 23 23:35:11 2016 +0000 URL: https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=c0e9d131 iproute2: capture the family and always set netmask explicitly. Signed-off-by: Robin H. Johnson gentoo.org> net/iproute2.sh | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/net/iproute2.sh b/net/iproute2.sh index 6cf9aef..f15f3af 100644 --- a/net/iproute2.sh +++ b/net/iproute2.sh @@ -109,17 +109,31 @@ _add_address() local x local address netmask broadcast peer anycast label scope local valid_lft preferred_lft home nodad - local confflaglist - address="$1" ; shift + local confflaglist family raw_address family_maxnetmask + raw_address="$1" ; shift + # Extract the netmask on address if present. + if [ "${address%\/*}" != "${address}" ]; then + address="${raw_address%\/*}" + netmask="${raw_address#*\/}" + else + address="$raw_address" + fi + + # Some options are not valid for one family or the other. + case ${address} in + *:*) family=6 family_maxnetmask=128 ;; + *) family=4 family_maxnetmask=32 ;; + esac + while [ -n "$*" ]; do x=$1 ; shift case "$x" in netmask|ne*) - netmask="/$(_netmask2cidr "$1")" - if [ "${address/\/}" != "${address}" ]; then - eerror "Too many netmasks: $address netmask $1" + if [ -n "${netmask}" ]; then + eerror "Too many netmasks: $raw_address netmask $1" return 1 fi + netmask="/$(_netmask2cidr "$1")" shift ;; broadcast|brd|br*) broadcast="$1" ; shift ;; @@ -155,15 +169,16 @@ _add_address() # figure out the broadcast address if it is not specified # This must NOT be set for IPv6 addresses - if [ "${address#*:}" = "${address}" ]; then - [ -z "$broadcast" ] && broadcast="+" - elif [ -n "$broadcast" ]; then - eerror "Broadcast keywords are not valid with IPv6 addresses" - return 1 - fi + case $family in + 4) [ -z "$broadcast" ] && broadcast="+" ;; + 6) [ -n "$broadcast" ] && eerror "Broadcast keywords are not valid with IPv6 addresses" && return 1 ;; + esac + + # Always have a netmask + [ -z "$netmask" ] && netmask=$family_maxnetmask # This must appear on a single line, continuations cannot be used - set -- "${address}${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 + 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=$?