routing revision 42270
13062Scindi#!/bin/sh -
23062Scindi#
33062Scindi#	$Id: rc.network,v 1.36 1998/11/27 07:06:11 jkoshy Exp $
43062Scindi#	From: @(#)netstart	5.9 (Berkeley) 3/30/91
53062Scindi
63062Scindi# Note that almost all the user-configurable behavior is no longer in
73062Scindi# this file, but rather in /etc/rc.conf.  Please check that file
83062Scindi# first before contemplating any changes here.  If you do need to change
93062Scindi# this file for some reason, we would like to know about it.
103062Scindi
113062Scindi# First pass startup stuff.
123062Scindi
133062Scindinetwork_pass1() {
143062Scindi    echo -n 'Doing initial network setup:'
153062Scindi    # Set the host name if it is not already set
163062Scindi    if [ -z "`hostname -s`" ] ; then
173062Scindi	    hostname $hostname
183062Scindi	    echo -n ' hostname'
193062Scindi    fi
203062Scindi
213062Scindi    # Set the domainname if we're using NIS
223062Scindi    if [ -n "$nisdomainname" -a "x$nisdomainname" != "xNO" ] ; then
236828Stsien	    domainname $nisdomainname
243062Scindi	    echo -n ' domain'
253062Scindi    fi
263062Scindi    echo '.'
273062Scindi
283062Scindi    # Initial ATM interface configuration
293062Scindi    if [ "X${atm_enable}" = X"YES" -a -f /etc/rc.atm ]; then
303062Scindi	    . /etc/rc.atm
313062Scindi	    atm_pass1
323062Scindi    fi
333062Scindi
346869Seschrock    # Set up all the network interfaces, calling startup scripts if needed
354087Scindi    for ifn in ${network_interfaces}; do
364087Scindi	    if [ -e /etc/start_if.${ifn} ]; then
374087Scindi		    . /etc/start_if.${ifn}
384087Scindi	    fi
394087Scindi	    # Do the primary ifconfig if specified
404087Scindi	    eval ifconfig_args=\$ifconfig_${ifn}
414087Scindi	    if [ -n "${ifconfig_args}" ] ; then
424087Scindi		    ifconfig ${ifn} ${ifconfig_args}
434087Scindi	    fi
444087Scindi	    # Check to see if aliases need to be added
454087Scindi	    alias=0
464087Scindi	    while :
474087Scindi	    do
484087Scindi		    eval ifconfig_args=\$ifconfig_${ifn}_alias${alias}
494087Scindi		    if [ -n "${ifconfig_args}" ]; then
504087Scindi			    ifconfig ${ifn} ${ifconfig_args} alias
514087Scindi			    alias=`expr ${alias} + 1`
524087Scindi		    else
534087Scindi			    break;
544087Scindi		    fi
554087Scindi	    done
563062Scindi	    # Do ipx address if specified
573062Scindi	    eval ifconfig_args=\$ifconfig_${ifn}_ipx
583062Scindi	    if [ -n "${ifconfig_args}" ]; then
593062Scindi		    ifconfig ${ifn} ${ifconfig_args}
603062Scindi	    fi
613062Scindi	    ifconfig ${ifn}
623062Scindi    done
633062Scindi
643062Scindi    # Initialize IP filtering using ipfw
654087Scindi    echo ""
664087Scindi    /sbin/ipfw -q flush > /dev/null 2>&1
674087Scindi    if [ $? = 0 ] ; then
687243Srobj	firewall_in_kernel=1
693062Scindi    else 
703062Scindi	firewall_in_kernel=0
713062Scindi    fi
723062Scindi
733062Scindi    if [ $firewall_in_kernel = 0 -a "x$firewall_enable"  = "xYES" ] ; then
743062Scindi	if kldload ipfw; then
753062Scindi		firewall_in_kernel=1		# module loaded successfully
764087Scindi		echo "Kernel firewall module loaded."
774087Scindi	else
784087Scindi		echo "Warning: firewall kernel module failed to load."
797243Srobj	fi
803062Scindi    fi
814087Scindi
824087Scindi    # Load the filters if required
834087Scindi    if [ $firewall_in_kernel = 1 ]; then
844087Scindi	if [ -n "$firewall_enable" -a -f /etc/rc.firewall -a \
854087Scindi		"x$firewall_enable" = "xYES" ] ; then
864087Scindi	    . /etc/rc.firewall
874087Scindi	    echo "Firewall rules loaded."
884087Scindi	else
894087Scindi	    IPFW_DEFAULT=`ipfw l 65535`
907243Srobj	    if [ "$IPFW_DEFAULT" = "65535 deny ip from any to any" ]; then
914087Scindi		echo -n "Warning: kernel has firewall functionality, "
927732SRobert.Johnston@Sun.COM		echo "but firewall rules are not enabled."
933062Scindi		echo "         All ip services are disabled."
943062Scindi	    fi
953062Scindi	fi
963062Scindi    fi
973062Scindi
983062Scindi    # Additional ATM interface configuration
993062Scindi    if [ -n "${atm_pass1_done}" ]; then
1003062Scindi	    atm_pass2
1013062Scindi    fi
1023062Scindi
1034087Scindi    # Configure routing
1044087Scindi
1054087Scindi    if [ "x$defaultrouter" != "xNO" ] ; then
1064087Scindi	    static_routes="default ${static_routes}"
1073062Scindi	    route_default="default ${defaultrouter}"
1083062Scindi    fi
1093062Scindi    
1103062Scindi    # Set up any static routes.  This should be done before router discovery.
1113062Scindi    if [ "x${static_routes}" != "x" ]; then
1123062Scindi	    for i in ${static_routes}; do
113		    eval route_args=\$route_${i}
114		    route add ${route_args}
115	    done
116    fi
117
118    echo -n 'Additional routing options:'
119    if [ -n "$tcp_extensions" -a "x$tcp_extensions" != "xYES" ] ; then
120	    echo -n ' tcp extensions=NO'
121	    sysctl -w net.inet.tcp.rfc1323=0 >/dev/null 2>&1
122    fi
123
124    if [ X"$icmp_bmcastecho" = X"YES" ]; then
125	    echo -n ' broadcast ping responses=YES'
126	    sysctl -w net.inet.icmp.bmcastecho=1 >/dev/null 2>&1
127    fi
128
129    if [ "X$gateway_enable" = X"YES" ]; then
130	    echo -n ' IP gateway=YES'
131	    sysctl -w net.inet.ip.forwarding=1 >/dev/null 2>&1
132    fi
133    
134    if [ "X$forward_sourceroute" = X"YES" ]; then
135	    echo -n ' do source routing=YES'
136	    sysctl -w net.inet.ip.sourceroute=1 >/dev/null 2>&1
137    fi
138
139    if [ "X$accept_sourceroute" = X"YES" ]; then
140	    echo -n ' accept source routing=YES'
141	    sysctl -w net.inet.ip.accept_sourceroute=1 >/dev/null 2>&1
142    fi
143
144    if [ "X$ipxgateway_enable" = X"YES" ]; then
145	    echo -n ' IPX gateway=YES'
146	    sysctl -w net.ipx.ipx.ipxforwarding=1 >/dev/null 2>&1
147    fi
148    
149    if [ "X$arpproxy_all" = X"YES" ]; then
150	    echo -n ' enabling ARP_PROXY_ALL: '
151	    sysctl -w net.link.ether.inet.proxyall=1 2>&1
152    fi
153    echo '.'
154
155    echo -n 'routing daemons:'
156    if [ "X$router_enable" = X"YES" ]; then
157	    echo -n " ${router}";	${router} ${router_flags}
158    fi
159    
160    if [ "X$ipxrouted_enable" = X"YES" ]; then
161	    echo -n ' IPXrouted'
162	    IPXrouted ${ipxrouted_flags} > /dev/null 2>&1
163    fi
164    
165    if [ "X${mrouted_enable}" = X"YES" ]; then
166	    echo -n ' mrouted'; mrouted ${mrouted_flags}
167    fi
168
169    if [ "X$rarpd_enable" = X"YES" ]; then
170	    echo -n ' rarpd';     rarpd ${rarpd_flags}
171    fi
172    echo '.'
173    network_pass1_done=YES	# Let future generations know we made it.
174}
175
176network_pass2() {
177    echo -n 'Doing additional network setup:'
178    if [ "X${named_enable}" = X"YES" ]; then
179	    echo -n ' named';		${named_program-"named"} ${named_flags}
180    fi
181
182    if [ "X${ntpdate_enable}" = X"YES" ]; then
183	    echo -n ' ntpdate';	${ntpdate_program} ${ntpdate_flags} >/dev/null 2>&1
184    fi
185
186    if [ "X${xntpd_enable}" = X"YES" ]; then
187	    echo -n ' xntpd';	${xntpd_program} ${xntpd_flags}
188    fi
189
190    if [ "X${timed_enable}" = X"YES" ]; then
191	    echo -n ' timed';		timed ${timed_flags}
192    fi
193
194    if [ "X${portmap_enable}" = X"YES" ]; then
195	    echo -n ' portmap';		portmap ${portmap_flags}
196    fi
197
198    # Start ypserv if we're an NIS server.
199    # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server.
200    if [ "X${nis_server_enable}" = X"YES" ]; then
201	    echo -n ' ypserv'; ypserv ${nis_server_flags}
202	    
203	    if [ "X${nis_ypxfrd_enable}" = X"YES" ]; then
204		    echo -n ' rpc.ypxfrd'; rpc.ypxfrd ${nis_ypxfrd_flags}
205	    fi
206	    
207	    if [ "X${nis_yppasswdd_enable}" = X"YES" ]; then
208		    echo -n ' rpc.yppasswdd'; rpc.yppasswdd ${nis_yppasswdd_flags}
209	    fi
210    fi
211
212    # Start ypbind if we're an NIS client
213    if [ "X${nis_client_enable}" = X"YES" ]; then
214	    echo -n ' ypbind'; ypbind ${nis_client_flags}
215	    if [ "X${nis_ypset_enable}" = X"YES" ]; then
216		    echo -n ' ypset'; ypset ${nis_ypset_flags}
217	    fi
218    fi
219
220    # Start keyserv if we are running Secure RPC
221    if [ "X${keyserv_enable}" = X"YES" ]; then
222	    echo -n ' keyserv';		keyserv ${keyserv_flags}
223    fi
224    # Start ypupdated if we are running Secure RPC and we are NIS master
225    if [ "X$rpc_ypupdated_enable" = X"YES" ]; then
226	    echo -n ' rpc.ypupdated';	rpc.ypupdated
227    fi
228
229    # Start ATM daemons
230    if [ -n "${atm_pass2_done}" ]; then
231	    atm_pass3
232    fi
233
234    echo '.'
235    network_pass2_done=YES
236}
237
238network_pass3() {
239    echo -n 'Starting final network daemons:'
240
241    if [ "X${nfs_server_enable}" = X"YES" -a -r /etc/exports ]; then
242	    echo -n ' mountd'
243	    if [ "X${weak_mountd_authentication}" = X"YES" ]; then
244		    mountd_flags="-n"
245	    fi
246	    mountd ${mountd_flags}
247	    if [ "X${nfs_reserved_port_only}" = X"YES" ]; then
248		    sysctl -w vfs.nfs.nfs_privport=1 >/dev/null 2>&1
249	    fi
250	    echo -n ' nfsd';		nfsd ${nfs_server_flags}
251	    if [ "X$rpc_lockd_enable" = X"YES" ]; then
252		echo -n ' rpc.lockd';		rpc.lockd
253	    fi
254	    if [ "X$rpc_statd_enable" = X"YES" ]; then
255		echo -n ' rpc.statd';		rpc.statd
256	    fi
257    fi
258    
259    if [ "X${nfs_client_enable}" = X"YES" ]; then
260	    echo -n ' nfsiod';		nfsiod ${nfs_client_flags}
261	    if [ "X${nfs_access_cache}" != X ]; then
262		sysctl -w vfs.nfs.access_cache_timeout=${nfs_access_cache} \
263			>/dev/null 2>&1
264	    fi
265    fi
266
267    if [ "X${amd_enable}" = X"YES" ]; then
268	    echo -n ' amd'
269	    if [ "X${amd_map_program}" != X"NO" ]; then
270		amd_flags="${amd_flags} `eval ${amd_map_program}`"
271	    fi
272	    amd -p ${amd_flags} > /var/run/amd.pid 2> /dev/null
273    fi
274
275    if [ "X${rwhod_enable}" = X"YES" ]; then
276	    echo -n ' rwhod';	rwhod ${rwhod_flags}
277    fi
278
279    # Kerberos runs ONLY on the Kerberos server machine
280    if [ "X${kerberos_server_enable}" = X"YES" ]; then
281	    if [ "X${kerberos_stash}" = "XYES" ]; then
282		stash_flag=-n
283	    else
284		stash_flag=
285	    fi
286	    echo -n ' kerberos'; \
287		kerberos ${stash_flag} >> /var/log/kerberos.log &
288	    if [ "X${kadmind_server_enable}" = "XYES" ]; then
289		echo -n ' kadmind'; \
290		(sleep 20; kadmind ${stash_flag} >/dev/null 2>&1 &) &
291	    fi
292	    unset stash_flag
293    fi
294    
295    # Network Address Translation daemon
296       if [ "X${natd_enable}" = X"YES" -a X"${natd_interface}" != X"" \
297               -a X"${firewall_enable}" = X"YES" ]; then
298               if echo ${natd_interface} | \
299                       grep -q -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'; then
300                       natd_ifarg="-a ${natd_interface}"
301               else
302                       natd_ifarg="-n ${natd_interface}"
303               fi
304               echo -n ' natd'; natd ${natd_flags} ${natd_ifarg}
305       fi
306
307    echo '.'
308    network_pass3_done=YES
309}
310