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
This commit is contained in:
Robin H. Johnson 2011-07-18 07:09:28 +00:00
parent e3b02abd7a
commit 6fa6f9523f

View File

@ -111,38 +111,32 @@ _add_address()
return 0 return 0
fi fi
# Convert an ifconfig line to iproute2 local address netmask broadcast peer anycast label scope
if [ "$2" = "netmask" ]; then local valid_lft preferred_lft home nodad
local one="$1" three="$3" address="$1" ; shift
shift; shift; shift while [ -n "$*" ]; do
set -- "${one}/$(_netmask2cidr "${three}")" "$@" case "$1" in
fi netmask)
netmask="/$(_netmask2cidr "$2")" ; shift ; shift ;;
# tunnel keyword is 'peer' in iproute2, but 'pointopoint' in ifconfig. broadcast|brd)
if [ "$2" = "pointopoint" ]; then broadcast="broadcast $2" ; shift ; shift ;;
local one="$1" pointopoint|pointtopoint|peer)
shift; shift peer="peer $2" ; shift ; shift ;;
set -- "${one}" "peer" "$@" anycast|label|scope|valid_lft|preferred_lft)
fi eval "$1=$2" ; shift ; shift ;;
home|nodad)
eval "$1=$1" ; shift ;;
esac
done
# Always scope lo addresses as host unless specified otherwise # Always scope lo addresses as host unless specified otherwise
if [ "${IFACE}" = "lo" ]; then if [ "${IFACE}" = "lo" ]; then
set -- "$@" "scope" "host" [ -z "$scope" ] && scope="scope host"
fi fi
# IPv4 specifics set -- "${address}${netmask}" $peer $broadcast $anycast $label $scope dev "${IFACE}" $valid_lft $preferred_lft $home $nodad
case "$1" in veinfo ip addr add "$@"
*.*.*.*) ip addr add "$@"
case "$@" in
*" brd "*);;
*" broadcast "*);;
*) set -- "$@" brd +;;
esac
;;
esac
veinfo ip addr add "$@" dev "${IFACE}"
ip addr add "$@" dev "${IFACE}"
} }
_add_route() _add_route()