netif revision 149725
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 149725 2005-09-02 17:05:07Z 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 54149725Sbrooks # disable SIGQUIT (Ctrl-c) when running at at startup 55149725Sbrooks trap : 3 56149725Sbrooks 57117021Smtm # Create cloned interfaces 58117021Smtm clone_up 59113674Smtm 60117021Smtm # Create IPv6<-->IPv4 tunnels 61117021Smtm gif_up 62137070Spjd 63137070Spjd # Rename interfaces. 64137070Spjd ifnet_rename 65117021Smtm fi 66117021Smtm 67117021Smtm # Configure the interface(s). 68117021Smtm network_common ifn_start verbose 69117021Smtm 70128714Sphk if [ -f /etc/rc.d/ipfilter ] ; then 71128714Sphk # Resync ipfilter 72128714Sphk /etc/rc.d/ipfilter resync 73128714Sphk fi 74117021Smtm} 75117021Smtm 76117021Smtmnetwork_stop() 77117021Smtm{ 78132892Smtm # Set the list of interfaces to work on. 79132892Smtm # 80132892Smtm _cmdifn=$* 81132892Smtm 82117021Smtm echo -n "Stopping network:" 83117021Smtm 84117021Smtm # Deconfigure the interface(s) 85117021Smtm network_common ifn_stop 86117021Smtm echo '.' 87117021Smtm} 88117021Smtm 89117021Smtm# network_common routine verbose 90117021Smtm# Common configuration subroutine for network interfaces. This 91117021Smtm# routine takes all the preparatory steps needed for configuriing 92117021Smtm# an interface and then calls $routine. If $verbose is specified, 93117021Smtm# it will call ifconfig(8) to show, in long format, the configured 94117021Smtm# interfaces. If $verbose is not given, it will simply output the 95117021Smtm# configured interface(s). 96117021Smtmnetwork_common() 97117021Smtm{ 98117021Smtm _func= 99117021Smtm _verbose= 100117021Smtm 101117021Smtm if [ -z "$1" ]; then 102129492Smtm err 1 "network_common(): No function name specified." 103117021Smtm else 104117021Smtm _func="$1" 105117021Smtm fi 106117021Smtm [ -n "$2" ] && _verbose=yes 107117021Smtm 108117021Smtm # Set the scope of the command (all interfaces or just one). 109113674Smtm # 110132892Smtm _cooked_list= 111117021Smtm if [ -n "$_cmdifn" ]; then 112147681Sbrooks # Don't check that the interfaces exist. We need to run 113147681Sbrooks # the down code even when the interface doesn't exist to 114147681Sbrooks # kill off wpa_supplicant. 115147681Sbrooks _cooked_list="$_cmdifn" 116132892Smtm else 117149725Sbrooks _cooked_list="`list_net_interfaces`" 118117021Smtm fi 119113674Smtm 120117021Smtm for ifn in ${_cooked_list}; do 121117021Smtm if ${_func} ${ifn} ; then 122117021Smtm eval showstat_$ifn=1 123117021Smtm else 124117021Smtm _fail="$_fail $ifn" 125117021Smtm fi 126113674Smtm done 127113674Smtm 128113674Smtm # Display interfaces configured by this script 129113674Smtm # 130117021Smtm for ifn in ${_cooked_list}; do 131113674Smtm eval showstat=\$showstat_${ifn} 132113674Smtm if [ ! -z ${showstat} ]; then 133117021Smtm if [ -n "$_verbose" ]; then 134117021Smtm ifconfig ${ifn} 135117021Smtm else 136117021Smtm echo -n " ${ifn}" 137117021Smtm fi 138113674Smtm fi 139113674Smtm done 140117021Smtm debug "The following interfaces were not configured: $_fail" 141117021Smtm} 142113674Smtm 143117021Smtmifn_start() 144117021Smtm{ 145117021Smtm local ifn cfg 146117021Smtm ifn="$1" 147117021Smtm cfg=1 148117021Smtm 149117021Smtm [ -z "$ifn" ] && return 1 150117021Smtm 151117021Smtm ifscript_up ${ifn} && cfg=0 152117021Smtm ifconfig_up ${ifn} && cfg=0 153117021Smtm ifalias_up ${ifn} && cfg=0 154117021Smtm ipx_up ${ifn} && cfg=0 155117021Smtm 156117021Smtm return $cfg 157113674Smtm} 158113674Smtm 159117021Smtmifn_stop() 160113674Smtm{ 161117021Smtm local ifn cfg 162117021Smtm ifn="$1" 163117021Smtm cfg=1 164113674Smtm 165117021Smtm [ -z "$ifn" ] && return 1 166117021Smtm 167117021Smtm ipx_down ${ifn} && cfg=0 168117021Smtm ifalias_down ${ifn} && cfg=0 169117021Smtm ifconfig_down ${ifn} && cfg=0 170117021Smtm ifscript_down ${ifn} && cfg=0 171117021Smtm 172117021Smtm return $cfg 173113674Smtm} 174113674Smtm 175113674Smtmload_rc_config $name 176132892Smtmrun_rc_command $* 177