defaultroute revision 183714
1106611Ssimokawa#!/bin/sh
2106611Ssimokawa#
3106611Ssimokawa# Wait for the default route to be up
4106611Ssimokawa#
5106611Ssimokawa# $FreeBSD: head/etc/rc.d/defaultroute 183714 2008-10-09 02:25:18Z peter $
6106611Ssimokawa#
7106611Ssimokawa
8106611Ssimokawa# PROVIDE: defaultroute
9106611Ssimokawa# REQUIRE: devd netif network_ipv6
10106611Ssimokawa# KEYWORD: nojail
11106611Ssimokawa
12106611Ssimokawa. /etc/rc.subr
13106611Ssimokawa. /etc/network.subr
14106611Ssimokawa
15106611Ssimokawaname="defaultroute"
16106611Ssimokawastart_cmd="defaultroute_start"
17106611Ssimokawastop_cmd=":"
18106611Ssimokawa
19106611Ssimokawadefaultroute_start()
20106611Ssimokawa{
21106611Ssimokawa	# Return without waiting if we don't have dhcp interfaces.
22106611Ssimokawa	# Once we can test that the link is actually up, we should
23106611Ssimokawa	# remove this test and always wait.
24107728Sru	dhcp_interfaces=`list_net_interfaces dhcp`
25106611Ssimokawa	[ -z "`list_net_interfaces dhcp`" ] && return
26106611Ssimokawa
27106611Ssimokawa	# Wait for a default route
28148145Strhodes	delay=${if_up_delay}
29106611Ssimokawa	while [ ${delay} -gt 0 ]; do
30106611Ssimokawa		defif=`get_default_if -inet`
31106611Ssimokawa		if [ -n "${defif}" ]; then
32106611Ssimokawa			if [ ${delay} -ne ${if_up_delay} ]; then
33148145Strhodes				echo "($defif)"
34106611Ssimokawa			fi
35151046Strhodes			break
36151046Strhodes		fi
37148220Strhodes		if [ ${delay} -eq ${if_up_delay} ]; then
38148145Strhodes			echo -n "Waiting ${delay}s for an interface to come up: "
39138860Sbrueffer		else
40106611Ssimokawa			echo -n .
41148145Strhodes		fi
42148145Strhodes		sleep 1
43151046Strhodes		delay=`expr $delay - 1`
44151046Strhodes	done
45148145Strhodes}
46148145Strhodes
47148145Strhodesload_rc_config $name
48148145Strhodesrun_rc_command "$1"
49106611Ssimokawa