Skip to content

fix: harden netfilter hook against DHCP renew races - #116

Open
dmiales wants to merge 5 commits into
jameszeroX:mainfrom
dmiales:contrib/07-hook-renew
Open

fix: harden netfilter hook against DHCP renew races#116
dmiales wants to merge 5 commits into
jameszeroX:mainfrom
dmiales:contrib/07-hook-renew

Conversation

@dmiales

@dmiales dmiales commented Jul 28, 2026

Copy link
Copy Markdown

Что и зачем

  • Атомарная запись хука (временный файл + mv) — renew посреди генерации не увидит пустой/обрезанный proxy.sh.
  • Не затираем deny-MAC ipset пустым набором при сбое RCI (иначе снимается родительский контроль «без интернета»).
  • PID-based mkdir-lock для respawn mihomo из хука — не залипает после OOM.
  • Снятие netfilter-лока до медленного вызова hotspot API, чтобы соседние события NDM не ждали.

Как проверял

На роутере 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 очистится после их мержа.

@dmiales
dmiales force-pushed the contrib/07-hook-renew branch 2 times, most recently from 08f6f83 to ca32597 Compare July 29, 2026 00:23
dmiales added 5 commits July 29, 2026 03:28
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
dmiales force-pushed the contrib/07-hook-renew branch from ca32597 to 279c4b5 Compare July 29, 2026 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant