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