source: projects/initscripts/tags/initscripts-8.91.3/rc.d/init.d/network @ 1108

Revision 1108, 7.7 KB checked in by daisuke, 14 years ago (diff)

import initscripts-8.90.6 from internal cvs repository

Line 
1#! /bin/bash
2#
3# network       Bring up/down networking
4#
5# chkconfig: - 10 90
6# description: Activates/Deactivates all network interfaces configured to \
7#              start at boot time.
8#
9### BEGIN INIT INFO
10# Provides: $network
11# Should-Start: iptables ip6tables
12### END INIT INFO
13
14# Source function library.
15. /etc/init.d/functions
16
17if [ ! -f /etc/sysconfig/network ]; then
18    exit 0
19fi
20
21. /etc/sysconfig/network
22
23if [ -f /etc/sysconfig/pcmcia ]; then
24        . /etc/sysconfig/pcmcia
25fi
26
27
28# Check that networking is up.
29[ "${NETWORKING}" = "no" ] && exit 0
30
31# if the ip configuration utility isn't around we can't function.
32[ -x /sbin/ip ] || exit 1
33
34# Even if IPX is configured, without the utilities we can't do much
35[ ! -x /sbin/ipx_internal_net -o ! -x /sbin/ipx_configure ] && IPX=
36
37# Even if VLAN is configured, without the utility we can't do much
38[ ! -x /sbin/vconfig ] && VLAN=
39
40CWD=`pwd`
41cd /etc/sysconfig/network-scripts
42
43. ./network-functions
44
45# find all the interfaces besides loopback.
46# ignore aliases, alternative configurations, and editor backup files
47interfaces=$(ls ifcfg* | \
48            LANG=C sed -e "$__sed_discard_ignored_files" \
49                       -e '/\(ifcfg-lo\|:\|ifcfg-.*-range\)/d' \
50                       -e '/ifcfg-[A-Za-z0-9\._-]\+$/ { s/^ifcfg-//g;s/[0-9]/ &/}' | \
51            LANG=C sort -k 1,1 -k 2n | \
52            LANG=C sed 's/ //')
53
54# See how we were called.
55case "$1" in
56  start)
57        # IPv6 hook (pre IPv4 start)
58        if [ -x /etc/sysconfig/network-scripts/init.ipv6-global ]; then
59                /etc/sysconfig/network-scripts/init.ipv6-global start pre
60        fi
61 
62        sysctl -e -p /etc/sysctl.conf >/dev/null 2>&1
63
64        # bring up loopback interface
65        action $"Bringing up loopback interface: " ./ifup ifcfg-lo
66
67        case "$IPX" in
68          yes|true)
69            /sbin/ipx_configure --auto_primary=$IPXAUTOPRIMARY \
70                                   --auto_interface=$IPXAUTOFRAME
71            if [ "$IPXINTERNALNETNUM" != "0" ]; then
72               /sbin/ipx_internal_net add $IPXINTERNALNETNUM $IPXINTERNALNODENUM
73            fi
74            ;;
75        esac
76
77        case "$VLAN" in
78          yes)
79            if [ -d /proc/net/vlan ] || modprobe 8021q >/dev/null 2>&1 ; then
80                test -z "$VLAN_NAME_TYPE" && VLAN_NAME_TYPE=DEV_PLUS_VID_NO_PAD
81                action $"Setting 802.1Q VLAN parameters: " /sbin/vconfig set_name_type "$VLAN_NAME_TYPE"
82            else
83                echo $"No 802.1Q VLAN support available in kernel."
84            fi
85            ;;
86        esac
87
88        vlaninterfaces=""
89        cipeinterfaces=""
90        xdslinterfaces=""
91        bridgeinterfaces=""
92
93        # bring up all other interfaces configured to come up at boot time
94        for i in $interfaces; do
95                unset DEVICE TYPE SLAVE
96                eval $(LANG=C fgrep "DEVICE=" ifcfg-$i)
97                eval $(LANG=C fgrep "TYPE=" ifcfg-$i)
98                eval $(LANG=C fgrep "SLAVE=" ifcfg-$i)
99
100                if [ -z "$DEVICE" ] ; then DEVICE="$i"; fi
101
102                if [ "${DEVICE##cipcb}" != "$DEVICE" ] ; then
103                        cipeinterfaces="$cipeinterfaces $i"
104                        continue
105                fi
106                if [ "$TYPE" = "xDSL" ]; then
107                        xdslinterfaces="$xdslinterfaces $i"
108                        continue
109                fi
110
111                if [ "$TYPE" = "Bridge" ]; then
112                        bridgeinterfaces="$bridgeinterfaces $i"
113                        continue
114                fi
115
116                if [ "${DEVICE%%.*}" != "$DEVICE"  -o  "${DEVICE##vlan}" != "$DEVICE" ] ; then
117                        vlaninterfaces="$vlaninterfaces $i"
118                        continue
119                fi
120               
121                if [ "$SLAVE" = "yes" ]; then
122                        continue
123                fi
124
125                if LANG=C egrep -L "^ONBOOT=['\"]?[Nn][Oo]['\"]?" ifcfg-$i > /dev/null ; then
126                        # this loads the module, to preserve ordering
127                        is_available $i
128                        continue
129                fi
130                # If we're in confirmation mode, get user confirmation.
131                if [ -f /var/run/confirm ]; then
132                        confirm $i
133                        test $? = 1 && continue
134                fi
135                action $"Bringing up interface $i: " ./ifup $i boot
136        done
137       
138        # Bring up xDSL and CIPE interfaces
139        for i in $vlaninterfaces $bridgeinterfaces $xdslinterfaces $cipeinterfaces ; do
140            if ! LANG=C egrep -L "^ONBOOT=['\"]?[Nn][Oo]['\"]?" ifcfg-$i >/dev/null 2>&1 ; then
141                # If we're in confirmation mode, get user confirmation.
142                if [ -f /var/run/confirm ]; then
143                        confirm $i
144                        test $? = 1 && continue
145                fi
146                action $"Bringing up interface $i: " ./ifup $i boot
147            fi
148        done
149
150        # Add non interface-specific static-routes.
151        if [ -f /etc/sysconfig/static-routes ]; then
152           grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do
153              /sbin/route add -$args
154           done
155        fi   
156
157        # IPv6 hook (post IPv4 start)
158        if [ -x /etc/sysconfig/network-scripts/init.ipv6-global ]; then
159                /etc/sysconfig/network-scripts/init.ipv6-global start post
160        fi
161        # Run this again to catch any interface-specific actions
162        sysctl -e -p /etc/sysctl.conf >/dev/null 2>&1
163 
164        touch /var/lock/subsys/network
165
166        [ -n "${NETWORKDELAY}" ] && /bin/sleep ${NETWORKDELAY}
167        ;;
168  stop)
169        # Don't shut the network down if root is on NFS or a network
170        # block device.
171        rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' /etc/mtab)
172        rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
173       
174        if [[ "$rootfs" =~ ^nfs ]] || [[ "$rootopts" =~ "_netdev|_rnetdev" ]] ; then
175                exit 1
176        fi
177 
178        # If this is a final shutdown/halt, check for network FS,
179        # and unmount them even if the user didn't turn on netfs
180        if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
181                NFSMTAB=`LC_ALL=C awk '$3  ~ /^nfs/ { print $2 }' /proc/mounts`
182                SMBMTAB=`LC_ALL=C awk '$3 == "smbfs" { print $2 }' /proc/mounts`
183                NCPMTAB=`LC_ALL=C awk '$3 == "ncpfs" { print $2 }' /proc/mounts`
184                if [ -n "$NFSMTAB" -o -n "$SMBMTAB" -o -n "$NCPMTAB" ] ; then
185                        /etc/init.d/netfs stop
186                fi
187        fi
188       
189        # IPv6 hook (pre IPv4 stop)
190        if [ -x /etc/sysconfig/network-scripts/init.ipv6-global ]; then
191                /etc/sysconfig/network-scripts/init.ipv6-global stop pre
192        fi
193 
194        vlaninterfaces=""
195        cipeinterfaces=""
196        xdslinterfaces=""
197        bridgeinterfaces=""
198        remaining=""
199
200        # get list of bonding, cipe, and xdsl interfaces
201        for i in $interfaces; do
202                unset DEVICE TYPE
203                eval $(LANG=C fgrep "DEVICE=" ifcfg-$i)
204                eval $(LANG=C fgrep "TYPE=" ifcfg-$i)
205
206                if [ -z "$DEVICE" ] ; then DEVICE="$i"; fi
207
208                if [ "${DEVICE##cipcb}" != "$DEVICE" ] ; then
209                        cipeinterfaces="$cipeinterfaces $i"
210                        continue
211                fi
212                if [ "$TYPE" = "Bridge" ]; then
213                        bridgeinterfaces="$bridgeinterfaces $i"
214                        continue
215                fi
216                if [ "$TYPE" = "xDSL" ]; then
217                        xdslinterfaces="$xdslinterfaces $i"
218                        continue
219                fi
220
221                if [ "${DEVICE%%.*}" != "$DEVICE"  -o  "${DEVICE##vlan}" != "$DEVICE" ] ; then
222                        vlaninterfaces="$vlaninterfaces $i"
223                        continue
224                fi
225                remaining="$remaining $i"
226        done
227       
228        for i in $cipeinterfaces $xdslinterfaces $bridgeinterfaces $vlaninterfaces $remaining; do
229                (. ifcfg-$i
230                if [ -z "$DEVICE" ] ; then DEVICE="$i"; fi
231
232                if ! check_device_down $DEVICE; then
233                   action $"Shutting down interface $i: " ./ifdown $i boot
234                fi
235                )
236        done
237
238        case "$IPX" in
239          yes|true)
240            if [ "$IPXINTERNALNETNUM" != "0" ]; then
241               /sbin/ipx_internal_net del
242            fi
243            ;;
244        esac
245
246        action $"Shutting down loopback interface: " ./ifdown ifcfg-lo
247
248        if [ -d /proc/sys/net/ipv4 ]; then
249          if [ -f /proc/sys/net/ipv4/ip_forward ]; then
250                if [ `cat /proc/sys/net/ipv4/ip_forward` != 0 ]; then
251                        action $"Disabling IPv4 packet forwarding: " sysctl -w net.ipv4.ip_forward=0
252                fi
253          fi
254          if [ -f /proc/sys/net/ipv4/ip_always_defrag ]; then
255                if [ `cat /proc/sys/net/ipv4/ip_always_defrag` != 0 ]; then
256                        action $"Disabling IPv4 automatic defragmentation: " sysctl -w net.ipv4.ip_always_defrag=0
257                fi
258          fi
259        fi
260
261        # IPv6 hook (post IPv4 stop)
262        if [ -x /etc/sysconfig/network-scripts/init.ipv6-global ]; then
263                /etc/sysconfig/network-scripts/init.ipv6-global stop post
264        fi
265       
266        rm -f /var/lock/subsys/network
267        ;;
268  status)
269        echo $"Configured devices:"
270        echo lo $interfaces
271
272        echo $"Currently active devices:"
273        echo $(/sbin/ip -o link show up | awk -F ": " '{ print $2 }')
274        ;;
275  restart|reload)
276        cd "$CWD"
277        $0 stop
278        $0 start
279        ;;
280  *)
281        echo $"Usage: $0 {start|stop|restart|reload|status}"
282        exit 1
283esac
284
285exit 0
Note: See TracBrowser for help on using the repository browser.