Commit 84f15cc3 authored by Vitaly Lipatov's avatar Vitaly Lipatov

route-update.sh: auto-detect and reload lost rules/routes

When ip rules or routing tables are empty (e.g. after networkctl reconfigure), force reload even if list hashes match. Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent bd96de95
...@@ -203,8 +203,19 @@ process_routes() ...@@ -203,8 +203,19 @@ process_routes()
local saved_hash local saved_hash
read -r saved_hash < "$STATE_DIR/$state/hash" read -r saved_hash < "$STATE_DIR/$state/hash"
if [ "$current_hash" = "$saved_hash" ] ; then if [ "$current_hash" = "$saved_hash" ] ; then
[ -n "$SHOW" ] && log "[$name]$label No changes (hash match), skipping" # Check if rules/routes were lost (e.g. after network restart)
continue local need_reload=
if ! $ipcmd rule show | grep -q "lookup $table" ; then
need_reload=1
elif [ "$($ipcmd route show table "$table" 2>/dev/null | wc -l)" = "0" ] ; then
need_reload=1
fi
if [ -n "$need_reload" ] ; then
log "[$name]$label Rules/routes lost, forcing reload"
else
[ -n "$SHOW" ] && log "[$name]$label No changes (hash match), skipping"
continue
fi
fi fi
fi fi
...@@ -238,7 +249,7 @@ process_routes() ...@@ -238,7 +249,7 @@ process_routes()
} | sort -u > "$resolved_new" } | sort -u > "$resolved_new"
# Check if resolved IPs actually changed # Check if resolved IPs actually changed
if [ -z "$FORCE" ] && [ -f "$STATE_DIR/$state/resolved" ] ; then if [ -z "$FORCE" ] && [ -z "$need_reload" ] && [ -f "$STATE_DIR/$state/resolved" ] ; then
if diff -q "$STATE_DIR/$state/resolved" "$resolved_new" >/dev/null 2>&1 ; then if diff -q "$STATE_DIR/$state/resolved" "$resolved_new" >/dev/null 2>&1 ; then
# IPs same, but gateway may have changed # IPs same, but gateway may have changed
if [ -f "$STATE_DIR/$state/gateway" ] && diff -q "$STATE_DIR/$state/gateway" "$gwdir/gateway" >/dev/null 2>&1 ; then if [ -f "$STATE_DIR/$state/gateway" ] && diff -q "$STATE_DIR/$state/gateway" "$gwdir/gateway" >/dev/null 2>&1 ; then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment