netif revision 126392
11769Sjkh#!/bin/sh
21769Sjkh#
31769Sjkh# Copyright (c) 2003 The FreeBSD Project. All rights reserved.
41769Sjkh#
51769Sjkh# Redistribution and use in source and binary forms, with or without
61769Sjkh# modification, are permitted provided that the following conditions
71769Sjkh# are met:
81769Sjkh# 1. Redistributions of source code must retain the above copyright
91769Sjkh#    notice, this list of conditions and the following disclaimer.
101769Sjkh# 2. Redistributions in binary form must reproduce the above copyright
111769Sjkh#    notice, this list of conditions and the following disclaimer in the
121769Sjkh#    documentation and/or other materials provided with the distribution.
131769Sjkh#
141769Sjkh# THIS SOFTWARE IS PROVIDED BY THE PROJECT ``AS IS'' AND ANY EXPRESS OR
151769Sjkh# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
161769Sjkh# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
171769Sjkh# IN NO EVENT SHALL THE PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT,
181769Sjkh# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
191769Sjkh# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
201769Sjkh# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
211769Sjkh# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
221769Sjkh# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
231769Sjkh# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
241769Sjkh#
251769Sjkh# $FreeBSD: head/etc/rc.d/netif 126392 2004-02-29 01:42:48Z green $
261769Sjkh#
271769Sjkh
281769Sjkh# PROVIDE: netif
291769Sjkh# REQUIRE: atm1 ipfilter mountcritlocal pccard serial sppp sysctl
301769Sjkh# KEYWORD: FreeBSD
311769Sjkh
321769Sjkh. /etc/rc.subr
3351237Speter. /etc/network.subr
34130151Sschweikh
351769Sjkhname="network"
363876Sachestart_cmd="network_start"
373876Sachestop_cmd="network_stop"
3875786Sachecloneup_cmd="clone_up"
3975786Sacheclonedown_cmd="clone_down"
4075786Sacheextra_commands="cloneup clonedown"
4175786Sache_cmdifn=
4275786Sache
4375786Sachenetwork_start()
443120Sache{
455559Sache	if [ -z "$_cmdifn" ]; then
4675786Sache		#
4762284Sache		# We're operating as a general network start routine.
481769Sjkh		#
4975786Sache
5081669Sache		# Create cloned interfaces
5181669Sache		clone_up
5286793Sache
533876Sache		# Create IPv6<-->IPv4 tunnels
5486793Sache		gif_up
553876Sache	fi
563623Sache
5763728Sache	# Configure the interface(s).
5862284Sache	network_common ifn_start verbose
5962284Sache
6062284Sache	# Resync ipfilter
6162284Sache	/etc/rc.d/ipfilter resync
6262284Sache}
6362284Sache
6462284Sachenetwork_stop()
6562284Sache{
661769Sjkh	echo -n "Stopping network:"
677708Srgrimes
683623Sache	# Deconfigure the interface(s)
693623Sache	network_common ifn_stop
7062284Sache	echo '.'
7162284Sache}
7262284Sache
7362284Sache# network_common routine verbose
74194107Sedwin#	Common configuration subroutine for network interfaces. This
75194107Sedwin#	routine takes all the preparatory steps needed for configuriing
76194107Sedwin#	an interface and then calls $routine. If $verbose is specified,
77194107Sedwin#	it will call ifconfig(8) to show, in long format, the configured
78194107Sedwin#	interfaces. If $verbose is not given, it will simply output the
79194107Sedwin#	configured interface(s).
80194107Sedwinnetwork_common()
81194107Sedwin{
82194107Sedwin	_func=
83194107Sedwin	_verbose=
84194107Sedwin
8575717Sache	if [ -z "$1" ]; then
8675717Sache		err "network_common(): No function name specified."
8786791Sache	else
8865073Sache		_func="$1"
8975717Sache	fi
9063728Sache	[ -n "$2" ] && _verbose=yes
9175717Sache
9262284Sache	# Get a list of network interfaces. Do not include dhcp interfaces.
9375717Sache	_ifn_list="`list_net_interfaces nodhcp`"
9462284Sache
9575717Sache	# Set the scope of the command (all interfaces or just one).
9662284Sache	#
9775717Sache	_cooked_list="$_ifn_list"
9862284Sache	if [ -n "$_cmdifn" ]; then
9975717Sache		eval _cooked_list=\"`expr "$_ifn_list" : ".*\($_cmdifn\).*"`\"
1003132Sache		if [ -z "$_cooked_list" ]; then
10175717Sache			err "No such network interface: $_cmdifn"
1023623Sache			return 1
10375717Sache		fi
10462284Sache	fi
10575717Sache
10662284Sache	for ifn in ${_cooked_list}; do
107194107Sedwin		if ${_func} ${ifn} ; then
108194107Sedwin			eval showstat_$ifn=1
109194107Sedwin		else
110194107Sedwin			_fail="$_fail $ifn"
111194107Sedwin		fi
112194107Sedwin	done
113194107Sedwin
114194107Sedwin	# Display interfaces configured by this script
115194107Sedwin	#
116194107Sedwin	for ifn in ${_cooked_list}; do
117194107Sedwin		eval showstat=\$showstat_${ifn}
118194107Sedwin		if [ ! -z ${showstat} ]; then
119194107Sedwin			if [ -n "$_verbose" ]; then
120194107Sedwin				ifconfig ${ifn}
121194107Sedwin			else
122194107Sedwin				echo -n " ${ifn}"
123194107Sedwin			fi
124194107Sedwin		fi
125194107Sedwin	done
126194107Sedwin	debug "The following interfaces were not configured: $_fail"
127194107Sedwin}
128194107Sedwin
12962284Sacheifn_start()
13062284Sache{
13186791Sache	local ifn cfg
13262284Sache	ifn="$1"
13362284Sache	cfg=1
13463728Sache
13562284Sache	[ -z "$ifn" ] && return 1
13662284Sache
13762284Sache	ifscript_up ${ifn} && cfg=0
13862284Sache	ifconfig_up ${ifn} && cfg=0
13962284Sache	ifalias_up ${ifn} && cfg=0
14062284Sache	ipx_up ${ifn} && cfg=0
14162284Sache
14262284Sache	return $cfg
14362284Sache}
14462284Sache
14562284Sacheifn_stop()
14662284Sache{
14762284Sache	local ifn cfg
14862284Sache	ifn="$1"
14962284Sache	cfg=1
15062284Sache
15162284Sache	[ -z "$ifn" ] && return 1
1523623Sache
15386791Sache	ipx_down ${ifn} && cfg=0
1543876Sache	ifalias_down ${ifn} && cfg=0
1553623Sache	ifconfig_down ${ifn} && cfg=0
15663728Sache	ifscript_down ${ifn} && cfg=0
15762284Sache
15862284Sache	return $cfg
15962284Sache}
16062284Sache
16162284Sacheif [ -n "$2" ]; then
16262284Sache	_cmdifn="$2"
16362284Sachefi
16462284Sache
1653623Sacheload_rc_config $name
1663132Sacherun_rc_command "$1"
1673623Sache