diff options
author | Robin H. Johnson <robbat2@gentoo.org> | 2011-07-18 07:09:28 +0000 |
---|---|---|
committer | Robin H. Johnson <robbat2@gentoo.org> | 2011-07-18 23:55:32 +0000 |
commit | 6fa6f9523f80b2fcb49728b349f3eefc3e45a769 (patch) | |
tree | b83efd174e8dbe3910d8413d528593af1a158877 | |
parent | e3b02abd7abe0cd6265cb56324018b6db003f293 (diff) |
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 <robbat2@gentoo.org>
Reported-by: Tony Vroon <chainsaw@gentoo.org>
X-Gentoo-Bug: 366905
X-Gentoo-Bug-URL: https://bugs.gentoo.org/366905
-rw-r--r-- | net/iproute2.sh | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/net/iproute2.sh b/net/iproute2.sh index d76e60f6..2e02fbe0 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() |