Proposal ipv6_addrs_common
Dirk Engling
erdgeist at erdgeist.org
Wed Feb 1 04:04:44 UTC 2012
Dear FreeBSD rc team,
echoing Philipp Wuensches great ipv4_addrs patch I'd like to contribute
the corresponding patch for v6 addresses, as their config clobbers my
rc.conf considerably.
The attached network6.subr is a shell script demonstrating the
ipv6_addrs_common function inside, for playing around one can use some
of the values the supplied get_if_var dummy function returns.
The function handles one single range but allows it in any parts of the
ip address, so
2002:50ed:991c-991f:50ed:c401::/64
2002:50ed:991c:50ed:c401-c409::
are both valid and work as expected. It can also parse ranges in
v6mapped v4 addresses, again anywhere, so configuring a router that
listens on all subnets on address .1 is possible:
::ffff:192.168.2-16.1
I would have the function called in ifn_start and ifn_stop.
Feedback is very welcome. Thank you for your attention.
erdgeist
P.S.: Since I am not sure the .subr file will pass the mailing list
filters, I copied the file to http://erdgeist.org/network6.subr
-------------- next part --------------
#!/bin/sh
get_if_var() {
# echo "2002:50ed:991c:50ed:c401-c409::"
# echo "2002:50ed:991c:50ed:c401-c409::c409"
echo "::ffff:192.168.2-4.2/12"
# echo "::ffff:192.168.2.23-25/12"
# echo "::ffff:192.168.2.23/12"
# echo "2002:50ed:991c:50ed:c401::"
# echo "2002:50ed:991c-991f:50ed:c401::"
}
ipv6_addrs_common()
{
_ret=1
_if=$1
_action=$2
# get ipv6-addresses
cidr_addr=`get_if_var $_if ipv6_addrs_IF`
for _cidr in ${cidr_addr}; do
_ipaddr="${_cidr%%/*}"
[ "${_ipaddr}" != "${_cidr}" ] && _netmask="/"${_cidr##*/} || unset _netmask
[ "$_action" = "-alias" ] && unset _netmask
if [ "${_ipaddr%:*.*.*.*}" = "${_ipaddr}" ]; then
_ipleft=${_ipaddr%-*}
_ipright=${_ipaddr#*-}
_iplow=${_ipleft##*:}
_iphigh=${_ipright%%:*}
_ipleft=${_ipleft%:*}
_ipright=${_ipright#*:}
[ "${_iphigh}" = "${_ipright}" ] && unset _ipright || _ipright=:$_ipright
if [ "${_iplow}" ]; then
while [ $(( 0x$_iplow )) -le $(( 0x$_iphigh )) ]; do
echo ifconfig ${_if} inet6 ${_ipleft}:${_iplow}${_ipright}${_netmask} ${_action}
_iplow=`printf %04x $(( 0x$_iplow + 1 ))`
_ret=0
done
else
# no range
echo ifconfig ${_if} inet6 ${_ipaddr}${_netmask} ${_action}
_ret=0
fi
else
# v4 range
_ipv6part=${_ipaddr%:*}
_ipv4part=${_ipaddr##*:}
_ipleft=${_ipv4part%-*}
_ipright=${_ipv4part#*-}
_iplow=${_ipleft##*.}
_iphigh=${_ipright%%.*}
_ipleft=${_ipleft%.*}
_ipright=${_ipright#*.}
[ "${_iphigh}" = "${_ipright}" ] && unset _ipright || _ipright=.$_ipright
if [ "${_iplow}" ]; then
while [ ${_iplow} -le ${_iphigh} ]; do
echo ifconfig ${_if} inet6 ${_ipv6part}:${_ipleft}.${_iplow}${_ipright}${_netmask} ${_action}
: $(( _iplow++ ))
_ret=0
done
else
# no range
echo ifconfig ${_if} inet6 ${_ipaddr}${_netmask} ${_action}
_ret=0
fi
fi
done
return $_ret
}
ipv6_addrs_common if0 alias
More information about the freebsd-rc
mailing list