netif revision 179003
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 179003 2008-05-15 01:06:10Z brooks $ 26# 27 28# PROVIDE: netif 29# REQUIRE: atm1 cleanvar ipfilter FILESYSTEMS 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 Fast EtherChannel interfaces 61 fec_up 62 63 # Create IPv6<-->IPv4 tunnels 64 gif_up 65 66 # Rename interfaces. 67 ifnet_rename 68 fi 69 70 # Configure the interface(s). 71 network_common ifn_start 72 73 if [ -z "$cmdifn" ]; then 74 dhcp_interfaces=`list_net_interfaces dhcp` 75 if [ -n "${dhcp_interfaces}" ]; then 76 delay=${if_up_delay} 77 while [ ${delay} -gt 0 ]; do 78 defif=`get_default_if -inet` 79 if [ -n "${defif}" ]; then 80 if [ ${delay} -ne ${if_up_delay} ]; then 81 echo "($defif)" 82 fi 83 break 84 fi 85 if [ ${delay} -eq ${if_up_delay} ]; then 86 echo -n "Waiting for an interface to come up: " 87 else 88 echo -n . 89 fi 90 sleep 1 91 delay=`expr $delay - 1` 92 done 93 fi 94 fi 95 96 if [ -f /etc/rc.d/ipfilter ] ; then 97 # Resync ipfilter 98 /etc/rc.d/ipfilter quietresync 99 fi 100 if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then 101 /etc/rc.d/bridge start $cmdifn 102 fi 103} 104 105network_stop() 106{ 107 # Set the list of interfaces to work on. 108 # 109 cmdifn=$* 110 111 echo -n "Stopping network:" 112 113 # Deconfigure the interface(s) 114 network_common ifn_stop 115 echo '.' 116} 117 118# network_common routine 119# Common configuration subroutine for network interfaces. This 120# routine takes all the preparatory steps needed for configuriing 121# an interface and then calls $routine. 122network_common() 123{ 124 local _cooked_list _fail _func 125 126 _func= 127 128 if [ -z "$1" ]; then 129 err 1 "network_common(): No function name specified." 130 else 131 _func="$1" 132 fi 133 134 # Set the scope of the command (all interfaces or just one). 135 # 136 _cooked_list= 137 if [ -n "$cmdifn" ]; then 138 # Don't check that the interface(s) exist. We need to run 139 # the down code even when the interface doesn't exist to 140 # kill off wpa_supplicant. 141 # XXXBED: is this really true or does wpa_supplicant die? 142 # if so, we should get rid of the devd entry 143 _cooked_list="$cmdifn" 144 else 145 _cooked_list="`list_net_interfaces`" 146 fi 147 148 _fail= 149 for ifn in ${_cooked_list}; do 150 if ! ${_func} ${ifn} $2; then 151 _fail="${_fail} ${ifn}" 152 fi 153 done 154 155 debug "The following interfaces were not configured: $_fail" 156} 157 158load_rc_config $name 159run_rc_command $* 160