]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/init.d/network
- added support for sysconfig/masquerade (NEW)
[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: network,v 1.50 2002/02/02 17:13:01 adasi Exp $
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
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 #   - forwarding,
52 #   - spoofig protection,
53 #   - icmp echo ignore broadcasts,
54 # - setup lo interface
55 network_init()
56 {
57 # Modprobe needed devices
58 modprobe_net
59
60 # Kernel network parameters
61 run_cmd "Setting network parameters" sysctl -p /etc/sysctl.conf
62
63 # Set UP loopback interface
64 set_up_loopback
65
66 # Setup configuration
67 setup_forwarding on
68 setup_nat on
69 setup_routes on
70 setup_masq on
71 # Setup IPX
72 if is_yes "$IPX"; then
73         if [ -n $IPXAUTOPRIMARY ] ; then
74                 if is_yes "$IPXAUTOPRIMARY"; then
75                         IPXAUTOPRIMARY="on"
76                 else
77                         IPXAUTOPRIMARY="off"
78                 fi
79                 /usr/bin/ipx_configure --auto_primary=$IPXAUTOPRIMARY
80         fi
81         if [ -n $IPXAUTOFRAME ] ; then
82                 if is_yes "$IPXAUTOFRAME"; then
83                         IPXAUTOFRAME="on"
84                 else
85                         IPXAUTOFRAME="off"
86                 fi
87                 /usr/bin/ipx_configure --auto_interface=$IPXAUTOFRAME
88         fi
89         if [ -n "$IPXINTERNALNETNUM" -a "$IPXINTERNALNETNUM" != "0" ]; then
90                 /usr/bin/ipx_internal_net add $IPXINTERNALNETNUM $IPXINTERNALNODENUM
91         fi
92 fi
93 }
94
95 network_postinit()
96 {
97 # Set static RARP table
98 static_rarp
99
100 # Set static ARP table
101 static_arp
102 }
103
104 ######
105 # deinitialize networking
106 # - down lo interface.
107 network_deinit()
108 {
109 setup_forwarding off
110 setup_routes off
111
112 # Set down NAT rules
113 setup_nat off
114 # Set down masquerade rules
115 setup_masq off
116 # Set DOWN loopback interface
117 set_down_loopback
118 }
119
120 # find all the interfaces besides loopback.
121 # ignore aliases, alternative configurations, and editor backup files
122 interfaces=$((cd /etc/sysconfig/interfaces && ls -1 ifcfg* | \
123         egrep -v '(ifcfg-lo|:)' | egrep 'ifcfg-[a-z0-9]+$' | \
124         awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
125 interfaces_boot=$((cd /etc/sysconfig/interfaces && ls -1 ifcfg* | \
126         egrep -v '(ifcfg-lo|ifcfg-sit|ifcfg-atm|ifcfg-lec|ifcfg-nas|:)' | egrep 'ifcfg-[a-z0-9\.]+$' | \
127         xargs egrep -l "ONBOOT=[^n][^o]" | \
128         awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
129 interfaces_sit_boot=$((cd /etc/sysconfig/interfaces && ls -1 ifcfg-sit* | \
130         egrep 'ifcfg-[a-z0-9]+$' | xargs egrep -l "ONBOOT=[^n][^o]" | \
131         awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
132 tunnels=$((cd /etc/sysconfig/interfaces && ls -1 tnlcfg-* | \
133         xargs egrep -l "ONBOOT=[^n][^o]" | \
134         awk ' { gsub(/tnlcfg-/,NIL); print $0 } ') 2> /dev/null)
135
136 # See how we were called.
137 case "$1" in
138   start)
139         network_init
140
141         for i in $interfaces_boot $interfaces_sit_boot ; do
142                 run_cmd -a "$(nls 'Bringing up interface') $i" /sbin/ifup $i boot
143         done
144
145         for i in $(find_ldap_interfaces) ; do
146                 run_cmd -a "$(nls 'Bringing up interface from LDAP') $i" /sbin/ifup $i boot
147         done
148
149         for i in $tunnels; do
150                 run_cmd -a "$(nls 'Setting tunnel') $i" /sbin/tnlup $i boot
151                 run_cmd -a "$(nls 'Bringing up tunnel interface') $i" /sbin/ifup tnlcfg-$i boot
152         done
153         
154         network_postinit
155
156         touch /var/lock/subsys/network
157         ;;
158   stop)
159         # If we go to runlevel 0, 1 or 6 then umount all network fs
160         if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
161                 if [ -x /etc/rc.d/init.d/netfs -a -f /var/lock/subsys/netfs ];
162                 then
163                         /etc/rc.d/init.d/netfs stop
164                 else
165                         netmtab=$(awk '{ if ($3 ~ /^(nfs|smbfs|ncpfs)$/ ) print $3}' /proc/mounts)
166                         if (echo "$netmtab" | grep -q nfs); then
167                            run_cmd "Unmounting NFS filesystems" umount -fat nfs
168                         fi
169                         if (echo "$netmtab" | grep -q smbfs); then
170                            run_cmd "Unmounting SMB filesystems" umount -at smbfs
171                         fi
172                         if (echo "$netmtab" | grep -q ncpfs); then
173                            run_cmd "Unmounting NCP filesystems" umount -at ncpfs
174                         fi
175                 fi
176         fi
177
178         for i in $tunnels; do
179                 run_cmd -a "$(nls 'Shutting down tunnel interface') $i" /sbin/ifdown tnlcfg-$i boot
180                 run_cmd -a "$(nls 'Removing tunnel') $i" /sbin/tnldown $i boot
181         done
182
183         for i in $(find_ldap_interfaces) ; do
184                 run_cmd -a "$(nls 'Shutting down interface from LDAP') $i" /sbin/ifdown $i boot
185         done
186
187         for i in $interfaces_sit_boot $interfaces_boot ; do
188                 run_cmd -a "$(nls 'Shutting down interface') $i" /sbin/ifdown $i boot
189         done
190
191         network_deinit
192
193         rm -f /var/lock/subsys/network
194         ;;
195   status)
196         nls "Configured devices:"
197         echo "lo $interfaces"
198         nls "Configured tunnels:"
199         echo "$tunnels"
200         echo
201         nls "Currently inactive devices and tunnels:"
202         /sbin/ip link show | awk -F":" '(/^[0-90-90-9]:/) && ! (/UP/) { print $2 }' | xargs
203         nls "Currently active devices and tunnels:"
204         /sbin/ip link show | awk -F":" ' (/UP/) { print $2 }' | xargs
205         ;;
206   restart)
207         $0 stop
208         $0 start
209         ;;
210   *)
211         echo "Usage: $0 {start|stop|restart|status}"
212         exit 1
213 esac
214
215 exit 0
216
217 # This must be last line !
218 # vi:syntax=sh:tw=78:ts=8:sw=4
This page took 0.040928 seconds and 4 git commands to generate.