1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-21 15:45:02 +00:00

Fix address range specification with ifconfig(8) options such as:

- inet 192.0.2.1-10 netmask 255.255.255.0 (inet range spec + ifconfig options)
- inet6 2001:db8:1::1-f prefixlen 60 (inet6 range spec + ifconfig options)

If prefixlen or netmask option is specified with CIDR notation at
the same time, the option is used.

Tested by:	Michael Grimm
MFC after:	3 days
This commit is contained in:
Hiroki Sato 2013-07-20 16:58:17 +00:00
parent 247ba4776c
commit fd1fba7ce3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=253505

View File

@ -721,9 +721,14 @@ ifalias()
#
ifalias_expand_addr()
{
local _af _action
afexists $1 || return
ifalias_expand_addr_$1 $2 $3
_af=$1
_action=$2
shift 2
afexists $_af || return
ifalias_expand_addr_$_af $_action $*
}
# ifalias_expand_addr_inet action addr
@ -731,19 +736,34 @@ ifalias_expand_addr()
#
ifalias_expand_addr_inet()
{
local _action _arg _cidr _cidr_addr
local _action _arg _cidr _cidr_addr _exargs
local _ipaddr _plen _range _iphead _iptail _iplow _iphigh _ipcount
local _retstr _c
_action=$1
_arg=$2
shift 2
_exargs=$*
_retstr=
case $_action:$_arg in
*:*--*) return ;; # invalid
tmp:*) echo $_arg && return ;; # already expanded
tmp:*-*) _action="alias" ;; # to be expanded
*:*-*) ;; # to be expanded
*:*) echo inet $_arg && return ;; # already expanded
case $_action:$_arg:$_exargs in
*:*--*) return ;; # invalid
tmp:*[0-9]-[0-9]*:*) # to be expanded
_action="alias"
;;
*:*[0-9]-[0-9]*:*) # to be expanded
;;
tmp:*:*netmask*) # already expanded w/ netmask option
echo ${_arg%/[0-9]*} $_exargs && return
;;
tmp:*:*) # already expanded w/o netmask option
echo $_arg $_exargs && return
;;
*:*:*netmask*) # already expanded w/ netmask option
echo inet ${_arg%/[0-9]*} $_exargs && return
;;
*:*:*) # already expanded w/o netmask option
echo inet $_arg $_exargs && return
;;
esac
for _cidr in $_arg; do
@ -796,7 +816,7 @@ ifalias_expand_addr_inet()
done
for _c in $_retstr; do
ifalias_expand_addr_inet $_action $_c
ifalias_expand_addr_inet $_action $_c $_exargs
done
}
@ -805,20 +825,35 @@ ifalias_expand_addr_inet()
#
ifalias_expand_addr_inet6()
{
local _action _arg _cidr _cidr_addr
local _action _arg _cidr _cidr_addr _exargs
local _ipaddr _plen _ipleft _ipright _iplow _iphigh _ipcount
local _ipv4part
local _retstr _c
_action=$1
_arg=$2
shift 2
_exargs=$*
_retstr=
case $_action:$_arg in
*:*--*) return ;; # invalid
tmp:*) echo $_arg && return ;;
tmp:*-*) _action="alias" ;;
*:*-*) ;;
*:*) echo inet6 $_arg && return ;;
case $_action:$_arg:$_exargs in
*:*--*:*) return ;; # invalid
tmp:*[0-9a-zA-Z]-[0-9a-zA-Z]*:*)# to be expanded
_action="alias"
;;
*:*[0-9a-zA-Z]-[0-9a-zA-Z]*:*) # to be expanded
;;
tmp:*:*prefixlen*) # already expanded w/ prefixlen option
echo ${_arg%/[0-9]*} $_exargs && return
;;
tmp:*:*) # already expanded w/o prefixlen option
echo $_arg $_exargs && return
;;
*:*:*prefixlen*) # already expanded w/ prefixlen option
echo inet6 ${_arg%/[0-9]*} $_exargs && return
;;
*:*:*) # already expanded w/o prefixlen option
echo inet6 $_arg $_exargs && return
;;
esac
for _cidr in $_arg; do
@ -872,7 +907,7 @@ ifalias_expand_addr_inet6()
fi
for _c in $_retstr; do
ifalias_expand_addr_inet6 $_action $_c
ifalias_expand_addr_inet6 $_action $_c $_exargs
done
else
# v4mapped/v4compat should handle as an IPv4 alias
@ -888,7 +923,7 @@ ifalias_expand_addr_inet6()
_retstr=`ifalias_expand_addr_inet \
tmp ${_ipv4part}${_plen:+/}${_plen}`
for _c in $_retstr; do
ifalias_expand_addr_inet $_action $_c
ifalias_expand_addr_inet $_action $_c $_exargs
done
fi
done