Commit 592e5f2d authored by Vitaly Lipatov's avatar Vitaly Lipatov

route-update: support explicit per-group pref override via options

ip rule pref is otherwise derived from alphabetical group order, so a group cannot be consulted before a lexicographically-earlier one (e.g. fr vs egw) without renaming it — and digits sort after letters in ru_RU.UTF-8, so even a '0-fr' rename goes the wrong way. Allow an options line "pref N" to set the group's pref base directly, independent of name or locale. Used on fr (pref 900) so claude.ai via fr wins over the egw/ai table (pref 1210). Also call _fixup_rule_pref on the "resolved unchanged" skip path, so an options-only change actually migrates the ip rule to the new pref (previously the rule kept its old pref because load was skipped). Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
parent a7a51ff4
......@@ -16,6 +16,9 @@ ipcmd_for() { case "$1" in *routes6*) echo "ip -6" ;; *) echo "ip" ;; esac ; }
# Check if option is set in group's options file
has_option() { [ -f "$1/options" ] && grep -q "^$2$" "$1/options" 2>/dev/null ; }
# Read a key's value from group's options file: line "key value" → value (e.g. "pref 900")
option_value() { [ -f "$1/options" ] && awk -v k="$2" '$1==k{print $2; exit}' "$1/options" 2>/dev/null ; }
# Special route-type keywords for gateway: instead of 'via <gw>', emit a kernel route type.
# blackhole = silent drop; unreachable/prohibit/throw = ICMP back to client → fast failure.
is_route_type_keyword() {
......
......@@ -710,6 +710,7 @@ load_list_routes()
if diff -q "$STATE_DIR/$_state/resolved" "$_resolved_new" >/dev/null 2>&1 ; then
if [ -f "$STATE_DIR/$_state/gateway" ] && diff -q "$STATE_DIR/$_state/gateway" "$_gwdir/gateway" >/dev/null 2>&1 ; then
log "$_tag$_label Resolved IPs unchanged, updating hash only"
_fixup_rule_pref # options (pref) may have changed even if routes/gateway didn't
echo "$_current_hash" > "$STATE_DIR/$_state/hash"
rm -f "$_resolved_new"
return 1 # signal: skip loading
......@@ -971,6 +972,12 @@ process_routes()
local pref_base=$((PREF_BASE + group_index * PREF_GROUP_STEP))
group_index=$((group_index + 1))
# Explicit per-group pref override (options file: "pref N") — beats the default
# alphabetical assignment, e.g. so a group is consulted before 'egw'/'ai' regardless
# of its name or locale collation (digits sort last in ru_RU.UTF-8).
local _pref_override=$(option_value "$_gwdir" "pref")
[ -n "$_pref_override" ] && pref_base="$_pref_override"
process_group "$_gwdir" "$_resolve_func" "$_ipcmd" "$_label" "$pref_base" &
pids="$pids $!"
done
......
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