xref: /dragonfly/etc/rc.d/netif (revision 2540cca8)
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: src/etc/rc.d/netif,v 1.2 2003/06/29 05:34:41 mtm Exp $
26# $DragonFly: src/etc/rc.d/netif,v 1.6 2007/06/17 14:08:00 swildner Exp $
27#
28
29# PROVIDE: netif
30# REQUIRE: atm1 ipfilter mountcritlocal serial sppp sysctl tty
31
32. /etc/rc.subr
33. /etc/network.subr
34
35name="network"
36start_cmd="network_start"
37stop_cmd="network_stop"
38cloneup_cmd="clone_up"
39clonedown_cmd="clone_down"
40extra_commands="cloneup clonedown"
41_cmdifn=
42
43network_start()
44{
45	if [ -z "$_cmdifn" ]; then
46		#
47		# We're operating as a general network start routine.
48		#
49
50		# Create cloned interfaces
51		clone_up
52
53		# Create IPv6<-->IPv4 tunnels
54		gif_up
55	fi
56
57	# Configure the interface(s).
58	network_common ifn_start verbose
59
60	# Give our interfaces a little time to come up
61	# before we start pounding them.  In particular, dhclient
62	# and named can get mightily confused.
63	sleep 2
64
65	# Resync ipfilter
66	/etc/rc.d/ipfilter resync
67}
68
69network_stop()
70{
71	echo -n "Stopping network:"
72
73	# Deconfigure the interface(s)
74	network_common ifn_stop
75	echo '.'
76}
77
78# network_common routine verbose
79#	Common configuration subroutine for network interfaces. This
80#	routine takes all the preparatory steps needed for configuriing
81#	an interface and then calls $routine. If $verbose is specified,
82#	it will call ifconfig(8) to show, in long format, the configured
83#	interfaces. If $verbose is not given, it will simply output the
84#	configured interface(s).
85network_common()
86{
87	_func=
88	_verbose=
89
90	if [ -z "$1" ]; then
91		err 1 "network_common(): No function name specified."
92	else
93		_func="$1"
94	fi
95	[ -n "$2" ] && _verbose=yes
96
97	# Get a list of network interfaces. Do not include dhcp interfaces.
98	_ifn_list="`list_net_interfaces nodhcp`"
99
100	# Set the scope of the command (all interfaces or just one).
101	#
102	_cooked_list="$_ifn_list"
103	if [ -n "$_cmdifn" ]; then
104		eval _cooked_list=\"`expr "$_ifn_list" : ".*\($_cmdifn\).*"`\"
105		if [ -z "$_cooked_list" ]; then
106			err 1 "No such network interface: $_cmdifn"
107		fi
108	fi
109
110	for ifn in ${_cooked_list}; do
111		if ${_func} ${ifn} ; then
112			eval showstat_$ifn=1
113		else
114			_fail="$_fail $ifn"
115		fi
116	done
117
118	# Display interfaces configured by this script
119	#
120	for ifn in ${_cooked_list}; do
121		eval showstat=\$showstat_${ifn}
122		if [ ! -z ${showstat} ]; then
123			if [ -n "$_verbose" ]; then
124				ifconfig ${ifn}
125			else
126				echo -n " ${ifn}"
127			fi
128		fi
129	done
130	debug "The following interfaces were not configured: $_fail"
131}
132
133ifn_start()
134{
135	local ifn cfg
136	ifn="$1"
137	cfg=1
138
139	[ -z "$ifn" ] && return 1
140
141	ifscript_up ${ifn} && cfg=0
142	ifconfig_up ${ifn} && cfg=0
143	ifalias_up ${ifn} && cfg=0
144	ipx_up ${ifn} && cfg=0
145
146	return $cfg
147}
148
149ifn_stop()
150{
151	local ifn cfg
152	ifn="$1"
153	cfg=1
154
155	[ -z "$ifn" ] && return 1
156
157	ipx_down ${ifn} && cfg=0
158	ifalias_down ${ifn} && cfg=0
159	ifconfig_down ${ifn} && cfg=0
160	ifscript_down ${ifn} && cfg=0
161
162	return $cfg
163}
164
165if [ -n "$2" ]; then
166	_cmdifn="$2"
167fi
168
169load_rc_config $name
170run_rc_command "$1"
171