netoptions revision 45542
1#!/bin/sh -
2#
3#	$Id: rc.network,v 1.42 1999/03/28 20:36:03 imp 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 [ -z "${firewall_script}" ] ; then
104	    firewall_script="/etc/rc.firewall"
105	fi
106	if [ -f ${firewall_script} -a X"$firewall_enable" = X"YES" ]; then
107	    . ${firewall_script}
108	    echo -n 'Firewall rules loaded, starting divert daemons: '
109
110	    # Network Address Translation daemon
111	    if [ X"${natd_enable}" = X"YES" -a -n "${natd_interface}" ]; then
112		if echo ${natd_interface} | \
113		    grep -q -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'; then
114		    natd_ifarg="-a ${natd_interface}"
115		else
116		    natd_ifarg="-n ${natd_interface}"
117		fi
118		echo -n ' natd'; ${natd_program} ${natd_flags} ${natd_ifarg}
119	    fi
120	    echo '.'
121	else
122	    IPFW_DEFAULT=`ipfw l 65535`
123	    if [ "$IPFW_DEFAULT" = "65535 deny ip from any to any" ]; then
124		echo -n "Warning: kernel has firewall functionality, "
125		echo "but firewall rules are not enabled."
126		echo "         All ip services are disabled."
127	    fi
128	fi
129    fi
130
131    # Additional ATM interface configuration
132    if [ -n "${atm_pass1_done}" ]; then
133	    atm_pass2
134    fi
135
136    # Configure routing
137
138    if [ "x$defaultrouter" != "xNO" ] ; then
139	    static_routes="default ${static_routes}"
140	    route_default="default ${defaultrouter}"
141    fi
142    
143    # Set up any static routes.  This should be done before router discovery.
144    if [ "x${static_routes}" != "x" ]; then
145	    for i in ${static_routes}; do
146		    eval route_args=\$route_${i}
147		    route add ${route_args}
148	    done
149    fi
150
151    echo -n 'Additional routing options:'
152    if [ -n "$tcp_extensions" -a "x$tcp_extensions" != "xYES" ] ; then
153	    echo -n ' tcp extensions=NO'
154	    sysctl -w net.inet.tcp.rfc1323=0 >/dev/null 2>&1
155    fi
156
157    if [ -n "$log_in_vain" -a "x$log_in_vain" != "xNO" ] ; then
158	    echo -n ' log_in_vain=YES'
159	    sysctl -w net.inet.tcp.log_in_vain=1 >/dev/null 2>&1
160	    sysctl -w net.inet.udp.log_in_vain=1 >/dev/null 2>&1
161    fi
162
163    if [ X"$icmp_bmcastecho" = X"YES" ]; then
164	    echo -n ' broadcast ping responses=YES'
165	    sysctl -w net.inet.icmp.bmcastecho=1 >/dev/null 2>&1
166    fi
167
168    if [ "X$gateway_enable" = X"YES" ]; then
169	    echo -n ' IP gateway=YES'
170	    sysctl -w net.inet.ip.forwarding=1 >/dev/null 2>&1
171    fi
172    
173    if [ "X$forward_sourceroute" = X"YES" ]; then
174	    echo -n ' do source routing=YES'
175	    sysctl -w net.inet.ip.sourceroute=1 >/dev/null 2>&1
176    fi
177
178    if [ "X$accept_sourceroute" = X"YES" ]; then
179	    echo -n ' accept source routing=YES'
180	    sysctl -w net.inet.ip.accept_sourceroute=1 >/dev/null 2>&1
181    fi
182
183    if [ "X$ipxgateway_enable" = X"YES" ]; then
184	    echo -n ' IPX gateway=YES'
185	    sysctl -w net.ipx.ipx.ipxforwarding=1 >/dev/null 2>&1
186    fi
187    
188    if [ "X$arpproxy_all" = X"YES" ]; then
189	    echo -n ' enabling ARP_PROXY_ALL: '
190	    sysctl -w net.link.ether.inet.proxyall=1 2>&1
191    fi
192    echo '.'
193
194    echo -n 'routing daemons:'
195    if [ "X$router_enable" = X"YES" ]; then
196	    echo -n " ${router}";	${router} ${router_flags}
197    fi
198    
199    if [ "X$ipxrouted_enable" = X"YES" ]; then
200	    echo -n ' IPXrouted'
201	    IPXrouted ${ipxrouted_flags} > /dev/null 2>&1
202    fi
203    
204    if [ "X${mrouted_enable}" = X"YES" ]; then
205	    echo -n ' mrouted'; mrouted ${mrouted_flags}
206    fi
207
208    if [ "X$rarpd_enable" = X"YES" ]; then
209	    echo -n ' rarpd';     rarpd ${rarpd_flags}
210    fi
211    echo '.'
212    network_pass1_done=YES	# Let future generations know we made it.
213}
214
215network_pass2() {
216    echo -n 'Doing additional network setup:'
217    if [ "X${named_enable}" = X"YES" ]; then
218	    echo -n ' named';		${named_program-"named"} ${named_flags}
219    fi
220
221    if [ "X${ntpdate_enable}" = X"YES" ]; then
222	    echo -n ' ntpdate';	${ntpdate_program} ${ntpdate_flags} >/dev/null 2>&1
223    fi
224
225    if [ "X${xntpd_enable}" = X"YES" ]; then
226	    echo -n ' xntpd';	${xntpd_program} ${xntpd_flags}
227    fi
228
229    if [ "X${timed_enable}" = X"YES" ]; then
230	    echo -n ' timed';		timed ${timed_flags}
231    fi
232
233    if [ "X${portmap_enable}" = X"YES" ]; then
234	    echo -n ' portmap';		${portmap_program} ${portmap_flags}
235    fi
236
237    # Start ypserv if we're an NIS server.
238    # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server.
239    if [ "X${nis_server_enable}" = X"YES" ]; then
240	    echo -n ' ypserv'; ypserv ${nis_server_flags}
241	    
242	    if [ "X${nis_ypxfrd_enable}" = X"YES" ]; then
243		    echo -n ' rpc.ypxfrd'; rpc.ypxfrd ${nis_ypxfrd_flags}
244	    fi
245	    
246	    if [ "X${nis_yppasswdd_enable}" = X"YES" ]; then
247		    echo -n ' rpc.yppasswdd'; rpc.yppasswdd ${nis_yppasswdd_flags}
248	    fi
249    fi
250
251    # Start ypbind if we're an NIS client
252    if [ "X${nis_client_enable}" = X"YES" ]; then
253	    echo -n ' ypbind'; ypbind ${nis_client_flags}
254	    if [ "X${nis_ypset_enable}" = X"YES" ]; then
255		    echo -n ' ypset'; ypset ${nis_ypset_flags}
256	    fi
257    fi
258
259    # Start keyserv if we are running Secure RPC
260    if [ "X${keyserv_enable}" = X"YES" ]; then
261	    echo -n ' keyserv';		keyserv ${keyserv_flags}
262    fi
263    # Start ypupdated if we are running Secure RPC and we are NIS master
264    if [ "X$rpc_ypupdated_enable" = X"YES" ]; then
265	    echo -n ' rpc.ypupdated';	rpc.ypupdated
266    fi
267
268    # Start ATM daemons
269    if [ -n "${atm_pass2_done}" ]; then
270	    atm_pass3
271    fi
272
273    echo '.'
274    network_pass2_done=YES
275}
276
277network_pass3() {
278    echo -n 'Starting final network daemons:'
279
280    if [ "X${nfs_server_enable}" = X"YES" -a -r /etc/exports ]; then
281	    echo -n ' mountd'
282	    if [ "X${weak_mountd_authentication}" = X"YES" ]; then
283		    mountd_flags="-n"
284	    fi
285	    mountd ${mountd_flags}
286	    if [ "X${nfs_reserved_port_only}" = X"YES" ]; then
287		    sysctl -w vfs.nfs.nfs_privport=1 >/dev/null 2>&1
288	    fi
289	    echo -n ' nfsd';		nfsd ${nfs_server_flags}
290	    if [ "X$rpc_lockd_enable" = X"YES" ]; then
291		echo -n ' rpc.lockd';		rpc.lockd
292	    fi
293	    if [ "X$rpc_statd_enable" = X"YES" ]; then
294		echo -n ' rpc.statd';		rpc.statd
295	    fi
296    fi
297    
298    if [ "X${nfs_client_enable}" = X"YES" ]; then
299	    echo -n ' nfsiod';		nfsiod ${nfs_client_flags}
300	    if [ "X${nfs_access_cache}" != X ]; then
301		sysctl -w vfs.nfs.access_cache_timeout=${nfs_access_cache} \
302			>/dev/null 2>&1
303	    fi
304    fi
305
306    if [ "X${amd_enable}" = X"YES" ]; then
307	    echo -n ' amd'
308	    if [ "X${amd_map_program}" != X"NO" ]; then
309		amd_flags="${amd_flags} `eval ${amd_map_program}`"
310	    fi
311	    amd -p ${amd_flags} > /var/run/amd.pid 2> /dev/null
312    fi
313
314    if [ "X${rwhod_enable}" = X"YES" ]; then
315	    echo -n ' rwhod';	rwhod ${rwhod_flags}
316    fi
317
318    # Kerberos runs ONLY on the Kerberos server machine
319    if [ "X${kerberos_server_enable}" = X"YES" ]; then
320	    if [ "X${kerberos_stash}" = "XYES" ]; then
321		stash_flag=-n
322	    else
323		stash_flag=
324	    fi
325	    echo -n ' kerberos'; \
326		kerberos ${stash_flag} >> /var/log/kerberos.log &
327	    if [ "X${kadmind_server_enable}" = "XYES" ]; then
328		echo -n ' kadmind'; \
329		(sleep 20; kadmind ${stash_flag} >/dev/null 2>&1 &) &
330	    fi
331	    unset stash_flag
332    fi
333    
334    echo '.'
335    network_pass3_done=YES
336}
337