Deleted Added
full compact
network.subr (253520) network.subr (253924)
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 253520 2013-07-21 15:26:25Z hrs $
25# $FreeBSD: head/etc/network.subr 253924 2013-08-04 06:36:17Z 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.

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

655 ifalias ${_if} inet -alias && _ret=0
656
657 inetList="`${IFCONFIG_CMD} ${_if} | grep 'inet ' | tr "\n" "$_ifs"`"
658
659 oldifs="$IFS"
660 IFS="$_ifs"
661 for _inet in $inetList ; do
662 # get rid of extraneous line
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.

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

655 ifalias ${_if} inet -alias && _ret=0
656
657 inetList="`${IFCONFIG_CMD} ${_if} | grep 'inet ' | tr "\n" "$_ifs"`"
658
659 oldifs="$IFS"
660 IFS="$_ifs"
661 for _inet in $inetList ; do
662 # get rid of extraneous line
663 case $_inet in
664 "") break ;;
665 inet\ *) ;;
666 *) continue ;;
667 esac
663 [ -z "$_inet" ] && break
664
665 _inet=`expr "$_inet" : '.*\(inet \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\).*'`
666
667 IFS="$oldifs"
668 ${IFCONFIG_CMD} ${_if} ${_inet} delete
669 IFS="$_ifs"
670 _ret=0

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

1187 fi
1188}
1189
1190# clone_up
1191# Create cloneable interfaces.
1192#
1193clone_up()
1194{
668 [ -z "$_inet" ] && break
669
670 _inet=`expr "$_inet" : '.*\(inet \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\).*'`
671
672 IFS="$oldifs"
673 ${IFCONFIG_CMD} ${_if} ${_inet} delete
674 IFS="$_ifs"
675 _ret=0

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

1192 fi
1193}
1194
1195# clone_up
1196# Create cloneable interfaces.
1197#
1198clone_up()
1199{
1195 local _prefix _list ifn
1200 local _prefix _list ifn ifopt _iflist _n tmpargs
1196 _prefix=
1197 _list=
1201 _prefix=
1202 _list=
1203 _iflist=$*
1198
1199 # create_args_IF
1200 for ifn in ${cloned_interfaces}; do
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
1213 # Skip if ifn already exists.
1214 if ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
1215 continue
1216 fi
1201 ${IFCONFIG_CMD} ${ifn} create `get_if_var ${ifn} create_args_IF`
1202 if [ $? -eq 0 ]; then
1203 _list="${_list}${_prefix}${ifn}"
1204 [ -z "$_prefix" ] && _prefix=' '
1205 fi
1206 done
1217 ${IFCONFIG_CMD} ${ifn} create `get_if_var ${ifn} create_args_IF`
1218 if [ $? -eq 0 ]; then
1219 _list="${_list}${_prefix}${ifn}"
1220 [ -z "$_prefix" ] && _prefix=' '
1221 fi
1222 done
1223 if [ -n "$gif_interfaces" ]; then
1224 warn "\$gif_interfaces is obsolete. Use \$cloned_interfaces instead."
1225 fi
1226 for ifn in ${gif_interfaces}; do
1227 # Parse ifn:ifopt.
1228 OIFS=$IFS; IFS=:; set -- $ifn; ifn=$1; ifopt=$2; IFS=$OIFS
1229 case $_iflist in
1230 ""|$ifn|$ifn\ *|*\ $ifn\ *|*\ $ifn) ;;
1231 *) continue ;;
1232 esac
1233 # Skip if ifn already exists.
1234 if ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
1235 continue
1236 fi
1237 case $ifn in
1238 gif[0-9]*)
1239 ${IFCONFIG_CMD} $ifn create
1240 ;;
1241 *)
1242 _n=$(${IFCONFIG_CMD} gif create)
1243 ${IFCONFIG_CMD} $_n name $ifn
1244 ;;
1245 esac
1246 if [ $? -eq 0 ]; then
1247 _list="${_list}${_prefix}${ifn}"
1248 [ -z "$_prefix" ] && _prefix=' '
1249 fi
1250 tmpargs=$(get_if_var $ifn gifconfig_IF)
1251 eval ifconfig_${ifn}=\"tunnel \$tmpargs\"
1252 done
1253 if [ -n "${_list}" ]; then
1254 echo "Created clone interfaces: ${_list}."
1255 fi
1207 debug "Cloned: ${_list}"
1208}
1209
1210# clone_down
1211# Destroy cloned interfaces. Destroyed interfaces are echoed to
1212# standard output.
1213#
1214clone_down()
1215{
1256 debug "Cloned: ${_list}"
1257}
1258
1259# clone_down
1260# Destroy cloned interfaces. Destroyed interfaces are echoed to
1261# standard output.
1262#
1263clone_down()
1264{
1216 local _prefix _list ifn
1265 local _prefix _list ifn ifopt _iflist _sticky
1217 _prefix=
1218 _list=
1266 _prefix=
1267 _list=
1268 _iflist=$*
1219
1269
1220 for ifn in ${cloned_interfaces}; do
1270 : ${cloned_interfaces_sticky:=NO}
1271 if checkyesno cloned_interfaces_sticky; then
1272 _sticky=1
1273 else
1274 _sticky=0
1275 fi
1276 for ifn in ${cloned_interfaces} ${gif_interfaces}; do
1277 # Parse ifn:ifopt.
1278 OIFS=$IFS; IFS=:; set -- $ifn; ifn=$1; ifopt=$2; IFS=$OIFS
1279 case $ifopt:$_sticky in
1280 sticky:*) continue ;; # :sticky => not destroy
1281 nosticky:*) ;; # :nosticky => destroy
1282 *:1) continue ;; # global sticky knob == 1
1283 esac
1284 case $_iflist in
1285 ""|$ifn|$ifn\ *|*\ $ifn\ *|*\ $ifn) ;;
1286 *) continue ;;
1287 esac
1288 # Skip if ifn does not exist.
1289 if ! ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
1290 continue
1291 fi
1221 ${IFCONFIG_CMD} -n ${ifn} destroy
1222 if [ $? -eq 0 ]; then
1223 _list="${_list}${_prefix}${ifn}"
1224 [ -z "$_prefix" ] && _prefix=' '
1225 fi
1226 done
1292 ${IFCONFIG_CMD} -n ${ifn} destroy
1293 if [ $? -eq 0 ]; then
1294 _list="${_list}${_prefix}${ifn}"
1295 [ -z "$_prefix" ] && _prefix=' '
1296 fi
1297 done
1298 if [ -n "${_list}" ]; then
1299 echo "Destroyed clone interfaces: ${_list}."
1300 fi
1227 debug "Destroyed clones: ${_list}"
1228}
1229
1230# childif_create
1231# Create and configure child interfaces. Return 0 if child
1232# interfaces are created.
1233#
1234childif_create()

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

