netif revision 159138
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 159138 2006-06-01 11:01:54Z thompsa $ 26113674Smtm# 27113674Smtm 28113674Smtm# PROVIDE: netif 29155610Simp# REQUIRE: atm1 ipfilter mountcritlocal 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" 41117021Smtm_cmdifn= 42113674Smtm 43113674Smtmnetwork_start() 44113674Smtm{ 45132892Smtm # Set the list of interfaces to work on. 46132892Smtm # 47132892Smtm _cmdifn=$* 48132892Smtm 49117021Smtm 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 60117021Smtm # Create IPv6<-->IPv4 tunnels 61117021Smtm gif_up 62137070Spjd 63137070Spjd # Rename interfaces. 64137070Spjd ifnet_rename 65117021Smtm fi 66117021Smtm 67117021Smtm # Configure the interface(s). 68117021Smtm network_common ifn_start verbose 69117021Smtm 70128714Sphk if [ -f /etc/rc.d/ipfilter ] ; then 71128714Sphk # Resync ipfilter 72128714Sphk /etc/rc.d/ipfilter resync 73128714Sphk fi 74159138Sthompsa if [ -f /etc/rc.d/bridge -a -n "$_cmdifn" ] ; then 75159138Sthompsa /etc/rc.d/bridge start $_cmdifn 76159138Sthompsa fi 77117021Smtm} 78117021Smtm 79117021Smtmnetwork_stop() 80117021Smtm{ 81132892Smtm # Set the list of interfaces to work on. 82132892Smtm # 83132892Smtm _cmdifn=$* 84132892Smtm 85117021Smtm echo -n "Stopping network:" 86117021Smtm 87117021Smtm # Deconfigure the interface(s) 88117021Smtm network_common ifn_stop 89117021Smtm echo '.' 90117021Smtm} 91117021Smtm 92117021Smtm# network_common routine verbose 93117021Smtm# Common configuration subroutine for network interfaces. This 94117021Smtm# routine takes all the preparatory steps needed for configuriing 95117021Smtm# an interface and then calls $routine. If $verbose is specified, 96117021Smtm# it will call ifconfig(8) to show, in long format, the configured 97117021Smtm# interfaces. If $verbose is not given, it will simply output the 98117021Smtm# configured interface(s). 99117021Smtmnetwork_common() 100117021Smtm{ 101117021Smtm _func= 102117021Smtm _verbose= 103117021Smtm 104117021Smtm if [ -z "$1" ]; then 105129492Smtm err 1 "network_common(): No function name specified." 106117021Smtm else 107117021Smtm _func="$1" 108117021Smtm fi 109117021Smtm [ -n "$2" ] && _verbose=yes 110117021Smtm 111117021Smtm # Set the scope of the command (all interfaces or just one). 112113674Smtm # 113132892Smtm _cooked_list= 114117021Smtm if [ -n "$_cmdifn" ]; then 115147681Sbrooks # Don't check that the interfaces exist. We need to run 116147681Sbrooks # the down code even when the interface doesn't exist to 117147681Sbrooks # kill off wpa_supplicant. 118147681Sbrooks _cooked_list="$_cmdifn" 119132892Smtm else 120149725Sbrooks _cooked_list="`list_net_interfaces`" 121117021Smtm fi 122113674Smtm 123117021Smtm for ifn in ${_cooked_list}; do 124117021Smtm if ${_func} ${ifn} ; then 125117021Smtm eval showstat_$ifn=1 126117021Smtm else 127117021Smtm _fail="$_fail $ifn" 128117021Smtm fi 129113674Smtm done 130113674Smtm 131113674Smtm # Display interfaces configured by this script 132113674Smtm # 133117021Smtm for ifn in ${_cooked_list}; do 134113674Smtm eval showstat=\$showstat_${ifn} 135113674Smtm if [ ! -z ${showstat} ]; then 136117021Smtm if [ -n "$_verbose" ]; then 137117021Smtm ifconfig ${ifn} 138117021Smtm else 139117021Smtm echo -n " ${ifn}" 140117021Smtm fi 141113674Smtm fi 142113674Smtm done 143117021Smtm debug "The following interfaces were not configured: $_fail" 144117021Smtm} 145113674Smtm 146117021Smtmifn_start() 147117021Smtm{ 148117021Smtm local ifn cfg 149117021Smtm ifn="$1" 150117021Smtm cfg=1 151117021Smtm 152117021Smtm [ -z "$ifn" ] && return 1 153117021Smtm 154117021Smtm ifscript_up ${ifn} && cfg=0 155117021Smtm ifconfig_up ${ifn} && cfg=0 156152441Sbrooks ipv4_up ${ifn} && cfg=0 157117021Smtm ipx_up ${ifn} && cfg=0 158117021Smtm 159117021Smtm return $cfg 160113674Smtm} 161113674Smtm 162117021Smtmifn_stop() 163113674Smtm{ 164117021Smtm local ifn cfg 165117021Smtm ifn="$1" 166117021Smtm cfg=1 167113674Smtm 168117021Smtm [ -z "$ifn" ] && return 1 169117021Smtm 170117021Smtm ipx_down ${ifn} && cfg=0 171152441Sbrooks ipv4_down ${ifn} && cfg=0 172117021Smtm ifconfig_down ${ifn} && cfg=0 173117021Smtm ifscript_down ${ifn} && cfg=0 174117021Smtm 175117021Smtm return $cfg 176113674Smtm} 177113674Smtm 178113674Smtmload_rc_config $name 179132892Smtmrun_rc_command $* 180