netif revision 253227
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: stable/9/etc/rc.d/netif 253227 2013-07-12 00:40:49Z 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"
41extra_commands="cloneup clonedown"
42cmdifn=
43
44set_rcvar_obsolete ipv6_enable ipv6_activate_all_interfaces
45set_rcvar_obsolete ipv6_prefer
46
47network_start()
48{
49	# Set the list of interfaces to work on.
50	#
51	cmdifn=$*
52
53	if [ -z "$cmdifn" ]; then
54		#
55		# We're operating as a general network start routine.
56		#
57
58		# disable SIGINT (Ctrl-c) when running at startup
59		trap : 2
60
61		# Create cloned interfaces
62		clone_up
63
64		# Create Fast EtherChannel interfaces
65		fec_up
66
67		# Create IPv6<-->IPv4 tunnels
68		gif_up
69
70		# Rename interfaces.
71		ifnet_rename
72	fi
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}
85
86network_stop()
87{
88	# Set the list of interfaces to work on.
89	#
90	cmdifn=$*
91
92	# Deconfigure the interface(s)
93	network_common ifn_stop
94}
95
96# network_common routine
97#	Common configuration subroutine for network interfaces. This
98#	routine takes all the preparatory steps needed for configuriing
99#	an interface and then calls $routine.
100network_common()
101{
102	local _cooked_list _fail _func _ok _str
103
104	_func=
105
106	if [ -z "$1" ]; then
107		err 1 "network_common(): No function name specified."
108	else
109		_func="$1"
110	fi
111
112	# Set the scope of the command (all interfaces or just one).
113	#
114	_cooked_list=
115	if [ -n "$cmdifn" ]; then
116		# Don't check that the interface(s) exist.  We need to run
117		# the down code even when the interface doesn't exist to
118		# kill off wpa_supplicant.
119		# XXXBED: is this really true or does wpa_supplicant die?
120		# if so, we should get rid of the devd entry
121		_cooked_list="$cmdifn"
122	else
123		_cooked_list="`list_net_interfaces`"
124	fi
125
126	_dadwait=
127	_fail=
128	_ok=
129	for ifn in ${_cooked_list}; do
130		if ${_func} ${ifn} $2; then
131			_ok="${_ok} ${ifn}"
132			if ipv6if ${ifn}; then
133				_dadwait=1
134			fi
135		else
136			_fail="${_fail} ${ifn}"
137		fi
138	done
139
140	# inet6 address configuration needs sleep for DAD.
141	case ${_func}:${_dadwait} in
142	ifn_start:1)
143		sleep `${SYSCTL_N} net.inet6.ip6.dad_count`
144		sleep 1
145	;;
146	esac
147
148	_str=
149	if [ -n "${_ok}" ]; then
150		case ${_func} in
151		ifn_start)
152			_str='Starting'
153			;;
154		ifn_stop)
155			_str='Stopping'
156			;;
157		esac
158		echo "${_str} Network:${_ok}."
159		if check_startmsgs; then
160			for ifn in ${_ok}; do
161				/sbin/ifconfig ${ifn}
162			done
163		fi
164	fi
165
166	debug "The following interfaces were not configured: $_fail"
167}
168
169load_rc_config $name
170run_rc_command $*
171