netif revision 206408
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 206408 2010-04-09 01:35:09Z dougb $ 26# 27 28# PROVIDE: netif 29# REQUIRE: atm1 cleanvar FILESYSTEMS serial sppp sysctl 30# REQUIRE: ipfilter ipfs 31# KEYWORD: nojail 32 33. /etc/rc.subr 34. /etc/network.subr 35 36name="network" 37start_precmd="network_prestart" 38start_cmd="network_start" 39stop_cmd="network_stop" 40cloneup_cmd="clone_up" 41clonedown_cmd="clone_down" 42extra_commands="cloneup clonedown" 43cmdifn= 44 45network_prestart() 46{ 47 if [ -n "$ipv6_enable" ]; then 48 warn 'The ipv6_enable option is deprecated.' 49 warn 'See rc.conf(5) for information on disabling IPv6.' 50 fi 51} 52 53network_start() 54{ 55 # Set the list of interfaces to work on. 56 # 57 cmdifn=$* 58 59 if [ -z "$cmdifn" ]; then 60 # 61 # We're operating as a general network start routine. 62 # 63 64 # disable SIGINT (Ctrl-c) when running at startup 65 trap : 2 66 67 # Create cloned interfaces 68 clone_up 69 70 # Create Fast EtherChannel interfaces 71 fec_up 72 73 # Create IPv6<-->IPv4 tunnels 74 gif_up 75 76 # Rename interfaces. 77 ifnet_rename 78 fi 79 80 # Configure the interface(s). 81 network_common ifn_start 82 83 if [ -f /etc/rc.d/ipfilter ] ; then 84 # Resync ipfilter 85 /etc/rc.d/ipfilter quietresync 86 fi 87 if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then 88 /etc/rc.d/bridge start $cmdifn 89 fi 90} 91 92network_stop() 93{ 94 # Set the list of interfaces to work on. 95 # 96 cmdifn=$* 97 98 # Deconfigure the interface(s) 99 network_common ifn_stop 100} 101 102# network_common routine 103# Common configuration subroutine for network interfaces. This 104# routine takes all the preparatory steps needed for configuriing 105# an interface and then calls $routine. 106network_common() 107{ 108 local _cooked_list _fail _func _ok _str 109 110 _func= 111 112 if [ -z "$1" ]; then 113 err 1 "network_common(): No function name specified." 114 else 115 _func="$1" 116 fi 117 118 # Set the scope of the command (all interfaces or just one). 119 # 120 _cooked_list= 121 if [ -n "$cmdifn" ]; then 122 # Don't check that the interface(s) exist. We need to run 123 # the down code even when the interface doesn't exist to 124 # kill off wpa_supplicant. 125 # XXXBED: is this really true or does wpa_supplicant die? 126 # if so, we should get rid of the devd entry 127 _cooked_list="$cmdifn" 128 else 129 _cooked_list="`list_net_interfaces`" 130 fi 131 132 _fail= 133 _ok= 134 for ifn in ${_cooked_list}; do 135 if ${_func} ${ifn} $2; then 136 _ok="${_ok} ${ifn}" 137 else 138 _fail="${_fail} ${ifn}" 139 fi 140 done 141 142 _str= 143 if [ -n "${_ok}" ]; then 144 case ${_func} in 145 ifn_start) 146 _str='Starting' 147 ;; 148 ifn_stop) 149 _str='Stopping' 150 ;; 151 esac 152 echo "${_str} Network:${_ok}." 153 if check_startmsgs; then 154 for ifn in ${_ok}; do 155 /sbin/ifconfig ${ifn} 156 done 157 fi 158 fi 159 160 debug "The following interfaces were not configured: $_fail" 161} 162 163load_rc_config $name 164run_rc_command $* 165