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 157706 2006-04-13 06:50:46Z brooks $ |
26# 27 28# 29# Subroutines commonly used from network startup scripts. 30# Requires that rc.conf be loaded first. 31# 32 33# ifconfig_up if --- 5 unchanged lines hidden (view full) --- 39# 40ifconfig_up() 41{ 42 _cfg=1 43 44 ifconfig_args=`ifconfig_getargs $1` 45 if [ -n "${ifconfig_args}" ]; then 46 ifconfig $1 up |
47 ifconfig $1 ${ifconfig_args} |
48 _cfg=0 49 fi 50 51 if wpaif $1; then 52 if [ $_cfg -ne 0 ] ; then 53 ifconfig $1 up 54 fi 55 /etc/rc.d/wpa_supplicant start $1 56 _cfg=0 # XXX: not sure this should count 57 fi 58 59 if dhcpif $1; then 60 if [ $_cfg -ne 0 ] ; then 61 ifconfig $1 up 62 fi |
63 if syncdhcpif $1; then 64 /etc/rc.d/dhclient start $1 65 fi |
66 _cfg=0 67 fi 68 69 return $_cfg 70} 71 72# ifconfig_down if 73# Remove all inet entries from the $if interface. It returns 74# 0 if inet entries were found and removed. It returns 1 if 75# no entries were found or they could not be removed. 76# |
77# XXX: should not be only inet 78# |
79ifconfig_down() 80{ 81 [ -z "$1" ] && return 1 82 _ifs="^" 83 _cfg=1 84 85 inetList="`ifconfig $1 | grep 'inet ' | tr "\n" "$_ifs"`" 86 --- 17 unchanged lines hidden (view full) --- 104 _cfg=0 105 fi 106 107 if dhcpif $1; then 108 /etc/rc.d/dhclient stop $1 109 _cfg=0 110 fi 111 |
112 ifconfig $1 down 113 |
114 return $_cfg 115} 116 |
117# get_if_var if var [default] 118# Return the value of the pseudo-hash corresponding to $if where 119# $var is a string containg the sub-string "IF" which will be 120# replaced with $if after the characters defined in _punct are 121# replaced with '_'. If the variable is unset, replace it with 122# $default if given. 123get_if_var() 124{ 125 if [ $# -ne 2 -a $# -ne 3 ]; then 126 err 3 'USAGE: get_if_var name var [default]' 127 fi 128 129 _if=$1 130 _punct=". - / +" 131 for _punct_c in $punct; do 132 _if=`ltr ${_if} ${_punct_c} '_'` 133 done 134 _var=$2 135 _default=$3 136 137 prefix=${_var%%IF*} 138 suffix=${_var##*IF} 139 eval echo \${${prefix}${_if}${suffix}-${_default}} 140} 141 |
142# _ifconfig_getargs if 143# Echos the arguments for the supplied interface to stdout. 144# returns 1 if empty. In general, ifconfig_getargs should be used 145# outside this file. 146_ifconfig_getargs() 147{ 148 _ifn=$1 149 if [ -z "$_ifn" ]; then 150 return 1 151 fi 152 |
153 get_if_var $_ifn ifconfig_IF "$ifconfig_DEFAULT" |
154} 155 156# ifconfig_getargs if 157# Takes the result from _ifconfig_getargs and removes pseudo 158# args such as DHCP and WPA. 159ifconfig_getargs() 160{ 161 _tmpargs=`_ifconfig_getargs $1` 162 if [ $? -eq 1 ]; then 163 return 1 164 fi 165 _args= 166 167 for _arg in $_tmpargs; do 168 case $_arg in |
169 [Dd][Hh][Cc][Pp]) ;; 170 [Nn][Oo][Aa][Uu][Tt][Oo]) ;; 171 [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) ;; 172 [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) ;; 173 [Ww][Pp][Aa]) ;; |
174 *) 175 _args="$_args $_arg" 176 ;; 177 esac 178 done 179 180 echo $_args 181} --- 19 unchanged lines hidden (view full) --- 201dhcpif() 202{ 203 _tmpargs=`_ifconfig_getargs $1` 204 for _arg in $_tmpargs; do 205 case $_arg in 206 [Dd][Hh][Cc][Pp]) 207 return 0 208 ;; |
209 [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) 210 return 0 211 ;; 212 [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) 213 return 0 214 ;; |
215 esac 216 done 217 return 1 218} 219 |
220# syncdhcpif 221# Returns 0 if the interface should be configured synchronously and 222# 1 otherwise. 223syncdhcpif() 224{ 225 _tmpargs=`_ifconfig_getargs $1` 226 for _arg in $_tmpargs; do 227 case $_arg in 228 [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) 229 return 1 230 ;; 231 [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) 232 return 0 233 ;; 234 esac 235 done 236 if checkyesno syncronous_dhclient; then 237 return 0 238 else 239 return 1 240 fi 241} 242 |
243# wpaif if 244# Returns 0 if the interface is a WPA interface and 1 otherwise. 245wpaif() 246{ 247 _tmpargs=`_ifconfig_getargs $1` 248 for _arg in $_tmpargs; do 249 case $_arg in 250 [Ww][Pp][Aa]) --- 27 unchanged lines hidden (view full) --- 278# and use $action to add or remove IPv4 addresses from $if. 279ipv4_addrs_common() 280{ 281 _ret=1 282 _if=$1 283 _action=$2 284 285 # get ipv4-addresses |
286 cidr_addr=`get_if_var $_if ipv4_addrs_IF` |
287 288 for _cidr in ${cidr_addr}; do 289 _ipaddr=${_cidr%%/*} 290 _netmask="/"${_cidr##*/} 291 _range=${_ipaddr##*.} 292 _ipnet=${_ipaddr%.*} 293 _iplow=${_range%-*} 294 _iphigh=${_range#*-} --- 23 unchanged lines hidden (view full) --- 318# It returns 0 if at least one alias was configured or 319# 1 if there were none. 320# 321ifalias_up() 322{ 323 _ret=1 324 alias=0 325 while : ; do |
326 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}` |
327 if [ -n "${ifconfig_args}" ]; then 328 ifconfig $1 ${ifconfig_args} alias 329 alias=$((${alias} + 1)) 330 _ret=0 331 else 332 break 333 fi 334 done --- 5 unchanged lines hidden (view full) --- 340# It returns 0 if at least one alias was removed or 341# 1 if there were none. 342# 343ifalias_down() 344{ 345 _ret=1 346 alias=0 347 while : ; do |
348 ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}` |
349 if [ -n "${ifconfig_args}" ]; then 350 ifconfig $1 ${ifconfig_args} -alias 351 alias=$((${alias} + 1)) 352 _ret=0 353 else 354 break 355 fi 356 done --- 62 unchanged lines hidden (view full) --- 419} 420 421gif_up() { 422 case ${gif_interfaces} in 423 [Nn][Oo] | '') 424 ;; 425 *) 426 for i in ${gif_interfaces}; do |
427 peers=`get_if_var $i gifconfig_IF` |
428 case ${peers} in 429 '') 430 continue 431 ;; 432 *) 433 ifconfig $i create >/dev/null 2>&1 434 ifconfig $i tunnel ${peers} 435 ifconfig $i up --- 7 unchanged lines hidden (view full) --- 443# 444# ipx_up ifn 445# Configure any IPX addresses for interface $ifn. Returns 0 if IPX 446# arguments were found and configured; returns 1 otherwise. 447# 448ipx_up() 449{ 450 ifn="$1" |
451 ifconfig_args=`get_if_var $ifn ifconfig_IF_ipx` |
452 if [ -n "${ifconfig_args}" ]; then 453 ifconfig ${ifn} ${ifconfig_args} 454 return 0 455 fi 456 return 1 457} 458 459# ipx_down ifn --- 30 unchanged lines hidden (view full) --- 490# Rename all requested interfaces. 491# 492ifnet_rename() 493{ 494 495 _ifn_list="`ifconfig -l`" 496 [ -z "$_ifn_list" ] && return 0 497 for _if in ${_ifn_list} ; do |
498 _ifname=`get_if_var $_if ifconfig_IF_name` |
499 if [ ! -z "$_ifname" ]; then 500 ifconfig $_if name $_ifname 501 fi 502 done 503 return 0 504} 505 506# --- 44 unchanged lines hidden (view full) --- 551 # Separate out dhcp and non-dhcp interfaces 552 # 553 _aprefix= 554 _bprefix= 555 for _if in ${_tmplist} ; do 556 if dhcpif $_if; then 557 _dhcplist="${_dhcplist}${_aprefix}${_if}" 558 [ -z "$_aprefix" ] && _aprefix=' ' |
559 elif [ -n "`_ifconfig_getargs $_if`" ]; then |
560 _nodhcplist="${_nodhcplist}${_bprefix}${_if}" 561 [ -z "$_bprefix" ] && _bprefix=' ' 562 fi 563 done 564 565 case "$type" in 566 nodhcp) 567 echo $_nodhcplist --- 48 unchanged lines hidden (view full) --- 616 rtsol_available=no 617 ;; 618 *) 619 rtsol_available=yes 620 ;; 621 esac 622 for i in $interfaces; do 623 rtsol_interface=yes |
624 prefix=`get_if_var $i ipv6_prefix_IF` |
625 if [ -n "${prefix}" ]; then 626 rtsol_available=no 627 rtsol_interface=no 628 laddr=`network6_getladdr $i` 629 hostid=`expr "${laddr}" : 'fe80::\(.*\)%\(.*\)'` 630 for j in ${prefix}; do 631 address=$j\:${hostid} 632 ifconfig $i inet6 ${address} prefixlen 64 alias 633 634 case ${ipv6_gateway_enable} in 635 [Yy][Ee][Ss]) 636 # subnet-router anycast address 637 # (rfc2373) 638 ifconfig $i inet6 $j:: prefixlen 64 \ 639 alias anycast 640 ;; 641 esac 642 done 643 fi |
644 ipv6_ifconfig=`get_if_var $i ipv6_ifconfig_IF` |
645 if [ -n "${ipv6_ifconfig}" ]; then 646 rtsol_available=no 647 rtsol_interface=no 648 ifconfig $i inet6 ${ipv6_ifconfig} alias 649 fi 650 651 if [ ${rtsol_available} = yes -a ${rtsol_interface} = yes ] 652 then --- 18 unchanged lines hidden (view full) --- 671 set ${rtsol_interfaces} 672 ifconfig $1 up 673 rtsol ${rtsol_flags} $1 674 fi 675 676 for i in $interfaces; do 677 alias=0 678 while : ; do |
679 ipv6_ifconfig=`get_if_var $i ipv6_ifconfig_IF_alias${alias}` |
680 if [ -z "${ipv6_ifconfig}" ]; then 681 break; 682 fi 683 ifconfig $i inet6 ${ipv6_ifconfig} alias 684 alias=$((${alias} + 1)) 685 done 686 done 687} --- 59 unchanged lines hidden (view full) --- 747 ipv6_route_default="default ${ipv6_defaultrouter}" 748 ;; 749 esac 750 case ${ipv6_static_routes} in 751 [Nn][Oo] | '') 752 ;; 753 *) 754 for i in ${ipv6_static_routes}; do |
755 ipv6_route_args=`get_if_var $i ipv6_route_IF` |
756 route add -inet6 ${ipv6_route_args} 757 done 758 ;; 759 esac 760} 761 762# Setup faith 763network6_faith_setup() --- 107 unchanged lines hidden --- |