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