netif revision 197947
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 197947 2009-10-10 22:17:03Z dougb $ 26113674Smtm# 27113674Smtm 28113674Smtm# PROVIDE: netif 29193198Sdougb# REQUIRE: atm1 cleanvar FILESYSTEMS serial sppp sysctl 30195026Sdougb# REQUIRE: ipfilter ipfs 31136224Smtm# KEYWORD: nojail 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 44197526Shrsset_rcvar_obsolete ipv6_enable ipv6_prefer 45197139Shrs 46113674Smtmnetwork_start() 47113674Smtm{ 48132892Smtm # Set the list of interfaces to work on. 49132892Smtm # 50165664Syar cmdifn=$* 51132892Smtm 52165664Syar if [ -z "$cmdifn" ]; then 53117021Smtm # 54117021Smtm # We're operating as a general network start routine. 55117021Smtm # 56113674Smtm 57149789Skeramida # disable SIGINT (Ctrl-c) when running at startup 58149730Sbrooks trap : 2 59149725Sbrooks 60117021Smtm # Create cloned interfaces 61117021Smtm clone_up 62113674Smtm 63166583Sflz # Create Fast EtherChannel interfaces 64166583Sflz fec_up 65166583Sflz 66117021Smtm # Create IPv6<-->IPv4 tunnels 67117021Smtm gif_up 68137070Spjd 69137070Spjd # Rename interfaces. 70137070Spjd ifnet_rename 71117021Smtm fi 72117021Smtm 73117021Smtm # Configure the interface(s). 74178356Ssam network_common ifn_start 75117021Smtm 76128714Sphk if [ -f /etc/rc.d/ipfilter ] ; then 77128714Sphk # Resync ipfilter 78175676Smtm /etc/rc.d/ipfilter quietresync 79128714Sphk fi 80165664Syar if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then 81165664Syar /etc/rc.d/bridge start $cmdifn 82159138Sthompsa fi 83117021Smtm} 84117021Smtm 85117021Smtmnetwork_stop() 86117021Smtm{ 87132892Smtm # Set the list of interfaces to work on. 88132892Smtm # 89165664Syar cmdifn=$* 90132892Smtm 91117021Smtm # Deconfigure the interface(s) 92117021Smtm network_common ifn_stop 93117021Smtm} 94117021Smtm 95178356Ssam# network_common routine 96117021Smtm# Common configuration subroutine for network interfaces. This 97117021Smtm# routine takes all the preparatory steps needed for configuriing 98178356Ssam# an interface and then calls $routine. 99117021Smtmnetwork_common() 100117021Smtm{ 101179961Smtm local _cooked_list _fail _func _ok _str 102165664Syar 103117021Smtm _func= 104117021Smtm 105117021Smtm if [ -z "$1" ]; then 106129492Smtm err 1 "network_common(): No function name specified." 107117021Smtm else 108117021Smtm _func="$1" 109117021Smtm fi 110117021Smtm 111117021Smtm # Set the scope of the command (all interfaces or just one). 112113674Smtm # 113132892Smtm _cooked_list= 114165664Syar if [ -n "$cmdifn" ]; then 115178356Ssam # Don't check that the interface(s) exist. We need to run 116147681Sbrooks # the down code even when the interface doesn't exist to 117147681Sbrooks # kill off wpa_supplicant. 118178356Ssam # XXXBED: is this really true or does wpa_supplicant die? 119178356Ssam # if so, we should get rid of the devd entry 120165664Syar _cooked_list="$cmdifn" 121132892Smtm else 122149725Sbrooks _cooked_list="`list_net_interfaces`" 123117021Smtm fi 124113674Smtm 125165664Syar _fail= 126179961Smtm _ok= 127117021Smtm for ifn in ${_cooked_list}; do 128179961Smtm if ${_func} ${ifn} $2; then 129179961Smtm _ok="${_ok} ${ifn}" 130179961Smtm else 131178356Ssam _fail="${_fail} ${ifn}" 132117021Smtm fi 133113674Smtm done 134113674Smtm 135179961Smtm _str= 136179961Smtm if [ -n "${_ok}" ]; then 137179961Smtm case ${_func} in 138179961Smtm ifn_start) 139179961Smtm _str='Starting' 140179961Smtm ;; 141179961Smtm ifn_stop) 142179961Smtm _str='Stopping' 143179961Smtm ;; 144179961Smtm esac 145179961Smtm echo "${_str} Network:${_ok}." 146197947Sdougb if check_startmsgs; then 147184485Spjd for ifn in ${_ok}; do 148184485Spjd /sbin/ifconfig ${ifn} 149184485Spjd done 150179961Smtm fi 151179961Smtm fi 152179961Smtm 153117021Smtm debug "The following interfaces were not configured: $_fail" 154117021Smtm} 155113674Smtm 156113674Smtmload_rc_config $name 157132892Smtmrun_rc_command $* 158