netif revision 250804
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 250804 2013-05-19 04:10:34Z jamie $ 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{ 49132892Smtm # Set the list of interfaces to work on. 50132892Smtm # 51165664Syar cmdifn=$* 52132892Smtm 53165664Syar if [ -z "$cmdifn" ]; then 54117021Smtm # 55117021Smtm # We're operating as a general network start routine. 56117021Smtm # 57113674Smtm 58149789Skeramida # disable SIGINT (Ctrl-c) when running at startup 59149730Sbrooks trap : 2 60149725Sbrooks 61117021Smtm # Create cloned interfaces 62117021Smtm clone_up 63113674Smtm 64166583Sflz # Create Fast EtherChannel interfaces 65166583Sflz fec_up 66166583Sflz 67117021Smtm # Create IPv6<-->IPv4 tunnels 68117021Smtm gif_up 69137070Spjd 70137070Spjd # Rename interfaces. 71137070Spjd ifnet_rename 72117021Smtm fi 73117021Smtm 74117021Smtm # Configure the interface(s). 75178356Ssam network_common ifn_start 76117021Smtm 77128714Sphk if [ -f /etc/rc.d/ipfilter ] ; then 78128714Sphk # Resync ipfilter 79175676Smtm /etc/rc.d/ipfilter quietresync 80128714Sphk fi 81165664Syar if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then 82165664Syar /etc/rc.d/bridge start $cmdifn 83159138Sthompsa fi 84117021Smtm} 85117021Smtm 86117021Smtmnetwork_stop() 87117021Smtm{ 88132892Smtm # Set the list of interfaces to work on. 89132892Smtm # 90165664Syar cmdifn=$* 91132892Smtm 92117021Smtm # Deconfigure the interface(s) 93117021Smtm network_common ifn_stop 94117021Smtm} 95117021Smtm 96178356Ssam# network_common routine 97117021Smtm# Common configuration subroutine for network interfaces. This 98117021Smtm# routine takes all the preparatory steps needed for configuriing 99178356Ssam# an interface and then calls $routine. 100117021Smtmnetwork_common() 101117021Smtm{ 102179961Smtm local _cooked_list _fail _func _ok _str 103165664Syar 104117021Smtm _func= 105117021Smtm 106117021Smtm if [ -z "$1" ]; then 107129492Smtm err 1 "network_common(): No function name specified." 108117021Smtm else 109117021Smtm _func="$1" 110117021Smtm fi 111117021Smtm 112117021Smtm # Set the scope of the command (all interfaces or just one). 113113674Smtm # 114132892Smtm _cooked_list= 115165664Syar if [ -n "$cmdifn" ]; then 116178356Ssam # Don't check that the interface(s) exist. We need to run 117147681Sbrooks # the down code even when the interface doesn't exist to 118147681Sbrooks # kill off wpa_supplicant. 119178356Ssam # XXXBED: is this really true or does wpa_supplicant die? 120178356Ssam # if so, we should get rid of the devd entry 121165664Syar _cooked_list="$cmdifn" 122132892Smtm else 123149725Sbrooks _cooked_list="`list_net_interfaces`" 124117021Smtm fi 125113674Smtm 126230453Shrs _dadwait= 127165664Syar _fail= 128179961Smtm _ok= 129117021Smtm for ifn in ${_cooked_list}; do 130179961Smtm if ${_func} ${ifn} $2; then 131179961Smtm _ok="${_ok} ${ifn}" 132230453Shrs if ipv6if ${ifn}; then 133230453Shrs _dadwait=1 134230453Shrs fi 135179961Smtm else 136178356Ssam _fail="${_fail} ${ifn}" 137117021Smtm fi 138113674Smtm done 139113674Smtm 140230453Shrs # inet6 address configuration needs sleep for DAD. 141230726Shrs case ${_func}:${_dadwait} in 142230726Shrs ifn_start:1) 143230453Shrs sleep `${SYSCTL_N} net.inet6.ip6.dad_count` 144230453Shrs sleep 1 145230726Shrs ;; 146230726Shrs esac 147230453Shrs 148179961Smtm _str= 149179961Smtm if [ -n "${_ok}" ]; then 150179961Smtm case ${_func} in 151179961Smtm ifn_start) 152179961Smtm _str='Starting' 153179961Smtm ;; 154179961Smtm ifn_stop) 155179961Smtm _str='Stopping' 156179961Smtm ;; 157179961Smtm esac 158179961Smtm echo "${_str} Network:${_ok}." 159197947Sdougb if check_startmsgs; then 160184485Spjd for ifn in ${_ok}; do 161184485Spjd /sbin/ifconfig ${ifn} 162184485Spjd done 163179961Smtm fi 164179961Smtm fi 165179961Smtm 166117021Smtm debug "The following interfaces were not configured: $_fail" 167117021Smtm} 168113674Smtm 169113674Smtmload_rc_config $name 170132892Smtmrun_rc_command $* 171