]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/init.d/network
- fixed CIFS unmounting
[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 #
9 # probe:        true
10
11 # $Id$
12
13 PATH=/sbin:/usr/sbin:/bin:/usr/bin
14
15 # NLS
16 NLS_DOMAIN="rc-scripts"
17
18 # Source function library.
19 . /etc/rc.d/init.d/functions
20 . /etc/sysconfig/network-scripts/functions.network
21
22 if [ ! -f /etc/sysconfig/network ]; then
23         nls "%s is missing. Can't continue." "/etc/sysconfig/network"
24         exit 1
25 fi
26
27 . /etc/sysconfig/network
28
29 # Check that networking is up.
30 is_no "${NETWORKING}" && exit 0
31
32 # Will be removed in the future
33 if is_yes "$NETWORKING" ; then
34         if [ -z "$IPV4_NETWORKING" ] ; then
35                 echo "NETWORKING is set to YES, but IPV4_NETWORKING is empty!"
36                 echo "Please upgrade your config"
37                 echo "Assuming you want IPv4 networking"
38                 IPV4_NETWORKING=yes
39         fi
40 fi
41
42 if [ ! -x /sbin/ip ]; then
43         nls "%s is missing. Can't continue." "/sbin/ip"
44         exit 1
45 fi
46
47 ######
48 # initialize networking:
49 # - check IPv4, IPv6, IPX can be handled by system
50 # - setup default IPv{4,6} interfaces policy like:
51 #   - spoofig protection,
52 #   - icmp echo ignore broadcasts,
53 # - setup lo interface
54 network_init()
55 {
56 # Modprobe needed devices
57 modprobe_net
58
59 # Setup interfaces names
60 [ -x /sbin/nameif -a -f /etc/mactab ] && run_cmd "Setting interfaces names (nameif)" /sbin/nameif
61
62 # Kernel network parameters
63 sysctl -e -p /etc/sysctl.conf > /dev/null 2>&1
64
65 # Set UP loopback interface
66 set_up_loopback
67
68 # Setup configuration
69 setup_nat on
70 setup_routes on
71 setup_ip_rules on
72 # Setup IPX
73 if is_yes "$IPX"; then
74         if [ -n $IPXAUTOPRIMARY ] ; then
75                 if is_yes "$IPXAUTOPRIMARY"; then
76                         IPXAUTOPRIMARY="on"
77                 else
78                         IPXAUTOPRIMARY="off"
79                 fi
80                 /sbin/ipx_configure --auto_primary=$IPXAUTOPRIMARY
81         fi
82         if [ -n $IPXAUTOFRAME ] ; then
83                 if is_yes "$IPXAUTOFRAME"; then
84                         IPXAUTOFRAME="on"
85                 else
86                         IPXAUTOFRAME="off"
87                 fi
88                 /sbin/ipx_configure --auto_interface=$IPXAUTOFRAME
89         fi
90         if [ -n "$IPXINTERNALNETNUM" -a "$IPXINTERNALNETNUM" != "0" ]; then
91                 /sbin/ipx_internal_net add $IPXINTERNALNETNUM $IPXINTERNALNODENUM
92         fi
93 fi
94 }
95
96 network_postinit()
97 {
98 # Set static RARP table
99 static_rarp
100
101 # Set static ARP table
102 static_arp
103 }
104
105 ######
106 # deinitialize networking
107 # - down lo interface.
108 network_deinit()
109 {
110 setup_routes off
111 setup_ip_rules off
112
113 # Set down NAT rules
114 setup_nat off
115 # Set DOWN loopback interface
116 set_down_loopback
117 }
118
119 # find all the interfaces besides loopback.
120 # ignore aliases, alternative configurations, and editor backup files
121 if [ -n "$(grep "^BOOTPRIO=" /etc/sysconfig/interfaces/ifcfg* 2> /dev/null)" ]; then
122         interfaces_boot=$(( \
123                 . /etc/rc.d/init.d/functions; \
124                 cd /etc/sysconfig/interfaces; \
125                 egrep 'BOOTPRIO' ifcfg* | sort -t= -n -k2,2 | \
126                 awk ' { gsub(/:BOOTPRIO.*/,NIL); print $0 } '| egrep -v 'ifcfg-lo' | \
127                 for i in `cat`; do \
128                     ONBOOT=""; . /etc/sysconfig/interfaces/"$i"; is_yes "$ONBOOT" &&
129                     echo "$i"; \
130                 done | \
131                 awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
132 else
133         interfaces_boot=$((
134                 . /etc/rc.d/init.d/functions; \
135                 cd /etc/sysconfig/interfaces && ls -1 ifcfg* | \
136                 egrep -v '(ifcfg-lo|ifcfg-sit|ifcfg-atm|ifcfg-lec|ifcfg-nas|ifcfg-br|ifcfg-(.*)\.(.*))' | \
137                 LC_ALL=C egrep 'ifcfg-[a-z0-9\.]+$' | \
138                 for i in `cat`; do \
139                     ONBOOT=""; . /etc/sysconfig/interfaces/"$i"; is_yes "$ONBOOT" && echo "$i"; \
140                 done | \
141                 awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
142         interfaces_vlan_boot=$((
143                 . /etc/rc.d/init.d/functions; \
144                 cd /etc/sysconfig/interfaces && ls -1 ifcfg* | \
145                 egrep 'ifcfg-(.*)\.(.*)' | \
146                 LC_ALL=C egrep 'ifcfg-[a-z0-9\.]+$' | \
147                 for i in `cat`; do \
148                     ONBOOT=""; . /etc/sysconfig/interfaces/"$i"; is_yes "$ONBOOT" && echo "$i"; \
149                 done | \
150                 awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
151         interfaces_br_boot=$((
152                 . /etc/rc.d/init.d/functions; \
153                 cd /etc/sysconfig/interfaces && ls -1 ifcfg-br* | \
154                 LC_ALL=C egrep 'ifcfg-[a-z0-9\.]+$' | \
155                 for i in `cat`; do \
156                     ONBOOT=""; . /etc/sysconfig/interfaces/"$i"; is_yes "$ONBOOT" && echo "$i"; \
157                 done | \
158                 awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
159         interfaces_sit_boot=$((
160                 . /etc/rc.d/init.d/functions; \
161                 cd /etc/sysconfig/interfaces && ls -1 ifcfg-sit* | \
162                 LC_ALL=C egrep 'ifcfg-[a-z0-9]+$' | \
163                 for i in `cat`; do \
164                     ONBOOT=""; . /etc/sysconfig/interfaces/"$i"; is_yes "$ONBOOT" && echo "$i"; \
165                 done | \
166                 awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
167 fi
168 tunnels=$((cd /etc/sysconfig/interfaces && ls -1 tnlcfg-* | \
169         xargs egrep -l "ONBOOT=[^n][^o]" | \
170         LC_ALL=C egrep 'tnlcfg-[a-z0-9]+$' | \
171         awk ' { gsub(/tnlcfg-/,NIL); print $0 } ') 2> /dev/null)
172
173 # See how we were called.
174 case "$1" in
175   start)
176         rc_splash "bootnetwork start"
177
178         network_init
179
180         for i in $interfaces_boot $interfaces_vlan_boot $interfaces_sit_boot ; do
181                 run_cmd -a "$(nls 'Bringing up interface %s' "$i")" /sbin/ifup $i boot
182         done
183         
184         for i in $interfaces_br_boot ; do
185                 run_cmd -a "$(nls 'Bringing up bridge interface %s' "$i")" /sbin/ifup $i boot
186         done
187
188         for i in $tunnels; do
189                 run_cmd -a "$(nls 'Setting tunnel %s' "$i")" /sbin/tnlup $i boot
190                 run_cmd -a "$(nls 'Bringing up tunnel interface %s' "$i")" /sbin/ifup tnlcfg-$i boot
191         done
192
193         network_postinit
194
195         touch /var/lock/subsys/network
196         ;;
197   stop)
198         # If we go to runlevel 0, 1 or 6 then umount all network fs
199         if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
200                 if [ -x /etc/rc.d/init.d/netfs -a -f /var/lock/subsys/netfs ];
201                 then
202                         /etc/rc.d/init.d/netfs stop
203                 else
204                         netmtab=$(awk '{ if ($3 ~ /^(nfs|smbfs|ncpfs|cifs)$/ ) print $3}' /proc/mounts)
205                         if (echo "$netmtab" | grep -q nfs); then
206                            run_cmd "Unmounting NFS filesystems" umount -fat nfs
207                         fi
208                         if (echo "$netmtab" | grep -q smbfs); then
209                            run_cmd "Unmounting SMB filesystems" umount -at smbfs
210                         fi
211                         if (echo "$netmtab" | grep -q ncpfs); then
212                            run_cmd "Unmounting NCP filesystems" umount -at ncpfs
213                         fi
214                         if (echo "$netmtab" | grep -q cifs); then
215                            run_cmd "Unmounting CIFS filesystems" umount -at cifs
216                         fi
217                 fi
218         fi
219
220         for i in $tunnels; do
221                 run_cmd -a "$(nls 'Shutting down tunnel interface %s' "$i")" /sbin/ifdown tnlcfg-$i boot
222                 run_cmd -a "$(nls 'Removing tunnel %s' "$i")" /sbin/tnldown $i boot
223         done
224
225         for i in $interfaces_br_boot ; do
226                 run_cmd -a "$(nls 'Shutting down bridge interface %s' "$i")" /sbin/ifdown $i boot
227         done
228
229         for i in $interfaces_sit_boot $interfaces_vlan_boot $interfaces_boot ; do
230                 run_cmd -a "$(nls 'Shutting down interface %s' "$i")" /sbin/ifdown $i boot
231         done
232
233         network_deinit
234
235         rm -f /var/lock/subsys/network
236         ;;
237   status)
238         nls "Configured devices:"
239         echo "lo $interfaces"
240         nls "Configured tunnels:"
241         echo "$tunnels"
242         echo
243         nls "Currently inactive devices and tunnels:"
244         /sbin/ip link show | awk -F":" '(/^[0-90-90-9]:/) && ! (/UP/) { print $2 }' | xargs
245         nls "Currently active devices and tunnels:"
246         /sbin/ip link show | awk -F":" ' (/UP/) { print $2 }' | xargs
247         ;;
248   restart)
249         $0 stop
250         $0 start
251         ;;
252   *)
253         echo "Usage: $0 {start|stop|restart|status}"
254         exit 1
255 esac
256
257 exit 0
258
259 # This must be last line !
260 # vi:syntax=sh:tw=78:ts=8:sw=4
This page took 0.057234 seconds and 3 git commands to generate.