defaultroute revision 45096
1#!/bin/sh -
2#
3#	$Id: rc.network,v 1.41 1999/03/24 10:28:49 brian Exp $
4#	From: @(#)netstart	5.9 (Berkeley) 3/30/91
5
6# Note that almost all the user-configurable behavior is no longer in
7# this file, but rather in /etc/rc.conf.  Please check that file
8# first before contemplating any changes here.  If you do need to change
9# this file for some reason, we would like to know about it.
10
11# First pass startup stuff.
12
13network_pass1() {
14    echo -n 'Doing initial network setup:'
15    # Set the host name if it is not already set
16    if [ -z "`hostname -s`" ] ; then
17	    hostname $hostname
18	    echo -n ' hostname'
19    fi
20
21    # Set the domainname if we're using NIS
22    if [ -n "$nisdomainname" -a "x$nisdomainname" != "xNO" ] ; then
23	    domainname $nisdomainname
24	    echo -n ' domain'
25    fi
26    echo '.'
27
28    # Initial ATM interface configuration
29    if [ "X${atm_enable}" = X"YES" -a -f /etc/rc.atm ]; then
30	    . /etc/rc.atm
31	    atm_pass1
32    fi
33
34    # ISDN subsystem startup
35    if [ "X${isdn_enable}" = X"YES" -a -f /etc/rc.isdn ]; then
36	    . /etc/rc.isdn
37    fi
38
39    # Special options for sppp(4) interfaces go here.  These need
40    # to go _before_ the general ifconfig section, since in the case
41    # of hardwired (no link1 flag) but required authentication, you
42    # cannot pass auth parameters down to the already running interface.
43    for ifn in ${sppp_interfaces}; do
44	    eval spppcontrol_args=\$spppconfig_${ifn}
45	    if [ -n "${spppcontrol_args}" ] ; then
46		    # The auth secrets might contain spaces; in order
47		    # to retain the quotation, we need to eval them
48		    # here.
49		    eval spppcontrol ${ifn} ${spppcontrol_args}
50	    fi
51    done
52
53    # Set up all the network interfaces, calling startup scripts if needed
54    for ifn in ${network_interfaces}; do
55	    if [ -e /etc/start_if.${ifn} ]; then
56		    . /etc/start_if.${ifn}
57	    fi
58	    # Do the primary ifconfig if specified
59	    eval ifconfig_args=\$ifconfig_${ifn}
60	    if [ -n "${ifconfig_args}" ] ; then
61		    ifconfig ${ifn} ${ifconfig_args}
62	    fi
63	    # Check to see if aliases need to be added
64	    alias=0
65	    while :
66	    do
67		    eval ifconfig_args=\$ifconfig_${ifn}_alias${alias}
68		    if [ -n "${ifconfig_args}" ]; then
69			    ifconfig ${ifn} ${ifconfig_args} alias
70			    alias=`expr ${alias} + 1`
71		    else
72			    break;
73		    fi
74	    done
75	    # Do ipx address if specified
76	    eval ifconfig_args=\$ifconfig_${ifn}_ipx
77	    if [ -n "${ifconfig_args}" ]; then
78		    ifconfig ${ifn} ${ifconfig_args}
79	    fi
80	    ifconfig ${ifn}
81    done
82
83    # Initialize IP filtering using ipfw
84    echo ""
85    /sbin/ipfw -q flush > /dev/null 2>&1
86    if [ $? = 0 ] ; then
87	firewall_in_kernel=1
88    else 
89	firewall_in_kernel=0
90    fi
91
92    if [ $firewall_in_kernel = 0 -a "x$firewall_enable"  = "xYES" ] ; then
93	if kldload ipfw; then
94		firewall_in_kernel=1		# module loaded successfully
95		echo "Kernel firewall module loaded."
96	else
97		echo "Warning: firewall kernel module failed to load."
98	fi
99    fi
100
101    # Load the filters if required
102    if [ $firewall_in_kernel = 1 ]; then
103	if [ -f /etc/rc.firewall -a X"$firewall_enable" = X"YES" ]; then
104	    . /etc/rc.firewall
105	    echo -n 'Firewall rules loaded, starting divert daemons: '
106
107	    # Network Address Translation daemon
108	    if [ X"${natd_enable}" = X"YES" -a -n "${natd_interface}" ]; then
109		if echo ${natd_interface} | \
110		    grep -q -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'; then
111		    natd_ifarg="-a ${natd_interface}"
112		else
113		    natd_ifarg="-n ${natd_interface}"
114		fi
115		echo -n ' natd'; ${natd_program} ${natd_flags} ${natd_ifarg}
116	    fi
117	    echo '.'
118	else
119	    IPFW_DEFAULT=`ipfw l 65535`
120	    if [ "$IPFW_DEFAULT" = "65535 deny ip from any to any" ]; then
121		echo -n "Warning: kernel has firewall functionality, "
122		echo "but firewall rules are not enabled."
123		echo "         All ip services are disabled."
124	    fi
125	fi
126    fi
127
128    # Additional ATM interface configuration
129    if [ -n "${atm_pass1_done}" ]; then
130	    atm_pass2
131    fi
132
133    # Configure routing
134
135    if [ "x$defaultrouter" != "xNO" ] ; then
136	    static_routes="default ${static_routes}"
137	    route_default="default ${defaultrouter}"
138    fi
139    
140    # Set up any static routes.  This should be done before router discovery.
141    if [ "x${static_routes}" != "x" ]; then
142	    for i in ${static_routes}; do
143		    eval route_args=\$route_${i}
144		    route add ${route_args}
145	    done
146    fi
147
148    echo -n 'Additional routing options:'
149    if [ -n "$tcp_extensions" -a "x$tcp_extensions" != "xYES" ] ; then
150	    echo -n ' tcp extensions=NO'
151	    sysctl -w net.inet.tcp.rfc1323=0 >/dev/null 2>&1
152    fi
153
154    if [ -n "$log_in_vain" -a "x$log_in_vain" != "xNO" ] ; then
155	    echo -n ' log_in_vain=YES'
156	    sysctl -w net.inet.tcp.log_in_vain=1 >/dev/null 2>&1
157	    sysctl -w net.inet.udp.log_in_vain=1 >/dev/null 2>&1
158    fi
159
160    if [ X"$icmp_bmcastecho" = X"YES" ]; then
161	    echo -n ' broadcast ping responses=YES'
162	    sysctl -w net.inet.icmp.bmcastecho=1 >/dev/null 2>&1
163    fi
164
165    if [ "X$gateway_enable" = X"YES" ]; then
166	    echo -n ' IP gateway=YES'
167	    sysctl -w net.inet.ip.forwarding=1 >/dev/null 2>&1
168    fi
169    
170    if [ "X$forward_sourceroute" = X"YES" ]; then
171	    echo -n ' do source routing=YES'
172	    sysctl -w net.inet.ip.sourceroute=1 >/dev/null 2>&1
173    fi
174
175    if [ "X$accept_sourceroute" = X"YES" ]; then
176	    echo -n ' accept source routing=YES'
177	    sysctl -w net.inet.ip.accept_sourceroute=1 >/dev/null 2>&1
178    fi
179
180    if [ "X$ipxgateway_enable" = X"YES" ]; then
181	    echo -n ' IPX gateway=YES'
182	    sysctl -w net.ipx.ipx.ipxforwarding=1 >/dev/null 2>&1
183    fi
184    
185    if [ "X$arpproxy_all" = X"YES" ]; then
186	    echo -n ' enabling ARP_PROXY_ALL: '
187	    sysctl -w net.link.ether.inet.proxyall=1 2>&1
188    fi
189    echo '.'
190
191    echo -n 'routing daemons:'
192    if [ "X$router_enable" = X"YES" ]; then
193	    echo -n " ${router}";	${router} ${router_flags}
194    fi
195    
196    if [ "X$ipxrouted_enable" = X"YES" ]; then
197	    echo -n ' IPXrouted'
198	    IPXrouted ${ipxrouted_flags} > /dev/null 2>&1
199    fi
200    
201    if [ "X${mrouted_enable}" = X"YES" ]; then
202	    echo -n ' mrouted'; mrouted ${mrouted_flags}
203    fi
204
205    if [ "X$rarpd_enable" = X"YES" ]; then
206	    echo -n ' rarpd';     rarpd ${rarpd_flags}
207    fi
208    echo '.'
209    network_pass1_done=YES	# Let future generations know we made it.
210}
211
212network_pass2() {
213    echo -n 'Doing additional network setup:'
214    if [ "X${named_enable}" = X"YES" ]; then
215	    echo -n ' named';		${named_program-"named"} ${named_flags}
216    fi
217
218    if [ "X${ntpdate_enable}" = X"YES" ]; then
219	    echo -n ' ntpdate';	${ntpdate_program} ${ntpdate_flags} >/dev/null 2>&1
220    fi
221
222    if [ "X${xntpd_enable}" = X"YES" ]; then
223	    echo -n ' xntpd';	${xntpd_program} ${xntpd_flags}
224    fi
225
226    if [ "X${timed_enable}" = X"YES" ]; then
227	    echo -n ' timed';		timed ${timed_flags}
228    fi
229
230    if [ "X${portmap_enable}" = X"YES" ]; then
231	    echo -n ' portmap';		${portmap_program} ${portmap_flags}
232    fi
233
234    # Start ypserv if we're an NIS server.
235    # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server.
236    if [ "X${nis_server_enable}" = X"YES" ]; then
237	    echo -n ' ypserv'; ypserv ${nis_server_flags}
238	    
239	    if [ "X${nis_ypxfrd_enable}" = X"YES" ]; then
240		    echo -n ' rpc.ypxfrd'; rpc.ypxfrd ${nis_ypxfrd_flags}
241	    fi
242	    
243	    if [ "X${nis_yppasswdd_enable}" = X"YES" ]; then
244		    echo -n ' rpc.yppasswdd'; rpc.yppasswdd ${nis_yppasswdd_flags}
245	    fi
246    fi
247
248    # Start ypbind if we're an NIS client
249    if [ "X${nis_client_enable}" = X"YES" ]; then
250	    echo -n ' ypbind'; ypbind ${nis_client_flags}
251	    if [ "X${nis_ypset_enable}" = X"YES" ]; then
252		    echo -n ' ypset'; ypset ${nis_ypset_flags}
253	    fi
254    fi
255
256    # Start keyserv if we are running Secure RPC
257    if [ "X${keyserv_enable}" = X"YES" ]; then
258	    echo -n ' keyserv';		keyserv ${keyserv_flags}
259    fi
260    # Start ypupdated if we are running Secure RPC and we are NIS master
261    if [ "X$rpc_ypupdated_enable" = X"YES" ]; then
262	    echo -n ' rpc.ypupdated';	rpc.ypupdated
263    fi
264
265    # Start ATM daemons
266    if [ -n "${atm_pass2_done}" ]; then
267	    atm_pass3
268    fi
269
270    echo '.'
271    network_pass2_done=YES
272}
273
274network_pass3() {
275    echo -n 'Starting final network daemons:'
276
277    if [ "X${nfs_server_enable}" = X"YES" -a -r /etc/exports ]; then
278	    echo -n ' mountd'
279	    if [ "X${weak_mountd_authentication}" = X"YES" ]; then
280		    mountd_flags="-n"
281	    fi
282	    mountd ${mountd_flags}
283	    if [ "X${nfs_reserved_port_only}" = X"YES" ]; then
284		    sysctl -w vfs.nfs.nfs_privport=1 >/dev/null 2>&1
285	    fi
286	    echo -n ' nfsd';		nfsd ${nfs_server_flags}
287	    if [ "X$rpc_lockd_enable" = X"YES" ]; then
288		echo -n ' rpc.lockd';		rpc.lockd
289	    fi
290	    if [ "X$rpc_statd_enable" = X"YES" ]; then
291		echo -n ' rpc.statd';		rpc.statd
292	    fi
293    fi
294    
295    if [ "X${nfs_client_enable}" = X"YES" ]; then
296	    echo -n ' nfsiod';		nfsiod ${nfs_client_flags}
297	    if [ "X${nfs_access_cache}" != X ]; then
298		sysctl -w vfs.nfs.access_cache_timeout=${nfs_access_cache} \
299			>/dev/null 2>&1
300	    fi
301    fi
302
303    if [ "X${amd_enable}" = X"YES" ]; then
304	    echo -n ' amd'
305	    if [ "X${amd_map_program}" != X"NO" ]; then
306		amd_flags="${amd_flags} `eval ${amd_map_program}`"
307	    fi
308	    amd -p ${amd_flags} > /var/run/amd.pid 2> /dev/null
309    fi
310
311    if [ "X${rwhod_enable}" = X"YES" ]; then
312	    echo -n ' rwhod';	rwhod ${rwhod_flags}
313    fi
314
315    # Kerberos runs ONLY on the Kerberos server machine
316    if [ "X${kerberos_server_enable}" = X"YES" ]; then
317	    if [ "X${kerberos_stash}" = "XYES" ]; then
318		stash_flag=-n
319	    else
320		stash_flag=
321	    fi
322	    echo -n ' kerberos'; \
323		kerberos ${stash_flag} >> /var/log/kerberos.log &
324	    if [ "X${kadmind_server_enable}" = "XYES" ]; then
325		echo -n ' kadmind'; \
326		(sleep 20; kadmind ${stash_flag} >/dev/null 2>&1 &) &
327	    fi
328	    unset stash_flag
329    fi
330    
331    echo '.'
332    network_pass3_done=YES
333}
334