Deleted Added
full compact
network.subr (255653) network.subr (256039)
1#
2# Copyright (c) 2003 The FreeBSD Project. All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions
6# are met:
7# 1. Redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer.

--- 8 unchanged lines hidden (view full) ---

17# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23# SUCH DAMAGE.
24#
1#
2# Copyright (c) 2003 The FreeBSD Project. All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions
6# are met:
7# 1. Redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer.

--- 8 unchanged lines hidden (view full) ---

17# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23# SUCH DAMAGE.
24#
25# $FreeBSD: head/etc/network.subr 255653 2013-09-17 20:22:24Z hrs $
25# $FreeBSD: head/etc/network.subr 256039 2013-10-04 02:44:04Z hrs $
26#
27IFCONFIG_CMD="/sbin/ifconfig"
28
29# Maximum number of addresses expanded from a address range specification.
30_IPEXPANDMAX=31
31
32#
33# Subroutines commonly used from network startup scripts.

--- 1159 unchanged lines hidden (view full) ---

1193 fi
1194}
1195
1196# clone_up
1197# Create cloneable interfaces.
1198#
1199clone_up()
1200{
26#
27IFCONFIG_CMD="/sbin/ifconfig"
28
29# Maximum number of addresses expanded from a address range specification.
30_IPEXPANDMAX=31
31
32#
33# Subroutines commonly used from network startup scripts.

--- 1159 unchanged lines hidden (view full) ---

1193 fi
1194}
1195
1196# clone_up
1197# Create cloneable interfaces.
1198#
1199clone_up()
1200{
1201 local _prefix _list ifn ifopt _iflist _n tmpargs
1202 _prefix=
1201 local _list ifn ifopt _iflist _n tmpargs
1203 _list=
1204 _iflist=$*
1205
1206 # create_args_IF
1207 for ifn in ${cloned_interfaces}; do
1208 # Parse ifn:ifopt.
1209 OIFS=$IFS; IFS=:; set -- $ifn; ifn=$1; ifopt=$2; IFS=$OIFS
1210 case $_iflist in
1211 ""|$ifn|$ifn\ *|*\ $ifn\ *|*\ $ifn) ;;
1212 *) continue ;;
1213 esac
1202 _list=
1203 _iflist=$*
1204
1205 # create_args_IF
1206 for ifn in ${cloned_interfaces}; do
1207 # Parse ifn:ifopt.
1208 OIFS=$IFS; IFS=:; set -- $ifn; ifn=$1; ifopt=$2; IFS=$OIFS
1209 case $_iflist in
1210 ""|$ifn|$ifn\ *|*\ $ifn\ *|*\ $ifn) ;;
1211 *) continue ;;
1212 esac
1214 # Skip if ifn already exists.
1215 if ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
1216 continue
1217 fi
1218 ${IFCONFIG_CMD} ${ifn} create `get_if_var ${ifn} create_args_IF`
1219 if [ $? -eq 0 ]; then
1220 _list="${_list}${_prefix}${ifn}"
1221 [ -z "$_prefix" ] && _prefix=' '
1222 fi
1213 case $ifn in
1214 epair[0-9]*)
1215 # epair(4) uses epair[0-9] for creation and
1216 # epair[0-9][ab] for configuration.
1217 #
1218 # Skip if ${ifn}a or ${ifn}b already exist.
1219 if ${IFCONFIG_CMD} ${ifn}a > /dev/null 2>&1; then
1220 continue
1221 elif ${IFCONFIG_CMD} ${ifn}b > /dev/null 2>&1; then
1222 continue
1223 fi
1224 ${IFCONFIG_CMD} ${ifn} create \
1225 `get_if_var ${ifn} create_args_IF`
1226 if [ $? -eq 0 ]; then
1227 _list="$_list ${ifn}a ${ifn}b"
1228 fi
1229 ;;
1230 *)
1231 # Skip if ${ifn} already exists.
1232 if ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
1233 continue
1234 fi
1235 ${IFCONFIG_CMD} ${ifn} create \
1236 `get_if_var ${ifn} create_args_IF`
1237 if [ $? -eq 0 ]; then
1238 _list="$_list $ifn"
1239 fi
1240 esac
1223 done
1224 if [ -n "$gif_interfaces" ]; then
1225 warn "\$gif_interfaces is obsolete. Use \$cloned_interfaces instead."
1226 fi
1227 for ifn in ${gif_interfaces}; do
1228 # Parse ifn:ifopt.
1229 OIFS=$IFS; IFS=:; set -- $ifn; ifn=$1; ifopt=$2; IFS=$OIFS
1230 case $_iflist in

--- 9 unchanged lines hidden (view full) ---

1240 ${IFCONFIG_CMD} $ifn create
1241 ;;
1242 *)
1243 _n=$(${IFCONFIG_CMD} gif create)
1244 ${IFCONFIG_CMD} $_n name $ifn
1245 ;;
1246 esac
1247 if [ $? -eq 0 ]; then
1241 done
1242 if [ -n "$gif_interfaces" ]; then
1243 warn "\$gif_interfaces is obsolete. Use \$cloned_interfaces instead."
1244 fi
1245 for ifn in ${gif_interfaces}; do
1246 # Parse ifn:ifopt.
1247 OIFS=$IFS; IFS=:; set -- $ifn; ifn=$1; ifopt=$2; IFS=$OIFS
1248 case $_iflist in

