]> git.pld-linux.org Git - projects/rc-scripts.git/blame - rc.d/init.d/network
- merge from TOTALNEW branch (see NEWS for more info)
[projects/rc-scripts.git] / rc.d / init.d / network
CommitLineData
12de71be 1#!/bin/sh
7742e157 2#
8d86e6df 3# network Bring up/down networking
7742e157 4#
458f14b7
AM
5# chkconfig: 2345 10 90
6# description: Activates/Deactivates all network interfaces configured to \
8d86e6df 7# start at boot time.
458f14b7 8#
8d86e6df 9# probe: true
7742e157 10
de1fc6ce
JR
11# $Id: network,v 1.44 2001/05/15 16:03:38 baggins Exp $
12
13PATH=/sbin:/usr/sbin:/bin:/usr/bin
38198f50
AM
14
15# NLS
16NLS_DOMAIN="rc-scripts"
17
7742e157
AF
18# Source function library.
19. /etc/rc.d/init.d/functions
ba26464c 20. /etc/sysconfig/network-scripts/.functions
7742e157 21
de1fc6ce
JR
22if [ ! -f /etc/sysconfig/network ]; then
23 nls "%s is missing. Can't continue." "/etc/sysconfig/network"
24 exit 1
25fi
7742e157
AF
26
27. /etc/sysconfig/network
28
7742e157 29# Check that networking is up.
dd4a755f 30is_no "${NETWORKING}" && exit 0
7742e157 31
de1fc6ce
JR
32# Will be removed in the future
33if 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
40fi
41
42if [ ! -x /sbin/ip ]; then
43 nls "%s is missing. Can't continue." "/sbin/ip"
44 exit 1
45fi
7742e157 46
7e04fe0e 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
55network_init()
7742e157 56{
de1fc6ce
JR
57# Kernel network parameters
58run_cmd "Setting network parameters" sysctl -p /etc/sysctl.conf
59
38198f50
AM
60# Set UP loopback interface
61set_up_loopback
62
63# Modprobe needed devices
e016cdae
AM
64modprobe_net
65
de1fc6ce
JR
66# Setup configuration
67setup_forwarding on
833bc9cf 68setup_nat on
47dbf68e 69setup_routes on
03f9cfee
JR
70
71# Setup IPX
dd4a755f 72if is_yes "$IPX"; then
de1fc6ce
JR
73 if [ -n $IPXAUTOPRIMARY ] ; then
74 if is_yes "$IPXAUTOPRIMARY"; then
75 IPXAUTOPRIMARY="on"
76 else
77 IPXAUTOPRIMARY="off"
78 fi
dd4a755f 79 /usr/bin/ipx_configure --auto_primary=$IPXAUTOPRIMARY
03f9cfee 80 fi
de1fc6ce
JR
81 if [ -n $IPXAUTOFRAME ] ; then
82 if is_yes "$IPXAUTOFRAME"; then
83 IPXAUTOFRAME="on"
84 else
85 IPXAUTOFRAME="off"
86 fi
dd4a755f 87 /usr/bin/ipx_configure --auto_interface=$IPXAUTOFRAME
03f9cfee 88 fi
de1fc6ce 89 if [ -n "$IPXINTERNALNETNUM" -a "$IPXINTERNALNETNUM" != "0" ]; then
dd4a755f 90 /usr/bin/ipx_internal_net add $IPXINTERNALNETNUM $IPXINTERNALNODENUM
03f9cfee 91 fi
dd4a755f 92fi
7742e157
AF
93}
94
21c12948
AF
95network_postinit()
96{
ea822d66 97# Set static RARP table
98static_rarp
99
21c12948
AF
100# Set static ARP table
101static_arp
21c12948
AF
102}
103
7e04fe0e 104######
105# deinitialize networking
106# - down lo interface.
107network_deinit()
108{
de1fc6ce 109setup_forwarding off
47dbf68e 110setup_routes off
fe648758 111
833bc9cf
AM
112# Set down NAT rules
113setup_nat off
e016cdae 114
38198f50
AM
115# Set DOWN loopback interface
116set_down_loopback
7742e157
AF
117}
118
5726f160
AM
119# find all the interfaces besides loopback.
120# ignore aliases, alternative configurations, and editor backup files
de1fc6ce 121interfaces=$((cd /etc/sysconfig/interfaces && ls -1 ifcfg* | \
8b51cc24
JR
122 egrep -v '(ifcfg-lo|:)' | egrep 'ifcfg-[a-z0-9]+$' | \
123 awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
de1fc6ce 124interfaces_boot=$((cd /etc/sysconfig/interfaces && ls -1 ifcfg* | \
7d21339a 125 egrep -v '(ifcfg-lo|ifcfg-sit|ifcfg-atm|ifcfg-lec|ifcfg-nas|:)' | egrep 'ifcfg-[a-z0-9]+$' | \
8b51cc24
JR
126 xargs egrep -l "ONBOOT=[^n][^o]" | \
127 awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
de1fc6ce 128interfaces_sit_boot=$((cd /etc/sysconfig/interfaces && ls -1 ifcfg-sit* | \
8b51cc24
JR
129 egrep 'ifcfg-[a-z0-9]+$' | xargs egrep -l "ONBOOT=[^n][^o]" | \
130 awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
de1fc6ce 131tunnels=$((cd /etc/sysconfig/interfaces && ls -1 tnlcfg-* | \
8b51cc24
JR
132 xargs egrep -l "ONBOOT=[^n][^o]" | \
133 awk ' { gsub(/tnlcfg-/,NIL); print $0 } ') 2> /dev/null)
12de71be 134
7742e157
AF
135# See how we were called.
136case "$1" in
137 start)
7e04fe0e 138 network_init
d4e799ff 139
97e54bef 140 for i in $interfaces_boot $interfaces_sit_boot ; do
de1fc6ce 141 run_cmd -a "$(nls 'Bringing up interface') $i" /sbin/ifup $i boot
97e54bef
JK
142 done
143
de1fc6ce
JR
144 for i in $(find_ldap_interfaces) ; do
145 run_cmd -a "$(nls 'Bringing up interface from LDAP') $i" /sbin/ifup $i boot
4ac87c24
AM
146 done
147
833bc9cf 148 for i in $tunnels; do
de1fc6ce
JR
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
7742e157 151 done
21c12948
AF
152
153 network_postinit
4ac87c24 154
7742e157
AF
155 touch /var/lock/subsys/network
156 ;;
157 stop)
de1fc6ce
JR
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
833bc9cf 177 for i in $tunnels; do
de1fc6ce
JR
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
7742e157 180 done
4ac87c24 181
de1fc6ce
JR
182 for i in $(find_ldap_interfaces) ; do
183 run_cmd -a "$(nls 'Shutting down interface from LDAP') $i" /sbin/ifdown $i boot
97e54bef
JK
184 done
185
186 for i in $interfaces_sit_boot $interfaces_boot ; do
de1fc6ce
JR
187 run_cmd -a "$(nls 'Shutting down interface') $i" /sbin/ifdown $i boot
188 done
189
190 for i in $(ip link show | awk -F":" ' (/UP/) && ($2 !~ "lo") { gsub(/@.*/,NIL); print $2; } ') ; do
191 show "Shutting down unconfigured interface %s" "$i"
192 ip addr flush dev $i 2>&1 | grep -v "Nothing to flush"
193 if (ip link set $i down); then ok; else fail; fi
833bc9cf 194 done
4ac87c24 195
7e04fe0e 196 network_deinit
d4e799ff 197
7742e157
AF
198 rm -f /var/lock/subsys/network
199 ;;
200 status)
38198f50 201 nls "Configured devices:"
4ac87c24 202 echo "lo $interfaces"
38198f50 203 nls "Configured tunnels:"
4ac87c24 204 echo "$tunnels"
de1fc6ce
JR
205 echo
206 nls "Currently inactive devices and tunnels:"
207 /sbin/ip link show | awk -F":" '(/^[0-90-90-9]:/) && ! (/UP/) { print $2 }' | xargs
60df57e7 208 nls "Currently active devices and tunnels:"
8192b17e 209 /sbin/ip link show | awk -F":" ' (/UP/) { print $2 }' | xargs
7742e157
AF
210 ;;
211 restart)
212 $0 stop
213 $0 start
214 ;;
7742e157 215 *)
38198f50 216 echo "Usage: $0 {start|stop|restart|status}"
7742e157
AF
217 exit 1
218esac
219
220exit 0
8192b17e
JR
221
222# This must be last line !
223# vi:syntax=sh:tw=78:ts=8:sw=4
This page took 0.075815 seconds and 4 git commands to generate.