Reinsert IPv4 in case of failure

This commit is contained in:
Alarig Le Lay 2019-01-25 13:45:25 +01:00
parent ab830f2694
commit 78467d27ff

View file

@ -20,6 +20,30 @@ write_log() {
fi
}
add_ipv4_route(){
VM_IPV4=$1
IFACE=$2
MAC=$3
# Ajout de la route associée
COMMAND="ip -4 route add ${VM_IPV4}/32 dev ${IFACE}"
echo "${COMMAND}"
write_log INFO "${COMMAND}"
${COMMAND}
# Updating ARP
COMMAND="ip neigh add ${VM_IPV4} lladdr ${MAC} dev ${IFACE}"
echo "${COMMAND}"
write_log INFO "${COMMAND}"
${COMMAND}
# If the previous command fails, its because trafic has
# already be sent to the VM
if [ $? = 2 ]; then
ip neigh replace ${VM_IPV4} lladdr ${MAC} dev ${IFACE}
fi
}
# IPAM creds
CREDS_FILE='/usr/local/etc/proxmox-routing/creds'
if [ -f $CREDS_FILE ]; then
@ -183,23 +207,11 @@ for ID_RANGE_V4 in ${ID_RANGES_V4}; do
# Si la valeur n'est pas vide et correspond à une IPV4
if [ -n "${VM_IPV4}" ]; then
# Ajout de la route associée
COMMAND="ip -4 route add ${VM_IPV4}/32 dev ${IFACE}"
echo "${COMMAND}"
write_log INFO "${COMMAND}"
${COMMAND}
# Updating ARP
COMMAND="ip neigh add ${VM_IPV4} lladdr ${MAC} dev ${IFACE}"
echo "${COMMAND}"
write_log INFO "${COMMAND}"
${COMMAND}
# If the previous command fails, its because trafic has
# already be sent to the VM
if [ $? = 2 ]; then
ip neigh replace ${VM_IPV4} lladdr ${MAC} dev ${IFACE}
fi
add_ipv4_route ${VM_IPV4} ${IFACE} ${MAC}
while [ "$( ip route sh dev ${IFACE})" = "" ]; do
add_ipv4_route ${VM_IPV4} ${IFACE} ${MAC}
sleep 1
done
GW_IPv4=$(jq -r ".data[] | select(.is_gateway==\"1\") | .ip" ${CHEMIN_CACHE}/${ID_RANGE_V4})
else