netif revision 166583
1134911Ssam#!/bin/sh 2134911Ssam# 3134911Ssam# Copyright (c) 2003 The FreeBSD Project. All rights reserved. 4134911Ssam# 5134911Ssam# Redistribution and use in source and binary forms, with or without 6134911Ssam# modification, are permitted provided that the following conditions 7134911Ssam# are met: 8134911Ssam# 1. Redistributions of source code must retain the above copyright 9134911Ssam# notice, this list of conditions and the following disclaimer. 10134911Ssam# 2. Redistributions in binary form must reproduce the above copyright 11134911Ssam# notice, this list of conditions and the following disclaimer in the 12134911Ssam# documentation and/or other materials provided with the distribution. 13134911Ssam# 14134911Ssam# THIS SOFTWARE IS PROVIDED BY THE PROJECT ``AS IS'' AND ANY EXPRESS OR 15134911Ssam# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16134911Ssam# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17134911Ssam# IN NO EVENT SHALL THE PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT, 18134911Ssam# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19134911Ssam# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20134911Ssam# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21134911Ssam# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22134911Ssam# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23134911Ssam# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24134911Ssam# 25134911Ssam# $FreeBSD: head/etc/rc.d/netif 166583 2007-02-09 12:11:27Z flz $ 26134911Ssam# 27134911Ssam 28134911Ssam# PROVIDE: netif 29134911Ssam# REQUIRE: atm1 ipfilter mountcritlocal serial sppp sysctl 30134911Ssam# KEYWORD: nojail 31134911Ssam 32134911Ssam. /etc/rc.subr 33134911Ssam. /etc/network.subr 34134911Ssam 35134911Ssamname="network" 36134911Ssamstart_cmd="network_start" 37134911Ssamstop_cmd="network_stop" 38134911Ssamcloneup_cmd="clone_up" 39134911Ssamclonedown_cmd="clone_down" 40134911Ssamextra_commands="cloneup clonedown" 41134911Ssamcmdifn= 42134911Ssam 43167755Ssamnetwork_start() 44134911Ssam{ 45134911Ssam # Set the list of interfaces to work on. 46134911Ssam # 47134911Ssam cmdifn=$* 48134911Ssam 49134911Ssam if [ -z "$cmdifn" ]; then 50134911Ssam # 51134911Ssam # We're operating as a general network start routine. 52134911Ssam # 53134911Ssam 54134911Ssam # disable SIGINT (Ctrl-c) when running at startup 55134911Ssam trap : 2 56134911Ssam 57134911Ssam # Create cloned interfaces 58134911Ssam clone_up 59134911Ssam 60134911Ssam # Create Fast EtherChannel interfaces 61134911Ssam fec_up 62134911Ssam 63134911Ssam # Create IPv6<-->IPv4 tunnels 64134911Ssam gif_up 65134911Ssam 66134911Ssam # Rename interfaces. 67134911Ssam ifnet_rename 68134911Ssam fi 69134911Ssam 70134911Ssam # Configure the interface(s). 71134911Ssam network_common ifn_start verbose 72134911Ssam 73134911Ssam if [ -f /etc/rc.d/ipfilter ] ; then 74134911Ssam # Resync ipfilter 75134911Ssam /etc/rc.d/ipfilter resync 76134911Ssam fi 77134911Ssam if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then 78134911Ssam /etc/rc.d/bridge start $cmdifn 79134911Ssam fi 80134911Ssam} 81134911Ssam 82134911Ssamnetwork_stop() 83134911Ssam{ 84134911Ssam # Set the list of interfaces to work on. 85134911Ssam # 86134911Ssam cmdifn=$* 87134911Ssam 88134911Ssam echo -n "Stopping network:" 89134911Ssam 90134911Ssam # Deconfigure the interface(s) 91134911Ssam network_common ifn_stop 92134911Ssam echo '.' 93134911Ssam} 94134911Ssam 95134911Ssam# network_common routine verbose 96175979Smatteo# Common configuration subroutine for network interfaces. This 97134911Ssam# routine takes all the preparatory steps needed for configuriing 98134911Ssam# an interface and then calls $routine. If $verbose is specified, 99134911Ssam# it will call ifconfig(8) to show, in long format, the configured 100134911Ssam# interfaces. If $verbose is not given, it will simply output the 101134911Ssam# configured interface(s). 102134911Ssamnetwork_common() 103134911Ssam{ 104134911Ssam local _cooked_list _fail _func _verbose 105134911Ssam 106134911Ssam _func= 107134911Ssam _verbose= 108134911Ssam 109134911Ssam if [ -z "$1" ]; then 110134911Ssam err 1 "network_common(): No function name specified." 111167755Ssam else 112134911Ssam _func="$1" 113134911Ssam fi 114134911Ssam [ -n "$2" ] && _verbose=yes 115134911Ssam 116134911Ssam # Set the scope of the command (all interfaces or just one). 117134911Ssam # 118134911Ssam _cooked_list= 119134911Ssam if [ -n "$cmdifn" ]; then 120134911Ssam # Don't check that the interfaces exist. We need to run 121134911Ssam # the down code even when the interface doesn't exist to 122134911Ssam # kill off wpa_supplicant. 123134911Ssam _cooked_list="$cmdifn" 124134911Ssam else 125134911Ssam _cooked_list="`list_net_interfaces`" 126134911Ssam fi 127134911Ssam 128134911Ssam _fail= 129134911Ssam for ifn in ${_cooked_list}; do 130134911Ssam if ${_func} ${ifn} ; then 131134911Ssam eval showstat_$ifn=1 132134911Ssam else 133134911Ssam _fail="$_fail $ifn" 134134911Ssam fi 135134911Ssam done 136134911Ssam 137158886Smr # Display interfaces configured by this script 138158886Smr # 139158886Smr for ifn in ${_cooked_list}; do 140134911Ssam eval showstat=\$showstat_${ifn} 141134911Ssam if [ ! -z ${showstat} ]; then 142134911Ssam if [ -n "$_verbose" ]; then 143134911Ssam ifconfig ${ifn} 144134911Ssam else 145167755Ssam echo -n " ${ifn}" 146134911Ssam fi 147134911Ssam fi 148134911Ssam done 149134911Ssam debug "The following interfaces were not configured: $_fail" 150134911Ssam} 151134911Ssam 152134911Ssamifn_start() 153134911Ssam{ 154167755Ssam local ifn cfg 155134911Ssam ifn="$1" 156134911Ssam cfg=1 157134911Ssam 158134911Ssam [ -z "$ifn" ] && return 1 159134911Ssam 160134911Ssam ifscript_up ${ifn} && cfg=0 161134911Ssam ifconfig_up ${ifn} && cfg=0 162134911Ssam ipv4_up ${ifn} && cfg=0 163134911Ssam ipx_up ${ifn} && cfg=0 164134911Ssam 165134911Ssam return $cfg 166134911Ssam} 167134911Ssam 168134911Ssamifn_stop() 169134911Ssam{ 170134911Ssam local ifn cfg 171134911Ssam ifn="$1" 172134911Ssam cfg=1 173134911Ssam 174134911Ssam [ -z "$ifn" ] && return 1 175134911Ssam 176134911Ssam ipx_down ${ifn} && cfg=0 177134911Ssam ipv4_down ${ifn} && cfg=0 178134911Ssam ifconfig_down ${ifn} && cfg=0 179134911Ssam ifscript_down ${ifn} && cfg=0 180134911Ssam 181134911Ssam return $cfg 182134911Ssam} 183134911Ssam 184134911Ssamload_rc_config $name 185134911Ssamrun_rc_command $* 186134911Ssam