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