Commit 60e7ed97 authored by Vitaly Lipatov's avatar Vitaly Lipatov

router: add unified route-update.sh with directory-based config

Replace ipset+mangle approach with pure ip route tables. Configuration via routes.d/ (IPv4) and routes6.d/ (IPv6) directories where each subdirectory = gateway and .list symlinks = domain/IP lists. Features: - Hash-based change detection (skip if lists unchanged) - Double check: file hash + resolved IPs diff - Batch route loading via ip -batch - Automatic cleanup of orphaned state - --show/--force/--add/--del/--flush options Also adds is_ipv6() and get_ipv6_list_bulk() to functions. Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent be2b56c3
web/config web/config
vz/azbyka/base.task vz/azbyka/base.task
dns/whois-cache/* dns/whois-cache/*
router/.state/
...@@ -19,6 +19,11 @@ is_ipv4() ...@@ -19,6 +19,11 @@ is_ipv4()
echo "$1" | grep -q -E "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" echo "$1" | grep -q -E "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
} }
is_ipv6()
{
echo "$1" | grep -q ':'
}
## Несколько диапазонов в одной строке ## Несколько диапазонов в одной строке
# $ expand_range "r[1-2][a-b].test" # $ expand_range "r[1-2][a-b].test"
# r1a.test # r1a.test
...@@ -96,3 +101,46 @@ get_ipv4_list_bulk() ...@@ -96,3 +101,46 @@ get_ipv4_list_bulk()
get_ipv4_list "$domain" get_ipv4_list "$domain"
done done
} }
# Bulk resolve domains to IPv6 via adnshost (async) with dig fallback for CNAMEs
# Usage: get_ipv6_list_bulk < domains.txt
# or: get_ipv6_list_bulk domains.txt
get_ipv6_list_bulk()
{
local domains=$(mktemp)
local adns_out=$(mktemp)
trap "rm -f $domains $adns_out" RETURN
# Read domains, skip IPs (output them directly)
while read -r entry ; do
[ -z "$entry" ] && continue
if is_ipv6 "$entry" ; then
echo "$entry"
elif ! is_ipv4 "$entry" ; then
echo "$entry" >> "$domains"
fi
done < "${1:-/dev/stdin}"
[ -s "$domains" ] || return 0
# Bulk async resolve: local resolver + Google DNS
{
adnshost -a -t aaaa -Fi -f < "$domains"
adnshost -a -t aaaa -Fi -f --config "nameserver 8.8.8.8" < "$domains"
} > "$adns_out" 2>/dev/null
# Output resolved IPs grouped by domain
awk '/ AAAA / { print $1, $3 }' "$adns_out" | sort -u | awk '{
if (domain != $1) { print ""; print "# " $1; domain = $1 }
print $2
}'
# Fallback to dig for CNAME/tempfail domains
grep "^;" "$adns_out" | grep -v 'nxdomain\|nodata\|querydomaintoolong' | \
awk '{ for(i=4;i<=NF;i++) if($i ~ /^[a-z0-9].*\.[a-z]/) { print $i; break } }' | \
sort -u | while read domain ; do
echo
echo "# $domain (dig fallback)"
get_ipv6_list "$domain"
done
}
/root/egw-route/egw.list
\ No newline at end of file
/root/antifilter/community.lst
\ No newline at end of file
/root/antifilter/ipresolve.lst
\ No newline at end of file
/root/antifilter/subnet.lst
\ No newline at end of file
/root/egw-route/ogw.list
\ No newline at end of file
/root/egw-route/telegram.list
\ No newline at end of file
/root/egw-route/whatsapp.list
\ No newline at end of file
/root/egw-route/youtube.list
\ No newline at end of file
/root/egw-route/egw.list
\ No newline at end of file
/root/egw-route/workaround.list
\ No newline at end of file
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