]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/init.d/network
- fixed status reporting
[projects/rc-scripts.git] / rc.d / init.d / network
1 #!/bin/sh
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 # probe: true
9
10 # $Id: network,v 1.21 1999/09/13 13:25:02 misiek Exp $
11
12 # NLS
13 NLS_DOMAIN="rc-scripts"
14
15 # Source function library.
16 . /etc/rc.d/init.d/functions
17 . /etc/rc.d/init.d/functions.network
18
19 [ ! -f /etc/sysconfig/network ] && exit 0
20
21 . /etc/sysconfig/network
22
23 # Check that networking is up.
24 [ "${NETWORKING}" == "no" -o "${NETWORKING}" == "" ] && exit 0
25
26 [ -x /sbin/ip ] || exit 0
27
28 ######
29 # initialize networking:
30 # - check IPv4, IPv6, IPX can be handled by system
31 # - setup default IPv{4,6} interfaces policy like:
32 #   - forwarding,
33 #   - spoofig protection,
34 #   - icmp echo ignore broadcasts,
35 # - setup lo interface
36 network_init()
37 {
38 # Set UP loopback interface
39 set_up_loopback
40
41 # Modprobe needed devices
42 modprobe_net
43
44 # Spoofing protection
45 ipv4_anti_spoofing on
46
47 # IPv4 forwarding
48 proc_net ipv4/ip_forward start 1 0 IPV4_FORWARDING "IPv4 forwarding"
49
50 # IPv6 forwarding
51 proc_net ipv6/conf/all/forwarding start 1 0 IPV6_FORWARDING "IPv6 forwarding"
52
53 # Setup NAT rules
54 setup_nat on
55 }
56
57 network_postinit()
58 {
59 # Set static ARP table
60 static_arp
61
62 }
63
64 ######
65 # deinitialize networking
66 # - down lo interface.
67 network_deinit()
68 {
69 # Set down NAT rules
70 setup_nat off
71
72 # IPv6 forwarding
73 proc_net ipv6/conf/all/forwarding stop 1 0 IPV6_FORWARDING "IPv6 forwarding"
74
75 # IPv4 forwarding
76 proc_net ipv4/ip_forward stop 1 0 IPV4_FORWARDING "IPv4 forwarding"
77
78 # Spoofing protection
79 ipv4_anti_spoofing off
80
81 # Set DOWN loopback interface
82 set_down_loopback
83 }
84
85 # find all the interfaces besides loopback.
86 # ignore aliases, alternative configurations, and editor backup files
87 interfaces="`(cd /etc/sysconfig/interfaces && ls ifcfg* | \
88 egrep -v '(ifcfg-lo|:)' | egrep 'ifcfg-[a-z0-9]+$' | sed 's/^ifcfg-//g' | xargs)`"
89 interfaces_boot="`(cd /etc/sysconfig/interfaces && ls ifcfg* | \
90 egrep -v '(ifcfg-lo|ifcfg-sit|:)' | egrep 'ifcfg-[a-z0-9]+$' | \
91 xargs egrep -l "ONBOOT=[^n][^o]" | sed 's/^ifcfg-//g')`"
92 interfaces_sit_boot="`(cd /etc/sysconfig/interfaces && ls ifcfg-sit* | \
93 egrep 'ifcfg-[a-z0-9]+$' | xargs egrep -l "ONBOOT=[^n][^o]" | sed 's/^ifcfg-//g')`"
94 tunnels="`(cd /etc/sysconfig/interfaces && ls -1 tnlcfg-* | \
95 xargs egrep -l "ONBOOT=[^n][^o]" | sed 's/^tnlcfg-//g')`"
96
97 # See how we were called.
98 case "$1" in
99   start)
100         network_init
101         for i in $interfaces_boot $interfaces_sit_boot; do
102                 /sbin/ifup $i boot
103         done
104
105         for i in $tunnels; do
106                 /sbin/tnlup $i boot
107                 /sbin/ifup tnlcfg-$i boot
108         done
109         
110         network_postinit
111
112         touch /var/lock/subsys/network
113         ;;
114   stop)
115         for i in $tunnels; do
116                 /sbin/ifdown tnlcfg-$i boot
117                 /sbin/tnldown $i boot
118         done
119
120         for i in $interfaces_sit_boot $interfaces_boot; do
121                 /sbin/ifdown $i boot
122         done
123
124         network_deinit
125         rm -f /var/lock/subsys/network
126         ;;
127   status)
128         nls "Configured devices:"
129         echo "lo $interfaces"
130         nls "Configured tunnels:"
131         echo "$tunnels"
132
133         nls "Currently active devices and tunnels:"
134         /sbin/ip link show | egrep '^[^ ].*' |sed 's/[0-9]*: \(.*\):.*/\1/'|xargs
135         ;;
136   restart)
137         $0 stop
138         $0 start
139         ;;
140   *)
141         echo "Usage: $0 {start|stop|restart|status}"
142         exit 1
143 esac
144
145 exit 0
This page took 0.05087 seconds and 4 git commands to generate.