]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/init.d/network
- remove bashizm in using test ("=" instead "==").
[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 # probe: true
9
10 # $Id: network,v 1.25 1999/10/06 16:52:37 kloczek Exp $
11
12 # NLS
13 NLS_DOMAIN="rc-scripts"
14
15 # Source function library.
16 . /etc/rc.d/init.d/functions
17 . /etc/rc.d/init.d/functions.network
18
19 [ ! -f /etc/sysconfig/network ] && exit 0
20
21 . /etc/sysconfig/network
22
23 # Check that networking is up.
24 [ "${NETWORKING}" = "no" -o "${NETWORKING}" = "" ] && exit 0
25
26 [ -x /sbin/ip ] || exit 0
27
28 ######
29 # initialize networking:
30 # - check IPv4, IPv6, IPX can be handled by system
31 # - setup default IPv{4,6} interfaces policy like:
32 #   - forwarding,
33 #   - spoofig protection,
34 #   - icmp echo ignore broadcasts,
35 # - setup lo interface
36 network_init()
37 {
38 # Set UP loopback interface
39 set_up_loopback
40
41 # Modprobe needed devices
42 modprobe_net
43
44 # Spoofing protection && dynamic IP && port range
45 ipv4_anti_spoofing on
46 ipv4_dynamic_ip_patch on
47 ipv4_local_port_range on
48
49 # Others proc/sys/net
50 proc_networking start
51
52 # Setup NAT rules
53 setup_nat on
54 }
55
56 network_postinit()
57 {
58 # Set static ARP table
59 static_arp
60
61 }
62
63 ######
64 # deinitialize networking
65 # - down lo interface.
66 network_deinit()
67 {
68 # Set down NAT rules
69 setup_nat off
70
71 # Spoofing protection && dynamic IP && port range
72 ipv4_anti_spoofing off
73 ipv4_dynamic_ip_patch off
74 ipv4_local_port_range off
75
76 # Others proc/sys/net
77 proc_networking stop
78
79 # Set DOWN loopback interface
80 set_down_loopback
81 }
82
83 proc_networking()
84 {
85 TODO="$1"
86
87 # IPv4 forwarding
88 proc_net ipv4/ip_forward $TODO 1 0 IPV4_FORWARDING "IPv4 forwarding"
89 # IPv6 forwarding
90 proc_net ipv6/conf/all/forwarding $TODO 1 0 IPV6_FORWARDING "IPv6 forwarding"
91 # Others proc/net
92 proc_net ipv4/conf/all/accept_redirects $TODO 1 0 IPV4_ACCEPT_ICMP_REDIR ""
93 proc_net ipv4/conf/all/accept_source_route $TODO 1 1 IPV4_ACCEPT_SOURCE_ROUTE ""
94 proc_net ipv4/conf/all/log_martians $TODO 1 0 IPV4_LOG_MARTIANS ""
95 proc_net ipv4/conf/all/mc_forwarding $TODO 1 0 IPV4_MULTICAST ""
96 proc_net ipv4/conf/all/proxy_arp $TODO 1 0 IPV4_PROXY_ARP ""
97 proc_net ipv4/conf/all/secure_redirects $TODO 1 1 IPV4_ACCEPT_ICMP_REDIR_GATE ""
98 proc_net ipv4/conf/all/send_redirects $TODO 1 1 IPV4_SEND_ICMP_REDIR ""
99 proc_net ipv4/icmp_echo_ignore_all $TODO 1 0 IPV4_IGN_ALL_ICMP ""
100 proc_net ipv4/icmp_echo_ignore_broadcasts $TODO 1 1 IPV4_IGN_CAST_ICMP ""
101 proc_net ipv4/ip_no_pmtu_disc $TODO 1 0 IPV4_MTU_DISCOVERY ""
102 proc_net ipv4/ip_masq_debug $TODO 1 0 IPV4_MASQ_DEBUGGING ""
103 proc_net ipv4/tcp_retrans_collapse $TODO 0 1 IPV4_RETRANS_COLLAPSE ""
104 proc_net ipv4/tcp_sack $TODO 0 1 IPV4_NO_SELECT_ACK ""
105 proc_net ipv4/tcp_timestamps $TODO 0 1 IPV4_NO_TIMESTAMPS ""
106 proc_net ipv4/tcp_stdurg $TODO 1 0 IPV4_RFC793 ""
107 proc_net ipv4/tcp_syncookies $TODO 1 0 IPV4_SYN_COOKIES ""
108 proc_net ipv4/tcp_window_scaling $TODO 1 0 IPV4_NO_WINDOW_SCALING ""
109 }
110
111 # find all the interfaces besides loopback.
112 # ignore aliases, alternative configurations, and editor backup files
113 interfaces="`(cd /etc/sysconfig/interfaces && ls ifcfg* | \
114 egrep -v '(ifcfg-lo|:)' | egrep 'ifcfg-[a-z0-9]+$' | sed 's/^ifcfg-//g' | xargs) 2> /dev/null`"
115 interfaces_boot="`(cd /etc/sysconfig/interfaces && ls ifcfg* | \
116 egrep -v '(ifcfg-lo|ifcfg-sit|:)' | egrep 'ifcfg-[a-z0-9]+$' | \
117 xargs egrep -l "ONBOOT=[^n][^o]" | sed 's/^ifcfg-//g') 2> /dev/null`"
118 interfaces_sit_boot="`(cd /etc/sysconfig/interfaces && ls ifcfg-sit* | \
119 egrep 'ifcfg-[a-z0-9]+$' | xargs egrep -l "ONBOOT=[^n][^o]" | sed 's/^ifcfg-//g') 2> /dev/null`"
120 tunnels="`(cd /etc/sysconfig/interfaces && ls -1 tnlcfg-* | \
121 xargs egrep -l "ONBOOT=[^n][^o]" | sed 's/^tnlcfg-//g') 2> /dev/null`"
122
123 # See how we were called.
124 case "$1" in
125   start)
126         network_init
127
128         for i in $interfaces_boot $interfaces_sit_boot ; do
129                 /sbin/ifup $i boot
130         done
131
132         for i in `find_ldap_interfaces` ; do
133                 /sbin/ifup $i boot
134         done
135
136         for i in $tunnels; do
137                 /sbin/tnlup $i boot
138                 /sbin/ifup tnlcfg-$i boot
139         done
140         
141         network_postinit
142
143         touch /var/lock/subsys/network
144         ;;
145   stop)
146         for i in $tunnels; do
147                 /sbin/ifdown tnlcfg-$i boot
148                 /sbin/tnldown $i boot
149         done
150
151         for i in `find_ldap_interfaces` ; do
152                 /sbin/ifdown $i boot
153         done
154
155         for i in $interfaces_sit_boot $interfaces_boot ; do
156                 /sbin/ifdown $i boot
157         done
158
159         network_deinit
160
161         rm -f /var/lock/subsys/network
162         ;;
163   status)
164         nls "Configured devices:"
165         echo "lo $interfaces"
166         nls "Configured tunnels:"
167         echo "$tunnels"
168
169         nls "Currently active devices and tunnels:"
170         /sbin/ip link show | egrep '^[^ ].*' |sed 's/[0-9]*: \(.*\):.*/\1/'|xargs
171         ;;
172   restart)
173         $0 stop
174         $0 start
175         ;;
176   *)
177         echo "Usage: $0 {start|stop|restart|status}"
178         exit 1
179 esac
180
181 exit 0
This page took 0.035551 seconds and 4 git commands to generate.