Skip to content

Commit 1f9107d

Browse files
authored
[DHCP relay]: Wait for all interfaces to be assigned IPv4 addresses before starting relay agent(s) (#1173)
1 parent dc9f19e commit 1f9107d

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

dockers/docker-dhcp-relay/start.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ rm -f /var/run/rsyslogd.pid
66
# Start rsyslog
77
supervisorctl start rsyslogd
88

9-
# Wait for all interfaces to come up before starting the DHCP relay agent(s)
9+
# Wait for all interfaces to come up and be assigned IPv4 addresses before
10+
# starting the DHCP relay agent(s). If an interface the relay should listen
11+
# on is down, the relay agent will not start. If an interface the relay should
12+
# listen on is up but does not have an IP address assigned when the relay
13+
# agent starts, it will not listen or send on that interface for the lifetime
14+
# of the process.
1015
/usr/bin/wait_for_intf.sh
1116

1217
# Start the DHCP relay agent(s)
+23-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,42 @@
11
#!/usr/bin/env bash
22

3-
function wait_until_iface_exists
3+
function wait_until_iface_ready
44
{
55
IFACE=$1
66

7-
echo "Waiting for interface ${IFACE}..."
7+
echo "Waiting until interface $IFACE is up..."
88

99
# Wait for the interface to come up (i.e., 'ip link show' returns 0)
10-
until ip link show $IFACE > /dev/null 2>&1; do
10+
until ip link show dev $IFACE up > /dev/null 2>&1; do
1111
sleep 1
1212
done
1313

14-
echo "Interface ${IFACE} is created"
14+
echo "Interface $IFACE is up"
15+
16+
echo "Waiting until interface $IFACE has an IPv4 address..."
17+
18+
# Wait until the interface gets assigned an IPv4 address
19+
while true; do
20+
IP=$(ip -4 addr show dev $IFACE | grep "inet " | awk '{ print $2 }' | cut -d '/' -f1)
21+
22+
if [ -n "$IP" ]; then
23+
break
24+
fi
25+
26+
sleep 1
27+
done
28+
29+
echo "Interface $IFACE is configured with IP $IP"
1530
}
1631

1732

18-
# Wait for all interfaces to come up before starting the DHCP relay
33+
# Wait for all interfaces to come up and have IPv4 addresses assigned
1934
{% for (name, prefix) in INTERFACE %}
20-
wait_until_iface_exists {{ name }}
35+
wait_until_iface_ready {{ name }}
2136
{% endfor %}
2237
{% for (name, prefix) in VLAN_INTERFACE %}
23-
wait_until_iface_exists {{ name }}
38+
wait_until_iface_ready {{ name }}
2439
{% endfor %}
2540
{% for (name, prefix) in PORTCHANNEL_INTERFACE %}
26-
wait_until_iface_exists {{ name }}
41+
wait_until_iface_ready {{ name }}
2742
{% endfor %}

0 commit comments

Comments
 (0)