netif revision 184485
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 184485 2008-10-30 20:24:25Z pjd $ 26113674Smtm# 27113674Smtm 28113674Smtm# PROVIDE: netif 29171590Sjhb# REQUIRE: atm1 cleanvar ipfilter FILESYSTEMS serial sppp sysctl 30136224Smtm# KEYWORD: nojail 31113674Smtm 32113674Smtm. /etc/rc.subr 33113674Smtm. /etc/network.subr 34113674Smtm 35113674Smtmname="network" 36113674Smtmstart_cmd="network_start" 37113674Smtmstop_cmd="network_stop" 38113674Smtmcloneup_cmd="clone_up" 39113674Smtmclonedown_cmd="clone_down" 40113674Smtmextra_commands="cloneup clonedown" 41165664Syarcmdifn= 42113674Smtm 43113674Smtmnetwork_start() 44113674Smtm{ 45132892Smtm # Set the list of interfaces to work on. 46132892Smtm # 47165664Syar cmdifn=$* 48132892Smtm 49165664Syar if [ -z "$cmdifn" ]; then 50117021Smtm # 51117021Smtm # We're operating as a general network start routine. 52117021Smtm # 53113674Smtm 54149789Skeramida # disable SIGINT (Ctrl-c) when running at startup 55149730Sbrooks trap : 2 56149725Sbrooks 57117021Smtm # Create cloned interfaces 58117021Smtm clone_up 59113674Smtm 60166583Sflz # Create Fast EtherChannel interfaces 61166583Sflz fec_up 62166583Sflz 63117021Smtm # Create IPv6<-->IPv4 tunnels 64117021Smtm gif_up 65137070Spjd 66137070Spjd # Rename interfaces. 67137070Spjd ifnet_rename 68117021Smtm fi 69117021Smtm 70117021Smtm # Configure the interface(s). 71178356Ssam network_common ifn_start 72117021Smtm 73128714Sphk if [ -f /etc/rc.d/ipfilter ] ; then 74128714Sphk # Resync ipfilter 75175676Smtm /etc/rc.d/ipfilter quietresync 76128714Sphk fi 77165664Syar if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then 78165664Syar /etc/rc.d/bridge start $cmdifn 79159138Sthompsa fi 80117021Smtm} 81117021Smtm 82117021Smtmnetwork_stop() 83117021Smtm{ 84132892Smtm # Set the list of interfaces to work on. 85132892Smtm # 86165664Syar cmdifn=$* 87132892Smtm 88117021Smtm # Deconfigure the interface(s) 89117021Smtm network_common ifn_stop 90117021Smtm} 91117021Smtm 92178356Ssam# network_common routine 93117021Smtm# Common configuration subroutine for network interfaces. This 94117021Smtm# routine takes all the preparatory steps needed for configuriing 95178356Ssam# an interface and then calls $routine. 96117021Smtmnetwork_common() 97117021Smtm{ 98179961Smtm local _cooked_list _fail _func _ok _str 99165664Syar 100117021Smtm _func= 101117021Smtm 102117021Smtm if [ -z "$1" ]; then 103129492Smtm err 1 "network_common(): No function name specified." 104117021Smtm else 105117021Smtm _func="$1" 106117021Smtm fi 107117021Smtm 108117021Smtm # Set the scope of the command (all interfaces or just one). 109113674Smtm # 110132892Smtm _cooked_list= 111165664Syar if [ -n "$cmdifn" ]; then 112178356Ssam # Don't check that the interface(s) exist. We need to run 113147681Sbrooks # the down code even when the interface doesn't exist to 114147681Sbrooks # kill off wpa_supplicant. 115178356Ssam # XXXBED: is this really true or does wpa_supplicant die? 116178356Ssam # if so, we should get rid of the devd entry 117165664Syar _cooked_list="$cmdifn" 118132892Smtm else 119149725Sbrooks _cooked_list="`list_net_interfaces`" 120117021Smtm fi 121113674Smtm 122165664Syar _fail= 123179961Smtm _ok= 124117021Smtm for ifn in ${_cooked_list}; do 125179961Smtm if ${_func} ${ifn} $2; then 126179961Smtm _ok="${_ok} ${ifn}" 127179961Smtm else 128178356Ssam _fail="${_fail} ${ifn}" 129117021Smtm fi 130113674Smtm done 131113674Smtm 132179961Smtm _str= 133179961Smtm if [ -n "${_ok}" ]; then 134179961Smtm case ${_func} in 135179961Smtm ifn_start) 136179961Smtm _str='Starting' 137179961Smtm ;; 138179961Smtm ifn_stop) 139179961Smtm _str='Stopping' 140179961Smtm ;; 141179961Smtm esac 142179961Smtm echo "${_str} Network:${_ok}." 143179961Smtm if [ -z "${rc_quiet}" ]; then 144184485Spjd for ifn in ${_ok}; do 145184485Spjd /sbin/ifconfig ${ifn} 146184485Spjd done 147179961Smtm fi 148179961Smtm fi 149179961Smtm 150117021Smtm debug "The following interfaces were not configured: $_fail" 151117021Smtm} 152113674Smtm 153113674Smtmload_rc_config $name 154132892Smtmrun_rc_command $* 155