]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.network
Add libufs to dependencies.
[FreeBSD/FreeBSD.git] / etc / rc.network
1 #!/bin/sh -
2 #
3 # Copyright (c) 1993  The FreeBSD Project
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 #    notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 #    notice, this list of conditions and the following disclaimer in the
13 #    documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 # SUCH DAMAGE.
26 #
27 # $FreeBSD$
28 #       From: @(#)netstart      5.9 (Berkeley) 3/30/91
29 #
30
31 # Note that almost all of the user-configurable behavior is no longer in
32 # this file, but rather in /etc/defaults/rc.conf.  Please check that file
33 # first before contemplating any changes here.  If you do need to change
34 # this file for some reason, we would like to know about it.
35
36 # First pass startup stuff.
37 #
38 network_pass1() {
39         echo -n 'Doing initial network setup:'
40
41         # Generate host.conf for compatibility
42         #
43         if [ -f "/etc/nsswitch.conf" ]; then
44                 echo -n ' host.conf'
45                 generate_host_conf /etc/nsswitch.conf /etc/host.conf
46         fi
47
48         # Convert host.conf to nsswitch.conf if necessary
49         #
50         if [ -f "/etc/host.conf" -a ! -f "/etc/nsswitch.conf" ]; then
51                 echo ''
52                 echo 'Warning: /etc/host.conf is no longer used'
53                 echo '  /etc/nsswitch.conf will be created for you'
54                 convert_host_conf /etc/host.conf /etc/nsswitch.conf
55         fi
56
57         # Set the host name if it is not already set
58         #
59         if [ -z "`hostname -s`" ]; then
60                 hostname ${hostname}
61                 echo -n ' hostname'
62         fi
63
64         # Establish ipfilter ruleset as early as possible (best in
65         # addition to IPFILTER_DEFAULT_BLOCK in the kernel config file)
66
67         # check whether ipfilter and/or ipnat is enabled
68         ipfilter_active="NO"
69         case ${ipfilter_enable} in
70         [Yy][Ee][Ss])
71                 ipfilter_active="YES"
72                 ;;
73         esac
74         case ${ipnat_enable} in
75         [Yy][Ee][Ss])
76                 ipfilter_active="YES"
77                 ;;
78         esac
79         case ${ipfilter_active} in
80         [Yy][Ee][Ss])
81                 # load ipfilter kernel module if needed
82                 if ! sysctl net.inet.ipf.fr_pass > /dev/null 2>&1; then
83                         if kldload ipl; then
84                                 echo 'IP-filter module loaded.'
85                         else
86                                 echo 'Warning: IP-filter module failed to load.'
87                                 # avoid further errors
88                                 ipfilter_active="NO"
89                                 ipmon_enable="NO"
90                                 ipfilter_enable="NO"
91                                 ipnat_enable="NO"
92                                 ipfs_enable="NO"
93                         fi
94                 fi
95                 # start ipmon before loading any rules
96                 case "${ipmon_enable}" in
97                 [Yy][Ee][Ss])
98                         echo -n ' ipmon'
99                         ${ipmon_program:-/sbin/ipmon} ${ipmon_flags}
100                         ;;
101                 esac
102                 case "${ipfilter_enable}" in
103                 [Yy][Ee][Ss])
104                         if [ -r "${ipfilter_rules}" -o \
105                              -r "${ipv6_ipfilter_rules}" ]; then
106                                 echo -n ' ipfilter'
107                                 ${ipfilter_program:-/sbin/ipf} -Fa
108                                 if [ -r "${ipfilter_rules}" ]; then
109                                         ${ipfilter_program:-/sbin/ipf} \
110                                             -f "${ipfilter_rules}" \
111                                             ${ipfilter_flags}
112                                 fi
113                                 if [ -r "${ipv6_ipfilter_rules}" ]; then
114                                         ${ipfilter_program:-/sbin/ipf} -6 \
115                                             -f "${ipv6_ipfilter_rules}" \
116                                             ${ipfilter_flags}
117                                 fi
118                         else
119                                 ipfilter_enable="NO"
120                                 echo -n ' NO IPF RULES'
121                         fi
122                         ;;
123                 esac
124                 case "${ipnat_enable}" in
125                 [Yy][Ee][Ss])
126                         if [ -r "${ipnat_rules}" ]; then
127                                 echo -n ' ipnat'
128                                 eval ${ipnat_program:-/sbin/ipnat} -CF -f \
129                                     "${ipnat_rules}" ${ipnat_flags}
130                         else
131                                 ipnat_enable="NO"
132                                 echo -n ' NO IPNAT RULES'
133                         fi
134                         ;;
135                 esac
136                 # restore filter/NAT state tables after loading the rules
137                 case "${ipfs_enable}" in
138                 [Yy][Ee][Ss])
139                         if [ -r "/var/db/ipf/ipstate.ipf" ]; then
140                                 echo -n ' ipfs'
141                                 ${ipfs_program:-/sbin/ipfs} -R ${ipfs_flags}
142                                 # remove files to avoid reloading old state
143                                 # after an ungraceful shutdown
144                                 rm -f /var/db/ipf/ipstate.ipf
145                                 rm -f /var/db/ipf/ipnat.ipf
146                         fi
147                         ;;
148                 esac
149                 ;;
150         esac
151
152         # Set the domainname if we're using NIS
153         #
154         case ${nisdomainname} in
155         [Nn][Oo] | '')
156                 ;;
157         *)
158                 domainname ${nisdomainname}
159                 echo -n ' domain'
160                 ;;
161         esac
162
163         echo '.'
164
165         # Initial ATM interface configuration
166         #
167         case ${atm_enable} in
168         [Yy][Ee][Ss])
169                 if [ -r /etc/rc.atm ]; then
170                         . /etc/rc.atm
171                         atm_pass1
172                 fi
173                 ;;
174         esac
175
176         # Attempt to create cloned interfaces.
177         for ifn in ${cloned_interfaces}; do
178                 ifconfig ${ifn} create
179         done
180
181         # Special options for sppp(4) interfaces go here.  These need
182         # to go _before_ the general ifconfig section, since in the case
183         # of hardwired (no link1 flag) but required authentication, you
184         # cannot pass auth parameters down to the already running interface.
185         #
186         for ifn in ${sppp_interfaces}; do
187                 eval spppcontrol_args=\$spppconfig_${ifn}
188                 if [ -n "${spppcontrol_args}" ]; then
189                         # The auth secrets might contain spaces; in order
190                         # to retain the quotation, we need to eval them
191                         # here.
192                         eval spppcontrol ${ifn} ${spppcontrol_args}
193                 fi
194         done
195
196         # gifconfig
197         network_gif_setup
198
199         # Set up all the network interfaces, calling startup scripts if needed
200         #
201         case ${network_interfaces} in
202         [Aa][Uu][Tt][Oo])
203                 network_interfaces="`ifconfig -l`"
204                 ;;
205         *)
206                 network_interfaces="${network_interfaces} ${cloned_interfaces}"
207                 ;;
208         esac
209
210         dhcp_interfaces=""
211         for ifn in ${network_interfaces}; do
212                 _up=`ifconfig ${ifn} | head -1 | grep -v LOOPBACK | grep UP,`
213                 if [ "$_up" != "" ]; then
214                         # Interface is already up, so ignore it.
215                         continue;
216                 fi
217
218                 if [ -r /etc/start_if.${ifn} ]; then
219                         . /etc/start_if.${ifn}
220                         eval showstat_$ifn=1
221                 fi
222
223                 # Do the primary ifconfig if specified
224                 #
225                 eval ifconfig_args=\$ifconfig_${ifn}
226
227                 case ${ifconfig_args} in
228                 '')
229                         ;;
230                 [Dd][Hh][Cc][Pp])
231                         # DHCP inits are done all in one go below
232                         dhcp_interfaces="$dhcp_interfaces $ifn"
233                         eval showstat_$ifn=1
234                         ;;
235                 *)
236                         ifconfig ${ifn} ${ifconfig_args}
237                         eval showstat_$ifn=1
238                         ;;
239                 esac
240         done
241
242         if [ ! -z "${dhcp_interfaces}" ]; then
243                 ${dhcp_program:-/sbin/dhclient} ${dhcp_flags} ${dhcp_interfaces}
244         fi
245
246         for ifn in ${network_interfaces}; do
247                 # Check to see if aliases need to be added
248                 #
249                 alias=0
250                 while : ; do
251                         eval ifconfig_args=\$ifconfig_${ifn}_alias${alias}
252                         if [ -n "${ifconfig_args}" ]; then
253                                 ifconfig ${ifn} ${ifconfig_args} alias
254                                 eval showstat_$ifn=1
255                                 alias=$((${alias} + 1))
256                         else
257                                 break;
258                         fi
259                 done
260
261                 # Do ipx address if specified
262                 #
263                 eval ifconfig_args=\$ifconfig_${ifn}_ipx
264                 if [ -n "${ifconfig_args}" ]; then
265                         ifconfig ${ifn} ${ifconfig_args}
266                         eval showstat_$ifn=1
267                 fi
268         done
269
270         for ifn in ${network_interfaces}; do
271                 eval showstat=\$showstat_${ifn}
272                 if [ ! -z ${showstat} ]; then
273                         ifconfig ${ifn}
274                 fi
275         done
276
277         # ISDN subsystem startup
278         #
279         case ${isdn_enable} in
280         [Yy][Ee][Ss])
281                 if [ -r /etc/rc.isdn ]; then
282                         . /etc/rc.isdn
283                 fi
284                 ;;
285         esac
286
287         # Start user ppp if required.  This must happen before natd.
288         #
289         case ${ppp_enable} in
290         [Yy][Ee][Ss])
291                 # Establish ppp mode.
292                 #
293                 if [ "${ppp_mode}" != "ddial" -a "${ppp_mode}" != "direct" \
294                         -a "${ppp_mode}" != "dedicated" \
295                         -a "${ppp_mode}" != "background" ]; then
296                         ppp_mode="auto"
297                 fi
298
299                 ppp_command="/usr/sbin/ppp -quiet -${ppp_mode}"
300
301                 # Switch on NAT mode?
302                 #
303                 case ${ppp_nat} in
304                 [Yy][Ee][Ss])
305                         ppp_command="${ppp_command} -nat"
306                         ;;
307                 esac
308
309                 ppp_command="${ppp_command} ${ppp_profile}"
310
311                 echo "Starting ppp as \"${ppp_user}\""
312                 su -m ${ppp_user} -c "exec ${ppp_command}"
313                 ;;
314         esac
315
316         # Re-Sync ipfilter so it picks up any new network interfaces
317         #
318         case ${ipfilter_active} in
319         [Yy][Ee][Ss])
320                 ${ipfilter_program:-/sbin/ipf} -y ${ipfilter_flags} >/dev/null
321                 ;;
322         esac
323         unset ipfilter_active
324
325         # Initialize IP filtering using ipfw
326         #
327         if /sbin/ipfw -q flush > /dev/null 2>&1; then
328                 firewall_in_kernel=1
329         else
330                 firewall_in_kernel=0
331         fi
332
333         case ${firewall_enable} in
334         [Yy][Ee][Ss])
335                 if [ "${firewall_in_kernel}" -eq 0 ] && kldload ipfw; then
336                         firewall_in_kernel=1
337                         echo 'Kernel firewall module loaded'
338                 elif [ "${firewall_in_kernel}" -eq 0 ]; then
339                         echo 'Warning: firewall kernel module failed to load'
340                 fi
341                 ;;
342         esac
343
344         # Load the filters if required
345         #
346         case ${firewall_in_kernel} in
347         1)
348                 if [ -z "${firewall_script}" ]; then
349                         firewall_script=/etc/rc.firewall
350                 fi
351
352                 case ${firewall_enable} in
353                 [Yy][Ee][Ss])
354                         if [ -r "${firewall_script}" ]; then
355                                 . "${firewall_script}"
356                                 echo -n 'Firewall rules loaded, starting divert daemons:'
357
358                                 # Network Address Translation daemon
359                                 #
360                                 case ${natd_enable} in
361                                 [Yy][Ee][Ss])
362                                         if [ -n "${natd_interface}" ]; then
363                                                 if echo ${natd_interface} | \
364                                                         grep -q -E '^[0-9]+(\.[0-9]+){0,3}$'; then
365                                                         natd_flags="$natd_flags -a ${natd_interface}"
366                                                 else
367                                                         natd_flags="$natd_flags -n ${natd_interface}"
368                                                 fi
369                                         fi
370                                         echo -n ' natd'; ${natd_program:-/sbin/natd} ${natd_flags}
371                                         ;;
372                                 esac
373
374                                 echo '.'
375
376                         elif [ "`ipfw l 65535`" = "65535 deny ip from any to any" ]; then
377                                 echo 'Warning: kernel has firewall functionality,' \
378                                      'but firewall rules are not enabled.'
379                                 echo '           All ip services are disabled.'
380                         fi
381
382                         case ${firewall_logging} in
383                         [Yy][Ee][Ss] | '')
384                                 echo 'Firewall logging=YES'
385                                 sysctl net.inet.ip.fw.verbose=1 >/dev/null
386                                 ;;
387                         *)
388                                 ;;
389                         esac
390
391                         ;;
392                 esac
393                 ;;
394         esac
395
396         # Additional ATM interface configuration
397         #
398         if [ -n "${atm_pass1_done}" ]; then
399                 atm_pass2
400         fi
401
402         # Configure routing
403         #
404         case ${defaultrouter} in
405         [Nn][Oo] | '')
406                 ;;
407         *)
408                 static_routes="default ${static_routes}"
409                 route_default="default ${defaultrouter}"
410                 ;;
411         esac
412
413         # Set up any static routes.  This should be done before router discovery.
414         #
415         if [ -n "${static_routes}" ]; then
416                 for i in ${static_routes}; do
417                         eval route_args=\$route_${i}
418                         route add ${route_args}
419                 done
420         fi
421
422         echo -n 'Additional routing options:'
423         case ${tcp_extensions} in
424         [Yy][Ee][Ss] | '')
425                 ;;
426         *)
427                 echo -n ' tcp extensions=NO'
428                 sysctl net.inet.tcp.rfc1323=0 >/dev/null
429                 ;;
430         esac
431
432         case ${icmp_bmcastecho} in
433         [Yy][Ee][Ss])
434                 echo -n ' broadcast ping responses=YES'
435                 sysctl net.inet.icmp.bmcastecho=1 >/dev/null
436                 ;;
437         esac
438
439         case ${icmp_drop_redirect} in
440         [Yy][Ee][Ss])
441                 echo -n ' ignore ICMP redirect=YES'
442                 sysctl net.inet.icmp.drop_redirect=1 >/dev/null
443                 ;;
444         esac
445
446         case ${icmp_log_redirect} in
447         [Yy][Ee][Ss])
448                 echo -n ' log ICMP redirect=YES'
449                 sysctl net.inet.icmp.log_redirect=1 >/dev/null
450                 ;;
451         esac
452
453         case ${gateway_enable} in
454         [Yy][Ee][Ss])
455                 echo -n ' IP gateway=YES'
456                 sysctl net.inet.ip.forwarding=1 >/dev/null
457                 ;;
458         esac
459
460         case ${forward_sourceroute} in
461         [Yy][Ee][Ss])
462                 echo -n ' do source routing=YES'
463                 sysctl net.inet.ip.sourceroute=1 >/dev/null
464                 ;;
465         esac
466
467         case ${accept_sourceroute} in
468         [Yy][Ee][Ss])
469                 echo -n ' accept source routing=YES'
470                 sysctl net.inet.ip.accept_sourceroute=1 >/dev/null
471                 ;;
472         esac
473
474         case ${tcp_keepalive} in
475         [Nn][Oo])
476                 echo -n ' TCP keepalive=NO'
477                 sysctl net.inet.tcp.always_keepalive=0 >/dev/null
478                 ;;
479         esac
480
481         case ${tcp_drop_synfin} in
482         [Yy][Ee][Ss])
483                 echo -n ' drop SYN+FIN packets=YES'
484                 sysctl net.inet.tcp.drop_synfin=1 >/dev/null
485                 ;;
486         esac
487
488         case ${ipxgateway_enable} in
489         [Yy][Ee][Ss])
490                 echo -n ' IPX gateway=YES'
491                 sysctl net.ipx.ipx.ipxforwarding=1 >/dev/null
492                 ;;
493         esac
494
495         case ${arpproxy_all} in
496         [Yy][Ee][Ss])
497                 echo -n ' ARP proxyall=YES'
498                 sysctl net.link.ether.inet.proxyall=1 >/dev/null
499                 ;;
500         esac
501
502         case ${ip_portrange_first} in
503         [Nn][Oo] | '')
504                 ;;
505         *)
506                 echo -n " ip_portrange_first=$ip_portrange_first"
507                 sysctl net.inet.ip.portrange.first=$ip_portrange_first >/dev/null
508                 ;;
509         esac
510
511         case ${ip_portrange_last} in
512         [Nn][Oo] | '')
513                 ;;
514         *)
515                 echo -n " ip_portrange_last=$ip_portrange_last"
516                 sysctl net.inet.ip.portrange.last=$ip_portrange_last >/dev/null
517                 ;;
518         esac
519
520         echo '.'
521
522         case ${ipsec_enable} in
523         [Yy][Ee][Ss])
524                 if [ -f ${ipsec_file} ]; then
525                     echo ' ipsec: enabled'
526                     setkey -f ${ipsec_file}
527                 else
528                     echo ' ipsec: file not found'
529                 fi
530                 ;;
531         esac
532
533         echo -n 'Routing daemons:'
534         case ${router_enable} in
535         [Yy][Ee][Ss])
536                 echo -n " ${router}";   ${router} ${router_flags}
537                 ;;
538         esac
539
540         case ${ipxrouted_enable} in
541         [Yy][Ee][Ss])
542                 echo -n ' IPXrouted'
543                 IPXrouted ${ipxrouted_flags} > /dev/null 2>&1
544                 ;;
545         esac
546
547         case ${mrouted_enable} in
548         [Yy][Ee][Ss])
549                 echo -n ' mrouted';     mrouted ${mrouted_flags}
550                 ;;
551         esac
552
553         case ${rarpd_enable} in
554         [Yy][Ee][Ss])
555                 echo -n ' rarpd';       rarpd ${rarpd_flags}
556                 ;;
557         esac
558         echo '.'
559
560         # Let future generations know we made it.
561         #
562         network_pass1_done=YES
563 }
564
565 network_pass2() {
566         echo -n 'Doing additional network setup:'
567         case ${named_enable} in
568         [Yy][Ee][Ss])
569                 echo -n ' named';       ${named_program:-named} ${named_flags}
570                 ;;
571         esac
572
573         case ${ntpdate_enable} in
574         [Yy][Ee][Ss])
575                 echo -n ' ntpdate'
576                 ${ntpdate_program:-ntpdate} ${ntpdate_flags} >/dev/null 2>&1
577                 ;;
578         esac
579
580         case ${ntpd_enable} in
581         [Yy][Ee][Ss])
582                 echo -n ' ntpd';        ${ntpd_program:-ntpd} ${ntpd_flags}
583                 ;;
584         esac
585
586         case ${timed_enable} in
587         [Yy][Ee][Ss])
588                 echo -n ' timed';       timed ${timed_flags}
589                 ;;
590         esac
591
592         case ${rpcbind_enable} in
593         [Yy][Ee][Ss])
594                 echo -n ' rpcbind';     ${rpcbind_program:-/usr/sbin/rpcbind} \
595                         ${rpcbind_flags}
596
597                 # Start ypserv if we're an NIS server.
598                 # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server.
599                 #
600                 case ${nis_server_enable} in
601                 [Yy][Ee][Ss])
602                         echo -n ' ypserv'; ypserv ${nis_server_flags}
603
604                         case ${nis_ypxfrd_enable} in
605                         [Yy][Ee][Ss])
606                                 echo -n ' rpc.ypxfrd'
607                                 rpc.ypxfrd ${nis_ypxfrd_flags}
608                                 ;;
609                         esac
610
611                         case ${nis_yppasswdd_enable} in
612                         [Yy][Ee][Ss])
613                                 echo -n ' rpc.yppasswdd'
614                                 rpc.yppasswdd ${nis_yppasswdd_flags}
615                                 ;;
616                         esac
617                         ;;
618                 esac
619
620                 # Start ypbind if we're an NIS client
621                 #
622                 case ${nis_client_enable} in
623                 [Yy][Ee][Ss])
624                         echo -n ' ypbind'; ypbind ${nis_client_flags}
625                         case ${nis_ypset_enable} in
626                         [Yy][Ee][Ss])
627                                 echo -n ' ypset';       ypset ${nis_ypset_flags}
628                                 ;;
629                         esac
630                         ;;
631                 esac
632
633                 # Start keyserv if we are running Secure RPC
634                 #
635                 case ${keyserv_enable} in
636                 [Yy][Ee][Ss])
637                         echo -n ' keyserv';     keyserv ${keyserv_flags}
638                         ;;
639                 esac
640
641                 # Start ypupdated if we are running Secure RPC
642                 # and we are NIS master
643                 #
644                 case ${rpc_ypupdated_enable} in
645                 [Yy][Ee][Ss])
646                         echo -n ' rpc.ypupdated';       rpc.ypupdated
647                         ;;
648                 esac
649                 ;;
650         esac
651
652         # Start ATM daemons
653         if [ -n "${atm_pass2_done}" ]; then
654                 atm_pass3
655         fi
656
657         echo '.'
658         network_pass2_done=YES
659 }
660
661 network_pass3() {
662         echo -n 'Starting final network daemons:'
663
664         case ${rpcbind_enable} in
665         [Yy][Ee][Ss])
666                 case ${nfs_server_enable} in
667                 [Yy][Ee][Ss])
668                         # Handle absent nfs server support
669                         nfsserver_in_kernel=0
670                         if sysctl vfs.nfsrv >/dev/null 2>&1; then
671                                 nfsserver_in_kernel=1
672                         else
673                                 kldload nfsserver && nfsserver_in_kernel=1
674                         fi
675
676                         if [ -r /etc/exports -a \
677                             ${nfsserver_in_kernel} -eq 1 ]; then
678                                 echo -n ' mountd'
679
680                                 case ${weak_mountd_authentication} in
681                                 [Yy][Ee][Ss])
682                                         mountd_flags="${mountd_flags} -n"
683                                         ;;
684                                 esac
685
686                                 mountd ${mountd_flags}
687
688                                 case ${nfs_reserved_port_only} in
689                                 [Yy][Ee][Ss])
690                                         echo -n ' NFS on reserved port only=YES'
691                                         sysctl vfs.nfsrv.nfs_privport=1 > /dev/null
692                                         ;;
693                                 esac
694
695                                 echo -n ' nfsd';        nfsd ${nfs_server_flags}
696
697                                 case ${rpc_statd_enable} in
698                                 [Yy][Ee][Ss])
699                                         echo -n ' rpc.statd';   rpc.statd
700                                         ;;
701                                 esac
702
703                                 case ${rpc_lockd_enable} in
704                                 [Yy][Ee][Ss])
705                                         echo -n ' rpc.lockd';   rpc.lockd
706                                         ;;
707                                 esac
708                         else
709                                 echo -n ' Warning: nfs server failed'
710                         fi
711                         ;;
712                 *)
713                         case ${mountd_enable} in
714                         [Yy][Ee][Ss])
715                                 if [ -r /etc/exports ]; then
716                                         echo -n ' mountd'
717
718                                         case ${weak_mountd_authentication} in
719                                         [Yy][Ee][Ss])
720                                                 mountd_flags="-n"
721                                                 ;;
722                                         esac
723
724                                         mountd ${mountd_flags}
725                                 fi
726                                 ;;
727                         esac
728                         ;;
729                 esac
730
731                 case ${nfs_client_enable} in
732                 [Yy][Ee][Ss])
733                         nfsclient_in_kernel=0
734                         # Handle absent nfs client support
735                         if sysctl vfs.nfs >/dev/null 2>&1; then
736                                 nfsclient_in_kernel=1
737                         else
738                                 kldload nfsclient && nfsclient_in_kernel=1
739                         fi
740
741                         if [ ${nfsclient_in_kernel} -eq 1 ]
742                         then
743                                 if [ -n "${nfs_access_cache}" ]; then
744                                         echo -n " NFS access cache time=${nfs_access_cache}"
745                                         sysctl vfs.nfs.access_cache_timeout=${nfs_access_cache} >/dev/null
746                                 fi
747                                 if [ -n "${nfs_bufpackets}" ]; then
748                                         sysctl vfs.nfs.bufpackets=${nfs_bufpackets} > /dev/null
749                                 fi
750                                 case ${rpc_statd_enable} in
751                                 [Yy][Ee][Ss])
752                                         echo -n ' rpc.statd';   rpc.statd
753                                         ;;
754                                 esac
755
756                                 case ${rpc_lockd_enable} in
757                                 [Yy][Ee][Ss])
758                                         echo -n ' rpc.lockd';   rpc.lockd
759                                         ;;
760                                 esac
761
762                                 case ${amd_enable} in
763                                 [Yy][Ee][Ss])
764                                         echo -n ' amd'
765                                         case ${amd_map_program} in
766                                         [Nn][Oo] | '')
767                                                 ;;
768                                         *)
769                                                 amd_flags="${amd_flags} `eval\
770                                                         ${amd_map_program}`"
771                                                 ;;
772                                         esac
773
774                                         case "${amd_flags}" in
775                                         '')
776                                                 if [ -r /etc/amd.conf ]; then
777                                                         amd &
778                                                 else
779                                                         echo ''
780                         echo 'Warning: amd will not load without arguments'
781                                                 fi
782                                                 ;;
783                                         *)
784                                                 amd -p ${amd_flags} \
785                                                          >/var/run/amd.pid \
786                                                         2>/dev/null &
787                                                 ;;
788                                         esac
789                                         ;;
790                                 esac
791                         else
792                                 echo 'Warning: NFS client kernel module failed to load'
793                                 nfs_client_enable=NO
794                         fi
795                         ;;
796                 esac
797
798                 # If /var/db/mounttab exists, some nfs-server has not been
799                 # successfully notified about a previous client shutdown.
800                 # If there is no /var/db/mounttab, we do nothing.
801                 if [ -f /var/db/mounttab ]; then
802                         rpc.umntall -k
803                 fi
804
805                 ;;
806         esac
807
808         case ${rwhod_enable} in
809         [Yy][Ee][Ss])
810                 echo -n ' rwhod';       rwhod ${rwhod_flags}
811                 ;;
812         esac
813
814         # Kerberos servers run ONLY on the Kerberos server machine
815         case ${kerberos4_server_enable} in
816         [Yy][Ee][Ss])
817                 case ${kerberos_stash} in
818                 [Yy][Ee][Ss])
819                         stash=-n
820                         ;;
821                 *)
822                         stash=
823                         ;;
824                 esac
825
826                 echo -n ' kerberosIV'
827                 ${kerberos4_server} ${stash} >> /var/log/kerberos.log &
828
829                 case ${kadmind4_server_enable} in
830                 [Yy][Ee][Ss])
831                         echo -n ' kadmindIV'
832                         (
833                                 sleep 20;
834                                 ${kadmind4_server} ${stash} >/dev/null 2>&1 &
835                         ) &
836                         ;;
837                 esac
838                 unset stash_flag
839                 ;;
840         esac
841
842         case ${kerberos5_server_enable} in
843         [Yy][Ee][Ss])
844                 echo -n ' kerberos5'
845                 ${kerberos5_server} &
846
847                 case ${kadmind5_server_enable} in
848                 [Yy][Ee][Ss])
849                         echo -n ' kadmind5'
850                         ${kadmind5_server} &
851                         ;;
852                 esac
853                 ;;
854         esac
855
856         case ${pppoed_enable} in
857         [Yy][Ee][Ss])
858                 if [ -n "${pppoed_provider}" ]; then
859                         pppoed_flags="${pppoed_flags} -p ${pppoed_provider}"
860                 fi
861                 echo -n ' pppoed';
862                 _opts=$-; set -f
863                 /usr/libexec/pppoed ${pppoed_flags} ${pppoed_interface}
864                 set +f; set -${_opts}
865                 ;;
866         esac
867
868         case ${sshd_enable} in
869         [Yy][Ee][Ss])
870                 if [ -x /usr/bin/ssh-keygen ]; then
871                         if [ ! -f /etc/ssh/ssh_host_key ]; then
872                                 echo ' creating ssh1 RSA host key';
873                                 /usr/bin/ssh-keygen -t rsa1 -N "" \
874                                         -f /etc/ssh/ssh_host_key
875                         fi
876                         if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
877                                 echo ' creating ssh2 RSA host key';
878                                 /usr/bin/ssh-keygen -t rsa -N "" \
879                                         -f /etc/ssh/ssh_host_rsa_key
880                         fi
881                         if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
882                                 echo ' creating ssh2 DSA host key';
883                                 /usr/bin/ssh-keygen -t dsa -N "" \
884                                         -f /etc/ssh/ssh_host_dsa_key
885                         fi
886                 fi
887                 ;;
888         esac
889
890         echo '.'
891         network_pass3_done=YES
892 }
893
894 network_pass4() {
895         echo -n 'Additional TCP options:'
896         case ${log_in_vain} in
897         [Nn][Oo] | '')
898                 log_in_vain=0
899                 ;;
900         [Yy][Ee][Ss])
901                 log_in_vain=1
902                 ;;
903         [0-9]*)
904                 ;;
905         *)
906                 echo " invalid log_in_vain setting: ${log_in_vain}"
907                 log_in_vain=0
908                 ;;
909         esac
910
911         [ "${log_in_vain}" -ne 0 ] && (
912             echo -n " log_in_vain=${log_in_vain}"
913             sysctl net.inet.tcp.log_in_vain="${log_in_vain}" >/dev/null
914             sysctl net.inet.udp.log_in_vain="${log_in_vain}" >/dev/null
915         )
916         echo '.'
917         network_pass4_done=YES
918 }
919
920 network_gif_setup() {
921         case ${gif_interfaces} in
922         [Nn][Oo] | '')
923                 ;;
924         *)
925                 for i in ${gif_interfaces}; do
926                         eval peers=\$gifconfig_$i
927                         case ${peers} in
928                         '')
929                                 continue
930                                 ;;
931                         *)
932                                 ifconfig $i create >/dev/null 2>&1
933                                 ifconfig $i tunnel ${peers}
934                                 ifconfig $i up
935                                 ;;
936                         esac
937                 done
938                 ;;
939         esac
940 }
941
942 convert_host_conf() {
943     host_conf=$1; shift;
944     nsswitch_conf=$1; shift;
945     awk '                                                                   \
946         /^[:blank:]*#/       { next }                                       \
947         /(hosts|local|file)/ { nsswitch[c] = "files"; c++; next }           \
948         /(dns|bind)/         { nsswitch[c] = "dns";   c++; next }           \
949         /nis/                { nsswitch[c] = "nis";   c++; next }           \
950         { printf "Warning: unrecognized line [%s]", $0 > "/dev/stderr" }    \
951         END {                                                               \
952                 printf "hosts: ";                                           \
953                 for (i in nsswitch) printf "%s ", nsswitch[i];              \
954                 printf "\n";                                                \
955         }' < $host_conf > $nsswitch_conf
956 }
957
958 generate_host_conf() {
959     nsswitch_conf=$1; shift;
960     host_conf=$1; shift;
961     
962     awk '
963 BEGIN {
964     xlat["files"] = "hosts";
965     xlat["dns"] = "bind";
966     xlat["nis"] = "nis";
967     cont = 0;
968 }
969 sub(/^[\t ]*hosts:/, "") || cont {
970     if (!cont)
971         srcs = ""
972     sub(/#.*/, "")
973     gsub(/[][]/, " & ")
974     cont = sub(/\\$/, "")
975     srcs = srcs " " $0
976 }
977 END {
978     print "# Auto-generated from nsswitch.conf, do not edit"
979     ns = split(srcs, s)
980     for (n = 1; n <= ns; ++n) {
981         if (s[n] in xlat)
982             print xlat[s[n]]
983     }
984 }
985 ' <$nsswitch_conf >$host_conf
986 }