]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/init.d/network
Synced with rc-scripts-0.0.1 from old repo.
[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 # Source function library.
11 . /etc/rc.d/init.d/functions
12
13 if [ ! -f /etc/sysconfig/network ]; then
14     exit 0
15 fi
16
17 . /etc/sysconfig/network
18
19 if [ -f /etc/sysconfig/pcmcia ]; then
20         . /etc/sysconfig/pcmcia
21 fi
22
23 if [ -f /etc/sysconfig/network-ip6 ]; then
24        . /etc/sysconfig/network-ip6
25 fi
26
27
28 # Check that networking is up.
29 [ "${NETWORKING}" = "no" ] && exit 0
30
31 [ -x /sbin/ifconfig ] || exit 0
32
33 # Load IPv6 module
34 if [ "${IP6NETWORKING}" = "yes" ]; then
35        if [ -r /lib/modules/`uname -r`/ipv6/ipv6.o ]; then
36        /sbin/modprobe net-pf-10
37        fi
38 fi
39
40 # Even if IPX is configured, without the utilities we can't do much
41 [ ! -x /usr/bin/ipx_internal_net -o ! -x /usr/bin/ipx_configure ] && IPX=
42
43 cd /etc/sysconfig/network-scripts
44
45 # find all the interfaces besides loopback.
46 # ignore aliases, alternative configurations, and editor backup files
47 interfaces=`ls ifcfg* | egrep -v '(ifcfg-lo|:)' | egrep 'ifcfg-[a-z0-9]+$' | \
48             sed 's/^ifcfg-//g'`
49
50 ipv4_forward_set ()
51 {
52         # Turn IP forwarding on or off. We do this before bringing up the
53         # interfaces to make sure we don't forward when we shouldn't, and
54         # we do it even if networking isn't configured (why not?).
55         if [ -d /proc/sys/net/ipv4 ]; then
56             # people could have left this out of their kernel, which isn't
57             # exactly an error
58             if [ ! -f /proc/sys/net/ipv4/ip_forward ] ; then
59                 echo "/proc/sys/net/ipv4/ip_forward is missing --" \
60                         "cannot control IP forwarding" >&2
61             else
62                 if [ "$FORWARD_IPV4" = "no" -o "$FORWARD_IPV4" = "false" ]; then
63                     value=0
64                     message="Disabling IPv4 packet forwarding: "
65                 else
66                     value=1
67                     message="Enabling IPv4 packet forwarding :"
68                 fi
69
70                 if [ $value != `cat /proc/sys/net/ipv4/ip_forward` ]; then
71                     show $message
72                     busy
73                     echo "$value" > /proc/sys/net/ipv4/ip_forward
74                     deltext; ok
75                 fi
76             fi
77         fi
78 }
79
80 ipv4_spoofing_protection ()
81  {
82         if [ -d /proc/sys/net/ipv4 ]; then
83             # people could have left this out of their kernel, which isn't
84             # exactly an error
85             if [ ! -f /proc/sys/net/ipv4/conf/all/rp_filter ] ; then
86                 echo "/proc/sys/net/ipv4/conf/all/rp_filter is missing --" \
87                         "cannot control IP spoofing protection" >&2
88             else
89                if [ "$SPOOFING_IPV4" = "no" -o "$SPOOFING_IPV4" = "false" ]; then
90                     value=0
91                     message="Disabling IPv4 spoofing protection: "
92                 else
93                     value=1
94                     message="Enabling IPv4 spoofing protection: "
95                 fi
96
97                 if [ $value != `cat /proc/sys/net/ipv4/conf/all/rp_filter` ]; then
98                     show $message
99                     busy
100                    for f in /proc/sys/net/ipv4/conf/*/rp_filter; do
101                         echo $value > $f
102                    done
103                     deltext
104                     ok
105                 fi
106             fi
107        fi
108 }
109
110 ipv4_icmp_echo_ignore_broadcasts ()
111 {
112         if [ -d /proc/sys/net/ipv4 ]; then
113             # people could have left this out of their kernel, which isn't
114             # exactly an error
115             if [ ! -f /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts ] ; then
116                 echo "/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts is missing --" \
117                         "cannot control IP ignoring icmp to broadcasts" >&2
118             else
119                 if [ "$IGNORE_ICMP_BCAST_IPV4" = "no" -o "$IGNORE_ICMP_BCAST_IPV4" = "false" ]; then
120                     value=0
121                     message="Disabling IPv4 ign icmp_echo to our bcasts: "
122                 else
123                     value=1
124                     message="Enabling IPv4 ign icmp_echo to our bcasts: "
125                 fi
126
127                 if [ $value != `cat /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts` ]; then
128                     show $message
129                     busy
130                     echo "$value" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
131                     deltext
132                     ok
133                 fi
134             fi
135        fi
136  }
137
138 # See how we were called.
139 case "$1" in
140   start)
141         ipv4_forward_set
142         ipv4_icmp_echo_ignore_broadcasts
143
144         ./ifup ifcfg-lo
145
146         case "$IPX" in
147           yes|true)
148             /usr/bin/ipx_configure --auto_primary=$IPXAUTOPRIMARY \
149                                    --auto_interface=$IPXAUTOFRAME
150             /usr/bin/ipx_internal_net add $IPXINTERNALNETNUM $IPXINTERNALNODENUM
151             ;;
152         esac
153
154         for i in $interfaces; do
155                 ./ifup $i boot
156         done
157
158         ipv4_spoofing_protection
159
160         touch /var/lock/subsys/network
161         ;;
162   stop)
163         SPOOFING_IPV4=no
164         ipv4_spoofing_protection
165
166         for i in $interfaces; do
167                 ./ifdown $i boot
168         done
169         case "$IPX" in
170           yes|true)
171             /usr/bin/ipx_internal_net del
172             ;;
173         esac
174         ./ifdown ifcfg-lo
175         show "Disabling IPv4 packet forwarding: "
176         busy
177         echo 0 > /proc/sys/net/ipv4/ip_forward
178         deltext; ok
179
180         IGNORE_ICMP_BCAST_IPV4=no
181         ipv4_icmp_echo_ignore_broadcasts
182
183         rm -f /var/lock/subsys/network
184         ;;
185   status)
186         echo "Configured devices:"
187         echo lo $interfaces
188
189         echo "Currently active devices:"
190         echo `/sbin/ifconfig | grep ^[a-z] | awk '{print $1}'`
191         ;;
192   restart)
193         $0 stop
194         $0 start
195         ;;
196   *)
197         echo "Usage: network {start|stop|restart|status}"
198         exit 1
199 esac
200
201 exit 0
This page took 0.055401 seconds and 4 git commands to generate.