summaryrefslogtreecommitdiffstats
path: root/etc/network.subr
diff options
context:
space:
mode:
authorhrs <hrs@FreeBSD.org>2013-10-04 02:44:04 +0000
committerhrs <hrs@FreeBSD.org>2013-10-04 02:44:04 +0000
commit1315bdcd1cb1cd6133a697efac8e34fd2b7903ab (patch)
tree230a4591ff8d7297e51d314631ce760e55075e73 /etc/network.subr
parente1fc8db7f4a9e657f4a1f9a4ea365414aee5f4e3 (diff)
downloadFreeBSD-src-1315bdcd1cb1cd6133a697efac8e34fd2b7903ab.zip
FreeBSD-src-1315bdcd1cb1cd6133a697efac8e34fd2b7903ab.tar.gz
Add epair(4) support in $cloned_interfaces. One should be specified
as "epair0" in $cloned_interfaces and "epair0[ab]" in the others in rc.conf like the following: cloned_interfaces="epair0" ifconfig_epair0a="inet 192.168.1.1/24" ifconfig_epair0b="inet 192.168.2.1/24" /etc/rc.d/netif now accepts both "netif start epair0" and "netif start epair0a". Approved by: re (kib)
Diffstat (limited to 'etc/network.subr')
-rw-r--r--etc/network.subr134
1 files changed, 93 insertions, 41 deletions
diff --git a/etc/network.subr b/etc/network.subr
index 057fb71..cff846a 100644
--- a/etc/network.subr
+++ b/etc/network.subr
@@ -1198,8 +1198,7 @@ ifscript_down()
#
clone_up()
{
- local _prefix _list ifn ifopt _iflist _n tmpargs
- _prefix=
+ local _list ifn ifopt _iflist _n tmpargs
_list=
_iflist=$*
@@ -1211,15 +1210,34 @@ clone_up()
""|$ifn|$ifn\ *|*\ $ifn\ *|*\ $ifn) ;;
*) continue ;;
esac
- # Skip if ifn already exists.
- if ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
- continue
- fi
- ${IFCONFIG_CMD} ${ifn} create `get_if_var ${ifn} create_args_IF`
- if [ $? -eq 0 ]; then
- _list="${_list}${_prefix}${ifn}"
- [ -z "$_prefix" ] && _prefix=' '
- fi
+ case $ifn in
+ epair[0-9]*)
+ # epair(4) uses epair[0-9] for creation and
+ # epair[0-9][ab] for configuration.
+ #
+ # Skip if ${ifn}a or ${ifn}b already exist.
+ if ${IFCONFIG_CMD} ${ifn}a > /dev/null 2>&1; then
+ continue
+ elif ${IFCONFIG_CMD} ${ifn}b > /dev/null 2>&1; then
+ continue
+ fi
+ ${IFCONFIG_CMD} ${ifn} create \
+ `get_if_var ${ifn} create_args_IF`
+ if [ $? -eq 0 ]; then
+ _list="$_list ${ifn}a ${ifn}b"
+ fi
+ ;;
+ *)
+ # Skip if ${ifn} already exists.
+ if ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
+ continue
+ fi
+ ${IFCONFIG_CMD} ${ifn} create \
+ `get_if_var ${ifn} create_args_IF`
+ if [ $? -eq 0 ]; then
+ _list="$_list $ifn"
+ fi
+ esac
done
if [ -n "$gif_interfaces" ]; then
warn "\$gif_interfaces is obsolete. Use \$cloned_interfaces instead."
@@ -1245,16 +1263,15 @@ clone_up()
;;
esac
if [ $? -eq 0 ]; then
- _list="${_list}${_prefix}${ifn}"
- [ -z "$_prefix" ] && _prefix=' '
+ _list="$_list $ifn"
fi
tmpargs=$(get_if_var $ifn gifconfig_IF)
eval ifconfig_${ifn}=\"tunnel \$tmpargs\"
done
- if [ -n "${_list}" ]; then
- echo "Created clone interfaces: ${_list}."
+ if [ -n "${_list# }" ]; then
+ echo "Created clone interfaces: ${_list# }."
fi
- debug "Cloned: ${_list}"
+ debug "Cloned: ${_list# }"
}
# clone_down
@@ -1263,8 +1280,7 @@ clone_up()
#
clone_down()
{
- local _prefix _list ifn ifopt _iflist _sticky
- _prefix=
+ local _list ifn _difn ifopt _iflist _sticky
_list=
_iflist=$*
@@ -1286,20 +1302,40 @@ clone_down()
""|$ifn|$ifn\ *|*\ $ifn\ *|*\ $ifn) ;;
*) continue ;;
esac
- # Skip if ifn does not exist.
- if ! ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
- continue
- fi
- ${IFCONFIG_CMD} -n ${ifn} destroy
- if [ $? -eq 0 ]; then
- _list="${_list}${_prefix}${ifn}"
- [ -z "$_prefix" ] && _prefix=' '
- fi
+ case $ifn in
+ epair[0-9]*)
+ # Note: epair(4) uses epair[0-9] for removal and
+ # epair[0-9][ab] for configuration.
+ #
+ # Skip if both of ${ifn}a and ${ifn}b do not exist.
+ if ${IFCONFIG_CMD} ${ifn}a > /dev/null 2>&1; then
+ _difn=${ifn}a
+ elif ${IFCONFIG_CMD} ${ifn}b > /dev/null 2>&1; then
+ _difn=${ifn}b
+ else
+ continue
+ fi
+ ${IFCONFIG_CMD} -n $_difn destroy
+ if [ $? -eq 0 ]; then
+ _list="$_list ${ifn}a ${ifn}b"
+ fi
+ ;;
+ *)
+ # Skip if ifn does not exist.
+ if ! ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
+ continue
+ fi
+ ${IFCONFIG_CMD} -n ${ifn} destroy
+ if [ $? -eq 0 ]; then
+ _list="$_list $ifn"
+ fi
+ ;;
+ esac
done
- if [ -n "${_list}" ]; then
- echo "Destroyed clone interfaces: ${_list}."
+ if [ -n "${_list# }" ]; then
+ echo "Destroyed clone interfaces: ${_list# }."
fi
- debug "Destroyed clones: ${_list}"
+ debug "Destroyed clones: ${_list# }"
}
# childif_create
@@ -1574,17 +1610,33 @@ list_net_interfaces()
fi
done
_tmplist="${_lo}${_tmplist# }"
- ;;
+ ;;
*)
- _tmplist="${network_interfaces} ${cloned_interfaces}"
-
+ for _if in ${network_interfaces} ${cloned_interfaces}; do
+ # epair(4) uses epair[0-9] for creation and
+ # epair[0-9][ab] for configuration.
+ case $_if in
+ epair[0-9]*)
+ _tmplist="$_tmplist ${_if}a ${_if}b"
+ ;;
+ *)
+ _tmplist="$_tmplist $_if"
+ ;;
+ esac
+ done
+ #
# lo0 is effectively mandatory, so help prevent foot-shooting
#
case "$_tmplist" in
- lo0|'lo0 '*|*' lo0'|*' lo0 '*) ;; # This is fine, do nothing
- *) _tmplist="lo0 ${_tmplist}" ;;
- esac
+ lo0|'lo0 '*|*' lo0'|*' lo0 '*)
+ # This is fine, do nothing
+ _tmplist="${_tmplist# }"
;;
+ *)
+ _tmplist="lo0 ${_tmplist# }"
+ ;;
+ esac
+ ;;
esac
_list=
@@ -1596,14 +1648,14 @@ list_net_interfaces()
_list="${_list# } ${_if}"
fi
done
- ;;
+ ;;
dhcp)
for _if in ${_tmplist} ; do
if dhcpif $_if; then
_list="${_list# } ${_if}"
fi
done
- ;;
+ ;;
noautoconf)
for _if in ${_tmplist} ; do
if ! ipv6_autoconfif $_if && \
@@ -1611,17 +1663,17 @@ list_net_interfaces()
_list="${_list# } ${_if}"
fi
done
- ;;
+ ;;
autoconf)
for _if in ${_tmplist} ; do
if ipv6_autoconfif $_if; then
_list="${_list# } ${_if}"
fi
done
- ;;
+ ;;
*)
_list=${_tmplist}
- ;;
+ ;;
esac
echo $_list
OpenPOWER on IntegriCloud