Subversion Repositories configs

Rev

Rev 97 | Details | Compare with Previous | Last modification | View Log | RSS feed

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