--- 9 unchanged lines hidden (view full) ---

1258 ${IFCONFIG_CMD} $ifn create
1259 ;;
1260 *)
1261 _n=$(${IFCONFIG_CMD} gif create)
1262 ${IFCONFIG_CMD} $_n name $ifn
1263 ;;
1264 esac
1265 if [ $? -eq 0 ]; then
1248 _list="${_list}${_prefix}${ifn}"
1249 [ -z "$_prefix" ] && _prefix=' '
1266 _list="$_list $ifn"
1250 fi
1251 tmpargs=$(get_if_var $ifn gifconfig_IF)
1252 eval ifconfig_${ifn}=\"tunnel \$tmpargs\"
1253 done
1267 fi
1268 tmpargs=$(get_if_var $ifn gifconfig_IF)
1269 eval ifconfig_${ifn}=\"tunnel \$tmpargs\"
1270 done
1254 if [ -n "${_list}" ]; then
1255 echo "Created clone interfaces: ${_list}."
1271 if [ -n "${_list# }" ]; then
1272 echo "Created clone interfaces: ${_list# }."
1256 fi
1273 fi
1257 debug "Cloned: ${_list}"
1274 debug "Cloned: ${_list# }"
1258}
1259
1260# clone_down
1261# Destroy cloned interfaces. Destroyed interfaces are echoed to
1262# standard output.
1263#
1264clone_down()
1265{
1275}
1276
1277# clone_down
1278# Destroy cloned interfaces. Destroyed interfaces are echoed to
1279# standard output.
1280#
1281clone_down()
1282{
1266 local _prefix _list ifn ifopt _iflist _sticky
1267 _prefix=
1283 local _list ifn _difn ifopt _iflist _sticky
1268 _list=
1269 _iflist=$*
1270
1271 : ${cloned_interfaces_sticky:=NO}
1272 if checkyesno cloned_interfaces_sticky; then
1273 _sticky=1
1274 else
1275 _sticky=0

--- 5 unchanged lines hidden (view full) ---

1281 sticky:*) continue ;; # :sticky => not destroy
1282 nosticky:*) ;; # :nosticky => destroy
1283 *:1) continue ;; # global sticky knob == 1
1284 esac
1285 case $_iflist in
1286 ""|$ifn|$ifn\ *|*\ $ifn\ *|*\ $ifn) ;;
1287 *) continue ;;
1288 esac
1284 _list=
1285 _iflist=$*
1286
1287 : ${cloned_interfaces_sticky:=NO}
1288 if checkyesno cloned_interfaces_sticky; then
1289 _sticky=1
1290 else
1291 _sticky=0

--- 5 unchanged lines hidden (view full) ---

