netif revision 195026
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 195026 2009-06-26 01:04:50Z 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
44113674Smtmnetwork_start()
45113674Smtm{
46132892Smtm	# Set the list of interfaces to work on.
47132892Smtm	#
48165664Syar	cmdifn=$*
49132892Smtm
50165664Syar	if [ -z "$cmdifn" ]; then
51117021Smtm		#
52117021Smtm		# We're operating as a general network start routine.
53117021Smtm		#
54113674Smtm
55149789Skeramida		# disable SIGINT (Ctrl-c) when running at startup
56149730Sbrooks		trap : 2
57149725Sbrooks
58117021Smtm		# Create cloned interfaces
59117021Smtm		clone_up
60113674Smtm
61166583Sflz		# Create Fast EtherChannel interfaces
62166583Sflz		fec_up
63166583Sflz
64117021Smtm		# Create IPv6<-->IPv4 tunnels
65117021Smtm		gif_up
66137070Spjd
67137070Spjd		# Rename interfaces.
68137070Spjd		ifnet_rename
69117021Smtm	fi
70117021Smtm
71117021Smtm	# Configure the interface(s).
72178356Ssam	network_common ifn_start
73117021Smtm
74128714Sphk	if [ -f /etc/rc.d/ipfilter ] ; then
75128714Sphk		# Resync ipfilter
76175676Smtm		/etc/rc.d/ipfilter quietresync
77128714Sphk	fi
78165664Syar	if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then
79165664Syar		/etc/rc.d/bridge start $cmdifn
80159138Sthompsa	fi
81117021Smtm}
82117021Smtm
83117021Smtmnetwork_stop()
84117021Smtm{
85132892Smtm	# Set the list of interfaces to work on.
86132892Smtm	#
87165664Syar	cmdifn=$*
88132892Smtm
89117021Smtm	# Deconfigure the interface(s)
90117021Smtm	network_common ifn_stop
91117021Smtm}
92117021Smtm
93178356Ssam# network_common routine
94117021Smtm#	Common configuration subroutine for network interfaces. This
95117021Smtm#	routine takes all the preparatory steps needed for configuriing
96178356Ssam#	an interface and then calls $routine.
97117021Smtmnetwork_common()
98117021Smtm{
99179961Smtm	local _cooked_list _fail _func _ok _str
100165664Syar
101117021Smtm	_func=
102117021Smtm
103117021Smtm	if [ -z "$1" ]; then
104129492Smtm		err 1 "network_common(): No function name specified."
105117021Smtm	else
106117021Smtm		_func="$1"
107117021Smtm	fi
108117021Smtm
109117021Smtm	# Set the scope of the command (all interfaces or just one).
110113674Smtm	#
111132892Smtm	_cooked_list=
112165664Syar	if [ -n "$cmdifn" ]; then
113178356Ssam		# Don't check that the interface(s) exist.  We need to run
114147681Sbrooks		# the down code even when the interface doesn't exist to
115147681Sbrooks		# kill off wpa_supplicant.
116178356Ssam		# XXXBED: is this really true or does wpa_supplicant die?
117178356Ssam		# if so, we should get rid of the devd entry
118165664Syar		_cooked_list="$cmdifn"
119132892Smtm	else
120149725Sbrooks		_cooked_list="`list_net_interfaces`"
121117021Smtm	fi
122113674Smtm
123165664Syar	_fail=
124179961Smtm	_ok=
125117021Smtm	for ifn in ${_cooked_list}; do
126179961Smtm		if ${_func} ${ifn} $2; then
127179961Smtm			_ok="${_ok} ${ifn}"
128179961Smtm		else
129178356Ssam			_fail="${_fail} ${ifn}"
130117021Smtm		fi
131113674Smtm	done
132113674Smtm
133179961Smtm	_str=
134179961Smtm	if [ -n "${_ok}" ]; then
135179961Smtm		case ${_func} in
136179961Smtm		ifn_start)
137179961Smtm			_str='Starting'
138179961Smtm			;;
139179961Smtm		ifn_stop)
140179961Smtm			_str='Stopping'
141179961Smtm			;;
142179961Smtm		esac
143179961Smtm		echo "${_str} Network:${_ok}."
144179961Smtm		if [ -z "${rc_quiet}" ]; then
145184485Spjd			for ifn in ${_ok}; do
146184485Spjd				/sbin/ifconfig ${ifn}
147184485Spjd			done
148179961Smtm		fi
149179961Smtm	fi
150179961Smtm
151117021Smtm	debug "The following interfaces were not configured: $_fail"
152117021Smtm}
153113674Smtm
154113674Smtmload_rc_config $name
155132892Smtmrun_rc_command $*
156