]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/init.d/network
Initial revision
[projects/rc-scripts.git] / rc.d / init.d / network
1 #!/bin/bash
2 #
3 # network       Bring up/down networking
4 #
5 # chkconfig: 345 10 97
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 # Check that networking is up.
28 [ ${NETWORKING} = "no" ] && exit 0
29
30 [ -x /sbin/ifconfig ] || exit 0
31
32 # Load IPv6 module
33
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
75                     ok
76                 fi
77             fi
78         fi
79 }
80
81 ipv4_spoof_protection ()
82 {
83 # This is the best method: turn on Source Address Verification and get
84 # spoof protection on all current and future interfaces.
85 if [ -e /proc/sys/net/ipv4/conf/all/rp_filter ]; then
86   show Setting up IP spoofing protection
87   busy
88   for f in /proc/sys/net/ipv4/conf/*/rp_filter; do
89       echo 1 > $f
90   done
91   deltext
92   ok
93   else
94   deltext
95   fail
96   echo "PROBLEMS SETTING UP IP SPOOFING PROTECTION.  BE WORRIED!"
97 fi
98 }
99
100 # See how we were called.
101 case "$1" in
102   start)
103         ipv4_forward_set
104
105         ./ifup ifcfg-lo
106
107         case "$IPX" in
108           yes|true)
109             /usr/bin/ipx_configure --auto_primary=$IPXAUTOPRIMARY \
110                                    --auto_interface=$IPXAUTOFRAME
111             /usr/bin/ipx_internal_net add $IPXINTERNALNETNUM $IPXINTERNALNODENUM
112             ;;
113         esac
114
115         for i in $interfaces; do
116                 ./ifup $i boot
117         done
118
119         ipv4_spoof_protection
120
121         touch /var/lock/subsys/network
122         ;;
123   stop)
124         for i in $interfaces; do
125                 ./ifdown $i boot
126         done
127         case "$IPX" in
128           yes|true)
129             /usr/bin/ipx_internal_net del
130             ;;
131         esac
132         ./ifdown ifcfg-lo
133         echo "Disabling IPv4 packet forwarding."
134         echo 0 > /proc/sys/net/ipv4/ip_forward
135         rm -f /var/lock/subsys/network
136         ;;
137   status)
138         echo "Configured devices:"
139         echo lo $interfaces
140
141         if [ -x /bin/linuxconf ] ; then
142                 eval `/bin/linuxconf --hint netdev`
143                 echo "Devices that are down:"
144                 echo $DEV_UP
145                 echo "Devices with modified configuration:"
146                 echo $DEV_RECONF
147         else
148                 echo "Currently active devices:"
149                 echo `/sbin/ifconfig | grep ^[a-z] | awk '{print $1}'`
150         fi
151         ;;
152   restart)
153         $0 stop
154         $0 start
155         ;;
156   reload)
157         if [ -x /bin/linuxconf ] ; then
158                 eval `/bin/linuxconf --hint netdev`
159                 if [ "$RECONF_IPV4ROUTING" = "yes" ] ; then
160                         ipv4_forward_set
161                 fi
162                 for device in $DEV_UP ; do
163                         ./ifup $device
164                 done
165                 for device in $DEV_DOWN ; do
166                         ./ifdown $device
167                 done
168                 for device in $DEV_RECONF ; do
169                         ./ifdown $device
170                         ./ifup $device
171                 done
172                 for device in $DEV_RECONF_ALIASES ; do
173                         /etc/sysconfig/network-scripts/ifup-aliases $device
174                 done
175                 for device in $DEV_RECONF_ROUTES ; do
176                         /etc/sysconfig/network-scripts/ifup-routes $device
177                 done
178                 case $IPX in yes|true)
179                   case $IPXINTERNALNET in
180                     reconf)
181                         /usr/bin/ipx_internal_net del
182                         /usr/bin/ipx_internal_net add $IPXINTERNALNETNUM \
183                                                       $IPXINTERNALNODENUM
184                         ;;
185                     add)
186                         /usr/bin/ipx_internal_net add $IPXINTERNALNETNUM \
187                                                       $IPXINTERNALNODENUM
188                         ;;
189                     del)
190                         /usr/bin/ipx_internal_net del
191                         ;;
192                   esac
193                   ;;
194                 esac
195         else
196                 $0 restart
197         fi
198         ;;
199   probe)
200         if [ -x /bin/linuxconf ] ; then
201                 eval `/bin/linuxconf --hint netdev`
202                 [ -n "$DEV_UP$DEV_DOWN$DEV_RECONF$DEV_RECONF_ALIASES" -o \
203                   -n "$DEV_RECONF_ROUTES$IPXINTERNALNET" -o \
204                   "$RECONF_IPV4ROUTING" = yes ] && \
205                         echo reload
206                 exit 0
207         else
208                 # if linuxconf isn't around to figure stuff out for us,
209                 # we punt.  Probably better than completely reloading
210                 # networking if user isn't sure which to do.  If user
211                 # is sure, they would run restart or reload, not probe.
212                 exit 0
213         fi
214         ;;
215   *)
216         echo "Usage: network {start|stop|restart|reload|status|probe}"
217         exit 1
218 esac
219
220 exit 0
This page took 0.095371 seconds and 4 git commands to generate.