fix: harden netfilter hook against DHCP renew races - #116
Open
dmiales wants to merge 5 commits into
Open
Conversation
dmiales
force-pushed
the
contrib/07-hook-renew
branch
2 times, most recently
from
July 29, 2026 00:23
08f6f83 to
ca32597
Compare
Unpack XKeen into a temp dir, verify, then move into place so an interrupted update never leaves a half-written install. Add a gzip -t pre-check for the mihomo archive with backup restore, and a minimum-size guard for core downloads to reject truncated/stub files.
Enable geo-auto-update in the generated mihomo config (mihomo manages its own GeoSite/GeoIP/ASN, XKeen's xray dat files are unused for it). Make 'xkeen -ug' aware of the active core: for mihomo it explains geo-auto-update and only reapplies GeoIPSET instead of touching unused xray dat files.
Make the mihomo Go GC soft memory limit configurable via xkeen.json (.xkeen.gomemlimit_percent / .xkeen.gomemlimit_mb) instead of a hardcoded value. Default stays at 50% of RAM (unchanged behaviour); an explicit MiB value has no default. An external GOMEMLIMIT still wins.
On short DHCP leases NDM invokes netfilter.d every renew, usually with the same WAN IP. Remember the last WAN IP and, if it hasn't changed and the chains are intact, skip the redundant route/rule work.
Write the generated hook atomically (temp + mv) so a renew mid-generation never sees an empty/truncated proxy.sh. Keep the deny-MAC ipset intact on RCI failure instead of swapping an empty set over it. Use a PID-based mkdir lock for the hook's mihomo respawn so it can't stick after an OOM, and release the netfilter lock before the slow hotspot API call so neighbouring NDM events don't stall.
dmiales
force-pushed
the
contrib/07-hook-renew
branch
from
July 29, 2026 00:29
ca32597 to
279c4b5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Что и зачем
mv) — renew посреди генерации не увидит пустой/обрезанныйproxy.sh.Как проверял
На роутере Keenetic (mihomo/TProxy): под частыми renew хук цел, прокси стабилен;
sh -n.Часть 7/8 — после части 6.
Часть стека харденинга. Полный порядок влития: 1 inject_var → 2 RCI/dry-run → 3 установка → 4 mihomo-geo → 5 GOMEMLIMIT → 6 WAN-skip → 7 hook-renew → 8 serialize. Ветка включает коммиты предыдущих частей — diff очистится после их мержа.