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