]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/init.d/network
- policy routing support
[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.53 2002/03/29 08:45:14 wojrus 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_ip_rules 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                 /sbin/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                 /sbin/ipx_configure --auto_interface=$IPXAUTOFRAME
88         fi
89         if [ -n "$IPXINTERNALNETNUM" -a "$IPXINTERNALNETNUM" != "0" ]; then
90                 /sbin/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 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 interfaces=$((cd /etc/sysconfig/interfaces && ls -1 ifcfg* | \
122         egrep -v '(ifcfg-lo|:)' | egrep 'ifcfg-[a-z0-9]+$' | \
123         awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
124 interfaces_boot=$((cd /etc/sysconfig/interfaces && ls -1 ifcfg* | \
125         egrep -v '(ifcfg-lo|ifcfg-sit|ifcfg-atm|ifcfg-lec|ifcfg-nas|:)' | egrep 'ifcfg-[a-z0-9\.]+$' | \
126         xargs egrep -l "ONBOOT=[^n][^o]" | \
127         awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
128 interfaces_sit_boot=$((cd /etc/sysconfig/interfaces && ls -1 ifcfg-sit* | \
129         egrep 'ifcfg-[a-z0-9]+$' | xargs egrep -l "ONBOOT=[^n][^o]" | \
130         awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
131 tunnels=$((cd /etc/sysconfig/interfaces && ls -1 tnlcfg-* | \
132         xargs egrep -l "ONBOOT=[^n][^o]" | \
133         awk ' { gsub(/tnlcfg-/,NIL); print $0 } ') 2> /dev/null)
134
135 # See how we were called.
136 case "$1" in
137   start)
138         network_init
139
140         for i in $interfaces_boot $interfaces_sit_boot ; do
141                 run_cmd -a "$(nls 'Bringing up interface') $i" /sbin/ifup $i boot
142         done
143
144         for i in $(find_ldap_interfaces) ; do
145                 run_cmd -a "$(nls 'Bringing up interface from LDAP') $i" /sbin/ifup $i boot
146         done
147
148         for i in $tunnels; do
149                 run_cmd -a "$(nls 'Setting tunnel') $i" /sbin/tnlup $i boot
150                 run_cmd -a "$(nls 'Bringing up tunnel interface') $i" /sbin/ifup tnlcfg-$i boot
151         done
152         
153         network_postinit
154
155         touch /var/lock/subsys/network
156         ;;
157   stop)
158         # If we go to runlevel 0, 1 or 6 then umount all network fs
159         if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
160                 if [ -x /etc/rc.d/init.d/netfs -a -f /var/lock/subsys/netfs ];
161                 then
162                         /etc/rc.d/init.d/netfs stop
163                 else
164                         netmtab=$(awk '{ if ($3 ~ /^(nfs|smbfs|ncpfs)$/ ) print $3}' /proc/mounts)
165                         if (echo "$netmtab" | grep -q nfs); then
166                            run_cmd "Unmounting NFS filesystems" umount -fat nfs
167                         fi
168                         if (echo "$netmtab" | grep -q smbfs); then
169                            run_cmd "Unmounting SMB filesystems" umount -at smbfs
170                         fi
171                         if (echo "$netmtab" | grep -q ncpfs); then
172                            run_cmd "Unmounting NCP filesystems" umount -at ncpfs
173                         fi
174                 fi
175         fi
176
177         for i in $tunnels; do
178                 run_cmd -a "$(nls 'Shutting down tunnel interface') $i" /sbin/ifdown tnlcfg-$i boot
179                 run_cmd -a "$(nls 'Removing tunnel') $i" /sbin/tnldown $i boot
180         done
181
182         for i in $(find_ldap_interfaces) ; do
183                 run_cmd -a "$(nls 'Shutting down interface from LDAP') $i" /sbin/ifdown $i boot
184         done
185
186         for i in $interfaces_sit_boot $interfaces_boot ; do
187                 run_cmd -a "$(nls 'Shutting down interface') $i" /sbin/ifdown $i boot
188         done
189
190         network_deinit
191
192         rm -f /var/lock/subsys/network
193         ;;
194   status)
195         nls "Configured devices:"
196         echo "lo $interfaces"
197         nls "Configured tunnels:"
198         echo "$tunnels"
199         echo
200         nls "Currently inactive devices and tunnels:"
201         /sbin/ip link show | awk -F":" '(/^[0-90-90-9]:/) && ! (/UP/) { print $2 }' | xargs
202         nls "Currently active devices and tunnels:"
203         /sbin/ip link show | awk -F":" ' (/UP/) { print $2 }' | xargs
204         ;;
205   restart)
206         $0 stop
207         $0 start
208         ;;
209   *)
210         echo "Usage: $0 {start|stop|restart|status}"
211         exit 1
212 esac
213
214 exit 0
215
216 # This must be last line !
217 # vi:syntax=sh:tw=78:ts=8:sw=4
This page took 0.125325 seconds and 4 git commands to generate.