1297 sticky:*) continue ;; # :sticky => not destroy
1298 nosticky:*) ;; # :nosticky => destroy
1299 *:1) continue ;; # global sticky knob == 1
1300 esac
1301 case $_iflist in
1302 ""|$ifn|$ifn\ *|*\ $ifn\ *|*\ $ifn) ;;
1303 *) continue ;;
1304 esac
1289 # Skip if ifn does not exist.
1290 if ! ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
1291 continue
1292 fi
1293 ${IFCONFIG_CMD} -n ${ifn} destroy
1294 if [ $? -eq 0 ]; then
1295 _list="${_list}${_prefix}${ifn}"
1296 [ -z "$_prefix" ] && _prefix=' '
1297 fi
1305 case $ifn in
1306 epair[0-9]*)
1307 # Note: epair(4) uses epair[0-9] for removal and
1308 # epair[0-9][ab] for configuration.
1309 #
1310 # Skip if both of ${ifn}a and ${ifn}b do not exist.
1311 if ${IFCONFIG_CMD} ${ifn}a > /dev/null 2>&1; then
1312 _difn=${ifn}a
1313 elif ${IFCONFIG_CMD} ${ifn}b > /dev/null 2>&1; then
1314 _difn=${ifn}b
1315 else
1316 continue
1317 fi
1318 ${IFCONFIG_CMD} -n $_difn destroy
1319 if [ $? -eq 0 ]; then
1320 _list="$_list ${ifn}a ${ifn}b"
1321 fi
1322 ;;
1323 *)
1324 # Skip if ifn does not exist.
1325 if ! ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
1326 continue
1327 fi
1328 ${IFCONFIG_CMD} -n ${ifn} destroy
1329 if [ $? -eq 0 ]; then
1330 _list="$_list $ifn"
1331 fi
1332 ;;
1333 esac
1298 done
1334 done
1299 if [ -n "${_list}" ]; then
1300 echo "Destroyed clone interfaces: ${_list}."
1335 if [ -n "${_list# }" ]; then
1336 echo "Destroyed clone interfaces: ${_list# }."
1301 fi
1337 fi
1302 debug "Destroyed clones: ${_list}"
1338 debug "Destroyed clones: ${_list# }"
1303}
1304
1305# childif_create
1306# Create and configure child interfaces. Return 0 if child
1307# interfaces are created.
1308#
1309childif_create()
1310{

--- 258 unchanged lines hidden (view full) ---

1569 if [ "$_if" = "lo0" ]; then
1570 _lo="lo0 "
1571 else
1572 _tmplist="${_tmplist} ${_if}"
1573 fi
1574 fi
1575 done
1576 _tmplist="${_lo}${_tmplist# }"
1339}
1340
1341# childif_create
1342# Create and configure child interfaces. Return 0 if child
1343# interfaces are created.
1344#
1345childif_create()
1346{

--- 258 unchanged lines hidden (view full) ---

1605 if [ "$_if" = "lo0" ]; then
1606 _lo="lo0 "
1607 else
1608 _tmplist="${_tmplist} ${_if}"
1609 fi
1610 fi
1611 done
1612 _tmplist="${_lo}${_tmplist# }"
1577 ;;
1613 ;;
1578 *)
1614 *)
1579 _tmplist="${network_interfaces} ${cloned_interfaces}"
1580
1615 for _if in ${network_interfaces} ${cloned_interfaces}; do
1616 # epair(4) uses epair[0-9] for creation and
1617 # epair[0-9][ab] for configuration.
1618 case $_if in
1619 epair[0-9]*)
1620 _tmplist="$_tmplist ${_if}a ${_if}b"
1621 ;;
1622 *)
1623 _tmplist="$_tmplist $_if"
1624 ;;
1625 esac
1626 done
1627 #
1581 # lo0 is effectively mandatory, so help prevent foot-shooting
1582 #
1583 case "$_tmplist" in
1628 # lo0 is effectively mandatory, so help prevent foot-shooting
1629 #
1630 case "$_tmplist" in
1584 lo0|'lo0 '*|*' lo0'|*' lo0 '*) ;; # This is fine, do nothing
1585 *) _tmplist="lo0 ${_tmplist}" ;;
1586 esac
1631 lo0|'lo0 '*|*' lo0'|*' lo0 '*)
1632 # This is fine, do nothing
1633 _tmplist="${_tmplist# }"
1587 ;;
1634 ;;
1635 *)
1636 _tmplist="lo0 ${_tmplist# }"
1637 ;;
1638 esac
1639 ;;
1588 esac
1589
1590 _list=
1591 case "$type" in
1592 nodhcp)
1593 for _if in ${_tmplist} ; do
1594 if ! dhcpif $_if && \
1595 [ -n "`_ifconfig_getargs $_if`" ]; then
1596 _list="${_list# } ${_if}"
1597 fi
1598 done
1640 esac
1641
1642 _list=
1643 case "$type" in
1644 nodhcp)
1645 for _if in ${_tmplist} ; do
1646 if ! dhcpif $_if && \
1647 [ -n "`_ifconfig_getargs $_if`" ]; then
1648 _list="${_list# } ${_if}"
1649 fi
1650 done
1599 ;;
1651 ;;
1600 dhcp)
1601 for _if in ${_tmplist} ; do
1602 if dhcpif $_if; then
1603 _list="${_list# } ${_if}"
1604 fi
1605 done
1652 dhcp)
1653 for _if in ${_tmplist} ; do
1654 if dhcpif $_if; then
1655 _list="${_list# } ${_if}"
1656 fi
1657 done
1606 ;;
1658 ;;
1607 noautoconf)
1608 for _if in ${_tmplist} ; do
1609 if ! ipv6_autoconfif $_if && \
1610 [ -n "`_ifconfig_getargs $_if ipv6`" ]; then
1611 _list="${_list# } ${_if}"
1612 fi
1613 done
1659 noautoconf)
1660 for _if in ${_tmplist} ; do
1661 if ! ipv6_autoconfif $_if && \
1662 [ -n "`_ifconfig_getargs $_if ipv6`" ]; then
1663 _list="${_list# } ${_if}"
1664 fi
1665 done
1614 ;;
1666 ;;
1615 autoconf)
1616 for _if in ${_tmplist} ; do
1617 if ipv6_autoconfif $_if; then
1618 _list="${_list# } ${_if}"
1619 fi
1620 done
1667 autoconf)
1668 for _if in ${_tmplist} ; do
1669 if ipv6_autoconfif $_if; then
1670 _list="${_list# } ${_if}"
1671 fi
1672 done
1621 ;;
1673 ;;
1622 *)
1623 _list=${_tmplist}
1674 *)
1675 _list=${_tmplist}
1624 ;;
1676 ;;
1625 esac
1626
1627 echo $_list
1628
1629 return 0
1630}
1631
1632# get_default_if -address_family

--- 76 unchanged lines hidden ---
1677 esac
1678
1679 echo $_list
1680
1681 return 0
1682}
1683
1684# get_default_if -address_family

--- 76 unchanged lines hidden ---