blob: abd6969f16ea5bb0646ae5807d53a93dee6c1c7a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
#! /bin/bash
#
### BEGIN INIT INFO
# Provides: $network $named
# Should-Start: portreserve
# Required-Start: network
# Required-Stop: network
# Default-Start: 2 3 4 5
# Short-Description: Wait for the hotplugged network to be up
# Description: Wait for all network interfaces started asynchronously
# at boot time.
### END INIT INFO
# Source function library.
. /etc/init.d/functions
NETWORKDELAY=20
DEFAULT_LINK_DETECTION_DELAY=2
MIN_LINK_DETECTION_DELAY=0
MAX_LINK_DETECTION_DELAY=$MIN_LINK_DETECTION_DELAY
ELAPSED_TIME=0
RESOLVCONF_FLAGFILE=/var/run/resolvconf/enable-updates
RESOLVCONF_DIR=/var/run/resolvconf/interface
# source network configuration
. /etc/sysconfig/network
# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0
cd /etc/sysconfig/network-scripts
. network-functions
# find all the interfaces besides loopback.
# ignore aliases, alternative configurations, and editor backup files
interfaces=$(ls ifcfg* | \
LANG=C sed -e "$__sed_discard_ignored_files" \
-e '/\(ifcfg-lo\|:\|ifcfg-.*-range\)/d' \
-e '/ifcfg-[A-Za-z0-9\._-]\+$/ { s/^ifcfg-//g;s/[0-9]/ &/}' | \
LANG=C sort -k 1,1 -k 2n | \
LANG=C sed 's/ //')
function may_have_link() {
local DEVICE=$1
local LINKDELAY=0
! check_link_down ${DEVICE} || is_associating ${DEVICE}
}
function is_associating() {
local DEVICE=$1
is_wireless_device ${DEVICE} || return 1
local AP=`iwgetid -a -r ${DEVICE} 2>/dev/null`
[ -n "$AP" ] && [ "$AP" != "00:00:00:00:00:00" ] && [ "$AP" != "44:44:44:44:44:44" ] && [ "$AP" != "FF:FF:FF:FF:FF:FF" ]
}
function should_wait_network() {
for i in $interfaces; do
unset DEVICE TYPE BOOTPROTO MII_NOT_SUPPORTED PEERDNS DNS1 DNS2
unset REALDEVICE PARENTDEVICE NM_CONTROLLED
LINK_DETECTION_DELAY=$DEFAULT_LINK_DETECTION_DELAY
eval $(LANG=C fgrep "DEVICE=" ifcfg-$i)
eval $(LANG=C fgrep "REALDEVICE=" ifcfg-$i)
eval $(LANG=C fgrep "PARENTDEVICE=" ifcfg-$i)
eval $(LANG=C fgrep "TYPE=" ifcfg-$i)
eval $(LANG=C fgrep "BOOTPROTO=" ifcfg-$i)
eval $(LANG=C fgrep "MII_NOT_SUPPORTED=" ifcfg-$i)
eval $(LANG=C fgrep "LINK_DETECTION_DELAY=" ifcfg-$i)
eval $(LANG=C fgrep "PEERDNS=" ifcfg-$i)
eval $(LANG=C fgrep "DNS1=" ifcfg-$i)
eval $(LANG=C fgrep "DNS2=" ifcfg-$i)
eval $(LANG=C fgrep "NM_CONTROLLED=" ifcfg-$i)
[ -z "$REALDEVICE" -a -n "$PARENTDEVICE" ] && REALDEVICE=$PARENTDEVICE
[ -z "$REALDEVICE" ] && REALDEVICE=${DEVICE%%:*}
if [ $LINK_DETECTION_DELAY -lt $MIN_LINK_DETECTION_DELAY ]; then
LINK_DETECTION_DELAY=$MIN_LINK_DETECTION_DELAY
fi
if [ -z "$DEVICE" ] ; then DEVICE="$i"; fi
if [ "$BOOTPROTO" != "static" ] \
&& [ "$BOOTPROTO" != "dhcp" ] \
&& [ "$BOOTPROTO" != "bootp" ]; then
continue
fi
# only check interfaces using ifplug, other interfaces are
# started synchronously from the network service
if [ "$MII_NOT_SUPPORTED" = "yes" ]; then
continue
fi
# only check interfaces automatically launched
if LANG=C egrep -q "^ONBOOT=['\"]?[Nn][Oo]['\"]?" ifcfg-$i; then
continue
fi
# for NM controlled just ask NetworkManager
if is_true $NM_CONTROLLED; then
[ -x /usr/bin/nmcli ] || continue
[ "$(LC_ALL=C /usr/bin/nmcli -t -f state nm)" = connected ] && \
continue || return 0
fi
# ignore devices that are not present
ip -o link show ${DEVICE} &>/dev/null || continue
# check link beat
if ! may_have_link ${DEVICE}; then
# before configured delay, consider a lack of link beat
# as not ready, and unplugged thereafter
if [ $ELAPSED_TIME -lt $LINK_DETECTION_DELAY ]; then
return 0
fi
# no need to wait for unplugged devices to come up
continue
fi
# check address is set
ADDR=`ip addr show scope global ${DEVICE} | awk '/inet/ {print $2;}'`
if [ -z "$ADDR" ]; then
return 0
fi
# wait for changes to be propagated by resolvconf if needed
if [ -e $RESOLVCONF_FLAGFILE ]; then
if [ "$BOOTPROTO" = "dhcp" -a "$PEERDNS" != "no" ] \
|| [ -n "$DNS1" -o -n "$DNS2" ]; then
if [ ! -e $RESOLVCONF_DIR/$DEVICE ]; then
return 0
fi
if [ $RESOLVCONF_DIR/$DEVICE -nt /etc/resolv.conf ]; then
return 0
fi
fi
fi
done
# all interfaces are ready
return 1
}
case "$1" in
start)
gprintf "Waiting for network to be up"
for i in $interfaces; do
LINK_DETECTION_DELAY=$DEFAULT_LINK_DETECTION_DELAY
eval $(LANG=C fgrep "LINK_DETECTION_DELAY=" ifcfg-$i)
if [ "$LINK_DETECTION_DELAY" -gt $MAX_LINK_DETECTION_DELAY ]; then
MAX_LINK_DETECTION_DELAY=$LINK_DETECTION_DELAY
fi
done
NETWORKDELAY=$(( NETWORKDELAY + MAX_LINK_DETECTION_DELAY ))
while should_wait_network && [ $ELAPSED_TIME -lt $NETWORKDELAY ]; do
sleep 1
let ELAPSED_TIME=$ELAPSED_TIME+1
done
[ $ELAPSED_TIME -ge $NETWORKDELAY ] && failure || success
echo
;;
stop)
;;
*)
gprintf "Usage: %s\n" "$(basename $0) {start|stop}"
exit 1
esac
exit 0
|