netif revision 301615
150472Speter#!/bin/sh 238738Sbrian# 337Srgrimes# Copyright (c) 2003 The FreeBSD Project. All rights reserved. 4234Snate# 5234Snate# Redistribution and use in source and binary forms, with or without 6234Snate# modification, are permitted provided that the following conditions 719033Sache# are met: 819911Sache# 1. Redistributions of source code must retain the above copyright 919033Sache# notice, this list of conditions and the following disclaimer. 1019033Sache# 2. Redistributions in binary form must reproduce the above copyright 119249Sache# notice, this list of conditions and the following disclaimer in the 1219033Sache# documentation and/or other materials provided with the distribution. 134994Sache# 1412391Sache# THIS SOFTWARE IS PROVIDED BY THE PROJECT ``AS IS'' AND ANY EXPRESS OR 1512392Sache# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1619033Sache# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1719033Sache# IN NO EVENT SHALL THE PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT, 18# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24# 25# $FreeBSD: stable/10/etc/rc.d/netif 301615 2016-06-08 13:40:07Z ngie $ 26# 27 28# PROVIDE: netif 29# REQUIRE: atm1 FILESYSTEMS serial sppp sysctl 30# REQUIRE: hostid ipfilter ipfs 31# KEYWORD: nojailvnet 32 33. /etc/rc.subr 34. /etc/network.subr 35 36name="network" 37start_cmd="network_start" 38stop_cmd="network_stop" 39cloneup_cmd="clone_up" 40clonedown_cmd="clone_down" 41clear_cmd="doclear" 42vnetup_cmd="vnet_up" 43vnetdown_cmd="vnet_down" 44extra_commands="cloneup clonedown clear vnetup vnetdown" 45cmdifn= 46 47set_rcvar_obsolete ipv6_enable ipv6_activate_all_interfaces 48set_rcvar_obsolete ipv6_prefer 49 50network_start() 51{ 52 local _if 53 54 # Set the list of interfaces to work on. 55 # 56 cmdifn=$* 57 58 if [ -z "$cmdifn" ]; then 59 # 60 # We're operating as a general network start routine. 61 # 62 63 # disable SIGINT (Ctrl-c) when running at startup 64 trap : 2 65 66 # Create Fast EtherChannel interfaces 67 fec_up 68 fi 69 70 # Create cloned interfaces 71 clone_up $cmdifn 72 73 # Rename interfaces. 74 ifnet_rename $cmdifn 75 76 # Configure the interface(s). 77 network_common ifn_start $cmdifn 78 79 if [ -f /etc/rc.d/ipfilter ] ; then 80 # Resync ipfilter 81 /etc/rc.d/ipfilter quietresync 82 fi 83 if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then 84 /etc/rc.d/bridge start $cmdifn 85 fi 86 if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then 87 for _if in $cmdifn; do 88 /etc/rc.d/routing static any $_if 89 done 90 fi 91} 92 93network_stop() 94{ 95 _clone_down=1 96 network_stop0 $* 97} 98 99doclear() 100{ 101 _clone_down= 102 network_stop0 $* 103} 104 105network_stop0() 106{ 107 local _if 108 109 # Set the list of interfaces to work on. 110 # 111 cmdifn=$* 112 113 # Deconfigure the interface(s) 114 network_common ifn_stop $cmdifn 115 116 # Destroy cloned interfaces 117 if [ -n "$_clone_down" ]; then 118 clone_down $cmdifn 119 fi 120 121 if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then 122 for _if in $cmdifn; do 123 /etc/rc.d/routing stop any $_if 124 done 125 fi 126} 127 128vnet_up() 129{ 130 cmdifn=$* 131 132 network_common ifn_vnetup $cmdifn 133} 134 135vnet_down() 136{ 137 cmdifn=$* 138 139 network_common ifn_vnetdown $cmdifn 140} 141 142# network_common routine 143# Common configuration subroutine for network interfaces. This 144# routine takes all the preparatory steps needed for configuriing 145# an interface and then calls $routine. 146network_common() 147{ 148 local _cooked_list _tmp_list _fail _func _ok _str _cmdifn 149 150 _func= 151 152 if [ -z "$1" ]; then 153 err 1 "network_common(): No function name specified." 154 else 155 _func="$1" 156 shift 157 fi 158 159 # Set the scope of the command (all interfaces or just one). 160 # 161 _cooked_list= 162 _tmp_list= 163 _cmdifn=$* 164 if [ -n "$_cmdifn" ]; then 165 # Don't check that the interface(s) exist. We need to run 166 # the down code even when the interface doesn't exist to 167 # kill off wpa_supplicant. 168 # XXXBED: is this really true or does wpa_supplicant die? 169 # if so, we should get rid of the devd entry 170 _cooked_list="$_cmdifn" 171 else 172 _cooked_list="`list_net_interfaces`" 173 fi 174 175 # Expand epair[0-9] to epair[0-9][ab]. 176 for ifn in $_cooked_list; do 177 case ${ifn#epair} in 178 [0-9]*[ab]) ;; # Skip epair[0-9]*[ab]. 179 [0-9]*) 180 for _str in $_cooked_list; do 181 case $_str in 182 $ifn) _tmp_list="$_tmp_list ${ifn}a ${ifn}b" ;; 183 *) _tmp_list="$_tmp_list ${ifn}" ;; 184 esac 185 done 186 _cooked_list=${_tmp_list# } 187 ;; 188 esac 189 done 190 191 _dadwait= 192 _fail= 193 _ok= 194 for ifn in ${_cooked_list# }; do 195 # Skip if ifn does not exist. 196 case $_func in 197 ifn_stop) 198 if ! ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then 199 warn "$ifn does not exist. Skipped." 200 _fail="${_fail} ${ifn}" 201 continue 202 fi 203 ;; 204 esac 205 if ${_func} ${ifn} $2; then 206 _ok="${_ok} ${ifn}" 207 if ipv6if ${ifn}; then 208 _dadwait=1 209 fi 210 else 211 _fail="${_fail} ${ifn}" 212 fi 213 done 214 215 # inet6 address configuration needs sleep for DAD. 216 case ${_func}:${_dadwait} in 217 ifn_start:1|ifn_vnetup:1|ifn_vnetdown:1) 218 sleep `${SYSCTL_N} net.inet6.ip6.dad_count` 219 sleep 1 220 ;; 221 esac 222 223 _str= 224 if [ -n "${_ok}" ]; then 225 case ${_func} in 226 ifn_start) 227 _str='Starting' 228 ;; 229 ifn_stop) 230 _str='Stopping' 231 ;; 232 ifn_vnetup) 233 _str='Moving' 234 ;; 235 ifn_vnetdown) 236 _str='Reclaiming' 237 ;; 238 esac 239 echo "${_str} Network:${_ok}." 240 case ${_func} in 241 ifn_vnetup) 242 # Clear _ok not to do "ifconfig $ifn" 243 # because $ifn is no longer in the current vnet. 244 _ok= 245 ;; 246 esac 247 if check_startmsgs; then 248 for ifn in ${_ok}; do 249 /sbin/ifconfig ${ifn} 250 done 251 fi 252 fi 253 254 debug "The following interfaces were not configured: $_fail" 255} 256 257load_rc_config $name 258run_rc_command $* 259