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