netif revision 147088
1113674Smtm#!/bin/sh 2113674Smtm# 3113674Smtm# Copyright (c) 2003 The FreeBSD Project. All rights reserved. 4113674Smtm# 5113674Smtm# Redistribution and use in source and binary forms, with or without 6113674Smtm# modification, are permitted provided that the following conditions 7113674Smtm# are met: 8113674Smtm# 1. Redistributions of source code must retain the above copyright 9113674Smtm# notice, this list of conditions and the following disclaimer. 10113674Smtm# 2. Redistributions in binary form must reproduce the above copyright 11113674Smtm# notice, this list of conditions and the following disclaimer in the 12113674Smtm# documentation and/or other materials provided with the distribution. 13113674Smtm# 14113674Smtm# THIS SOFTWARE IS PROVIDED BY THE PROJECT ``AS IS'' AND ANY EXPRESS OR 15113674Smtm# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16113674Smtm# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17113674Smtm# IN NO EVENT SHALL THE PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT, 18113674Smtm# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19113674Smtm# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20113674Smtm# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21113674Smtm# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22113674Smtm# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23113674Smtm# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24113674Smtm# 25113674Smtm# $FreeBSD: head/etc/rc.d/netif 147088 2005-06-07 04:49:12Z brooks $ 26113674Smtm# 27113674Smtm 28113674Smtm# PROVIDE: netif 29126392Sgreen# REQUIRE: atm1 ipfilter mountcritlocal pccard serial sppp sysctl 30136224Smtm# KEYWORD: nojail 31113674Smtm 32113674Smtm. /etc/rc.subr 33113674Smtm. /etc/network.subr 34113674Smtm 35113674Smtmname="network" 36113674Smtmstart_cmd="network_start" 37113674Smtmstop_cmd="network_stop" 38113674Smtmcloneup_cmd="clone_up" 39113674Smtmclonedown_cmd="clone_down" 40113674Smtmextra_commands="cloneup clonedown" 41117021Smtm_cmdifn= 42113674Smtm 43113674Smtmnetwork_start() 44113674Smtm{ 45132892Smtm # Set the list of interfaces to work on. 46132892Smtm # 47132892Smtm _cmdifn=$* 48132892Smtm 49117021Smtm if [ -z "$_cmdifn" ]; then 50117021Smtm # 51117021Smtm # We're operating as a general network start routine. 52117021Smtm # 53113674Smtm 54117021Smtm # Create cloned interfaces 55117021Smtm clone_up 56113674Smtm 57117021Smtm # Create IPv6<-->IPv4 tunnels 58117021Smtm gif_up 59137070Spjd 60137070Spjd # Rename interfaces. 61137070Spjd ifnet_rename 62117021Smtm fi 63117021Smtm 64117021Smtm # Configure the interface(s). 65117021Smtm network_common ifn_start verbose 66117021Smtm 67128714Sphk if [ -f /etc/rc.d/ipfilter ] ; then 68128714Sphk # Resync ipfilter 69128714Sphk /etc/rc.d/ipfilter resync 70128714Sphk fi 71117021Smtm} 72117021Smtm 73117021Smtmnetwork_stop() 74117021Smtm{ 75132892Smtm # Set the list of interfaces to work on. 76132892Smtm # 77132892Smtm _cmdifn=$* 78132892Smtm 79117021Smtm echo -n "Stopping network:" 80117021Smtm 81117021Smtm # Deconfigure the interface(s) 82117021Smtm network_common ifn_stop 83117021Smtm echo '.' 84117021Smtm} 85117021Smtm 86117021Smtm# network_common routine verbose 87117021Smtm# Common configuration subroutine for network interfaces. This 88117021Smtm# routine takes all the preparatory steps needed for configuriing 89117021Smtm# an interface and then calls $routine. If $verbose is specified, 90117021Smtm# it will call ifconfig(8) to show, in long format, the configured 91117021Smtm# interfaces. If $verbose is not given, it will simply output the 92117021Smtm# configured interface(s). 93117021Smtmnetwork_common() 94117021Smtm{ 95117021Smtm _func= 96117021Smtm _verbose= 97117021Smtm 98117021Smtm if [ -z "$1" ]; then 99129492Smtm err 1 "network_common(): No function name specified." 100117021Smtm else 101117021Smtm _func="$1" 102117021Smtm fi 103117021Smtm [ -n "$2" ] && _verbose=yes 104117021Smtm 105147088Sbrooks # Get a list of network interfaces. 106147088Sbrooks _ifn_list="`list_net_interfaces`" 107113674Smtm 108117021Smtm # Set the scope of the command (all interfaces or just one). 109113674Smtm # 110132892Smtm _cooked_list= 111117021Smtm if [ -n "$_cmdifn" ]; then 112132892Smtm for i in $_cmdifn ; do 113132892Smtm eval _if=\"`expr "$_ifn_list" : ".*\(${i}\).*"`\" 114132892Smtm if [ -z "$_if" ]; then 115132892Smtm err 1 "No such network interface: $i" 116132892Smtm fi 117132892Smtm _cooked_list="$_cooked_list $_if" 118132892Smtm done 119132892Smtm else 120132892Smtm _cooked_list="$_ifn_list" 121117021Smtm fi 122113674Smtm 123117021Smtm for ifn in ${_cooked_list}; do 124117021Smtm if ${_func} ${ifn} ; then 125117021Smtm eval showstat_$ifn=1 126117021Smtm else 127117021Smtm _fail="$_fail $ifn" 128117021Smtm fi 129113674Smtm done 130113674Smtm 131113674Smtm # Display interfaces configured by this script 132113674Smtm # 133117021Smtm for ifn in ${_cooked_list}; do 134113674Smtm eval showstat=\$showstat_${ifn} 135113674Smtm if [ ! -z ${showstat} ]; then 136117021Smtm if [ -n "$_verbose" ]; then 137117021Smtm ifconfig ${ifn} 138117021Smtm else 139117021Smtm echo -n " ${ifn}" 140117021Smtm fi 141113674Smtm fi 142113674Smtm done 143117021Smtm debug "The following interfaces were not configured: $_fail" 144117021Smtm} 145113674Smtm 146117021Smtmifn_start() 147117021Smtm{ 148117021Smtm local ifn cfg 149117021Smtm ifn="$1" 150117021Smtm cfg=1 151117021Smtm 152117021Smtm [ -z "$ifn" ] && return 1 153117021Smtm 154117021Smtm ifscript_up ${ifn} && cfg=0 155117021Smtm ifconfig_up ${ifn} && cfg=0 156117021Smtm ifalias_up ${ifn} && cfg=0 157117021Smtm ipx_up ${ifn} && cfg=0 158117021Smtm 159117021Smtm return $cfg 160113674Smtm} 161113674Smtm 162117021Smtmifn_stop() 163113674Smtm{ 164117021Smtm local ifn cfg 165117021Smtm ifn="$1" 166117021Smtm cfg=1 167113674Smtm 168117021Smtm [ -z "$ifn" ] && return 1 169117021Smtm 170117021Smtm ipx_down ${ifn} && cfg=0 171117021Smtm ifalias_down ${ifn} && cfg=0 172117021Smtm ifconfig_down ${ifn} && cfg=0 173117021Smtm ifscript_down ${ifn} && cfg=0 174117021Smtm 175117021Smtm return $cfg 176113674Smtm} 177113674Smtm 178113674Smtmload_rc_config $name 179132892Smtmrun_rc_command $* 180