netoptions revision 47838
125184Sjkh#!/bin/sh -
225184Sjkh#
347838Sbrian#	$Id: rc.network,v 1.46 1999/06/05 12:06:19 bde Exp $
425184Sjkh#	From: @(#)netstart	5.9 (Berkeley) 3/30/91
525184Sjkh
625184Sjkh# Note that almost all the user-configurable behavior is no longer in
725184Sjkh# this file, but rather in /etc/rc.conf.  Please check that file
825184Sjkh# first before contemplating any changes here.  If you do need to change
925184Sjkh# this file for some reason, we would like to know about it.
1025184Sjkh
1125184Sjkh# First pass startup stuff.
1225184Sjkh
1325184Sjkhnetwork_pass1() {
1425184Sjkh    echo -n 'Doing initial network setup:'
1525184Sjkh    # Set the host name if it is not already set
1625184Sjkh    if [ -z "`hostname -s`" ] ; then
1725184Sjkh	    hostname $hostname
1825184Sjkh	    echo -n ' hostname'
1925184Sjkh    fi
2025184Sjkh
2125184Sjkh    # Set the domainname if we're using NIS
2225184Sjkh    if [ -n "$nisdomainname" -a "x$nisdomainname" != "xNO" ] ; then
2325184Sjkh	    domainname $nisdomainname
2425184Sjkh	    echo -n ' domain'
2525184Sjkh    fi
2625184Sjkh    echo '.'
2725184Sjkh
2840006Sphk    # Initial ATM interface configuration
2940006Sphk    if [ "X${atm_enable}" = X"YES" -a -f /etc/rc.atm ]; then
3040006Sphk	    . /etc/rc.atm
3140006Sphk	    atm_pass1
3240006Sphk    fi
3340006Sphk
3442621Shm    # ISDN subsystem startup
3542621Shm    if [ "X${isdn_enable}" = X"YES" -a -f /etc/rc.isdn ]; then
3642621Shm	    . /etc/rc.isdn
3742621Shm    fi
3842621Shm
3942627Sjoerg    # Special options for sppp(4) interfaces go here.  These need
4042627Sjoerg    # to go _before_ the general ifconfig section, since in the case
4142627Sjoerg    # of hardwired (no link1 flag) but required authentication, you
4242627Sjoerg    # cannot pass auth parameters down to the already running interface.
4342627Sjoerg    for ifn in ${sppp_interfaces}; do
4442627Sjoerg	    eval spppcontrol_args=\$spppconfig_${ifn}
4542627Sjoerg	    if [ -n "${spppcontrol_args}" ] ; then
4642627Sjoerg		    # The auth secrets might contain spaces; in order
4742627Sjoerg		    # to retain the quotation, we need to eval them
4842627Sjoerg		    # here.
4942627Sjoerg		    eval spppcontrol ${ifn} ${spppcontrol_args}
5042627Sjoerg	    fi
5142627Sjoerg    done
5242627Sjoerg
5325184Sjkh    # Set up all the network interfaces, calling startup scripts if needed
5425184Sjkh    for ifn in ${network_interfaces}; do
5525184Sjkh	    if [ -e /etc/start_if.${ifn} ]; then
5633682Sbrian		    . /etc/start_if.${ifn}
5725184Sjkh	    fi
5825184Sjkh	    # Do the primary ifconfig if specified
5925184Sjkh	    eval ifconfig_args=\$ifconfig_${ifn}
6025184Sjkh	    if [ -n "${ifconfig_args}" ] ; then
6125184Sjkh		    ifconfig ${ifn} ${ifconfig_args}
6225184Sjkh	    fi
6325184Sjkh	    # Check to see if aliases need to be added
6425184Sjkh	    alias=0
6525184Sjkh	    while :
6625184Sjkh	    do
6725184Sjkh		    eval ifconfig_args=\$ifconfig_${ifn}_alias${alias}
6825184Sjkh		    if [ -n "${ifconfig_args}" ]; then
6925184Sjkh			    ifconfig ${ifn} ${ifconfig_args} alias
7025184Sjkh			    alias=`expr ${alias} + 1`
7125184Sjkh		    else
7225184Sjkh			    break;
7325184Sjkh		    fi
7425184Sjkh	    done
7525184Sjkh	    # Do ipx address if specified
7625184Sjkh	    eval ifconfig_args=\$ifconfig_${ifn}_ipx
7725184Sjkh	    if [ -n "${ifconfig_args}" ]; then
7825184Sjkh		    ifconfig ${ifn} ${ifconfig_args}
7925184Sjkh	    fi
8025184Sjkh	    ifconfig ${ifn}
8125184Sjkh    done
8229300Sdanny
8329300Sdanny    # Initialize IP filtering using ipfw
8429300Sdanny    echo ""
8529300Sdanny    /sbin/ipfw -q flush > /dev/null 2>&1
8632382Salex    if [ $? = 0 ] ; then
8732382Salex	firewall_in_kernel=1
8832382Salex    else 
8929300Sdanny	firewall_in_kernel=0
9029300Sdanny    fi
9129300Sdanny
9229300Sdanny    if [ $firewall_in_kernel = 0 -a "x$firewall_enable"  = "xYES" ] ; then
9341077Speter	if kldload ipfw; then
9429300Sdanny		firewall_in_kernel=1		# module loaded successfully
9529300Sdanny		echo "Kernel firewall module loaded."
9629300Sdanny	else
9729300Sdanny		echo "Warning: firewall kernel module failed to load."
9829300Sdanny	fi
9929300Sdanny    fi
10029300Sdanny
10129300Sdanny    # Load the filters if required
10229300Sdanny    if [ $firewall_in_kernel = 1 ]; then
10345542Sdes	if [ -z "${firewall_script}" ] ; then
10445542Sdes	    firewall_script="/etc/rc.firewall"
10545542Sdes	fi
10645542Sdes	if [ -f ${firewall_script} -a X"$firewall_enable" = X"YES" ]; then
10745542Sdes	    . ${firewall_script}
10845622Sbrian	    echo -n 'Firewall rules loaded, starting divert daemons:'
10944992Sbrian
11044992Sbrian	    # Network Address Translation daemon
11144992Sbrian	    if [ X"${natd_enable}" = X"YES" -a -n "${natd_interface}" ]; then
11244992Sbrian		if echo ${natd_interface} | \
11344992Sbrian		    grep -q -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'; then
11444992Sbrian		    natd_ifarg="-a ${natd_interface}"
11544992Sbrian		else
11644992Sbrian		    natd_ifarg="-n ${natd_interface}"
11744992Sbrian		fi
11844992Sbrian		echo -n ' natd'; ${natd_program} ${natd_flags} ${natd_ifarg}
11944992Sbrian	    fi
12044992Sbrian	    echo '.'
12129300Sdanny	else
12233337Salex	    IPFW_DEFAULT=`ipfw l 65535`
12333337Salex	    if [ "$IPFW_DEFAULT" = "65535 deny ip from any to any" ]; then
12433149Salex		echo -n "Warning: kernel has firewall functionality, "
12533149Salex		echo "but firewall rules are not enabled."
12633149Salex		echo "         All ip services are disabled."
12733149Salex	    fi
12829300Sdanny	fi
12925184Sjkh    fi
13025184Sjkh
13140006Sphk    # Additional ATM interface configuration
13240006Sphk    if [ -n "${atm_pass1_done}" ]; then
13340006Sphk	    atm_pass2
13440006Sphk    fi
13540006Sphk
13629300Sdanny    # Configure routing
13729300Sdanny
13825184Sjkh    if [ "x$defaultrouter" != "xNO" ] ; then
13925184Sjkh	    static_routes="default ${static_routes}"
14025184Sjkh	    route_default="default ${defaultrouter}"
14125184Sjkh    fi
14225184Sjkh    
14325184Sjkh    # Set up any static routes.  This should be done before router discovery.
14425184Sjkh    if [ "x${static_routes}" != "x" ]; then
14525184Sjkh	    for i in ${static_routes}; do
14625184Sjkh		    eval route_args=\$route_${i}
14725184Sjkh		    route add ${route_args}
14825184Sjkh	    done
14925184Sjkh    fi
15025184Sjkh
15125184Sjkh    echo -n 'Additional routing options:'
15227218Spst    if [ -n "$tcp_extensions" -a "x$tcp_extensions" != "xYES" ] ; then
15327218Spst	    echo -n ' tcp extensions=NO'
15447755Sbde	    sysctl -w net.inet.tcp.rfc1323=0 >/dev/null
15527218Spst    fi
15627218Spst
15745096Simp    if [ -n "$log_in_vain" -a "x$log_in_vain" != "xNO" ] ; then
15845096Simp	    echo -n ' log_in_vain=YES'
15947755Sbde	    sysctl -w net.inet.tcp.log_in_vain=1 >/dev/null
16047755Sbde	    sysctl -w net.inet.udp.log_in_vain=1 >/dev/null
16145096Simp    fi
16245096Simp
16339267Sjkoshy    if [ X"$icmp_bmcastecho" = X"YES" ]; then
16439267Sjkoshy	    echo -n ' broadcast ping responses=YES'
16547755Sbde	    sysctl -w net.inet.icmp.bmcastecho=1 >/dev/null
16639267Sjkoshy    fi
16739267Sjkoshy
16825184Sjkh    if [ "X$gateway_enable" = X"YES" ]; then
16925365Sjkh	    echo -n ' IP gateway=YES'
17047755Sbde	    sysctl -w net.inet.ip.forwarding=1 >/dev/null
17125184Sjkh    fi
17225184Sjkh    
17333439Sguido    if [ "X$forward_sourceroute" = X"YES" ]; then
17433439Sguido	    echo -n ' do source routing=YES'
17547755Sbde	    sysctl -w net.inet.ip.sourceroute=1 >/dev/null
17633439Sguido    fi
17733439Sguido
17833439Sguido    if [ "X$accept_sourceroute" = X"YES" ]; then
17933439Sguido	    echo -n ' accept source routing=YES'
18047755Sbde	    sysctl -w net.inet.ip.accept_sourceroute=1 >/dev/null
18133439Sguido    fi
18233439Sguido
18347752Sphk    if [ "X$tcp_keepalive" = X"YES" ]; then
18447752Sphk	    echo -n ' TCP keepalive=YES'
18547755Sbde	    sysctl -w net.inet.tcp.always_keepalive=1 >/dev/null
18647752Sphk    fi
18747752Sphk
18825184Sjkh    if [ "X$ipxgateway_enable" = X"YES" ]; then
18925365Sjkh	    echo -n ' IPX gateway=YES'
19047755Sbde	    sysctl -w net.ipx.ipx.ipxforwarding=1 >/dev/null
19125184Sjkh    fi
19225184Sjkh    
19336174Sjkh    if [ "X$arpproxy_all" = X"YES" ]; then
19447755Sbde	    echo -n ' ARP proxyall=YES'
19547755Sbde	    sysctl -w net.link.ether.inet.proxyall=1 >/dev/null
19636174Sjkh    fi
19736174Sjkh    echo '.'
19836174Sjkh
19936174Sjkh    echo -n 'routing daemons:'
20036174Sjkh    if [ "X$router_enable" = X"YES" ]; then
20136174Sjkh	    echo -n " ${router}";	${router} ${router_flags}
20236174Sjkh    fi
20336174Sjkh    
20425184Sjkh    if [ "X$ipxrouted_enable" = X"YES" ]; then
20536174Sjkh	    echo -n ' IPXrouted'
20625184Sjkh	    IPXrouted ${ipxrouted_flags} > /dev/null 2>&1
20725184Sjkh    fi
20825765Sjkh    
20936174Sjkh    if [ "X${mrouted_enable}" = X"YES" ]; then
21036174Sjkh	    echo -n ' mrouted'; mrouted ${mrouted_flags}
21125765Sjkh    fi
21236174Sjkh
21334395Sjkh    if [ "X$rarpd_enable" = X"YES" ]; then
21434395Sjkh	    echo -n ' rarpd';     rarpd ${rarpd_flags}
21534395Sjkh    fi
21625184Sjkh    echo '.'
21725184Sjkh    network_pass1_done=YES	# Let future generations know we made it.
21825184Sjkh}
21925184Sjkh
22025184Sjkhnetwork_pass2() {
22125184Sjkh    echo -n 'Doing additional network setup:'
22225184Sjkh    if [ "X${named_enable}" = X"YES" ]; then
22332949Swollman	    echo -n ' named';		${named_program-"named"} ${named_flags}
22425184Sjkh    fi
22525184Sjkh
22631472Sobrien    if [ "X${ntpdate_enable}" = X"YES" ]; then
22735787Sandreas	    echo -n ' ntpdate';	${ntpdate_program} ${ntpdate_flags} >/dev/null 2>&1
22831472Sobrien    fi
22925184Sjkh
23031472Sobrien    if [ "X${xntpd_enable}" = X"YES" ]; then
23135787Sandreas	    echo -n ' xntpd';	${xntpd_program} ${xntpd_flags}
23225184Sjkh    fi
23325184Sjkh
23425184Sjkh    if [ "X${timed_enable}" = X"YES" ]; then
23525184Sjkh	    echo -n ' timed';		timed ${timed_flags}
23625184Sjkh    fi
23725184Sjkh
23825184Sjkh    if [ "X${portmap_enable}" = X"YES" ]; then
23944668Sjfitz	    echo -n ' portmap';		${portmap_program} ${portmap_flags}
24025184Sjkh    fi
24125184Sjkh
24225184Sjkh    # Start ypserv if we're an NIS server.
24325184Sjkh    # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server.
24425184Sjkh    if [ "X${nis_server_enable}" = X"YES" ]; then
24525184Sjkh	    echo -n ' ypserv'; ypserv ${nis_server_flags}
24625184Sjkh	    
24725184Sjkh	    if [ "X${nis_ypxfrd_enable}" = X"YES" ]; then
24825184Sjkh		    echo -n ' rpc.ypxfrd'; rpc.ypxfrd ${nis_ypxfrd_flags}
24925184Sjkh	    fi
25025184Sjkh	    
25125184Sjkh	    if [ "X${nis_yppasswdd_enable}" = X"YES" ]; then
25225184Sjkh		    echo -n ' rpc.yppasswdd'; rpc.yppasswdd ${nis_yppasswdd_flags}
25325184Sjkh	    fi
25425184Sjkh    fi
25525184Sjkh
25625184Sjkh    # Start ypbind if we're an NIS client
25725184Sjkh    if [ "X${nis_client_enable}" = X"YES" ]; then
25825184Sjkh	    echo -n ' ypbind'; ypbind ${nis_client_flags}
25925184Sjkh	    if [ "X${nis_ypset_enable}" = X"YES" ]; then
26025184Sjkh		    echo -n ' ypset'; ypset ${nis_ypset_flags}
26125184Sjkh	    fi
26225184Sjkh    fi
26325184Sjkh
26435149Smarkm    # Start keyserv if we are running Secure RPC
26535149Smarkm    if [ "X${keyserv_enable}" = X"YES" ]; then
26635149Smarkm	    echo -n ' keyserv';		keyserv ${keyserv_flags}
26735149Smarkm    fi
26835149Smarkm    # Start ypupdated if we are running Secure RPC and we are NIS master
26935149Smarkm    if [ "X$rpc_ypupdated_enable" = X"YES" ]; then
27035149Smarkm	    echo -n ' rpc.ypupdated';	rpc.ypupdated
27135149Smarkm    fi
27235149Smarkm
27340006Sphk    # Start ATM daemons
27440006Sphk    if [ -n "${atm_pass2_done}" ]; then
27540006Sphk	    atm_pass3
27640006Sphk    fi
27740006Sphk
27825184Sjkh    echo '.'
27925184Sjkh    network_pass2_done=YES
28025184Sjkh}
28125184Sjkh
28225184Sjkhnetwork_pass3() {
28325184Sjkh    echo -n 'Starting final network daemons:'
28425184Sjkh
28525184Sjkh    if [ "X${nfs_server_enable}" = X"YES" -a -r /etc/exports ]; then
28625184Sjkh	    echo -n ' mountd'
28725184Sjkh	    if [ "X${weak_mountd_authentication}" = X"YES" ]; then
28825184Sjkh		    mountd_flags="-n"
28925184Sjkh	    fi
29025184Sjkh	    mountd ${mountd_flags}
29125184Sjkh	    if [ "X${nfs_reserved_port_only}" = X"YES" ]; then
29247755Sbde		    echo -n ' NFS on reserved port only=YES'
29347755Sbde		    sysctl -w vfs.nfs.nfs_privport=1 >/dev/null
29425184Sjkh	    fi
29525916Sjkh	    echo -n ' nfsd';		nfsd ${nfs_server_flags}
29625184Sjkh	    if [ "X$rpc_lockd_enable" = X"YES" ]; then
29725184Sjkh		echo -n ' rpc.lockd';		rpc.lockd
29825184Sjkh	    fi
29925184Sjkh	    if [ "X$rpc_statd_enable" = X"YES" ]; then
30025184Sjkh		echo -n ' rpc.statd';		rpc.statd
30125184Sjkh	    fi
30225184Sjkh    fi
30325184Sjkh    
30425184Sjkh    if [ "X${nfs_client_enable}" = X"YES" ]; then
30525916Sjkh	    echo -n ' nfsiod';		nfsiod ${nfs_client_flags}
30641371Sjkoshy	    if [ "X${nfs_access_cache}" != X ]; then
30747755Sbde		echo -n " NFS access cache time=${nfs_access_cache}"
30841371Sjkoshy		sysctl -w vfs.nfs.access_cache_timeout=${nfs_access_cache} \
30947755Sbde		    >/dev/null
31041185Smsmith	    fi
31125184Sjkh    fi
31225184Sjkh
31325184Sjkh    if [ "X${amd_enable}" = X"YES" ]; then
31425184Sjkh	    echo -n ' amd'
31535459Sphk	    if [ "X${amd_map_program}" != X"NO" ]; then
31639380Scracauer		amd_flags="${amd_flags} `eval ${amd_map_program}`"
31735459Sphk	    fi
31847838Sbrian	    if [ -n "$amd_flags" ]
31947838Sbrian	    then
32047838Sbrian	      amd -p ${amd_flags} > /var/run/amd.pid 2> /dev/null
32147838Sbrian	    else
32247838Sbrian	      amd 2> /dev/null
32347838Sbrian	    fi
32425184Sjkh    fi
32525184Sjkh
32625184Sjkh    if [ "X${rwhod_enable}" = X"YES" ]; then
32742270Sjkh	    echo -n ' rwhod';	rwhod ${rwhod_flags}
32825184Sjkh    fi
32925184Sjkh
33025184Sjkh    # Kerberos runs ONLY on the Kerberos server machine
33125184Sjkh    if [ "X${kerberos_server_enable}" = X"YES" ]; then
33231033Ssef	    if [ "X${kerberos_stash}" = "XYES" ]; then
33331033Ssef		stash_flag=-n
33431033Ssef	    else
33531033Ssef		stash_flag=
33631033Ssef	    fi
33731033Ssef	    echo -n ' kerberos'; \
33838316Sphk		kerberos ${stash_flag} >> /var/log/kerberos.log &
33931033Ssef	    if [ "X${kadmind_server_enable}" = "XYES" ]; then
34031033Ssef		echo -n ' kadmind'; \
34138316Sphk		(sleep 20; kadmind ${stash_flag} >/dev/null 2>&1 &) &
34231033Ssef	    fi
34331033Ssef	    unset stash_flag
34425184Sjkh    fi
34525184Sjkh    
34625184Sjkh    echo '.'
34725184Sjkh    network_pass3_done=YES
34825184Sjkh}
349