View | Details | Raw Unified | Return to bug 205186
Collapse All | Expand All

(-)etc/rc.d/NETWORKING (-1 / +1 lines)
Lines 4-10 Link Here
4
#
4
#
5
5
6
# PROVIDE: NETWORKING NETWORK
6
# PROVIDE: NETWORKING NETWORK
7
# REQUIRE: netif netoptions routing ppp ipfw stf
7
# REQUIRE: netif netwait netoptions routing ppp ipfw stf
8
# REQUIRE: defaultroute routed route6d mroute6d resolv bridge
8
# REQUIRE: defaultroute routed route6d mroute6d resolv bridge
9
# REQUIRE: static_arp static_ndp
9
# REQUIRE: static_arp static_ndp
10
10
(-)etc/rc.d/netwait (-56 / +73 lines)
Lines 3-15 Link Here
3
# $FreeBSD$
3
# $FreeBSD$
4
#
4
#
5
# PROVIDE: netwait
5
# PROVIDE: netwait
6
# REQUIRE: NETWORKING
6
# REQUIRE: devd routing
7
# KEYWORD: nojail
7
# KEYWORD: nojail
8
#
8
#
9
# The netwait script is intended to be used by systems which have
9
# The netwait script helps handle two situations:
10
# statically-configured IP addresses in rc.conf(5).  If your system
10
#  - Systems with USB or other late-attaching network hardware which
11
# uses DHCP, you should use synchronous_dhclient="YES" in your
11
#    is initialized by devd events.  The script waits for all the
12
# /etc/rc.conf instead of using netwait.
12
#    interfaces named in the netwait_if list to appear.
13
#  - Systems with statically-configured IP addresses in rc.conf(5).
14
#    The IP addresses in the netwait_ip list are pinged.  The script
15
#    waits for any single IP in the list to respond to the ping.  If your
16
#    system uses DHCP, you should probably use synchronous_dhclient="YES"
17
#    in your /etc/rc.conf instead of netwait_ip.
18
# Either or both of the wait lists can be used (at least one must be
19
# non-empty if netwait is enabled).
13
20
14
. /etc/rc.subr
21
. /etc/rc.subr
15
22
Lines 21-30 stop_cmd=":" Link Here
21
28
22
netwait_start()
29
netwait_start()
23
{
30
{
24
	local ip rc count output link
31
	local ip rc count output link wait_if got_if any_error
25
32
26
	if [ -z "${netwait_ip}" ]; then
33
	if [ -z "${netwait_if}" ] && [ -z "${netwait_ip}" ]; then
27
		err 1 "You must define one or more IP addresses in netwait_ip"
34
		err 1 "No interface or IP addresses listed, nothing to wait for"
28
	fi
35
	fi
29
36
30
	if [ ${netwait_timeout} -lt 1 ]; then
37
	if [ ${netwait_timeout} -lt 1 ]; then
Lines 31-97 netwait_start() Link Here
31
		err 1 "netwait_timeout must be >= 1"
38
		err 1 "netwait_timeout must be >= 1"
32
	fi
39
	fi
33
40
34
	# Handle SIGINT (Ctrl-C); force abort of while() loop
35
	trap break SIGINT
36
37
	if [ -n "${netwait_if}" ]; then
41
	if [ -n "${netwait_if}" ]; then
38
		echo -n "Waiting for $netwait_if to have link"
42
		any_error=0
39
43
		for wait_if in ${netwait_if}; do
40
		count=1
44
			echo -n "Waiting for ${wait_if}"
41
		while [ ${count} -le ${netwait_if_timeout} ]; do
45
			link=""
42
			if output=`/sbin/ifconfig ${netwait_if} 2>/dev/null`; then
46
			got_if=0
43
				link=`expr "${output}" : '.*[[:blank:]]status: \(no carrier\)'`
47
			count=1
44
				if [ -z "${link}" ]; then
48
			# Handle SIGINT (Ctrl-C); force abort of while() loop
45
					echo '.'
49
			trap break SIGINT
46
					break
50
			while [ ${count} -le ${netwait_if_timeout} ]; do
51
				if output=`/sbin/ifconfig ${wait_if} 2>/dev/null`; then
52
					if [ ${got_if} -eq 0 ]; then
53
						echo -n ", interface present"
54
						got_if=1
55
					fi
56
					link=`expr "${output}" : '.*[[:blank:]]status: \(no carrier\)'`
57
					if [ -z "${link}" ]; then
58
						echo ', got link.'
59
						break
60
					fi
47
				fi
61
				fi
48
			else
62
				sleep 1
49
				echo ''
63
				count=$((count+1))
50
				err 1 "ifconfig ${netwait_if} failed"
64
			done
65
			# Restore default SIGINT handler
66
			trap - SIGINT
67
			if [ ${got_if} -eq 0 ]; then
68
				echo ", wait failed: interface never appeared."
69
				any_error=1
70
			elif [ -n "${link}" ]; then
71
				echo ", wait failed: interface still has no link."
72
				any_error=1
51
			fi
73
			fi
52
			sleep 1
53
			count=$((count+1))
54
		done
74
		done
55
		if [ -n "${link}" ]; then
75
		if [ ${any_error} -eq 1 ]; then
56
			# Restore default SIGINT handler
76
		    warn "Continuing with startup, but be aware you may not have "
57
			trap - SIGINT
77
		    warn "a fully functional networking layer at this point."
58
59
			echo ''
60
			warn "Interface still has no link.  Continuing with startup, but"
61
			warn "be aware you may not have a fully functional networking"
62
			warn "layer at this point."
63
			return
64
		fi
78
		fi
65
	fi
79
	fi
80
	
81
	if [ -n "${netwait_ip}" ]; then
82
		# Handle SIGINT (Ctrl-C); force abort of for() loop
83
		trap break SIGINT
66
84
67
	# Handle SIGINT (Ctrl-C); force abort of while() loop
85
		for ip in ${netwait_ip}; do
68
	trap break SIGINT
86
			echo -n "Waiting for ${ip} to respond to ICMP ping"
69
87
70
	for ip in ${netwait_ip}; do
88
			count=1
71
		echo -n "Waiting for ${ip} to respond to ICMP"
89
			while [ ${count} -le ${netwait_timeout} ]; do
90
				/sbin/ping -t 1 -c 1 -o ${ip} >/dev/null 2>&1
91
				rc=$?
72
92
73
		count=1
93
				if [ $rc -eq 0 ]; then
74
		while [ ${count} -le ${netwait_timeout} ]; do
94
					# Restore default SIGINT handler
75
			/sbin/ping -t 1 -c 1 -o ${ip} >/dev/null 2>&1
95
					trap - SIGINT
76
			rc=$?
77
96
78
			if [ $rc -eq 0 ]; then
97
					echo ', got response.'
79
				# Restore default SIGINT handler
98
					return
80
				trap - SIGINT
99
				fi
81
100
				count=$((count+1))
82
				echo '.'
101
			done
83
				return
102
			echo ', failed: No response from host.'
84
			fi
85
			count=$((count+1))
86
		done
103
		done
87
		echo ': No response from host.'
88
	done
89
104
90
	# Restore default SIGINT handler
105
		# Restore default SIGINT handler
91
	trap - SIGINT
106
		trap - SIGINT
92
107
93
	warn "Exhausted IP list.  Continuing with startup, but be aware you may"
108
		warn "Exhausted IP list.  Continuing with startup, but be aware you may"
94
	warn "not have a fully functional networking layer at this point."
109
		warn "not have a fully functional networking layer at this point."
110
	fi
111
95
}
112
}
96
113
97
load_rc_config $name
114
load_rc_config $name

Return to bug 205186