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