netif revision 129492
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 129492 2004-05-20 14:16:05Z mtm $
26#
27
28# PROVIDE: netif
29# REQUIRE: atm1 ipfilter mountcritlocal pccard serial sppp sysctl
30# KEYWORD: FreeBSD nojail
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	if [ -f /etc/rc.d/ipfilter ] ; then
61		# Resync ipfilter
62		/etc/rc.d/ipfilter resync
63	fi
64}
65
66network_stop()
67{
68	echo -n "Stopping network:"
69
70	# Deconfigure the interface(s)
71	network_common ifn_stop
72	echo '.'
73}
74
75# network_common routine verbose
76#	Common configuration subroutine for network interfaces. This
77#	routine takes all the preparatory steps needed for configuriing
78#	an interface and then calls $routine. If $verbose is specified,
79#	it will call ifconfig(8) to show, in long format, the configured
80#	interfaces. If $verbose is not given, it will simply output the
81#	configured interface(s).
82network_common()
83{
84	_func=
85	_verbose=
86
87	if [ -z "$1" ]; then
88		err 1 "network_common(): No function name specified."
89	else
90		_func="$1"
91	fi
92	[ -n "$2" ] && _verbose=yes
93
94	# Get a list of network interfaces. Do not include dhcp interfaces.
95	_ifn_list="`list_net_interfaces nodhcp`"
96
97	# Set the scope of the command (all interfaces or just one).
98	#
99	_cooked_list="$_ifn_list"
100	if [ -n "$_cmdifn" ]; then
101		eval _cooked_list=\"`expr "$_ifn_list" : ".*\($_cmdifn\).*"`\"
102		if [ -z "$_cooked_list" ]; then
103			err 1 "No such network interface: $_cmdifn"
104			return 1
105		fi
106	fi
107
108	for ifn in ${_cooked_list}; do
109		if ${_func} ${ifn} ; then
110			eval showstat_$ifn=1
111		else
112			_fail="$_fail $ifn"
113		fi
114	done
115
116	# Display interfaces configured by this script
117	#
118	for ifn in ${_cooked_list}; do
119		eval showstat=\$showstat_${ifn}
120		if [ ! -z ${showstat} ]; then
121			if [ -n "$_verbose" ]; then
122				ifconfig ${ifn}
123			else
124				echo -n " ${ifn}"
125			fi
126		fi
127	done
128	debug "The following interfaces were not configured: $_fail"
129}
130
131ifn_start()
132{
133	local ifn cfg
134	ifn="$1"
135	cfg=1
136
137	[ -z "$ifn" ] && return 1
138
139	ifscript_up ${ifn} && cfg=0
140	ifconfig_up ${ifn} && cfg=0
141	ifalias_up ${ifn} && cfg=0
142	ipx_up ${ifn} && cfg=0
143
144	return $cfg
145}
146
147ifn_stop()
148{
149	local ifn cfg
150	ifn="$1"
151	cfg=1
152
153	[ -z "$ifn" ] && return 1
154
155	ipx_down ${ifn} && cfg=0
156	ifalias_down ${ifn} && cfg=0
157	ifconfig_down ${ifn} && cfg=0
158	ifscript_down ${ifn} && cfg=0
159
160	return $cfg
161}
162
163if [ -n "$2" ]; then
164	_cmdifn="$2"
165fi
166
167load_rc_config $name
168run_rc_command "$1"
169