netif revision 137070
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 137070 2004-10-30 13:44:06Z pjd $ 26# 27 28# PROVIDE: netif 29# REQUIRE: atm1 ipfilter mountcritlocal pccard 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" 41_cmdifn= 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 # Create cloned interfaces 55 clone_up 56 57 # Create IPv6<-->IPv4 tunnels 58 gif_up 59 60 # Rename interfaces. 61 ifnet_rename 62 fi 63 64 # Configure the interface(s). 65 network_common ifn_start verbose 66 67 if [ -f /etc/rc.d/ipfilter ] ; then 68 # Resync ipfilter 69 /etc/rc.d/ipfilter resync 70 fi 71} 72 73network_stop() 74{ 75 # Set the list of interfaces to work on. 76 # 77 _cmdifn=$* 78 79 echo -n "Stopping network:" 80 81 # Deconfigure the interface(s) 82 network_common ifn_stop 83 echo '.' 84} 85 86# network_common routine verbose 87# Common configuration subroutine for network interfaces. This 88# routine takes all the preparatory steps needed for configuriing 89# an interface and then calls $routine. If $verbose is specified, 90# it will call ifconfig(8) to show, in long format, the configured 91# interfaces. If $verbose is not given, it will simply output the 92# configured interface(s). 93network_common() 94{ 95 _func= 96 _verbose= 97 98 if [ -z "$1" ]; then 99 err 1 "network_common(): No function name specified." 100 else 101 _func="$1" 102 fi 103 [ -n "$2" ] && _verbose=yes 104 105 # Get a list of network interfaces. Do not include dhcp interfaces. 106 _ifn_list="`list_net_interfaces nodhcp`" 107 108 # Set the scope of the command (all interfaces or just one). 109 # 110 _cooked_list= 111 if [ -n "$_cmdifn" ]; then 112 for i in $_cmdifn ; do 113 eval _if=\"`expr "$_ifn_list" : ".*\(${i}\).*"`\" 114 if [ -z "$_if" ]; then 115 err 1 "No such network interface: $i" 116 fi 117 _cooked_list="$_cooked_list $_if" 118 done 119 else 120 _cooked_list="$_ifn_list" 121 fi 122 123 for ifn in ${_cooked_list}; do 124 if ${_func} ${ifn} ; then 125 eval showstat_$ifn=1 126 else 127 _fail="$_fail $ifn" 128 fi 129 done 130 131 # Display interfaces configured by this script 132 # 133 for ifn in ${_cooked_list}; do 134 eval showstat=\$showstat_${ifn} 135 if [ ! -z ${showstat} ]; then 136 if [ -n "$_verbose" ]; then 137 ifconfig ${ifn} 138 else 139 echo -n " ${ifn}" 140 fi 141 fi 142 done 143 debug "The following interfaces were not configured: $_fail" 144} 145 146ifn_start() 147{ 148 local ifn cfg 149 ifn="$1" 150 cfg=1 151 152 [ -z "$ifn" ] && return 1 153 154 ifscript_up ${ifn} && cfg=0 155 ifconfig_up ${ifn} && cfg=0 156 ifalias_up ${ifn} && cfg=0 157 ipx_up ${ifn} && cfg=0 158 159 return $cfg 160} 161 162ifn_stop() 163{ 164 local ifn cfg 165 ifn="$1" 166 cfg=1 167 168 [ -z "$ifn" ] && return 1 169 170 ipx_down ${ifn} && cfg=0 171 ifalias_down ${ifn} && cfg=0 172 ifconfig_down ${ifn} && cfg=0 173 ifscript_down ${ifn} && cfg=0 174 175 return $cfg 176} 177 178load_rc_config $name 179run_rc_command $* 180