shater-core — data-plane glue for the Shater transparent proxy
==============================================================

This package is the static, rock-solid ("железно") layer beneath the Go
control-plane (xrayctl) and the LuCI app. It ships no business logic and
compiles nothing; it only wires the kernel + procd so xrayctl's generated
artifacts come to life reliably.

Files installed
---------------
  /etc/init.d/shater
      procd supervisor (START=99). Runs the stock xray engine
      (/usr/bin/xray run -c /etc/xray/run.json) as a supervised, respawning
      instance and drives `xrayctl reconcile` on start to (re)persist policy
      routing and our nft table. Fully inert unless globals.enabled=1 AND
      /etc/xray/run.json exists. stop tears down only our own resources.

  /etc/hotplug.d/iface/99-shater
      On ifup/ifdown, re-runs `xrayctl reconcile` (ip rules/routes are volatile
      and wiped on `network reload`). Inert unless enabled.

  /etc/sysctl.d/99-shater.conf
      ip_forward, rp_filter=0, route_localnet=1, accept_local=1,
      src_valid_mark=1 (+ IPv6 forwarding) — required for TPROXY + the
      `local ... dev lo` policy-routing trick.

  /etc/config/shater
      Minimal INERT UCI default (globals.enabled='0'). Installed as a conffile:
      your edits survive upgrades. Full schema in CONTRACT.md.

  /etc/uci-defaults/30_shater-core
      First-boot idempotent setup: seeds an rt_tables name for the reserved
      table base (0x2000) and enables the service.

Ownership & reliability invariants
----------------------------------
  * We own the nft table `inet shater` (generated by xrayctl at apply time,
    not shipped here) — fw4's table is NEVER touched.
  * Reserved fwmark base 0x2000, routing-table base 0x2000.
  * Management/LAN/SSH/LuCI paths are always bypassed (enforced by xrayctl's
    generated ruleset); this package's teardown only removes `inet shater` and
    routing tables in the reserved block.
  * Safe on boot even if xray or run.json is absent: the init exits cleanly and
    never breaks connectivity.

Runtime layout (created/managed by xrayctl, for reference)
----------------------------------------------------------
  /etc/xray/run.json        generated live xray config (do not hand-edit)
  /etc/xray/last-good.json  last valid config (rollback)
  /etc/xray/nft/shater.nft  generated nft table `inet shater`
  /var/run/xray/            runtime: pid, pending-apply, stats

Operating
---------
  Configure via LuCI or `uci set shater.globals.enabled=1` then apply:
      xrayctl apply            # gen -> test -> atomic apply (+ optional confirm)
      /etc/init.d/shater start # or restart; reconcile runs automatically
  Inspect:
      /etc/init.d/shater status ; logread -e xray
      ip rule show ; ip route show table 8192
      nft list table inet shater