1342 t=`expr "${line}" : '.* name="\([a-z]*[0-9]*\)" .*'`
1343 if [ -n "${t}" ]; then
1344 echo ${t}
1345 return
1346 fi
1347 done
1348}
1349
1301 debug "Destroyed clones: ${_list}"
1302}
1303
1304# childif_create
1305# Create and configure child interfaces. Return 0 if child
1306# interfaces are created.
1307#
1308childif_create()

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

1416 t=`expr "${line}" : '.* name="\([a-z]*[0-9]*\)" .*'`
1417 if [ -n "${t}" ]; then
1418 echo ${t}
1419 return
1420 fi
1421 done
1422}
1423
1350# gif_up
1351# Create gif(4) tunnel interfaces.
1352gif_up()
1353{
1354 local i peers
1355
1356 for i in ${gif_interfaces}; do
1357 peers=`get_if_var $i gifconfig_IF`
1358 case ${peers} in
1359 '')
1360 continue
1361 ;;
1362 *)
1363 if expr $i : 'gif[0-9][0-9]*$' >/dev/null 2>&1; then
1364 ${IFCONFIG_CMD} $i create >/dev/null 2>&1
1365 else
1366 gif=`${IFCONFIG_CMD} gif create`
1367 ${IFCONFIG_CMD} $gif name $i
1368 fi
1369 ${IFCONFIG_CMD} $i tunnel ${peers}
1370 ${IFCONFIG_CMD} $i up
1371 ;;
1372 esac
1373 done
1374}
1375
1376# ng_fec_create ifn
1377# Configure Fast EtherChannel for interface $ifn. Returns 0 if
1378# FEC arguments were found and configured; returns !0 otherwise.
1379ng_fec_create()
1380{
1381 local req_iface iface bogus
1382 req_iface="$1"
1383

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

1465 IFS="$_ifs"
1466 _ret=0
1467 done
1468 IFS="$oldifs"
1469
1470 return $_ret
1471}
1472
1424# ng_fec_create ifn
1425# Configure Fast EtherChannel for interface $ifn. Returns 0 if
1426# FEC arguments were found and configured; returns !0 otherwise.
1427ng_fec_create()
1428{
1429 local req_iface iface bogus
1430 req_iface="$1"
1431

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

1513 IFS="$_ifs"
1514 _ret=0
1515 done
1516 IFS="$oldifs"
1517
1518 return $_ret
1519}
1520
1473# ifnet_rename
1474# Rename all requested interfaces.
1521# ifnet_rename [ifname]
1522# Rename interfaces if ifconfig_IF_name is defined.
1475#
1476ifnet_rename()
1477{
1478 local _if _ifname
1479
1480 # ifconfig_IF_name
1523#
1524ifnet_rename()
1525{
1526 local _if _ifname
1527
1528 # ifconfig_IF_name
1481 for _if in `${IFCONFIG_CMD} -l`; do
1529 for _if in ${*:-$(${IFCONFIG_CMD} -l)}; do
1482 _ifname=`get_if_var $_if ifconfig_IF_name`
1483 if [ ! -z "$_ifname" ]; then
1484 ${IFCONFIG_CMD} $_if name $_ifname
1485 fi
1486 done
1487
1488 return 0
1489}

--- 170 unchanged lines hidden ---
1530 _ifname=`get_if_var $_if ifconfig_IF_name`
1531 if [ ! -z "$_ifname" ]; then
1532 ${IFCONFIG_CMD} $_if name $_ifname
1533 fi
1534 done
1535
1536 return 0
1537}

--- 170 unchanged lines hidden ---