From 6fa6f9523f80b2fcb49728b349f3eefc3e45a769 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Mon, 18 Jul 2011 07:09:28 +0000 Subject: Rewrite iproute2 addr argument parsing. This was originally to fix the fact that our code did not handle certain orders of arguments in conversion, but it was easier to rewrite the entire argument handling to support more options at the same time. Now supports all options documented in the ip manpage, including the IPv6-specific options that must be passed after the interface argument. Signed-off-by: Robin H. Johnson Reported-by: Tony Vroon X-Gentoo-Bug: 366905 X-Gentoo-Bug-URL: https://bugs.gentoo.org/366905 --- net/iproute2.sh | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/net/iproute2.sh b/net/iproute2.sh index d76e60f..2e02fbe 100644 --- a/net/iproute2.sh +++ b/net/iproute2.sh @@ -111,38 +111,32 @@ _add_address() return 0 fi - # Convert an ifconfig line to iproute2 - if [ "$2" = "netmask" ]; then - local one="$1" three="$3" - shift; shift; shift - set -- "${one}/$(_netmask2cidr "${three}")" "$@" - fi - - # tunnel keyword is 'peer' in iproute2, but 'pointopoint' in ifconfig. - if [ "$2" = "pointopoint" ]; then - local one="$1" - shift; shift - set -- "${one}" "peer" "$@" - fi + local address netmask broadcast peer anycast label scope + local valid_lft preferred_lft home nodad + address="$1" ; shift + while [ -n "$*" ]; do + case "$1" in + netmask) + netmask="/$(_netmask2cidr "$2")" ; shift ; shift ;; + broadcast|brd) + broadcast="broadcast $2" ; shift ; shift ;; + pointopoint|pointtopoint|peer) + peer="peer $2" ; shift ; shift ;; + anycast|label|scope|valid_lft|preferred_lft) + eval "$1=$2" ; shift ; shift ;; + home|nodad) + eval "$1=$1" ; shift ;; + esac + done # Always scope lo addresses as host unless specified otherwise if [ "${IFACE}" = "lo" ]; then - set -- "$@" "scope" "host" + [ -z "$scope" ] && scope="scope host" fi - # IPv4 specifics - case "$1" in - *.*.*.*) - case "$@" in - *" brd "*);; - *" broadcast "*);; - *) set -- "$@" brd +;; - esac - ;; - esac - - veinfo ip addr add "$@" dev "${IFACE}" - ip addr add "$@" dev "${IFACE}" + set -- "${address}${netmask}" $peer $broadcast $anycast $label $scope dev "${IFACE}" $valid_lft $preferred_lft $home $nodad + veinfo ip addr add "$@" + ip addr add "$@" } _add_route() -- cgit v1.2.3