defaultroute revision 53158
1193640Sariff#!/bin/sh -
2193640Sariff#
3193640Sariff# $FreeBSD: head/etc/rc.d/routing 53158 1999-11-14 21:28:13Z ache $
4193640Sariff#	From: @(#)netstart	5.9 (Berkeley) 3/30/91
5193640Sariff
6193640Sariff# Note that almost all of the user-configurable behavior is no longer in
7193640Sariff# this file, but rather in /etc/defaults/rc.conf.  Please check that file
8193640Sariff# first before contemplating any changes here.  If you do need to change
9193640Sariff# this file for some reason, we would like to know about it.
10193640Sariff
11193640Sariff# First pass startup stuff.
12193640Sariff#
13193640Sariffnetwork_pass1() {
14193640Sariff	echo -n 'Doing initial network setup:'
15193640Sariff
16193640Sariff	# Set the host name if it is not already set
17193640Sariff	#
18193640Sariff	if [ -z "`hostname -s`" ]; then
19193640Sariff		hostname ${hostname}
20193640Sariff		echo -n ' hostname'
21193640Sariff	fi
22193640Sariff
23193640Sariff	# Set the domainname if we're using NIS
24193640Sariff	#
25193640Sariff	case ${nisdomainname} in
26193640Sariff	[Nn][Oo] | '')
27193640Sariff		;;
28193640Sariff	*)
29193640Sariff		domainname ${nisdomainname}
30193640Sariff		echo -n ' domain'
31193640Sariff		;;
32193640Sariff	esac
33193640Sariff
34193640Sariff	echo '.'
35193640Sariff
36193640Sariff	# Initial ATM interface configuration
37193640Sariff	#
38193640Sariff	case ${atm_enable} in
39193640Sariff	[Yy][Ee][Ss])
40193640Sariff		if [ -r /etc/rc.atm ]; then
41193640Sariff			. /etc/rc.atm
42193640Sariff			atm_pass1
43193640Sariff		fi
44193640Sariff		;;
45193640Sariff	esac
46193640Sariff
47193640Sariff	# ISDN subsystem startup
48193640Sariff	#
49193640Sariff	case ${isdn_enable} in
50193640Sariff	[Yy][Ee][Ss])
51193640Sariff		if [ -r /etc/rc.isdn ]; then
52193640Sariff			. /etc/rc.isdn
53193640Sariff		fi
54193640Sariff		;;
55193640Sariff	esac
56193640Sariff
57193640Sariff	# Special options for sppp(4) interfaces go here.  These need
58193640Sariff	# to go _before_ the general ifconfig section, since in the case
59193640Sariff	# of hardwired (no link1 flag) but required authentication, you
60193640Sariff	# cannot pass auth parameters down to the already running interface.
61193640Sariff	#
62193640Sariff	for ifn in ${sppp_interfaces}; do
63193640Sariff		eval spppcontrol_args=\$spppconfig_${ifn}
64193640Sariff		if [ -n "${spppcontrol_args}" ]; then
65193640Sariff			# The auth secrets might contain spaces; in order
66193640Sariff			# to retain the quotation, we need to eval them
67193640Sariff			# here.
68193640Sariff			eval spppcontrol ${ifn} ${spppcontrol_args}
69193640Sariff		fi
70193640Sariff	done
71193640Sariff
72193640Sariff	# Set up all the network interfaces, calling startup scripts if needed
73193640Sariff	#
74193640Sariff	case ${network_interfaces} in
75193640Sariff	[Aa][Uu][Tt][Oo])
76193640Sariff		network_interfaces="`ifconfig -l`"
77193640Sariff		;;
78193640Sariff	esac
79193640Sariff
80193640Sariff	for ifn in ${network_interfaces}; do
81193640Sariff		showstat=false
82193640Sariff		if [ -r /etc/start_if.${ifn} ]; then
83193640Sariff			. /etc/start_if.${ifn}
84193640Sariff			showstat=true
85193640Sariff		fi
86193640Sariff
87193640Sariff		# Do the primary ifconfig if specified
88193640Sariff		#
89193640Sariff		eval ifconfig_args=\$ifconfig_${ifn}
90193640Sariff
91193640Sariff		case ${ifconfig_args} in
92193640Sariff		'')
93193640Sariff			;;
94193640Sariff		[Dd][Hh][Cc][Pp])
95193640Sariff			${dhcp_program:-/sbin/dhclient} ${dhcp_flags} ${ifn}
96193640Sariff			showstat=true
97193640Sariff			;;
98193640Sariff		*)
99193640Sariff			ifconfig ${ifn} ${ifconfig_args}
100193640Sariff			showstat=true
101193640Sariff			;;
102193640Sariff		esac
103193640Sariff
104193640Sariff		# Check to see if aliases need to be added
105193640Sariff		#
106193640Sariff		alias=0
107193640Sariff		while : ; do
108193640Sariff			eval ifconfig_args=\$ifconfig_${ifn}_alias${alias}
109193640Sariff			if [ -n "${ifconfig_args}" ]; then
110193640Sariff				ifconfig ${ifn} ${ifconfig_args} alias
111193640Sariff				showstat=true
112193640Sariff				alias=`expr ${alias} + 1`
113193640Sariff			else
114193640Sariff				break;
115193640Sariff			fi
116193640Sariff		done
117193640Sariff
118193640Sariff		# Do ipx address if specified
119193640Sariff		#
120193640Sariff		eval ifconfig_args=\$ifconfig_${ifn}_ipx
121193640Sariff		if [ -n "${ifconfig_args}" ]; then
122193640Sariff			ifconfig ${ifn} ${ifconfig_args}
123193640Sariff			showstat=true
124193640Sariff		fi
125193640Sariff
126193640Sariff		case ${showstat} in
127193640Sariff		true)
128193640Sariff			ifconfig ${ifn}
129193640Sariff			;;
130193640Sariff		esac
131193640Sariff	done
132193640Sariff
133193640Sariff	# Warm up user ppp if required, must happen before natd.
134193640Sariff	#
135193640Sariff	case ${ppp_enable} in
136193640Sariff	[Yy][Ee][Ss])
137193640Sariff		# Establish ppp mode.
138193640Sariff		#
139193640Sariff		if [ "${ppp_mode}" != "ddial" -a "${ppp_mode}" != "direct" \
140193640Sariff			-a "${ppp_mode}" != "dedicated" \
141193640Sariff			-a "${ppp_mode}" != "background" ]; then
142193640Sariff			ppp_mode="auto";
143193640Sariff		fi
144193640Sariff
145193640Sariff		ppp_command="-${ppp_mode} ";
146193640Sariff
147193640Sariff		# Switch on alias mode?
148193640Sariff		#
149193640Sariff		case ${ppp_nat} in
150193640Sariff		[Yy][Ee][Ss])
151193640Sariff			ppp_command="${ppp_command} -nat";
152193640Sariff			;;
153193640Sariff		esac
154193640Sariff
155193640Sariff		echo -n 'Starting ppp: '; ppp ${ppp_command} -quiet ${ppp_profile}
156193640Sariff		;;
157193640Sariff	esac
158193640Sariff
159193640Sariff	# Initialize IP filtering using ipfw
160193640Sariff	#
161193640Sariff	echo ''
162193640Sariff
163193640Sariff	if /sbin/ipfw -q flush > /dev/null 2>&1; then
164193640Sariff		firewall_in_kernel=1
165193640Sariff	else
166193640Sariff		firewall_in_kernel=0
167193640Sariff	fi
168193640Sariff
169193640Sariff	case ${firewall_enable} in
170193640Sariff	[Yy][Ee][Ss])
171193640Sariff		if [ "${firewall_in_kernel}" -eq 0 ] && kldload ipfw; then
172193640Sariff			firewall_in_kernel=1
173193640Sariff			echo "Kernel firewall module loaded."
174193640Sariff		elif [ "${firewall_in_kernel}" -eq 0 ]; then
175193640Sariff			echo "Warning: firewall kernel module failed to load."
176193640Sariff		fi
177193640Sariff		;;
178193640Sariff	esac
179193640Sariff
180193640Sariff	# Load the filters if required
181193640Sariff	#
182193640Sariff	case ${firewall_in_kernel} in
183193640Sariff	1)
184193640Sariff		if [ -z "${firewall_script}" ]; then
185193640Sariff			firewall_script=/etc/rc.firewall
186193640Sariff		fi
187193640Sariff
188193640Sariff		case ${firewall_enable} in
189193640Sariff		[Yy][Ee][Ss])
190193640Sariff			if [ -r "${firewall_script}" ]; then
191193640Sariff				. "${firewall_script}"
192193640Sariff				echo -n 'Firewall rules loaded, starting divert daemons:'
193193640Sariff
194193640Sariff				# Network Address Translation daemon
195193640Sariff				#
196193640Sariff				case ${natd_enable} in
197193640Sariff				[Yy][Ee][Ss])
198193640Sariff					if [ -n "${natd_interface}" ]; then
199193640Sariff						if echo ${natd_interface} | \
200193640Sariff							grep -q -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'; then
201193640Sariff							natd_ifarg="-a ${natd_interface}"
202193640Sariff						else
203193640Sariff							natd_ifarg="-n ${natd_interface}"
204193640Sariff						fi
205193640Sariff
206193640Sariff						echo -n ' natd'; ${natd_program:-/sbin/natd} ${natd_flags} ${natd_ifarg}
207193640Sariff					fi
208193640Sariff					;;
209193640Sariff				esac
210193640Sariff
211193640Sariff				echo '.'
212193640Sariff
213193640Sariff			elif [ "`ipfw l 65535`" = "65535 deny ip from any to any" ]; then
214193640Sariff				echo -n "Warning: kernel has firewall functionality, "
215193640Sariff				echo "but firewall rules are not enabled."
216193640Sariff				echo "		 All ip services are disabled."
217193640Sariff			fi
218193640Sariff			;;
219193640Sariff		esac
220193640Sariff		;;
221193640Sariff	esac
222193640Sariff
223193640Sariff	# Additional ATM interface configuration
224193640Sariff	#
225193640Sariff	if [ -n "${atm_pass1_done}" ]; then
226		atm_pass2
227	fi
228
229	# Configure routing
230	#
231	case ${defaultrouter} in
232	[Nn][Oo] | '')
233		;;
234	*)
235		static_routes="default ${static_routes}"
236		route_default="default ${defaultrouter}"
237		;;
238	esac
239
240	# Set up any static routes.  This should be done before router discovery.
241	#
242	if [ -n "${static_routes}" ]; then
243		for i in ${static_routes}; do
244			eval route_args=\$route_${i}
245			route add ${route_args}
246		done
247	fi
248
249	echo -n 'Additional routing options:'
250	case ${tcp_extensions} in
251	[Yy][Ee][Ss] | '')
252		;;
253	*)
254		echo -n ' tcp extensions=NO'
255		sysctl -w net.inet.tcp.rfc1323=0 >/dev/null
256		;;
257	esac
258
259	case ${log_in_vain} in
260	[Nn][Oo] | '')
261		;;
262	*)
263		echo -n ' log_in_vain=YES'
264		sysctl -w net.inet.tcp.log_in_vain=1 >/dev/null
265		sysctl -w net.inet.udp.log_in_vain=1 >/dev/null
266		;;
267	esac
268
269	case ${icmp_bmcastecho} in
270	[Yy][Ee][Ss])
271		echo -n ' broadcast ping responses=YES'
272		sysctl -w net.inet.icmp.bmcastecho=1 >/dev/null
273		;;
274	esac
275
276	case ${icmp_drop_redirect} in
277	[Yy][Ee][Ss])
278		echo -n ' ignore ICMP redirect=YES'
279		sysctl -w net.inet.icmp.drop_redirect=1 >/dev/null
280		;;
281	esac
282
283	case ${icmp_log_redirect} in
284	[Yy][Ee][Ss])
285		echo -n ' log ICMP redirect=YES'
286		sysctl -w net.inet.icmp.log_redirect=1 >/dev/null
287		;;
288	esac
289
290	case ${gateway_enable} in
291	[Yy][Ee][Ss])
292		echo -n ' IP gateway=YES'
293		sysctl -w net.inet.ip.forwarding=1 >/dev/null
294		;;
295	esac
296
297	case ${forward_sourceroute} in
298	[Yy][Ee][Ss])
299		echo -n ' do source routing=YES'
300		sysctl -w net.inet.ip.sourceroute=1 >/dev/null
301		;;
302	esac
303
304	case ${accept_sourceroute} in
305	[Yy][Ee][Ss])
306		echo -n ' accept source routing=YES'
307		sysctl -w net.inet.ip.accept_sourceroute=1 >/dev/null
308		;;
309	esac
310
311	case ${tcp_keepalive} in
312	[Yy][Ee][Ss])
313		echo -n ' TCP keepalive=YES'
314		sysctl -w net.inet.tcp.always_keepalive=1 >/dev/null
315		;;
316	esac
317
318	case ${tcp_restrict_rst} in
319	[Yy][Ee][Ss])
320		echo -n ' restrict TCP reset=YES'
321		sysctl -w net.inet.tcp.restrict_rst=1 >/dev/null
322		;;
323	esac
324
325	case ${tcp_drop_synfin} in
326	[Yy][Ee][Ss])
327		echo -n ' drop SYN+FIN packets=YES'
328		sysctl -w net.inet.tcp.drop_synfin=1 >/dev/null
329		;;
330	esac
331
332	case ${ipxgateway_enable} in
333	[Yy][Ee][Ss])
334		echo -n ' IPX gateway=YES'
335		sysctl -w net.ipx.ipx.ipxforwarding=1 >/dev/null
336		;;
337	esac
338
339	case ${arpproxy_all} in
340	[Yy][Ee][Ss])
341		echo -n ' ARP proxyall=YES'
342		sysctl -w net.link.ether.inet.proxyall=1 >/dev/null
343		;;
344	esac
345	echo '.'
346
347	echo -n 'routing daemons:'
348	case ${router_enable} in
349	[Yy][Ee][Ss])
350		echo -n " ${router}";	${router} ${router_flags}
351		;;
352	esac
353
354	case ${ipxrouted_enable} in
355	[Yy][Ee][Ss])
356		echo -n ' IPXrouted'
357		IPXrouted ${ipxrouted_flags} > /dev/null 2>&1
358		;;
359	esac
360
361	case ${mrouted_enable} in
362	[Yy][Ee][Ss])
363		echo -n ' mrouted';	mrouted ${mrouted_flags}
364		;;
365	esac
366
367	case ${rarpd_enable} in
368	[Yy][Ee][Ss])
369		echo -n ' rarpd';	rarpd ${rarpd_flags}
370		;;
371	esac
372	echo '.'
373
374	# Let future generations know we made it.
375	#
376	network_pass1_done=YES
377}
378
379network_pass2() {
380	echo -n 'Doing additional network setup:'
381	case ${named_enable} in
382	[Yy][Ee][Ss])
383		echo -n ' named';	${named_program:-named} ${named_flags}
384		;;
385	esac
386
387	case ${ntpdate_enable} in
388	[Yy][Ee][Ss])
389		echo -n ' ntpdate'
390		${ntpdate_program:-ntpdate} ${ntpdate_flags} >/dev/null 2>&1
391		;;
392	esac
393
394	case ${xntpd_enable} in
395	[Yy][Ee][Ss])
396		echo -n ' xntpd';	${xntpd_program:-xntpd} ${xntpd_flags}
397		;;
398	esac
399
400	case ${timed_enable} in
401	[Yy][Ee][Ss])
402		echo -n ' timed';	timed ${timed_flags}
403		;;
404	esac
405
406	case ${portmap_enable} in
407	[Yy][Ee][Ss])
408		echo -n ' portmap';	${portmap_program:-/usr/sbin/portmap} ${portmap_flags}
409		;;
410	esac
411
412	# Start ypserv if we're an NIS server.
413	# Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server.
414	#
415	case ${nis_server_enable} in
416	[Yy][Ee][Ss])
417		echo -n ' ypserv'; ypserv ${nis_server_flags}
418
419		case ${nis_ypxfrd_enable} in
420		[Yy][Ee][Ss])
421			echo -n ' rpc.ypxfrd'
422			rpc.ypxfrd ${nis_ypxfrd_flags}
423			;;
424		esac
425
426		case ${nis_yppasswdd_enable} in
427		[Yy][Ee][Ss])
428			echo -n ' rpc.yppasswdd'
429			rpc.yppasswdd ${nis_yppasswdd_flags}
430			;;
431		esac
432		;;
433	esac
434
435	# Start ypbind if we're an NIS client
436	#
437	case ${nis_client_enable} in
438	[Yy][Ee][Ss])
439		echo -n ' ypbind'; ypbind ${nis_client_flags}
440		case ${nis_ypset_enable} in
441		[Yy][Ee][Ss])
442			echo -n ' ypset';	ypset ${nis_ypset_flags}
443			;;
444		esac
445		;;
446	esac
447
448	# Start keyserv if we are running Secure RPC
449	#
450	case ${keyserv_enable} in
451	[Yy][Ee][Ss])
452		echo -n ' keyserv';	keyserv ${keyserv_flags}
453		;;
454	esac
455
456	# Start ypupdated if we are running Secure RPC and we are NIS master
457	#
458	case ${rpc_ypupdated_enable} in
459	[Yy][Ee][Ss])
460		echo -n ' rpc.ypupdated';	rpc.ypupdated
461		;;
462	esac
463
464	# Start ATM daemons
465	if [ -n "${atm_pass2_done}" ]; then
466		atm_pass3
467	fi
468
469	echo '.'
470	network_pass2_done=YES
471}
472
473network_pass3() {
474	echo -n 'Starting final network daemons:'
475
476	case ${nfs_server_enable} in
477	[Yy][Ee][Ss])
478		if [ -r /etc/exports ]; then
479			echo -n ' mountd'
480
481			case ${weak_mountd_authentication} in
482			[Yy][Ee][Ss])
483				mountd_flags="-n"
484				;;
485			esac
486
487			mountd ${mountd_flags}
488
489			case ${nfs_reserved_port_only} in
490			[Yy][Ee][Ss])
491				echo -n ' NFS on reserved port only=YES'
492				sysctl -w vfs.nfs.nfs_privport=1 >/dev/null
493				;;
494			esac
495
496			echo -n ' nfsd';	nfsd ${nfs_server_flags}
497
498			case ${rpc_lockd_enable} in
499			[Yy][Ee][Ss])
500				echo -n ' rpc.lockd';	rpc.lockd
501				;;
502			esac
503
504			case ${rpc_statd_enable} in
505			[Yy][Ee][Ss])
506				echo -n ' rpc.statd';	rpc.statd
507				;;
508			esac
509		fi
510		;;
511	*)
512		case ${single_mountd_enable} in
513		[Yy][Ee][Ss])
514			if [ -r /etc/exports ]; then
515				echo -n ' mountd'
516
517				case ${weak_mountd_authentication} in
518				[Yy][Ee][Ss])
519					mountd_flags="-n"
520					;;
521				esac
522
523				mountd ${mountd_flags}
524			fi
525			;;
526		esac
527		;;
528	esac
529
530	case ${nfs_client_enable} in
531	[Yy][Ee][Ss])
532		echo -n ' nfsiod';	nfsiod ${nfs_client_flags}
533		if [ -n "${nfs_access_cache}" ]; then
534		echo -n " NFS access cache time=${nfs_access_cache}"
535		sysctl -w vfs.nfs.access_cache_timeout=${nfs_access_cache} \
536			>/dev/null
537		fi
538		;;
539	esac
540
541	case ${amd_enable} in
542	[Yy][Ee][Ss])
543		echo -n ' amd'
544		case ${amd_map_program} in
545		[Nn][Oo] | '')
546			;;
547		*)
548			amd_flags="${amd_flags} `eval ${amd_map_program}`"
549			;;
550		esac
551
552		if [ -n "${amd_flags}" ]; then
553			amd -p ${amd_flags} > /var/run/amd.pid 2> /dev/null
554		else
555			amd 2> /dev/null
556		fi
557		;;
558	esac
559
560	case ${rwhod_enable} in
561	[Yy][Ee][Ss])
562		echo -n ' rwhod';	rwhod ${rwhod_flags}
563		;;
564	esac
565
566	# Kerberos runs ONLY on the Kerberos server machine
567	case ${kerberos_server_enable} in
568	[Yy][Ee][Ss])
569		case ${kerberos_stash} in
570		[Yy][Ee][Ss])
571			stash_flag=-n
572			;;
573		*)
574			stash_flag=
575			;;
576		esac
577
578		echo -n ' kerberos'
579		kerberos ${stash_flag} >> /var/log/kerberos.log &
580
581		case ${kadmind_server_enable} in
582		[Yy][Ee][Ss])
583			echo -n ' kadmind'
584			(sleep 20; kadmind ${stash_flag} >/dev/null 2>&1 &) &
585			;;
586		esac
587		unset stash_flag
588		;;
589	esac
590
591	echo '.'
592	network_pass3_done=YES
593}
594