netif revision 251584
1113674Smtm#!/bin/sh 2113674Smtm# 3113674Smtm# Copyright (c) 2003 The FreeBSD Project. All rights reserved. 4113674Smtm# 5113674Smtm# Redistribution and use in source and binary forms, with or without 6113674Smtm# modification, are permitted provided that the following conditions 7113674Smtm# are met: 8113674Smtm# 1. Redistributions of source code must retain the above copyright 9113674Smtm# notice, this list of conditions and the following disclaimer. 10113674Smtm# 2. Redistributions in binary form must reproduce the above copyright 11113674Smtm# notice, this list of conditions and the following disclaimer in the 12113674Smtm# documentation and/or other materials provided with the distribution. 13113674Smtm# 14113674Smtm# THIS SOFTWARE IS PROVIDED BY THE PROJECT ``AS IS'' AND ANY EXPRESS OR 15113674Smtm# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16113674Smtm# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17113674Smtm# IN NO EVENT SHALL THE PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT, 18113674Smtm# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19113674Smtm# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20113674Smtm# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21113674Smtm# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22113674Smtm# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23113674Smtm# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24113674Smtm# 25113674Smtm# $FreeBSD: head/etc/rc.d/netif 251584 2013-06-09 18:11:36Z hrs $ 26113674Smtm# 27113674Smtm 28113674Smtm# PROVIDE: netif 29240336Sobrien# REQUIRE: atm1 FILESYSTEMS serial sppp sysctl 30195026Sdougb# REQUIRE: ipfilter ipfs 31250804Sjamie# KEYWORD: nojailvnet 32113674Smtm 33113674Smtm. /etc/rc.subr 34113674Smtm. /etc/network.subr 35113674Smtm 36113674Smtmname="network" 37113674Smtmstart_cmd="network_start" 38113674Smtmstop_cmd="network_stop" 39113674Smtmcloneup_cmd="clone_up" 40113674Smtmclonedown_cmd="clone_down" 41113674Smtmextra_commands="cloneup clonedown" 42165664Syarcmdifn= 43113674Smtm 44212579Shrsset_rcvar_obsolete ipv6_enable ipv6_activate_all_interfaces 45212579Shrsset_rcvar_obsolete ipv6_prefer 46197139Shrs 47113674Smtmnetwork_start() 48113674Smtm{ 49251584Shrs local _if 50251584Shrs 51132892Smtm # Set the list of interfaces to work on. 52132892Smtm # 53165664Syar cmdifn=$* 54132892Smtm 55165664Syar if [ -z "$cmdifn" ]; then 56117021Smtm # 57117021Smtm # We're operating as a general network start routine. 58117021Smtm # 59113674Smtm 60149789Skeramida # disable SIGINT (Ctrl-c) when running at startup 61149730Sbrooks trap : 2 62149725Sbrooks 63117021Smtm # Create cloned interfaces 64117021Smtm clone_up 65113674Smtm 66166583Sflz # Create Fast EtherChannel interfaces 67166583Sflz fec_up 68166583Sflz 69117021Smtm # Create IPv6<-->IPv4 tunnels 70117021Smtm gif_up 71137070Spjd 72137070Spjd # Rename interfaces. 73137070Spjd ifnet_rename 74117021Smtm fi 75117021Smtm 76117021Smtm # Configure the interface(s). 77178356Ssam network_common ifn_start 78117021Smtm 79128714Sphk if [ -f /etc/rc.d/ipfilter ] ; then 80128714Sphk # Resync ipfilter 81175676Smtm /etc/rc.d/ipfilter quietresync 82128714Sphk fi 83165664Syar if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then 84165664Syar /etc/rc.d/bridge start $cmdifn 85159138Sthompsa fi 86251584Shrs if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then 87251584Shrs for _if in $cmdifn; do 88251584Shrs /etc/rc.d/routing start any $_if 89251584Shrs done 90251584Shrs fi 91117021Smtm} 92117021Smtm 93117021Smtmnetwork_stop() 94117021Smtm{ 95251584Shrs local _if 96251584Shrs 97132892Smtm # Set the list of interfaces to work on. 98132892Smtm # 99165664Syar cmdifn=$* 100132892Smtm 101117021Smtm # Deconfigure the interface(s) 102117021Smtm network_common ifn_stop 103251584Shrs 104251584Shrs if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then 105251584Shrs for _if in $cmdifn; do 106251584Shrs /etc/rc.d/routing stop any $_if 107251584Shrs done 108251584Shrs fi 109117021Smtm} 110117021Smtm 111178356Ssam# network_common routine 112117021Smtm# Common configuration subroutine for network interfaces. This 113117021Smtm# routine takes all the preparatory steps needed for configuriing 114178356Ssam# an interface and then calls $routine. 115117021Smtmnetwork_common() 116117021Smtm{ 117179961Smtm local _cooked_list _fail _func _ok _str 118165664Syar 119117021Smtm _func= 120117021Smtm 121117021Smtm if [ -z "$1" ]; then 122129492Smtm err 1 "network_common(): No function name specified." 123117021Smtm else 124117021Smtm _func="$1" 125117021Smtm fi 126117021Smtm 127117021Smtm # Set the scope of the command (all interfaces or just one). 128113674Smtm # 129132892Smtm _cooked_list= 130165664Syar if [ -n "$cmdifn" ]; then 131178356Ssam # Don't check that the interface(s) exist. We need to run 132147681Sbrooks # the down code even when the interface doesn't exist to 133147681Sbrooks # kill off wpa_supplicant. 134178356Ssam # XXXBED: is this really true or does wpa_supplicant die? 135178356Ssam # if so, we should get rid of the devd entry 136165664Syar _cooked_list="$cmdifn" 137132892Smtm else 138149725Sbrooks _cooked_list="`list_net_interfaces`" 139117021Smtm fi 140113674Smtm 141230453Shrs _dadwait= 142165664Syar _fail= 143179961Smtm _ok= 144117021Smtm for ifn in ${_cooked_list}; do 145179961Smtm if ${_func} ${ifn} $2; then 146179961Smtm _ok="${_ok} ${ifn}" 147230453Shrs if ipv6if ${ifn}; then 148230453Shrs _dadwait=1 149230453Shrs fi 150179961Smtm else 151178356Ssam _fail="${_fail} ${ifn}" 152117021Smtm fi 153113674Smtm done 154113674Smtm 155230453Shrs # inet6 address configuration needs sleep for DAD. 156230726Shrs case ${_func}:${_dadwait} in 157230726Shrs ifn_start:1) 158230453Shrs sleep `${SYSCTL_N} net.inet6.ip6.dad_count` 159230453Shrs sleep 1 160230726Shrs ;; 161230726Shrs esac 162230453Shrs 163179961Smtm _str= 164179961Smtm if [ -n "${_ok}" ]; then 165179961Smtm case ${_func} in 166179961Smtm ifn_start) 167179961Smtm _str='Starting' 168179961Smtm ;; 169179961Smtm ifn_stop) 170179961Smtm _str='Stopping' 171179961Smtm ;; 172179961Smtm esac 173179961Smtm echo "${_str} Network:${_ok}." 174197947Sdougb if check_startmsgs; then 175184485Spjd for ifn in ${_ok}; do 176184485Spjd /sbin/ifconfig ${ifn} 177184485Spjd done 178179961Smtm fi 179179961Smtm fi 180179961Smtm 181117021Smtm debug "The following interfaces were not configured: $_fail" 182117021Smtm} 183113674Smtm 184113674Smtmload_rc_config $name 185132892Smtmrun_rc_command $* 186