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
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()