Commit Graph
4 Commits
Author SHA1 Message Date
omarandClaude Opus 4.8 65883e20d9 feat(core): fail-safe hardening — live-flag, watchdog, procd fixes
Close the "rules live, engine dead" LAN-blackout class and make an admin
`stop` durable:
- live-flag /var/run/shater.active gates hotplug/cron reconcile, so `stop`
  sticks — a WAN flap can no longer resurrect interception behind a stopped
  engine.
- procd respawn retry=0 (never abandon the engine while rules stand) + guard
  that /usr/bin/xray is executable before installing the data plane.
- shater-cron watchdog: engine dead N ticks with interception live escalates
  per kill_switch (open -> auto-stop/fail-open, closed -> crit log).
- fix procd cron detach: `command "$INIT_SCRIPT" loop` (rc.common dispatch)
  instead of `/bin/sh $INIT_SCRIPT loop`, which detached the loop from procd
  (running:false + respawn churn) — the auto-updater/watchdog ran unsupervised.
- run.json regenerated at start after sysupgrade; cron stamps only on success
  with backoff, and waits for a default route before boot-time fetches.
- sysctl route_localnet/accept_local scoped to lo (was all — WAN anti-spoof
  weakening); applied at install time so no reboot is needed.
- fix stale example filenames; bump shater-core to r19.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LLthkP2S8WAfxu7fcYbPfE
2026-07-13 03:37:26 +03:00
omarandClaude Opus 4.8 3449ff32fc feat(routing): preset packs [T1] + schedule rules [T3]
build / aarch64_cortex-a53 (push) Successful in 3m4s
build / x86_64 (push) Successful in 3m3s
Preset packs: `config preset` toggles (block-ads / ru-bypass / private) inject
synthetic rules ahead of user rules (by low Order, first-match). They flow
through the same geoStrip pipeline, so geo-only packs degrade gracefully.

Empty-matcher guard (fixes a block-everything trap): a rule that HAD dst matchers
but lost them ALL to the geo-strip and has no other selector is now DROPPED — not
promoted to a tcp,udp catch-all. So a geo-only block-ads with no geodata fails
open (ads unblocked) instead of blackholing the LAN.

Schedule rules: xray has no time match, so buildRoutingRules consults
ruleActiveNow(timeNow()) and skips out-of-window rules — a plain gen/reconcile at
any instant emits the correct ruleset. `xrayctl schedule due` (shater-cron hook)
reconciles only at window boundaries. Wrap-around windows + day-of-week + optional
tz supported; malformed windows fail open.

- model.go: Preset + Rule.Sched* fields; uci.go parses config preset + sched_*.
- preset.go, schedule.go (new); generate.go: preset injection + schedule gate +
  empty-matcher guard; main.go: `schedule due`. timeNow seam (SHATER_FAKE_NOW).
- shater-cron: reconcile on schedule boundary; uci-defaults seeds the 3 presets.
- rules.js: Preset packs panel + per-rule schedule fields.
- tests: schedule_test.go, preset_test.go (windows/wrap/dow/fail-open, preset
  inject/override/drop, scheduled-rule inclusion).

Verified live on the 512M VM: block-ads→geosite rule, private→10.0.0.0/8 direct;
geodata-absent drops block-ads (0 matches, no block-all); example.com scheduled
rule absent@12:00 present@22:30; schedule due fires at boundary; xray -test OK. r12.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-09 15:41:36 +03:00
omarandClaude Opus 4.8 05920f83ad fix: eliminate reconcile fork-storm (OOM) + resolve UCI config conflict with xray-core
build / aarch64_cortex-a53 (push) Successful in 3m0s
build / x86_64 (push) Successful in 2m59s
Two release-blocking defects found via live 512M OpenWrt VM testing.

1) Fork-storm / OOM (critical). Reconcile() -> reloadXray() ->
   "/etc/init.d/shater reload" -> reload_service -> shater_reconcile ->
   `xrayctl reconcile` -> Reconcile() was an infinite mutual recursion; each
   level blocked on CombinedOutput and spawned a process (854x reconcile +
   853x reload observed), exhausting RAM and pinning both vCPUs -> OOM-killer.
   - Reconcile() no longer calls reloadXray(); procd's file-watch on run.json
     restarts xray. Reconcile runs inside the init lifecycle, so calling the
     init back is the recursion.
   - reloadXray() now runs `/etc/init.d/shater start` (not `reload`); it is only
     invoked from Apply()/Rollback() (LuCI/ubus/CLI), never the init lifecycle.
   - init reload_service() simplified to start/stop (dropped the double reconcile).
   Verified: `xrayctl apply` 0.39s (was >185s hang); 93 procs / load 0.00 stable
   with an active 254-node config on 512M; xray binds :10853 API + :12345 tproxy.

2) UCI config namespace clash. shater shipped /etc/config/xray, which collides
   with the xray-core dependency's own /etc/config/xray (opkg dropped ours to
   /etc/config/xray-opkg, so the schema never took effect). Renamed the UCI
   namespace xray -> shater everywhere (Go uci export/commit, all 11 LuCI views +
   acl, init scripts, hotplug, Makefile conffiles, examples). Runtime paths
   (/etc/xray/run.json, /usr/share/xray), the xray-core package, and the ubus
   object name are intentionally unchanged.

Also: ci/pack-xrayctl.sh (local ipk packer) with a postinst chmod so the binary
is executable regardless of host-tar mode handling; PKG_RELEASE bumped to r3.

Verified end-to-end on a fresh 512M OpenWrt 24.10.3 VM: feed install
(opkg install luci-app-shater pulls xrayctl+shater-core), real LAN client
(netns in br-lan) proxied through a live subscription node -> exit IP changed
(104.156.233.234 vs 45.131.214.140 direct); per-client nft counters + xray
stats API populated. See PROOFS.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-09 11:36:48 +03:00
omar 71a6f127a1 T1 features: egress, kill-switch, full DNS, stats/API, rulesets, live nodes, sub scheduling, all LuCI pages (4-agent build + integration); real xray -test 'Configuration OK' with full-feature config
build / aarch64_cortex-a53 (push) Successful in 3m2s
build / x86_64 (push) Successful in 3m1s
2026-07-09 10:12:55 +03:00