network.subr revision 51231
1#!/bin/sh -
2#
3# $FreeBSD: head/etc/network.subr 51231 1999-09-13 15:44:20Z sheldonh $
4#	From: @(#)netstart	5.9 (Berkeley) 3/30/91
5
6# Note that almost all of the user-configurable behavior is no longer in
7# this file, but rather in /etc/defaults/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
16	# Set the host name if it is not already set
17	#
18	if [ -z "`hostname -s`" ]; then
19		hostname ${hostname}
20		echo -n ' hostname'
21	fi
22
23	# Set the domainname if we're using NIS
24	#
25	case ${nisdomainname} in
26	[Nn][Oo] | '')
27		;;
28	*)
29		domainname ${nisdomainname}
30		echo -n ' domain'
31		;;
32	esac
33
34	echo '.'
35
36	# Initial ATM interface configuration
37	#
38	case ${atm_enable} in
39	[Yy][Ee][Ss])
40		if [ -r /etc/rc.atm ]; then
41			. /etc/rc.atm
42			atm_pass1
43		fi
44		;;
45	esac
46
47	# ISDN subsystem startup
48	#
49	case ${isdn_enable} in
50	[Yy][Ee][Ss])
51		if [ -r /etc/rc.isdn ]; then
52			. /etc/rc.isdn
53		fi
54		;;
55	esac
56
57	# Special options for sppp(4) interfaces go here.  These need
58	# to go _before_ the general ifconfig section, since in the case
59	# of hardwired (no link1 flag) but required authentication, you
60	# cannot pass auth parameters down to the already running interface.
61	#
62	for ifn in ${sppp_interfaces}; do
63		eval spppcontrol_args=\$spppconfig_${ifn}
64		if [ -n "${spppcontrol_args}" ]; then
65			# The auth secrets might contain spaces; in order
66			# to retain the quotation, we need to eval them
67			# here.
68			eval spppcontrol ${ifn} ${spppcontrol_args}
69		fi
70	done
71
72	# Set up all the network interfaces, calling startup scripts if needed
73	#
74	case ${network_interfaces} in
75	[Aa][Uu][Tt][Oo])
76		network_interfaces="`ifconfig -l`"
77		;;
78	esac
79
80	for ifn in ${network_interfaces}; do
81		showstat=false
82		if [ -r /etc/start_if.${ifn} ]; then
83			. /etc/start_if.${ifn}
84			showstat=true
85		fi
86
87		# Do the primary ifconfig if specified
88		#
89		eval ifconfig_args=\$ifconfig_${ifn}
90
91		case ${ifconfig_args} in
92		'')
93			;;
94		[Dd][Hh][Cc][Pp])
95			${dhcp_program:-/sbin/dhclient} ${dhcp_flags} ${ifn}
96			showstat=true
97			;;
98		*)
99			ifconfig ${ifn} ${ifconfig_args}
100			showstat=true
101			;;
102		esac
103
104		# Check to see if aliases need to be added
105		#
106		alias=0
107		while : ; do
108			eval ifconfig_args=\$ifconfig_${ifn}_alias${alias}
109			if [ -n "${ifconfig_args}" ]; then
110				ifconfig ${ifn} ${ifconfig_args} alias
111				showstat=true
112				alias=`expr ${alias} + 1`
113			else
114				break;
115			fi
116		done
117
118		# Do ipx address if specified
119		#
120		eval ifconfig_args=\$ifconfig_${ifn}_ipx
121		if [ -n "${ifconfig_args}" ]; then
122			ifconfig ${ifn} ${ifconfig_args}
123			showstat=true
124		fi
125
126		case ${showstat} in
127		true)
128			ifconfig ${ifn}
129			;;
130		esac
131	done
132
133	# Warm up user ppp if required, must happen before natd.
134	#
135	case ${ppp_enable} in
136	[Yy][Ee][Ss])
137		# Establish ppp mode.
138		#
139		if [ "${ppp_mode}" != "ddial" -a "${ppp_mode}" != "direct" \
140			-a "${ppp_mode}" != "dedicated" \
141			-a "${ppp_mode}" != "background" ]; then
142			ppp_mode="auto";
143		fi
144
145		ppp_command="-${ppp_mode} ";
146
147		# Switch on alias mode?
148		#
149		case ${ppp_nat} in
150		[Yy][Ee][Ss])
151			ppp_command="${ppp_command} -nat";
152			;;
153		esac
154
155		echo -n 'Starting ppp: '; ppp ${ppp_command} -quiet ${ppp_profile}
156		;;
157	esac
158
159	# Initialize IP filtering using ipfw
160	#
161	echo ''
162
163	if /sbin/ipfw -q flush > /dev/null 2>&1; then
164		firewall_in_kernel=1
165	else
166		firewall_in_kernel=0
167	fi
168
169	case ${firewall_enable} in
170	[Yy][Ee][Ss])
171		if [ "${firewall_in_kernel}" -eq 0 ] && kldload ipfw; then
172			firewall_in_kernel=1
173			echo "Kernel firewall module loaded."
174		elif [ "${firewall_in_kernel}" -eq 0 ]; then
175			echo "Warning: firewall kernel module failed to load."
176		fi
177		;;
178	esac
179
180	# Load the filters if required
181	#
182	case ${firewall_in_kernel} in
183	1)
184		if [ -z "${firewall_script}" ]; then
185			firewall_script=/etc/rc.firewall
186		fi
187
188		case ${firewall_enable} in
189		[Yy][Ee][Ss])
190			if [ -r ${firewall_script} ]; then
191				. ${firewall_script}
192				echo -n 'Firewall rules loaded, starting divert daemons:'
193
194				# Network Address Translation daemon
195				#
196				case ${natd_enable} in
197				[Yy][Ee][Ss])
198					if [ -n "${natd_interface}" ]; then
199						if echo ${natd_interface} | \
200							grep -q -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'; then
201							natd_ifarg="-a ${natd_interface}"
202						else
203							natd_ifarg="-n ${natd_interface}"
204						fi
205
206						echo -n ' natd'; ${natd_program:-/sbin/natd} ${natd_flags} ${natd_ifarg}
207					fi
208					;;
209				esac
210
211				echo '.'
212
213			elif [ "`ipfw l 65535`" = "65535 deny ip from any to any" ]; then
214				echo -n "Warning: kernel has firewall functionality, "
215				echo "but firewall rules are not enabled."
216				echo "		 All ip services are disabled."
217			fi
218			;;
219		esac
220		;;
221	esac
222
223	# Additional ATM interface configuration
224	#
225	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	esac
512
513	case ${nfs_client_enable} in
514	[Yy][Ee][Ss])
515		echo -n ' nfsiod';	nfsiod ${nfs_client_flags}
516		if [ -n "${nfs_access_cache}" ]; then
517		echo -n " NFS access cache time=${nfs_access_cache}"
518		sysctl -w vfs.nfs.access_cache_timeout=${nfs_access_cache} \
519			>/dev/null
520		fi
521		;;
522	esac
523
524	case ${amd_enable} in
525	[Yy][Ee][Ss])
526		echo -n ' amd'
527		case ${amd_map_program} in
528		[Nn][Oo] | '')
529			;;
530		*)
531			amd_flags="${amd_flags} `eval ${amd_map_program}`"
532			;;
533		esac
534
535		if [ -n "${amd_flags}" ]; then
536			amd -p ${amd_flags} > /var/run/amd.pid 2> /dev/null
537		else
538			amd 2> /dev/null
539		fi
540		;;
541	esac
542
543	case ${rwhod_enable} in
544	[Yy][Ee][Ss])
545		echo -n ' rwhod';	rwhod ${rwhod_flags}
546		;;
547	esac
548
549	# Kerberos runs ONLY on the Kerberos server machine
550	case ${kerberos_server_enable} in
551	[Yy][Ee][Ss])
552		case ${kerberos_stash} in
553		[Yy][Ee][Ss])
554			stash_flag=-n
555			;;
556		*)
557			stash_flag=
558			;;
559		esac
560
561		echo -n ' kerberos'
562		kerberos ${stash_flag} >> /var/log/kerberos.log &
563
564		case ${kadmind_server_enable} in
565		[Yy][Ee][Ss])
566			echo -n ' kadmind'
567			(sleep 20; kadmind ${stash_flag} >/dev/null 2>&1 &) &
568			;;
569		esac
570		unset stash_flag
571		;;
572	esac
573
574	echo '.'
575	network_pass3_done=YES
576}
577