]> git.pld-linux.org Git - projects/rc-scripts.git/blame - rc.d/init.d/network
- preparation for upcoming 0.4.0.1 release
[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
ec8b15cb 11# $Id$
fa8aca70
JR
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
baa6b418 20. /etc/sysconfig/network-scripts/functions.network
7742e157 21
fa8aca70
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
fa8aca70
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:
7e04fe0e 51# - spoofig protection,
52# - icmp echo ignore broadcasts,
53# - setup lo interface
54network_init()
7742e157 55{
51e8dd01
JR
56# Modprobe needed devices
57modprobe_net
58
70db4cf0
AM
59# Setup interfaces names
60[ -x /sbin/nameif -a -f /etc/mactab ] && run_cmd "Setting interfaces names (nameif)" /sbin/nameif
61
fa8aca70
JR
62# Kernel network parameters
63run_cmd "Setting network parameters" sysctl -p /etc/sysctl.conf
64
38198f50
AM
65# Set UP loopback interface
66set_up_loopback
67
fa8aca70 68# Setup configuration
833bc9cf 69setup_nat on
47dbf68e 70setup_routes on
e686ef49 71setup_ip_rules on
03f9cfee 72# Setup IPX
dd4a755f 73if is_yes "$IPX"; then
fa8aca70
JR
74 if [ -n $IPXAUTOPRIMARY ] ; then
75 if is_yes "$IPXAUTOPRIMARY"; then
76 IPXAUTOPRIMARY="on"
77 else
78 IPXAUTOPRIMARY="off"
79 fi
f6e719eb 80 /sbin/ipx_configure --auto_primary=$IPXAUTOPRIMARY
03f9cfee 81 fi
fa8aca70
JR
82 if [ -n $IPXAUTOFRAME ] ; then
83 if is_yes "$IPXAUTOFRAME"; then
84 IPXAUTOFRAME="on"
85 else
86 IPXAUTOFRAME="off"
87 fi
f6e719eb 88 /sbin/ipx_configure --auto_interface=$IPXAUTOFRAME
03f9cfee 89 fi
fa8aca70 90 if [ -n "$IPXINTERNALNETNUM" -a "$IPXINTERNALNETNUM" != "0" ]; then
f6e719eb 91 /sbin/ipx_internal_net add $IPXINTERNALNETNUM $IPXINTERNALNODENUM
03f9cfee 92 fi
dd4a755f 93fi
7742e157
AF
94}
95
21c12948
AF
96network_postinit()
97{
ea822d66 98# Set static RARP table
99static_rarp
100
21c12948
AF
101# Set static ARP table
102static_arp
21c12948
AF
103}
104
7e04fe0e 105######
106# deinitialize networking
107# - down lo interface.
108network_deinit()
109{
47dbf68e 110setup_routes off
e686ef49 111setup_ip_rules off
fe648758 112
833bc9cf
AM
113# Set down NAT rules
114setup_nat off
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
4dd9596f
SZ
121interfaces_boot=$((
122 . /etc/rc.d/init.d/functions; \
123 cd /etc/sysconfig/interfaces && ls -1 ifcfg* | \
f3eff3ad
JR
124 egrep -v '(ifcfg-lo|ifcfg-sit|ifcfg-atm|ifcfg-lec|ifcfg-nas|ifcfg-br:)' | \
125 egrep 'ifcfg-[a-z0-9\.]+$' | \
126 for i in `cat`; do \
127 ONBOOT=""; . /etc/sysconfig/interfaces/"$i"; is_yes "$ONBOOT" && echo "$i"; \
128 done | \
129 awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
130interfaces_br_boot=$((
131 . /etc/rc.d/init.d/functions; \
132 cd /etc/sysconfig/interfaces && ls -1 ifcfg-br* | \
4dd9596f
SZ
133 egrep 'ifcfg-[a-z0-9\.]+$' | \
134 for i in `cat`; do \
135 ONBOOT=""; . /etc/sysconfig/interfaces/"$i"; is_yes "$ONBOOT" && echo "$i"; \
136 done | \
8b51cc24 137 awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
4dd9596f
SZ
138interfaces_sit_boot=$((
139 . /etc/rc.d/init.d/functions; \
140 cd /etc/sysconfig/interfaces && ls -1 ifcfg-sit* | \
141 egrep 'ifcfg-[a-z0-9]+$' | \
142 for i in `cat`; do \
143 ONBOOT=""; . /etc/sysconfig/interfaces/"$i"; is_yes "$ONBOOT" && echo "$i"; \
144 done | \
8b51cc24 145 awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
fa8aca70 146tunnels=$((cd /etc/sysconfig/interfaces && ls -1 tnlcfg-* | \
8b51cc24
JR
147 xargs egrep -l "ONBOOT=[^n][^o]" | \
148 awk ' { gsub(/tnlcfg-/,NIL); print $0 } ') 2> /dev/null)
12de71be 149
7742e157
AF
150# See how we were called.
151case "$1" in
152 start)
7e04fe0e 153 network_init
d4e799ff 154
97e54bef 155 for i in $interfaces_boot $interfaces_sit_boot ; do
fa8aca70 156 run_cmd -a "$(nls 'Bringing up interface') $i" /sbin/ifup $i boot
97e54bef
JK
157 done
158
833bc9cf 159 for i in $tunnels; do
fa8aca70
JR
160 run_cmd -a "$(nls 'Setting tunnel') $i" /sbin/tnlup $i boot
161 run_cmd -a "$(nls 'Bringing up tunnel interface') $i" /sbin/ifup tnlcfg-$i boot
7742e157 162 done
21c12948 163
f3eff3ad 164 for i in $interfaces_br_boot ; do
3fe008d3 165 run_cmd -a "$(nls 'Bringing up bridge interface') $i" /sbin/ifup $i boot
f3eff3ad
JR
166 done
167
21c12948 168 network_postinit
4ac87c24 169
7742e157
AF
170 touch /var/lock/subsys/network
171 ;;
172 stop)
fa8aca70
JR
173 # If we go to runlevel 0, 1 or 6 then umount all network fs
174 if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
175 if [ -x /etc/rc.d/init.d/netfs -a -f /var/lock/subsys/netfs ];
176 then
177 /etc/rc.d/init.d/netfs stop
178 else
179 netmtab=$(awk '{ if ($3 ~ /^(nfs|smbfs|ncpfs)$/ ) print $3}' /proc/mounts)
180 if (echo "$netmtab" | grep -q nfs); then
181 run_cmd "Unmounting NFS filesystems" umount -fat nfs
182 fi
183 if (echo "$netmtab" | grep -q smbfs); then
184 run_cmd "Unmounting SMB filesystems" umount -at smbfs
185 fi
186 if (echo "$netmtab" | grep -q ncpfs); then
187 run_cmd "Unmounting NCP filesystems" umount -at ncpfs
188 fi
189 fi
190 fi
191
3fe008d3
JR
192 for i in $interfaces_br_boot ; do
193 run_cmd -a "$(nls 'Shutting down bridge interface') $i" /sbin/ifdown $i boot
194 done
195
833bc9cf 196 for i in $tunnels; do
fa8aca70
JR
197 run_cmd -a "$(nls 'Shutting down tunnel interface') $i" /sbin/ifdown tnlcfg-$i boot
198 run_cmd -a "$(nls 'Removing tunnel') $i" /sbin/tnldown $i boot
7742e157 199 done
4ac87c24 200
97e54bef 201 for i in $interfaces_sit_boot $interfaces_boot ; do
fa8aca70 202 run_cmd -a "$(nls 'Shutting down interface') $i" /sbin/ifdown $i boot
de1fc6ce
JR
203 done
204
7e04fe0e 205 network_deinit
d4e799ff 206
7742e157
AF
207 rm -f /var/lock/subsys/network
208 ;;
209 status)
38198f50 210 nls "Configured devices:"
4ac87c24 211 echo "lo $interfaces"
38198f50 212 nls "Configured tunnels:"
4ac87c24 213 echo "$tunnels"
fa8aca70
JR
214 echo
215 nls "Currently inactive devices and tunnels:"
216 /sbin/ip link show | awk -F":" '(/^[0-90-90-9]:/) && ! (/UP/) { print $2 }' | xargs
60df57e7 217 nls "Currently active devices and tunnels:"
8192b17e 218 /sbin/ip link show | awk -F":" ' (/UP/) { print $2 }' | xargs
7742e157
AF
219 ;;
220 restart)
221 $0 stop
222 $0 start
223 ;;
7742e157 224 *)
38198f50 225 echo "Usage: $0 {start|stop|restart|status}"
7742e157
AF
226 exit 1
227esac
228
229exit 0
8192b17e
JR
230
231# This must be last line !
232# vi:syntax=sh:tw=78:ts=8:sw=4
This page took 0.27826 seconds and 4 git commands to generate.