netif revision 165664
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 165664 2006-12-30 22:53:20Z yar $ 26# 27 28# PROVIDE: netif 29# REQUIRE: atm1 ipfilter mountcritlocal serial sppp sysctl 30# KEYWORD: 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" 41cmdifn= 42 43network_start() 44{ 45 # Set the list of interfaces to work on. 46 # 47 cmdifn=$* 48 49 if [ -z "$cmdifn" ]; then 50 # 51 # We're operating as a general network start routine. 52 # 53 54 # disable SIGINT (Ctrl-c) when running at startup 55 trap : 2 56 57 # Create cloned interfaces 58 clone_up 59 60 # Create IPv6<-->IPv4 tunnels 61 gif_up 62 63 # Rename interfaces. 64 ifnet_rename 65 fi 66 67 # Configure the interface(s). 68 network_common ifn_start verbose 69 70 if [ -f /etc/rc.d/ipfilter ] ; then 71 # Resync ipfilter 72 /etc/rc.d/ipfilter resync 73 fi 74 if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then 75 /etc/rc.d/bridge start $cmdifn 76 fi 77} 78 79network_stop() 80{ 81 # Set the list of interfaces to work on. 82 # 83 cmdifn=$* 84 85 echo -n "Stopping network:" 86 87 # Deconfigure the interface(s) 88 network_common ifn_stop 89 echo '.' 90} 91 92# network_common routine verbose 93# Common configuration subroutine for network interfaces. This 94# routine takes all the preparatory steps needed for configuriing 95# an interface and then calls $routine. If $verbose is specified, 96# it will call ifconfig(8) to show, in long format, the configured 97# interfaces. If $verbose is not given, it will simply output the 98# configured interface(s). 99network_common() 100{ 101 local _cooked_list _fail _func _verbose 102 103 _func= 104 _verbose= 105 106 if [ -z "$1" ]; then 107 err 1 "network_common(): No function name specified." 108 else 109 _func="$1" 110 fi 111 [ -n "$2" ] && _verbose=yes 112 113 # Set the scope of the command (all interfaces or just one). 114 # 115 _cooked_list= 116 if [ -n "$cmdifn" ]; then 117 # Don't check that the interfaces exist. We need to run 118 # the down code even when the interface doesn't exist to 119 # kill off wpa_supplicant. 120 _cooked_list="$cmdifn" 121 else 122 _cooked_list="`list_net_interfaces`" 123 fi 124 125 _fail= 126 for ifn in ${_cooked_list}; do 127 if ${_func} ${ifn} ; then 128 eval showstat_$ifn=1 129 else 130 _fail="$_fail $ifn" 131 fi 132 done 133 134 # Display interfaces configured by this script 135 # 136 for ifn in ${_cooked_list}; do 137 eval showstat=\$showstat_${ifn} 138 if [ ! -z ${showstat} ]; then 139 if [ -n "$_verbose" ]; then 140 ifconfig ${ifn} 141 else 142 echo -n " ${ifn}" 143 fi 144 fi 145 done 146 debug "The following interfaces were not configured: $_fail" 147} 148 149ifn_start() 150{ 151 local ifn cfg 152 ifn="$1" 153 cfg=1 154 155 [ -z "$ifn" ] && return 1 156 157 ifscript_up ${ifn} && cfg=0 158 ifconfig_up ${ifn} && cfg=0 159 ipv4_up ${ifn} && cfg=0 160 ipx_up ${ifn} && cfg=0 161 162 return $cfg 163} 164 165ifn_stop() 166{ 167 local ifn cfg 168 ifn="$1" 169 cfg=1 170 171 [ -z "$ifn" ] && return 1 172 173 ipx_down ${ifn} && cfg=0 174 ipv4_down ${ifn} && cfg=0 175 ifconfig_down ${ifn} && cfg=0 176 ifscript_down ${ifn} && cfg=0 177 178 return $cfg 179} 180 181load_rc_config $name 182run_rc_command $* 183