diff options
author | hrs <hrs@FreeBSD.org> | 2013-07-20 16:58:17 +0000 |
---|---|---|
committer | hrs <hrs@FreeBSD.org> | 2013-07-20 16:58:17 +0000 |
commit | 43ff25fce868f013654ddbc0496bc7928c10bbdf (patch) | |
tree | 3557eb5c759d6c0910c5b2bdb53f60e37f5a3712 /etc/network.subr | |
parent | cdafd4ecfd87de54cc7a0c3e20f229603df4dc92 (diff) | |
download | FreeBSD-src-43ff25fce868f013654ddbc0496bc7928c10bbdf.zip FreeBSD-src-43ff25fce868f013654ddbc0496bc7928c10bbdf.tar.gz |
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
Diffstat (limited to 'etc/network.subr')
-rw-r--r-- | etc/network.subr | 73 |
1 files changed, 54 insertions, 19 deletions
diff --git a/etc/network.subr b/etc/network.subr index 3c26b13..f9c1950 100644 --- a/etc/network.subr +++ b/etc/network.subr @@ -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 |