Reinsert IPv4 in case of failure
This commit is contained in:
parent
ab830f2694
commit
78467d27ff
|
@ -20,6 +20,30 @@ write_log() {
|
||||||
fi
|
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, it’s because trafic has
|
||||||
|
# already be sent to the VM
|
||||||
|
if [ $? = 2 ]; then
|
||||||
|
ip neigh replace ${VM_IPV4} lladdr ${MAC} dev ${IFACE}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# IPAM creds
|
# IPAM creds
|
||||||
CREDS_FILE='/usr/local/etc/proxmox-routing/creds'
|
CREDS_FILE='/usr/local/etc/proxmox-routing/creds'
|
||||||
if [ -f $CREDS_FILE ]; then
|
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
|
# Si la valeur n'est pas vide et correspond à une IPV4
|
||||||
if [ -n "${VM_IPV4}" ]; then
|
if [ -n "${VM_IPV4}" ]; then
|
||||||
# Ajout de la route associée
|
add_ipv4_route ${VM_IPV4} ${IFACE} ${MAC}
|
||||||
COMMAND="ip -4 route add ${VM_IPV4}/32 dev ${IFACE}"
|
while [ "$( ip route sh dev ${IFACE})" = "" ]; do
|
||||||
echo "${COMMAND}"
|
add_ipv4_route ${VM_IPV4} ${IFACE} ${MAC}
|
||||||
write_log INFO "${COMMAND}"
|
sleep 1
|
||||||
${COMMAND}
|
done
|
||||||
|
|
||||||
# Updating ARP
|
|
||||||
COMMAND="ip neigh add ${VM_IPV4} lladdr ${MAC} dev ${IFACE}"
|
|
||||||
echo "${COMMAND}"
|
|
||||||
write_log INFO "${COMMAND}"
|
|
||||||
${COMMAND}
|
|
||||||
|
|
||||||
# If the previous command fails, it’s because trafic has
|
|
||||||
# already be sent to the VM
|
|
||||||
if [ $? = 2 ]; then
|
|
||||||
ip neigh replace ${VM_IPV4} lladdr ${MAC} dev ${IFACE}
|
|
||||||
fi
|
|
||||||
|
|
||||||
GW_IPv4=$(jq -r ".data[] | select(.is_gateway==\"1\") | .ip" ${CHEMIN_CACHE}/${ID_RANGE_V4})
|
GW_IPv4=$(jq -r ".data[] | select(.is_gateway==\"1\") | .ip" ${CHEMIN_CACHE}/${ID_RANGE_V4})
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue