defaultroute revision 208060
1254889Smarkj#!/bin/sh
2254889Smarkj#
3254889Smarkj# Wait for the default route to be up
4254889Smarkj#
5254889Smarkj# $FreeBSD: head/etc/rc.d/defaultroute 208060 2010-05-14 04:53:57Z dougb $
6254889Smarkj#
7254889Smarkj
8254889Smarkj# PROVIDE: defaultroute
9254889Smarkj# REQUIRE: devd faith netif stf
10254889Smarkj# KEYWORD: nojail
11254889Smarkj
12254889Smarkj. /etc/rc.subr
13254889Smarkj. /etc/network.subr
14254889Smarkj
15254889Smarkjname="defaultroute"
16254889Smarkjstart_cmd="defaultroute_start"
17254889Smarkjstop_cmd=":"
18254889Smarkj
19254889Smarkjdefaultroute_start()
20254889Smarkj{
21254889Smarkj	local output carrier nocarrier nl
22254889Smarkj
23254889Smarkj	afexists inet || return 0
24254889Smarkj
25254889Smarkj	# Return without waiting if we don't have dhcp interfaces or
26254889Smarkj	# if none of the dhcp interfaces is plugged in.
27254889Smarkj	dhcp_interfaces=`list_net_interfaces dhcp`
28254889Smarkj	[ -z "${dhcp_interfaces}" ] && return
29286420Smarkj	carrier=false
30254889Smarkj	for _if in ${dhcp_interfaces}; do
31254889Smarkj		output=`/sbin/ifconfig ${_if}`
32254889Smarkj		nocarrier=`expr "${output}" : '.*[[:blank:]]status: \(no carrier\)'`
33254889Smarkj		[ -z "${nocarrier}" ] && carrier=true
34254889Smarkj	done
35266082Smarkj	if ! ${carrier}; then
36254889Smarkj		return
37266082Smarkj	fi
38254889Smarkj
39266082Smarkj	# Wait for a default route
40254889Smarkj	delay=${defaultroute_delay}
41266082Smarkj	while [ ${delay} -gt 0 ]; do
42254889Smarkj		defif=`get_default_if -inet`
43266082Smarkj		if [ -n "${defif}" ]; then
44254889Smarkj			if [ ${delay} -ne ${defaultroute_delay} ]; then
45266082Smarkj				echo -n "($defif)"
46254889Smarkj				nl=1
47266082Smarkj			fi
48254889Smarkj			break
49266082Smarkj		fi
50254889Smarkj		if [ ${delay} -eq ${defaultroute_delay} ]; then
51266082Smarkj			echo -n "Waiting ${delay}s for the default route interface: "
52254889Smarkj		else
53266082Smarkj			echo -n .
54254889Smarkj		fi
55266082Smarkj		nl=1
56254889Smarkj		sleep 1
57254889Smarkj		delay=$(($delay - 1))
58254889Smarkj	done
59266082Smarkj
60254889Smarkj	[ -n "$nl" ] && echo
61266082Smarkj}
62254889Smarkj
63266082Smarkjload_rc_config $name
64254889Smarkjrun_rc_command "$1"
65266082Smarkj