netif revision 165664
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 165664 2006-12-30 22:53:20Z yar $ 26113674Smtm# 27113674Smtm 28113674Smtm# PROVIDE: netif 29155610Simp# REQUIRE: atm1 ipfilter mountcritlocal 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" 41165664Syarcmdifn= 42113674Smtm 43113674Smtmnetwork_start() 44113674Smtm{ 45132892Smtm # Set the list of interfaces to work on. 46132892Smtm # 47165664Syar cmdifn=$* 48132892Smtm 49165664Syar if [ -z "$cmdifn" ]; then 50117021Smtm # 51117021Smtm # We're operating as a general network start routine. 52117021Smtm # 53113674Smtm 54149789Skeramida # disable SIGINT (Ctrl-c) when running at startup 55149730Sbrooks trap : 2 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 74165664Syar if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then 75165664Syar /etc/rc.d/bridge start $cmdifn 76159138Sthompsa fi 77117021Smtm} 78117021Smtm 79117021Smtmnetwork_stop() 80117021Smtm{ 81132892Smtm # Set the list of interfaces to work on. 82132892Smtm # 83165664Syar cmdifn=$* 84132892Smtm 85117021Smtm echo -n "Stopping network:" 86117021Smtm 87117021Smtm # Deconfigure the interface(s) 88117021Smtm network_common ifn_stop 89117021Smtm echo '.' 90117021Smtm} 91117021Smtm 92117021Smtm# network_common routine verbose 93117021Smtm# Common configuration subroutine for network interfaces. This 94117021Smtm# routine takes all the preparatory steps needed for configuriing 95117021Smtm# an interface and then calls $routine. If $verbose is specified, 96117021Smtm# it will call ifconfig(8) to show, in long format, the configured 97117021Smtm# interfaces. If $verbose is not given, it will simply output the 98117021Smtm# configured interface(s). 99117021Smtmnetwork_common() 100117021Smtm{ 101165664Syar local _cooked_list _fail _func _verbose 102165664Syar 103117021Smtm _func= 104117021Smtm _verbose= 105117021Smtm 106117021Smtm if [ -z "$1" ]; then 107129492Smtm err 1 "network_common(): No function name specified." 108117021Smtm else 109117021Smtm _func="$1" 110117021Smtm fi 111117021Smtm [ -n "$2" ] && _verbose=yes 112117021Smtm 113117021Smtm # Set the scope of the command (all interfaces or just one). 114113674Smtm # 115132892Smtm _cooked_list= 116165664Syar if [ -n "$cmdifn" ]; then 117147681Sbrooks # Don't check that the interfaces exist. We need to run 118147681Sbrooks # the down code even when the interface doesn't exist to 119147681Sbrooks # kill off wpa_supplicant. 120165664Syar _cooked_list="$cmdifn" 121132892Smtm else 122149725Sbrooks _cooked_list="`list_net_interfaces`" 123117021Smtm fi 124113674Smtm 125165664Syar _fail= 126117021Smtm for ifn in ${_cooked_list}; do 127117021Smtm if ${_func} ${ifn} ; then 128117021Smtm eval showstat_$ifn=1 129117021Smtm else 130117021Smtm _fail="$_fail $ifn" 131117021Smtm fi 132113674Smtm done 133113674Smtm 134113674Smtm # Display interfaces configured by this script 135113674Smtm # 136117021Smtm for ifn in ${_cooked_list}; do 137113674Smtm eval showstat=\$showstat_${ifn} 138113674Smtm if [ ! -z ${showstat} ]; then 139117021Smtm if [ -n "$_verbose" ]; then 140117021Smtm ifconfig ${ifn} 141117021Smtm else 142117021Smtm echo -n " ${ifn}" 143117021Smtm fi 144113674Smtm fi 145113674Smtm done 146117021Smtm debug "The following interfaces were not configured: $_fail" 147117021Smtm} 148113674Smtm 149117021Smtmifn_start() 150117021Smtm{ 151117021Smtm local ifn cfg 152117021Smtm ifn="$1" 153117021Smtm cfg=1 154117021Smtm 155117021Smtm [ -z "$ifn" ] && return 1 156117021Smtm 157117021Smtm ifscript_up ${ifn} && cfg=0 158117021Smtm ifconfig_up ${ifn} && cfg=0 159152441Sbrooks ipv4_up ${ifn} && cfg=0 160117021Smtm ipx_up ${ifn} && cfg=0 161117021Smtm 162117021Smtm return $cfg 163113674Smtm} 164113674Smtm 165117021Smtmifn_stop() 166113674Smtm{ 167117021Smtm local ifn cfg 168117021Smtm ifn="$1" 169117021Smtm cfg=1 170113674Smtm 171117021Smtm [ -z "$ifn" ] && return 1 172117021Smtm 173117021Smtm ipx_down ${ifn} && cfg=0 174152441Sbrooks ipv4_down ${ifn} && cfg=0 175117021Smtm ifconfig_down ${ifn} && cfg=0 176117021Smtm ifscript_down ${ifn} && cfg=0 177117021Smtm 178117021Smtm return $cfg 179113674Smtm} 180113674Smtm 181113674Smtmload_rc_config $name 182132892Smtmrun_rc_command $* 183