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