netoptions revision 49603
1#!/bin/sh -
2#
3#	$Id: rc.network,v 1.52 1999/07/26 15:17:23 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    if [ "x${network_interfaces}" = "xauto" ]; then
55	    network_interfaces="`ifconfig -l`"
56    fi
57    for ifn in ${network_interfaces}; do
58	    showstat=false
59	    if [ -e /etc/start_if.${ifn} ]; then
60		    . /etc/start_if.${ifn}
61		    showstat=true
62	    fi
63	    # Do the primary ifconfig if specified
64	    eval ifconfig_args=\$ifconfig_${ifn}
65	    if [ -n "${ifconfig_args}" ] ; then
66		    # See if we are using DHCP
67		    if [ X"${ifconfig_args}" = X"DHCP" ]; then
68			     ${dhcp_program} ${dhcp_flags} ${ifn}
69		    else
70			     ifconfig ${ifn} ${ifconfig_args}
71		    fi
72		    showstat=true
73	    fi
74	    # Check to see if aliases need to be added
75	    alias=0
76	    while :
77	    do
78		    eval ifconfig_args=\$ifconfig_${ifn}_alias${alias}
79		    if [ -n "${ifconfig_args}" ]; then
80			    ifconfig ${ifn} ${ifconfig_args} alias
81			    showstat=true
82			    alias=`expr ${alias} + 1`
83		    else
84			    break;
85		    fi
86	    done
87	    # Do ipx address if specified
88	    eval ifconfig_args=\$ifconfig_${ifn}_ipx
89	    if [ -n "${ifconfig_args}" ]; then
90		    ifconfig ${ifn} ${ifconfig_args}
91		    showstat=true
92	    fi
93	    if [ "${showstat}" = "true" ]
94	    then
95		    ifconfig ${ifn}
96	    fi
97    done
98
99    # Warm up user ppp if required, must happen before natd.
100    if [ "X$ppp_enable" = X"YES" ]; then
101	    # Establish ppp mode.
102	    if [ "X$ppp_mode" != X"ddial" -a "X$ppp_mode" != X"direct" \
103		-a "X$ppp_mode" != X"dedicated" ]; then \
104	        ppp_mode="auto";
105	    fi
106	    ppp_command="-${ppp_mode} ";
107
108	    # Switch on alias mode?
109	    if [ "X$ppp_alias" = X"YES" ]; then
110		ppp_command="${ppp_command} -alias";
111	    fi
112
113	    echo -n 'Starting ppp: '; ppp ${ppp_command} ${ppp_profile}
114    fi
115
116    # Initialize IP filtering using ipfw
117    echo ""
118    /sbin/ipfw -q flush > /dev/null 2>&1
119    if [ $? = 0 ] ; then
120	firewall_in_kernel=1
121    else 
122	firewall_in_kernel=0
123    fi
124
125    if [ $firewall_in_kernel = 0 -a "x$firewall_enable"  = "xYES" ] ; then
126	if kldload ipfw; then
127		firewall_in_kernel=1		# module loaded successfully
128		echo "Kernel firewall module loaded."
129	else
130		echo "Warning: firewall kernel module failed to load."
131	fi
132    fi
133
134    # Load the filters if required
135    if [ $firewall_in_kernel = 1 ]; then
136	if [ -z "${firewall_script}" ] ; then
137	    firewall_script="/etc/rc.firewall"
138	fi
139	if [ -f ${firewall_script} -a X"$firewall_enable" = X"YES" ]; then
140	    . ${firewall_script}
141	    echo -n 'Firewall rules loaded, starting divert daemons:'
142
143	    # Network Address Translation daemon
144	    if [ X"${natd_enable}" = X"YES" -a -n "${natd_interface}" ]; then
145		if echo ${natd_interface} | \
146		    grep -q -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'; then
147		    natd_ifarg="-a ${natd_interface}"
148		else
149		    natd_ifarg="-n ${natd_interface}"
150		fi
151		echo -n ' natd'; ${natd_program} ${natd_flags} ${natd_ifarg}
152	    fi
153	    echo '.'
154	else
155	    IPFW_DEFAULT=`ipfw l 65535`
156	    if [ "$IPFW_DEFAULT" = "65535 deny ip from any to any" ]; then
157		echo -n "Warning: kernel has firewall functionality, "
158		echo "but firewall rules are not enabled."
159		echo "         All ip services are disabled."
160	    fi
161	fi
162    fi
163
164    # Additional ATM interface configuration
165    if [ -n "${atm_pass1_done}" ]; then
166	    atm_pass2
167    fi
168
169    # Configure routing
170
171    if [ "x$defaultrouter" != "xNO" ] ; then
172	    static_routes="default ${static_routes}"
173	    route_default="default ${defaultrouter}"
174    fi
175    
176    # Set up any static routes.  This should be done before router discovery.
177    if [ "x${static_routes}" != "x" ]; then
178	    for i in ${static_routes}; do
179		    eval route_args=\$route_${i}
180		    route add ${route_args}
181	    done
182    fi
183
184    echo -n 'Additional routing options:'
185    if [ -n "$tcp_extensions" -a "x$tcp_extensions" != "xYES" ] ; then
186	    echo -n ' tcp extensions=NO'
187	    sysctl -w net.inet.tcp.rfc1323=0 >/dev/null
188    fi
189
190    if [ -n "$log_in_vain" -a "x$log_in_vain" != "xNO" ] ; then
191	    echo -n ' log_in_vain=YES'
192	    sysctl -w net.inet.tcp.log_in_vain=1 >/dev/null
193	    sysctl -w net.inet.udp.log_in_vain=1 >/dev/null
194    fi
195
196    if [ X"$icmp_bmcastecho" = X"YES" ]; then
197	    echo -n ' broadcast ping responses=YES'
198	    sysctl -w net.inet.icmp.bmcastecho=1 >/dev/null
199    fi
200    
201    if [ "X$icmp_drop_redirect" = X"YES" ]; then
202	    echo -n ' ignore ICMP redirect=YES'
203	    sysctl -w net.inet.icmp.drop_redirect=1 >/dev/null
204    fi
205    
206    if [ "X$icmp_log_redirect" = X"YES" ]; then
207	    echo -n ' log ICMP redirect=YES'
208	    sysctl -w net.inet.icmp.log_redirect=1 >/dev/null
209    fi
210
211    if [ "X$gateway_enable" = X"YES" ]; then
212	    echo -n ' IP gateway=YES'
213	    sysctl -w net.inet.ip.forwarding=1 >/dev/null
214    fi
215    
216    if [ "X$forward_sourceroute" = X"YES" ]; then
217	    echo -n ' do source routing=YES'
218	    sysctl -w net.inet.ip.sourceroute=1 >/dev/null
219    fi
220
221    if [ "X$accept_sourceroute" = X"YES" ]; then
222	    echo -n ' accept source routing=YES'
223	    sysctl -w net.inet.ip.accept_sourceroute=1 >/dev/null
224    fi
225
226    if [ "X$tcp_keepalive" = X"YES" ]; then
227	    echo -n ' TCP keepalive=YES'
228	    sysctl -w net.inet.tcp.always_keepalive=1 >/dev/null
229    fi
230
231    if [ "X$ipxgateway_enable" = X"YES" ]; then
232	    echo -n ' IPX gateway=YES'
233	    sysctl -w net.ipx.ipx.ipxforwarding=1 >/dev/null
234    fi
235    
236    if [ "X$arpproxy_all" = X"YES" ]; then
237	    echo -n ' ARP proxyall=YES'
238	    sysctl -w net.link.ether.inet.proxyall=1 >/dev/null
239    fi
240    echo '.'
241
242    echo -n 'routing daemons:'
243    if [ "X$router_enable" = X"YES" ]; then
244	    echo -n " ${router}";	${router} ${router_flags}
245    fi
246    
247    if [ "X$ipxrouted_enable" = X"YES" ]; then
248	    echo -n ' IPXrouted'
249	    IPXrouted ${ipxrouted_flags} > /dev/null 2>&1
250    fi
251    
252    if [ "X${mrouted_enable}" = X"YES" ]; then
253	    echo -n ' mrouted'; mrouted ${mrouted_flags}
254    fi
255
256    if [ "X$rarpd_enable" = X"YES" ]; then
257	    echo -n ' rarpd';     rarpd ${rarpd_flags}
258    fi
259    echo '.'
260    network_pass1_done=YES	# Let future generations know we made it.
261}
262
263network_pass2() {
264    echo -n 'Doing additional network setup:'
265    if [ "X${named_enable}" = X"YES" ]; then
266	    echo -n ' named';		${named_program-"named"} ${named_flags}
267    fi
268
269    if [ "X${ntpdate_enable}" = X"YES" ]; then
270	    echo -n ' ntpdate';	${ntpdate_program} ${ntpdate_flags} >/dev/null 2>&1
271    fi
272
273    if [ "X${xntpd_enable}" = X"YES" ]; then
274	    echo -n ' xntpd';	${xntpd_program} ${xntpd_flags}
275    fi
276
277    if [ "X${timed_enable}" = X"YES" ]; then
278	    echo -n ' timed';		timed ${timed_flags}
279    fi
280
281    if [ "X${portmap_enable}" = X"YES" ]; then
282	    echo -n ' portmap';		${portmap_program} ${portmap_flags}
283    fi
284
285    # Start ypserv if we're an NIS server.
286    # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server.
287    if [ "X${nis_server_enable}" = X"YES" ]; then
288	    echo -n ' ypserv'; ypserv ${nis_server_flags}
289	    
290	    if [ "X${nis_ypxfrd_enable}" = X"YES" ]; then
291		    echo -n ' rpc.ypxfrd'; rpc.ypxfrd ${nis_ypxfrd_flags}
292	    fi
293	    
294	    if [ "X${nis_yppasswdd_enable}" = X"YES" ]; then
295		    echo -n ' rpc.yppasswdd'; rpc.yppasswdd ${nis_yppasswdd_flags}
296	    fi
297    fi
298
299    # Start ypbind if we're an NIS client
300    if [ "X${nis_client_enable}" = X"YES" ]; then
301	    echo -n ' ypbind'; ypbind ${nis_client_flags}
302	    if [ "X${nis_ypset_enable}" = X"YES" ]; then
303		    echo -n ' ypset'; ypset ${nis_ypset_flags}
304	    fi
305    fi
306
307    # Start keyserv if we are running Secure RPC
308    if [ "X${keyserv_enable}" = X"YES" ]; then
309	    echo -n ' keyserv';		keyserv ${keyserv_flags}
310    fi
311    # Start ypupdated if we are running Secure RPC and we are NIS master
312    if [ "X$rpc_ypupdated_enable" = X"YES" ]; then
313	    echo -n ' rpc.ypupdated';	rpc.ypupdated
314    fi
315
316    # Start ATM daemons
317    if [ -n "${atm_pass2_done}" ]; then
318	    atm_pass3
319    fi
320
321    echo '.'
322    network_pass2_done=YES
323}
324
325network_pass3() {
326    echo -n 'Starting final network daemons:'
327
328    if [ "X${nfs_server_enable}" = X"YES" -a -r /etc/exports ]; then
329	    echo -n ' mountd'
330	    if [ "X${weak_mountd_authentication}" = X"YES" ]; then
331		    mountd_flags="-n"
332	    fi
333	    mountd ${mountd_flags}
334	    if [ "X${nfs_reserved_port_only}" = X"YES" ]; then
335		    echo -n ' NFS on reserved port only=YES'
336		    sysctl -w vfs.nfs.nfs_privport=1 >/dev/null
337	    fi
338	    echo -n ' nfsd';		nfsd ${nfs_server_flags}
339	    if [ "X$rpc_lockd_enable" = X"YES" ]; then
340		echo -n ' rpc.lockd';		rpc.lockd
341	    fi
342	    if [ "X$rpc_statd_enable" = X"YES" ]; then
343		echo -n ' rpc.statd';		rpc.statd
344	    fi
345    fi
346    
347    if [ "X${nfs_client_enable}" = X"YES" ]; then
348	    echo -n ' nfsiod';		nfsiod ${nfs_client_flags}
349	    if [ "X${nfs_access_cache}" != X ]; then
350		echo -n " NFS access cache time=${nfs_access_cache}"
351		sysctl -w vfs.nfs.access_cache_timeout=${nfs_access_cache} \
352		    >/dev/null
353	    fi
354    fi
355
356    if [ "X${amd_enable}" = X"YES" ]; then
357	    echo -n ' amd'
358	    if [ "X${amd_map_program}" != X"NO" ]; then
359		amd_flags="${amd_flags} `eval ${amd_map_program}`"
360	    fi
361	    if [ -n "$amd_flags" ]
362	    then
363	      amd -p ${amd_flags} > /var/run/amd.pid 2> /dev/null
364	    else
365	      amd 2> /dev/null
366	    fi
367    fi
368
369    if [ "X${rwhod_enable}" = X"YES" ]; then
370	    echo -n ' rwhod';	rwhod ${rwhod_flags}
371    fi
372
373    # Kerberos runs ONLY on the Kerberos server machine
374    if [ "X${kerberos_server_enable}" = X"YES" ]; then
375	    if [ "X${kerberos_stash}" = "XYES" ]; then
376		stash_flag=-n
377	    else
378		stash_flag=
379	    fi
380	    echo -n ' kerberos'; \
381		kerberos ${stash_flag} >> /var/log/kerberos.log &
382	    if [ "X${kadmind_server_enable}" = "XYES" ]; then
383		echo -n ' kadmind'; \
384		(sleep 20; kadmind ${stash_flag} >/dev/null 2>&1 &) &
385	    fi
386	    unset stash_flag
387    fi
388    
389    echo '.'
390    network_pass3_done=YES
391}
392