2017-09-12 16:13:27 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2019-05-01 10:02:38 -05:00
|
|
|
function wait_until_iface_ready
|
|
|
|
{
|
2019-09-12 12:57:08 -05:00
|
|
|
IFACE_NAME=$1
|
|
|
|
IFACE_CIDR=$2
|
2017-11-20 23:07:28 -06:00
|
|
|
|
2019-09-12 12:57:08 -05:00
|
|
|
echo "Waiting until interface ${IFACE_NAME} is ready..."
|
2017-11-20 23:07:28 -06:00
|
|
|
|
2019-05-01 10:02:38 -05:00
|
|
|
# Wait for the interface to come up
|
|
|
|
# (i.e., interface is present in STATE_DB and state is "ok")
|
2017-11-20 23:07:28 -06:00
|
|
|
while true; do
|
2020-01-22 13:27:21 -06:00
|
|
|
RESULT=$(sonic-db-cli STATE_DB HGET "INTERFACE_TABLE|${IFACE_NAME}|${IFACE_CIDR}" "state" 2> /dev/null)
|
2019-05-01 10:02:38 -05:00
|
|
|
if [ x"$RESULT" == x"ok" ]; then
|
2017-11-20 23:07:28 -06:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
2019-09-12 12:57:08 -05:00
|
|
|
echo "Interface ${IFACE_NAME} is ready!"
|
2017-09-12 16:13:27 -05:00
|
|
|
}
|
|
|
|
|
2022-10-12 03:46:20 -05:00
|
|
|
function check_for_ipv6_link_local
|
|
|
|
{
|
|
|
|
IFACE_NAME=$1
|
|
|
|
echo "Waiting until interface ${IFACE_NAME} has a link-local ipv6 address configured...."
|
|
|
|
|
|
|
|
# Status of link local address is not populated in STATE_DB
|
|
|
|
while true; do
|
|
|
|
HAS_LL=$(ip -6 addr show ${IFACE_NAME} scope link 2> /dev/null)
|
|
|
|
RC=$?
|
|
|
|
if [[ ${RC} == "0" ]] && [[ ! -z ${HAS_LL} ]]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Link-Local address is configured on ${IFACE_NAME}"
|
|
|
|
}
|
2017-09-12 16:13:27 -05:00
|
|
|
|
2019-09-12 12:57:08 -05:00
|
|
|
# Wait for all interfaces with IPv4 addresses to be up and ready
|
2022-10-12 03:46:20 -05:00
|
|
|
# dhcp6relay binds to ipv6 addresses configured on these vlan ifaces
|
|
|
|
# Thus check if they are ready before launching dhcp6relay
|
2019-09-12 12:57:08 -05:00
|
|
|
{% for (name, prefix) in INTERFACE|pfx_filter %}
|
|
|
|
{% if prefix | ipv4 %}
|
|
|
|
wait_until_iface_ready {{ name }} {{ prefix }}
|
2019-08-09 13:28:15 -05:00
|
|
|
{% endif %}
|
2017-09-12 16:13:27 -05:00
|
|
|
{% endfor %}
|
2019-09-12 12:57:08 -05:00
|
|
|
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
|
|
|
|
{% if prefix | ipv4 %}
|
|
|
|
wait_until_iface_ready {{ name }} {{ prefix }}
|
2019-08-09 13:28:15 -05:00
|
|
|
{% endif %}
|
2022-10-12 03:46:20 -05:00
|
|
|
{% if prefix | ipv6 %}
|
|
|
|
{% if DHCP_RELAY and name in DHCP_RELAY %}
|
|
|
|
wait_until_iface_ready {{ name }} {{ prefix }}
|
|
|
|
check_for_ipv6_link_local {{ name }}
|
|
|
|
{% endif %}
|
|
|
|
{% endif %}
|
2017-09-12 16:13:27 -05:00
|
|
|
{% endfor %}
|
2019-09-12 12:57:08 -05:00
|
|
|
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
|
|
|
|
{% if prefix | ipv4 %}
|
|
|
|
wait_until_iface_ready {{ name }} {{ prefix }}
|
2019-08-09 13:28:15 -05:00
|
|
|
{% endif %}
|
2017-09-12 16:13:27 -05:00
|
|
|
{% endfor %}
|
2021-10-21 20:45:00 -05:00
|
|
|
|
|
|
|
# Wait 10 seconds for the rest of interfaces to get added/populated.
|
|
|
|
# dhcrelay listens on each of the interfaces (in addition to the port
|
|
|
|
# channels and vlan interfaces)
|
|
|
|
sleep 10
|