netif revision 184485
1107543Sscottl#!/bin/sh
2107543Sscottl#
3107543Sscottl# Copyright (c) 2003 The FreeBSD Project. All rights reserved.
4107543Sscottl#
5107543Sscottl# Redistribution and use in source and binary forms, with or without
6107543Sscottl# modification, are permitted provided that the following conditions
7107543Sscottl# are met:
8107543Sscottl# 1. Redistributions of source code must retain the above copyright
9107543Sscottl#    notice, this list of conditions and the following disclaimer.
10107543Sscottl# 2. Redistributions in binary form must reproduce the above copyright
11107543Sscottl#    notice, this list of conditions and the following disclaimer in the
12107543Sscottl#    documentation and/or other materials provided with the distribution.
13107543Sscottl#
14107543Sscottl# THIS SOFTWARE IS PROVIDED BY THE PROJECT ``AS IS'' AND ANY EXPRESS OR
15107543Sscottl# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16107543Sscottl# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17107543Sscottl# IN NO EVENT SHALL THE PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT,
18107543Sscottl# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19107543Sscottl# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20107543Sscottl# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21107543Sscottl# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22107543Sscottl# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23107543Sscottl# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24107543Sscottl#
25107543Sscottl# $FreeBSD: head/etc/rc.d/netif 184485 2008-10-30 20:24:25Z pjd $
26107543Sscottl#
27107543Sscottl
28107543Sscottl# PROVIDE: netif
29107543Sscottl# REQUIRE: atm1 cleanvar ipfilter FILESYSTEMS serial sppp sysctl
30107543Sscottl# KEYWORD: nojail
31107543Sscottl
32107543Sscottl. /etc/rc.subr
33107543Sscottl. /etc/network.subr
34107543Sscottl
35107543Sscottlname="network"
36107543Sscottlstart_cmd="network_start"
37107543Sscottlstop_cmd="network_stop"
38107543Sscottlcloneup_cmd="clone_up"
39107543Sscottlclonedown_cmd="clone_down"
40107543Sscottlextra_commands="cloneup clonedown"
41107543Sscottlcmdifn=
42107543Sscottl
43107543Sscottlnetwork_start()
44107543Sscottl{
45107543Sscottl	# Set the list of interfaces to work on.
46107543Sscottl	#
47107543Sscottl	cmdifn=$*
48107543Sscottl
49107543Sscottl	if [ -z "$cmdifn" ]; then
50107543Sscottl		#
51107543Sscottl		# We're operating as a general network start routine.
52107543Sscottl		#
53107543Sscottl
54107543Sscottl		# disable SIGINT (Ctrl-c) when running at startup
55107543Sscottl		trap : 2
56107543Sscottl
57107543Sscottl		# Create cloned interfaces
58107543Sscottl		clone_up
59107543Sscottl
60107543Sscottl		# Create Fast EtherChannel interfaces
61107543Sscottl		fec_up
62107543Sscottl
63107543Sscottl		# Create IPv6<-->IPv4 tunnels
64107543Sscottl		gif_up
65107543Sscottl
66107543Sscottl		# Rename interfaces.
67107543Sscottl		ifnet_rename
68107543Sscottl	fi
69107543Sscottl
70107543Sscottl	# Configure the interface(s).
71107543Sscottl	network_common ifn_start
72107543Sscottl
73107543Sscottl	if [ -f /etc/rc.d/ipfilter ] ; then
74107543Sscottl		# Resync ipfilter
75107543Sscottl		/etc/rc.d/ipfilter quietresync
76107543Sscottl	fi
77107543Sscottl	if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then
78107543Sscottl		/etc/rc.d/bridge start $cmdifn
79107543Sscottl	fi
80107543Sscottl}
81107543Sscottl
82107543Sscottlnetwork_stop()
83107543Sscottl{
84107543Sscottl	# Set the list of interfaces to work on.
85107543Sscottl	#
86107543Sscottl	cmdifn=$*
87107543Sscottl
88107543Sscottl	# Deconfigure the interface(s)
89107543Sscottl	network_common ifn_stop
90107543Sscottl}
91107543Sscottl
92107543Sscottl# network_common routine
93107543Sscottl#	Common configuration subroutine for network interfaces. This
94107543Sscottl#	routine takes all the preparatory steps needed for configuriing
95107543Sscottl#	an interface and then calls $routine.
96107543Sscottlnetwork_common()
97107543Sscottl{
98107543Sscottl	local _cooked_list _fail _func _ok _str
99107543Sscottl
100107543Sscottl	_func=
101107543Sscottl
102107543Sscottl	if [ -z "$1" ]; then
103107543Sscottl		err 1 "network_common(): No function name specified."
104107543Sscottl	else
105107543Sscottl		_func="$1"
106107543Sscottl	fi
107107543Sscottl
108107543Sscottl	# Set the scope of the command (all interfaces or just one).
109107543Sscottl	#
110107543Sscottl	_cooked_list=
111107543Sscottl	if [ -n "$cmdifn" ]; then
112107543Sscottl		# Don't check that the interface(s) exist.  We need to run
113107543Sscottl		# the down code even when the interface doesn't exist to
114107543Sscottl		# kill off wpa_supplicant.
115107543Sscottl		# XXXBED: is this really true or does wpa_supplicant die?
116107543Sscottl		# if so, we should get rid of the devd entry
117107543Sscottl		_cooked_list="$cmdifn"
118107543Sscottl	else
119107543Sscottl		_cooked_list="`list_net_interfaces`"
120107543Sscottl	fi
121107543Sscottl
122107543Sscottl	_fail=
123107543Sscottl	_ok=
124107543Sscottl	for ifn in ${_cooked_list}; do
125107543Sscottl		if ${_func} ${ifn} $2; then
126107543Sscottl			_ok="${_ok} ${ifn}"
127107543Sscottl		else
128107543Sscottl			_fail="${_fail} ${ifn}"
129107543Sscottl		fi
130107543Sscottl	done
131107543Sscottl
132107543Sscottl	_str=
133107543Sscottl	if [ -n "${_ok}" ]; then
134107543Sscottl		case ${_func} in
135107543Sscottl		ifn_start)
136107543Sscottl			_str='Starting'
137107543Sscottl			;;
138107543Sscottl		ifn_stop)
139107543Sscottl			_str='Stopping'
140107543Sscottl			;;
141107543Sscottl		esac
142107543Sscottl		echo "${_str} Network:${_ok}."
143107543Sscottl		if [ -z "${rc_quiet}" ]; then
144107543Sscottl			for ifn in ${_ok}; do
145107543Sscottl				/sbin/ifconfig ${ifn}
146107543Sscottl			done
147107543Sscottl		fi
148109751Sfjoe	fi
149107543Sscottl
150107543Sscottl	debug "The following interfaces were not configured: $_fail"
151107543Sscottl}
152107543Sscottl
153107543Sscottlload_rc_config $name
154107543Sscottlrun_rc_command $*
155107543Sscottl