]>
Commit | Line | Data |
---|---|---|
12de71be | 1 | #!/bin/sh |
7742e157 | 2 | # |
8d86e6df | 3 | # network Bring up/down networking |
7742e157 | 4 | # |
5e6dfc29 JR |
5 | # chkconfig: 2345 10 90 |
6 | # description: Activates/Deactivates all network interfaces configured to \ | |
8d86e6df | 7 | # start at boot time. |
458f14b7 | 8 | # |
8d86e6df | 9 | # probe: true |
ec8b15cb | 10 | # $Id$ |
fa8aca70 | 11 | |
fa8aca70 | 12 | if [ ! -f /etc/sysconfig/network ]; then |
f38190d4 | 13 | . /etc/rc.d/init.d/functions |
fa8aca70 JR |
14 | nls "%s is missing. Can't continue." "/etc/sysconfig/network" |
15 | exit 1 | |
16 | fi | |
7742e157 AF |
17 | |
18 | . /etc/sysconfig/network | |
19 | ||
f38190d4 ER |
20 | # Source function library. |
21 | . /etc/rc.d/init.d/functions | |
f67ce454 | 22 | . /lib/rc-scripts/functions.network |
f38190d4 | 23 | |
fa8aca70 | 24 | # Will be removed in the future |
f38190d4 | 25 | if [ -n "$NETWORKING" ] && is_yes "$NETWORKING"; then |
fb608ea2 | 26 | if [ -z "$IPV4_NETWORKING" ]; then |
fa8aca70 JR |
27 | echo "NETWORKING is set to YES, but IPV4_NETWORKING is empty!" |
28 | echo "Please upgrade your config" | |
29 | echo "Assuming you want IPv4 networking" | |
30 | IPV4_NETWORKING=yes | |
31 | fi | |
32 | fi | |
33 | ||
7e04fe0e | 34 | ###### |
35 | # initialize networking: | |
36 | # - check IPv4, IPv6, IPX can be handled by system | |
37 | # - setup default IPv{4,6} interfaces policy like: | |
7e04fe0e | 38 | # - spoofig protection, |
39 | # - icmp echo ignore broadcasts, | |
40 | # - setup lo interface | |
18bd13ac | 41 | network_init() { |
8834907c ER |
42 | if [ ! -x /sbin/ip ]; then |
43 | nls "%s is missing. Can't continue." "/sbin/ip" | |
44 | exit 1 | |
45 | fi | |
e95a55fb | 46 | |
8834907c ER |
47 | # Modprobe needed devices |
48 | modprobe_net | |
51e8dd01 | 49 | |
8834907c | 50 | # Setup interfaces names |
b075e23f | 51 | if ! is_empty_file /etc/mactab && [ -x /sbin/nameif ]; then |
8834907c ER |
52 | run_cmd "Setting interfaces names (nameif)" /sbin/nameif |
53 | fi | |
70db4cf0 | 54 | |
8834907c ER |
55 | # Kernel network parameters |
56 | sysctl -e -p /etc/sysctl.conf > /dev/null 2>&1 | |
57 | ||
58 | # Set UP loopback interface | |
59 | set_up_loopback | |
60 | ||
61 | # Setup configuration | |
62 | setup_nat on | |
63 | setup_routes on | |
64 | setup_ip_rules on | |
65 | # Setup IPX | |
66 | if is_yes "$IPX"; then | |
67 | if [ -n $IPXAUTOPRIMARY ] ; then | |
68 | if is_yes "$IPXAUTOPRIMARY"; then | |
69 | IPXAUTOPRIMARY="on" | |
70 | else | |
71 | IPXAUTOPRIMARY="off" | |
72 | fi | |
73 | /sbin/ipx_configure --auto_primary=$IPXAUTOPRIMARY | |
fa8aca70 | 74 | fi |
8834907c ER |
75 | if [ -n $IPXAUTOFRAME ] ; then |
76 | if is_yes "$IPXAUTOFRAME"; then | |
77 | IPXAUTOFRAME="on" | |
78 | else | |
79 | IPXAUTOFRAME="off" | |
80 | fi | |
81 | /sbin/ipx_configure --auto_interface=$IPXAUTOFRAME | |
82 | fi | |
83 | if [ -n "$IPXINTERNALNETNUM" -a "$IPXINTERNALNETNUM" != "0" ]; then | |
84 | /sbin/ipx_internal_net add $IPXINTERNALNETNUM $IPXINTERNALNODENUM | |
fa8aca70 | 85 | fi |
03f9cfee | 86 | fi |
7742e157 AF |
87 | } |
88 | ||
18bd13ac | 89 | network_postinit() { |
8834907c ER |
90 | # Set static RARP table |
91 | static_rarp | |
ea822d66 | 92 | |
8834907c ER |
93 | # Set static ARP table |
94 | static_arp | |
21c12948 AF |
95 | } |
96 | ||
7e04fe0e | 97 | ###### |
98 | # deinitialize networking | |
99 | # - down lo interface. | |
18bd13ac | 100 | network_deinit() { |
8834907c ER |
101 | setup_routes off |
102 | setup_ip_rules off | |
fe648758 | 103 | |
8834907c ER |
104 | # Set down NAT rules |
105 | setup_nat off | |
106 | # Set DOWN loopback interface | |
107 | set_down_loopback | |
7742e157 AF |
108 | } |
109 | ||
b21b8a02 | 110 | # Get list of interface configs |
a55d7641 | 111 | # ignores editor backup files and rpm backups |
fe42ef69 | 112 | network_interface_configs() { |
b21b8a02 ER |
113 | local match="$1" |
114 | for a in /etc/sysconfig/interfaces/$match; do | |
115 | case "$a" in | |
a55d7641 | 116 | *.rpmorig|*.rpmnew|*.rpmsave|*~|*.orig) |
b21b8a02 ER |
117 | continue |
118 | ;; | |
119 | *) | |
120 | echo $a | |
121 | ;; | |
122 | esac | |
123 | done | |
124 | } | |
125 | ||
fe42ef69 ER |
126 | find_boot_interfaces() { |
127 | ifcfg_files="$(network_interface_configs 'ifcfg-*')" | |
128 | bootprio=$(grep '^BOOTPRIO=' $ifcfg_files) | |
129 | ||
130 | if [ -n "$bootprio" ]; then | |
131 | # find all the interfaces besides loopback. | |
cd9ee56e | 132 | interfaces_boot=` |
9e90b313 | 133 | for a in $(echo "$bootprio" | sort -t= -s -n -k2,2); do |
fe42ef69 ER |
134 | i="${a%:BOOTPRIO*}" |
135 | case $i in | |
136 | *ifcfg-lo) continue ;; | |
137 | esac | |
18f291cc | 138 | DEVICE=""; ONBOOT=""; USERS=""; . "$i" 2>/dev/null |
2d951c61 | 139 | [ ${USERS:-no} != no ] && continue |
18f291cc | 140 | [ "${DEVICE:+set}" != "set" ] && continue |
fb608ea2 | 141 | [ ${ONBOOT:-no} = yes ] && echo "${i##*/ifcfg-}" |
fe42ef69 | 142 | done |
cd9ee56e | 143 | ` |
fe42ef69 | 144 | else |
cd9ee56e | 145 | interfaces_boot=` |
fe42ef69 ER |
146 | for i in $ifcfg_files; do |
147 | case ${i##*/} in | |
9e90b313 | 148 | ifcfg-lo|ifcfg-sit*|ifcfg-atm*|ifcfg-lec*|ifcfg-nas*|ifcfg-br*|ifcfg-macvlan*|ifcfg-macvtap*|ifcfg-*.*) continue ;; |
fe42ef69 | 149 | esac |
18f291cc | 150 | DEVICE=""; ONBOOT=""; USERS=""; . "$i" 2>/dev/null |
2d951c61 | 151 | [ ${USERS:-no} != no ] && continue |
18f291cc | 152 | [ "${DEVICE:+set}" != "set" ] && continue |
fb608ea2 | 153 | [ ${ONBOOT:-no} = yes ] && echo "${i##*/ifcfg-}" |
fe42ef69 | 154 | done |
cd9ee56e | 155 | ` |
fe42ef69 | 156 | |
cd9ee56e | 157 | interfaces_vlan_boot=` |
fe42ef69 ER |
158 | for i in $ifcfg_files; do |
159 | case ${i##*/} in | |
160 | ifcfg-*.*) ;; | |
161 | *) continue ;; | |
162 | esac | |
2d951c61 JR |
163 | ONBOOT=""; USERS=""; . "$i" 2>/dev/null |
164 | [ ${USERS:-no} != no ] && continue | |
fb608ea2 | 165 | [ ${ONBOOT:-no} = yes ] && echo "${i##*/ifcfg-}" |
fe42ef69 | 166 | done |
cd9ee56e | 167 | ` |
fe42ef69 | 168 | |
cd9ee56e | 169 | interfaces_br_boot=` |
fe42ef69 ER |
170 | for i in $ifcfg_files; do |
171 | case ${i##*/} in | |
172 | ifcfg-br*) ;; | |
173 | *) continue ;; | |
174 | esac | |
2d951c61 JR |
175 | ONBOOT=""; USERS=""; . "$i" 2>/dev/null |
176 | [ ${USERS:-no} != no ] && continue | |
fb608ea2 | 177 | [ ${ONBOOT:-no} = yes ] && echo "${i##*/ifcfg-}" |
fe42ef69 | 178 | done |
cd9ee56e | 179 | ` |
fe42ef69 | 180 | |
9e90b313 JR |
181 | interfaces_virt_boot=` |
182 | for i in $ifcfg_files; do | |
183 | case ${i##*/} in | |
184 | ifcfg-macvtap*|ifcfg-macvlan*) ;; | |
185 | *) continue ;; | |
186 | esac | |
2d951c61 JR |
187 | ONBOOT=""; USERS=""; . "$i" 2>/dev/null |
188 | [ ${USERS:-no} != no ] && continue | |
9e90b313 JR |
189 | [ ${ONBOOT:-no} = yes ] && echo "${i##*/ifcfg-}" |
190 | done | |
191 | ` | |
192 | ||
cd9ee56e | 193 | interfaces_sit_boot=` |
fe42ef69 ER |
194 | for i in $ifcfg_files; do |
195 | case ${i##*/} in | |
196 | ifcfg-sit*) ;; | |
197 | *) continue ;; | |
198 | esac | |
2d951c61 JR |
199 | ONBOOT=""; USERS=""; . "$i" 2>/dev/null |
200 | [ ${USERS:-no} != no ] && continue | |
fb608ea2 | 201 | [ ${ONBOOT:-no} = yes ] && echo "${i##*/ifcfg-}" |
fe42ef69 | 202 | done |
cd9ee56e | 203 | ` |
fe42ef69 ER |
204 | fi |
205 | ||
18bd13ac | 206 | tunnels=$( |
fe42ef69 | 207 | for i in $(network_interface_configs 'tnlcfg-*'); do |
2d951c61 JR |
208 | ONBOOT=""; USERS=""; . "$i" 2>/dev/null |
209 | [ ${USERS:-no} != no ] && continue | |
fb608ea2 | 210 | [ ${ONBOOT:-no} = yes ] && echo "${i##*/tnlcfg-}" |
fe42ef69 | 211 | done |
18bd13ac | 212 | ) |
fe42ef69 ER |
213 | } |
214 | ||
6236caca | 215 | start() { |
fd814d46 | 216 | emit pld.network-starting |
30a91466 ER |
217 | emit starting JOB=network |
218 | ||
6236caca ER |
219 | rc_splash "bootnetwork start" |
220 | network_init | |
221 | ||
fb608ea2 | 222 | for i in $interfaces_boot $interfaces_vlan_boot $interfaces_sit_boot; do |
6236caca ER |
223 | run_cmd -a "$(nls 'Bringing up interface %s' "$i")" /sbin/ifup $i boot |
224 | done | |
225 | ||
226 | for i in $interfaces_br_boot ; do | |
227 | run_cmd -a "$(nls 'Bringing up bridge interface %s' "$i")" /sbin/ifup $i boot | |
228 | done | |
229 | ||
9e90b313 JR |
230 | for i in $interfaces_virt_boot ; do |
231 | run_cmd -a "$(nls 'Bringing up virtual interface %s' "$i")" /sbin/ifup $i boot | |
232 | done | |
233 | ||
6236caca ER |
234 | for i in $tunnels; do |
235 | run_cmd -a "$(nls 'Setting tunnel %s' "$i")" /sbin/tnlup $i boot | |
236 | run_cmd -a "$(nls 'Bringing up tunnel interface %s' "$i")" /sbin/ifup tnlcfg-$i boot | |
237 | done | |
238 | ||
239 | network_postinit | |
240 | ||
241 | touch /var/lock/subsys/network | |
cc311639 | 242 | emit --no-wait pld.network-started |
30a91466 | 243 | emit --no-wait started JOB=network |
6236caca ER |
244 | } |
245 | ||
246 | stop() { | |
fd814d46 | 247 | emit pld.network-stopping |
30a91466 | 248 | emit stopping JOB=network |
6236caca ER |
249 | # If we go to runlevel 0, 1 or 6 then umount all network fs |
250 | if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then | |
251 | if [ -x /etc/rc.d/init.d/netfs -a -f /var/lock/subsys/netfs ]; | |
252 | then | |
253 | /etc/rc.d/init.d/netfs stop | |
6236caca ER |
254 | fi |
255 | fi | |
256 | ||
257 | for i in $tunnels; do | |
258 | run_cmd -a "$(nls 'Shutting down tunnel interface %s' "$i")" /sbin/ifdown tnlcfg-$i boot | |
259 | run_cmd -a "$(nls 'Removing tunnel %s' "$i")" /sbin/tnldown $i boot | |
260 | done | |
261 | ||
9e90b313 JR |
262 | for i in $interfaces_virt_boot ; do |
263 | run_cmd -a "$(nls 'Shutting down virtual interface %s' "$i")" /sbin/ifup $i boot | |
264 | done | |
265 | ||
6236caca ER |
266 | for i in $interfaces_br_boot ; do |
267 | run_cmd -a "$(nls 'Shutting down bridge interface %s' "$i")" /sbin/ifdown $i boot | |
268 | done | |
269 | ||
270 | for i in $interfaces_sit_boot $interfaces_vlan_boot $interfaces_boot ; do | |
271 | run_cmd -a "$(nls 'Shutting down interface %s' "$i")" /sbin/ifdown $i boot | |
272 | done | |
273 | ||
274 | network_deinit | |
275 | ||
354b37ce | 276 | rm -f /var/lock/subsys/network >/dev/null 2>&1 |
cc311639 | 277 | emit --no-wait pld.network-stopped |
30a91466 | 278 | emit --no-wait stopped JOB=network |
6236caca ER |
279 | } |
280 | ||
5699545c ER |
281 | # Reload all active interfaces |
282 | reload() { | |
283 | if [ ! -f /var/lock/subsys/network ]; then | |
284 | msg_not_running network | |
285 | RETVAL=7 | |
286 | return | |
287 | fi | |
288 | ||
289 | set_dhcpclient | |
290 | ||
291 | # if no DHCP client found we can't reload anything | |
292 | if [ -z "$DHCP_CLIENT" ]; then | |
293 | return | |
294 | fi | |
295 | ||
296 | local DHCP_ARGS | |
297 | case ${DHCP_CLIENT##*/} in | |
298 | # pump) | |
89c22c0f | 299 | # DHCP_ARGS="" |
5699545c ER |
300 | # ;; |
301 | dhcpcd) | |
302 | DHCP_ARGS="-n" | |
303 | ;; | |
304 | # dhcpxd) | |
89c22c0f | 305 | # DHCP_ARGS="" |
5699545c ER |
306 | # ;; |
307 | # dhclient) | |
89c22c0f | 308 | # DHCP_ARGS="" |
5699545c ER |
309 | # ;; |
310 | *) | |
311 | echo "Reloading using $DHCP_CLIENT DHCP Client is not implmemented in rc-scripts" | |
312 | RETVAL=1 | |
313 | return | |
314 | ;; | |
315 | esac | |
316 | ||
317 | # for IPv4 DHCP interfaces send signal to refresh interface | |
7aed5793 | 318 | local dev devs=${*:-$(/sbin/ip link show | awk -F: '/UP/{print $2}')} |
5699545c ER |
319 | for dev in $devs; do |
320 | if [ ! -f /etc/sysconfig/interfaces/ifcfg-$dev ]; then | |
321 | continue | |
322 | fi | |
323 | . /etc/sysconfig/interfaces/ifcfg-$dev | |
324 | ||
325 | if [ -n "$BOOTPROTO" -a "$BOOTPROTO" != "none" -a "$BOOTPROTO" != "static" ] && is_yes "$IPV4_NETWORKING"; then | |
326 | case ${DHCP_CLIENT##*/} in | |
327 | pump) | |
328 | DHCP_ARGS="$DHCP_ARGS -i $DEVICE" | |
329 | ;; | |
330 | dhcpcd) | |
331 | DHCP_ARGS="$DHCP_ARGS $DEVICE" | |
332 | ;; | |
333 | dhcpxd) | |
334 | DHCP_ARGS="$DHCP_ARGS $DEVICE" | |
335 | ;; | |
336 | dhclient) | |
337 | DHCP_ARGS="$DHCP_ARGS $DEVICE" | |
338 | ;; | |
339 | esac | |
340 | DHCP_ARGS="$DHCP_OPTIONS $DHCP_ARGS" | |
341 | ||
342 | show 'Reloading interface %s' $dev | |
343 | if $DHCP_CLIENT $DHCP_ARGS; then | |
344 | ok | |
345 | else | |
346 | fail | |
347 | fi | |
348 | fi | |
349 | done | |
350 | ||
351 | } | |
352 | ||
f38190d4 | 353 | find_boot_interfaces |
12de71be | 354 | |
7742e157 AF |
355 | # See how we were called. |
356 | case "$1" in | |
357 | start) | |
2a7fa780 | 358 | if is_yes "$VSERVER_ISOLATION_NET"; then |
fd814d46 | 359 | emit pld.network-starting |
30a91466 | 360 | emit starting JOB=network |
f10dcc7c | 361 | touch /var/lock/subsys/network |
fd814d46 | 362 | emit pld.network-started |
30a91466 | 363 | emit --no-wait started JOB=network |
f10dcc7c ER |
364 | exit 0 |
365 | fi | |
a2372c5f TP |
366 | start |
367 | ;; | |
368 | start_init) | |
369 | network_init | |
370 | ;; | |
371 | start_postinit) | |
372 | network_postinit | |
373 | touch /var/lock/subsys/network | |
374 | ;; | |
375 | stop_deinit) | |
376 | network_deinit | |
377 | rm -f /var/lock/subsys/network | |
5e6dfc29 | 378 | ;; |
7742e157 | 379 | stop) |
2a7fa780 | 380 | if is_yes "$VSERVER_ISOLATION_NET"; then |
fd814d46 | 381 | emit pld.network-stopping |
30a91466 | 382 | emit stopping JOB=network |
354b37ce | 383 | rm -f /var/lock/subsys/network >/dev/null 2>&1 |
fd814d46 | 384 | emit pld.network-stopped |
30a91466 | 385 | emit --no-wait stopped JOB=network |
f10dcc7c ER |
386 | exit 0 |
387 | fi | |
6236caca | 388 | stop |
5e6dfc29 | 389 | ;; |
f10dcc7c | 390 | |
7742e157 | 391 | status) |
38198f50 | 392 | nls "Configured devices:" |
4ac87c24 | 393 | echo "lo $interfaces" |
38198f50 | 394 | nls "Configured tunnels:" |
4ac87c24 | 395 | echo "$tunnels" |
fa8aca70 JR |
396 | echo |
397 | nls "Currently inactive devices and tunnels:" | |
398 | /sbin/ip link show | awk -F":" '(/^[0-90-90-9]:/) && ! (/UP/) { print $2 }' | xargs | |
60df57e7 | 399 | nls "Currently active devices and tunnels:" |
8192b17e | 400 | /sbin/ip link show | awk -F":" ' (/UP/) { print $2 }' | xargs |
7742e157 | 401 | ;; |
f10dcc7c | 402 | |
5699545c | 403 | reload) |
2a7fa780 | 404 | if is_yes "$VSERVER_ISOLATION_NET"; then |
5699545c ER |
405 | exit 0 |
406 | fi | |
407 | shift | |
408 | reload ${1:+"$@"} | |
409 | ;; | |
410 | ||
7742e157 | 411 | restart) |
2a7fa780 | 412 | if is_yes "$VSERVER_ISOLATION_NET"; then |
f10dcc7c ER |
413 | exit 0 |
414 | fi | |
415 | ||
6236caca ER |
416 | stop |
417 | start | |
7742e157 | 418 | ;; |
f10dcc7c | 419 | |
7742e157 | 420 | *) |
5699545c | 421 | msg_usage "$0 {start|stop|reload|restart|status}" |
c632d197 | 422 | exit 3 |
7742e157 AF |
423 | esac |
424 | ||
425 | exit 0 |