netif revision 253924
1#!/bin/sh
2#
3# Copyright (c) 2003 The FreeBSD Project. All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9#    notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11#    notice, this list of conditions and the following disclaimer in the
12#    documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE PROJECT ``AS IS'' AND ANY EXPRESS OR
15# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17# IN NO EVENT SHALL THE PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT,
18# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24#
25# $FreeBSD: head/etc/rc.d/netif 253924 2013-08-04 06:36:17Z hrs $
26#
27
28# PROVIDE: netif
29# REQUIRE: atm1 FILESYSTEMS serial sppp sysctl
30# REQUIRE: ipfilter ipfs
31# KEYWORD: nojailvnet
32
33. /etc/rc.subr
34. /etc/network.subr
35
36name="network"
37start_cmd="network_start"
38stop_cmd="network_stop"
39cloneup_cmd="clone_up"
40clonedown_cmd="clone_down"
41clear_cmd="doclear"
42extra_commands="cloneup clonedown clear"
43cmdifn=
44
45set_rcvar_obsolete ipv6_enable ipv6_activate_all_interfaces
46set_rcvar_obsolete ipv6_prefer
47
48network_start()
49{
50	local _if
51
52	# Set the list of interfaces to work on.
53	#
54	cmdifn=$*
55
56	if [ -z "$cmdifn" ]; then
57		#
58		# We're operating as a general network start routine.
59		#
60
61		# disable SIGINT (Ctrl-c) when running at startup
62		trap : 2
63
64		# Create Fast EtherChannel interfaces
65		fec_up
66	fi
67
68	# Create cloned interfaces
69	clone_up $cmdifn
70
71	# Rename interfaces.
72	ifnet_rename $cmdifn
73
74	# Configure the interface(s).
75	network_common ifn_start
76
77	if [ -f /etc/rc.d/ipfilter ] ; then
78		# Resync ipfilter
79		/etc/rc.d/ipfilter quietresync
80	fi
81	if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then
82		/etc/rc.d/bridge start $cmdifn
83	fi
84	if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then
85		for _if in $cmdifn; do
86			/etc/rc.d/routing start any $_if
87		done
88	fi
89}
90
91network_stop()
92{
93	_clone_down=1
94	network_stop0 $*
95}
96
97doclear()
98{
99	_clone_down=
100	network_stop0 $*
101}
102
103network_stop0()
104{
105	local _if
106
107	# Set the list of interfaces to work on.
108	#
109	cmdifn=$*
110
111	# Deconfigure the interface(s)
112	network_common ifn_stop
113
114	# Destroy cloned interfaces
115	if [ -n "$_clone_down" ]; then
116		clone_down $cmdifn
117	fi
118
119	if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then
120		for _if in $cmdifn; do
121			/etc/rc.d/routing stop any $_if
122		done
123	fi
124}
125
126# network_common routine
127#	Common configuration subroutine for network interfaces. This
128#	routine takes all the preparatory steps needed for configuriing
129#	an interface and then calls $routine.
130network_common()
131{
132	local _cooked_list _fail _func _ok _str
133
134	_func=
135
136	if [ -z "$1" ]; then
137		err 1 "network_common(): No function name specified."
138	else
139		_func="$1"
140	fi
141
142	# Set the scope of the command (all interfaces or just one).
143	#
144	_cooked_list=
145	if [ -n "$cmdifn" ]; then
146		# Don't check that the interface(s) exist.  We need to run
147		# the down code even when the interface doesn't exist to
148		# kill off wpa_supplicant.
149		# XXXBED: is this really true or does wpa_supplicant die?
150		# if so, we should get rid of the devd entry
151		_cooked_list="$cmdifn"
152	else
153		_cooked_list="`list_net_interfaces`"
154	fi
155
156	_dadwait=
157	_fail=
158	_ok=
159	for ifn in ${_cooked_list}; do
160		# Skip if ifn does not exist.
161		case $_func in
162		ifn_stop)
163			if ! ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
164				warn "$ifn does not exist.  Skipped."
165				_fail="${_fail} ${ifn}"
166				continue
167			fi
168		;;
169		esac
170		if ${_func} ${ifn} $2; then
171			_ok="${_ok} ${ifn}"
172			if ipv6if ${ifn}; then
173				_dadwait=1
174			fi
175		else
176			_fail="${_fail} ${ifn}"
177		fi
178	done
179
180	# inet6 address configuration needs sleep for DAD.
181	case ${_func}:${_dadwait} in
182	ifn_start:1)
183		sleep `${SYSCTL_N} net.inet6.ip6.dad_count`
184		sleep 1
185	;;
186	esac
187
188	_str=
189	if [ -n "${_ok}" ]; then
190		case ${_func} in
191		ifn_start)
192			_str='Starting'
193			;;
194		ifn_stop)
195			_str='Stopping'
196			;;
197		esac
198		echo "${_str} Network:${_ok}."
199		if check_startmsgs; then
200			for ifn in ${_ok}; do
201				/sbin/ifconfig ${ifn}
202			done
203		fi
204	fi
205
206	debug "The following interfaces were not configured: $_fail"
207}
208
209load_rc_config $name
210run_rc_command $*
211