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>
340 lines
16 KiB
Plaintext
340 lines
16 KiB
Plaintext
#
|
|
# =============================================================================
|
|
# /etc/config/shater -- FULL annotated example (shater / xrayctl control-plane)
|
|
# =============================================================================
|
|
#
|
|
# This file is the DESIRED STATE. It is edited by LuCI or by hand. `xrayctl`
|
|
# renders it into xray run.json + nftables + policy-routing and applies it
|
|
# atomically: uci edit -> `xrayctl test` -> `xrayctl apply [--confirm N]`.
|
|
#
|
|
# This sample exercises EVERY section type in CONTRACT.md and is deliberately
|
|
# over-populated so it can double as a manual test fixture. It generalizes the
|
|
# real BPi-R3 Mini setup (see 01-mini_router-audit.md): a qomar subscription
|
|
# feeding a 3-hop xray chain, an AmneziaWG tunnel egress (awgOut), split-DNS
|
|
# with no leaks, home-network access, and a SIM WAN-mode profile.
|
|
#
|
|
# Object model (see 03-features-and-model.md):
|
|
# Node -> Group -> Chain -> Egress ; Inbound (entry) ; Rule (match->target
|
|
# +egress) ; Ruleset (reusable lists) ; Resolver/dns_rule (DNS) ; Profile.
|
|
#
|
|
# Referencing convention used throughout: chain:<name> | group:<name> |
|
|
# node:<name> | direct | block (targets), and egress by its own name.
|
|
# =============================================================================
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# globals (exactly one section) -- box-wide defaults & our reserved resources
|
|
# -----------------------------------------------------------------------------
|
|
config globals 'globals'
|
|
option enabled '1' # master on/off for the whole plugin
|
|
option loglevel 'warning' # xray loglevel: debug|info|warning|error|none
|
|
option kill_switch 'closed' # global default: closed = fail-closed (block)
|
|
# open = fail-open (direct)
|
|
option dns_mode 'nftset' # nftset|fakeip -- how DNS split is implemented
|
|
option ipv6 '1' # enable IPv6 handling / dual-stack
|
|
option fwmark_base '0x2000' # base of OUR reserved fwmark range (we never
|
|
# touch fw4 marks); egress marks derive from it
|
|
option table_base '0x2000' # base id for OUR routing tables (per-egress)
|
|
option confirm_timeout '120' # sec; commit-confirm window for `apply --confirm`.
|
|
# 0 = disabled. Auto-rollback if no `confirm`.
|
|
option resolver_fallback 'system-local' # name of resolver used when a dns_rule
|
|
# resolver fails (see NOTE in README about this).
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# inbound (0..N) -- transparent TPROXY entry points; MULTI-LAN here
|
|
# -----------------------------------------------------------------------------
|
|
# Main trusted LAN (br-lan). TCP+UDP intercepted, sniffing on to recover SNI.
|
|
config inbound
|
|
option name 'lan'
|
|
option enabled '1'
|
|
option network 'lan' # UCI interface(s) to intercept; space-sep for many
|
|
option tproxy_port '12345' # nft tproxy -> this port (mirrors real router)
|
|
option tcp '1'
|
|
option udp '1'
|
|
option sniff '1' # recover SNI/Host/QUIC for domain rules (routeOnly)
|
|
|
|
# Second LAN: an isolated guest SSID / VLAN, its own tproxy port so rules can
|
|
# match by inbound. Demonstrates the multi-LAN capability.
|
|
config inbound
|
|
option name 'guest'
|
|
option enabled '1'
|
|
option network 'guest'
|
|
option tproxy_port '12346'
|
|
option tcp '1'
|
|
option udp '1'
|
|
option sniff '1'
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# subscription (0..N) -- remote node lists (nodes live in cache, not UCI)
|
|
# -----------------------------------------------------------------------------
|
|
# (1) qomar: HAPP emulation with AUTO hwid (generated once and remembered per-sub).
|
|
config subscription
|
|
option name 'qomar'
|
|
option enabled '1'
|
|
option url 'https://pro.qomar.pw/sub/EXAMPLEtoken0000'
|
|
option update_interval '6h' # 30m|6h|24h|<n>{m,h,d}
|
|
option fetch_via 'direct' # direct|proxy (proxy = fetch through the tunnel
|
|
# when the sub host itself is blocked)
|
|
# --- HAPP client emulation headers ---
|
|
option ua 'Happ/3.13.0'
|
|
option hwid 'auto' # auto = generate & persist a stable HWID per sub
|
|
option device_os 'Android'
|
|
option ver_os '14'
|
|
option device_model 'SM-G998B'
|
|
|
|
# (2) renawave: FIXED hwid + extra custom headers (mirrors the real SIM sub).
|
|
config subscription
|
|
option name 'renawave'
|
|
option enabled '1'
|
|
option url 'https://sub.renawave.space/EXAMPLEtoken1111'
|
|
option update_interval '24h'
|
|
option fetch_via 'proxy' # host sometimes blocked -> fetch via tunnel
|
|
option ua 'Happ/3.13.0'
|
|
option hwid '4378f94b-0000-4000-8000-EXAMPLEhwid00' # fixed, pinned HWID
|
|
option device_os 'Android'
|
|
option ver_os '13'
|
|
option device_model 'Pixel 7'
|
|
list header 'x-panel-token: EXAMPLEpaneltoken' # arbitrary extra headers
|
|
list header 'x-region: eu'
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# node (0..N) -- MANUAL static nodes (never auto-removed, never go stale)
|
|
# -----------------------------------------------------------------------------
|
|
# Added as a raw share-link; xrayctl parses it (see examples/sublinks.txt).
|
|
config node
|
|
option name 'reality-nl'
|
|
option enabled '1'
|
|
option uri 'vless://11111111-2222-3333-4444-555555555555@nl.example.net:443?type=tcp&security=reality&pbk=EXAMPLEpublickeyBASE64URL0000000000000000000&fp=chrome&sni=www.microsoft.com&sid=0123abcd&flow=xtls-rprx-vision#reality-nl'
|
|
|
|
config node
|
|
option name 'ss-backup-de'
|
|
option enabled '1'
|
|
option uri 'ss://YWVzLTI1Ni1nY206RVhBTVBMRXBhc3N3b3Jk@de.example.net:8388#ss-backup-de'
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# group (0..N) -- a set of nodes + a selection strategy (balancer)
|
|
# -----------------------------------------------------------------------------
|
|
# (a) Subscription-sourced group with a strategy + include/exclude regex filters.
|
|
config group
|
|
option name 'sub0'
|
|
option source 'subscription'
|
|
option subscription 'qomar' # which subscription feeds this group
|
|
option strategy 'leastping' # leastping|random|roundrobin|failover|single
|
|
list include '(?i)(nl|de|fi)' # regex over node NAME: keep only these
|
|
list exclude '(?i)(trial|test)'# regex over node NAME: drop these
|
|
option probe_url 'http://www.gstatic.com/generate_204'
|
|
option probe_interval '60s' # observatory health probe cadence
|
|
|
|
# (b) Manual-sourced group: an explicit set of manual nodes, fixed selection.
|
|
config group
|
|
option name 'manual-fallback'
|
|
option source 'manual'
|
|
list node 'reality-nl' # references config node names above
|
|
list node 'ss-backup-de'
|
|
option strategy 'failover' # try in listed order, first alive wins
|
|
option probe_url 'http://www.gstatic.com/generate_204'
|
|
option probe_interval '120s'
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# chain (0..N) -- multi-hop; hop order = layers L1 -> L2 -> L3 (inverted chain)
|
|
# -----------------------------------------------------------------------------
|
|
# Mirrors the real xray_chain: three hops from the qomar subscription groups.
|
|
# Here we build the groups sub0/sub1/sub2 implicitly by strategy; L1 is entry.
|
|
config chain
|
|
option name 'triple'
|
|
list hop 'group:sub0' # L1 (first hop the client reaches)
|
|
list hop 'group:manual-fallback' # L2
|
|
list hop 'node:reality-nl' # L3 (final hop -> exits here)
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# egress (0..N) -- where traffic ultimately leaves the box
|
|
# -----------------------------------------------------------------------------
|
|
# interface: bind out to a tunnel/iface (AmneziaWG tunnel, like real awgOut).
|
|
config egress
|
|
option name 'via-awg'
|
|
option type 'interface'
|
|
option interface 'awgOut' # any iface/tunnel name from /etc/config/network
|
|
|
|
# interface: the home AmneziaWG tunnel for reaching the home LAN.
|
|
config egress
|
|
option name 'via-home'
|
|
option type 'interface'
|
|
option interface 'awgHome'
|
|
|
|
# proxy: send out through a proxy chain (target = chain:/group:/node:).
|
|
config egress
|
|
option name 'via-chain'
|
|
option type 'proxy'
|
|
option target 'chain:triple'
|
|
|
|
# direct: leave via the box's normal WAN routing (no tunnel).
|
|
config egress
|
|
option name 'direct-wan'
|
|
option type 'direct'
|
|
|
|
# block: drop.
|
|
config egress
|
|
option name 'blackhole'
|
|
option type 'block'
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# ruleset (0..N) -- reusable named domain / ip-cidr lists
|
|
# -----------------------------------------------------------------------------
|
|
# domain list pulled from a URL (auto-refreshed), plain format.
|
|
config ruleset
|
|
option name 'ru-bypass'
|
|
option type 'domain'
|
|
option source 'url'
|
|
option url 'https://raw.githubusercontent.com/example/ru-bypass/main/domains.lst'
|
|
option format 'plain' # plain|clash|geosite
|
|
option update_interval '24h'
|
|
|
|
# ip-cidr list defined INLINE (no fetch). Useful for a few exit/allow CIDRs.
|
|
config ruleset
|
|
option name 'home-nets'
|
|
option type 'ipcidr'
|
|
option source 'inline'
|
|
list entry '10.10.10.0/24' # home blockchain/teamspeak/cameras LAN
|
|
list entry '10.11.0.0/24'
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# rule (0..N) -- ordered, FIRST-MATCH wins (by `order`)
|
|
# -----------------------------------------------------------------------------
|
|
# NOTE: lower `order` is evaluated first. Keep a numeric gap between rules.
|
|
|
|
# (1) Per-client by /32: one specific PC always through the triple chain via awg.
|
|
config rule
|
|
option name 'pc-triple'
|
|
option enabled '1'
|
|
option order '10'
|
|
list src '192.168.11.14/32' # cidr|host|mac|iface:<n>|zone:<n>
|
|
option target 'chain:triple' # chain:|group:|node:|direct|block
|
|
option egress 'via-awg' # pin the exit to the AmneziaWG tunnel
|
|
option kill 'closed' # if chain dies -> block (no leak)
|
|
|
|
# (2) Per-device by MAC: a phone that keeps its policy across DHCP IP changes.
|
|
config rule
|
|
option name 'phone-by-mac'
|
|
option enabled '1'
|
|
option order '20'
|
|
list src 'aa:bb:cc:dd:ee:ff' # MAC form of src
|
|
option target 'group:sub0'
|
|
option egress 'direct-wan' # proxy first hop, then plain WAN
|
|
option kill 'open' # if group dies -> direct (fail-open)
|
|
|
|
# (3) By domain-list (ruleset) + geosite: bypass RU + private straight out.
|
|
config rule
|
|
option name 'ru-bypass-direct'
|
|
option enabled '1'
|
|
option order '30'
|
|
list dst_ruleset 'ru-bypass' # references ruleset (domain type)
|
|
list dst_domain 'geosite:category-ru'
|
|
option target 'direct'
|
|
option kill 'default' # inherit globals.kill_switch
|
|
|
|
# (4) By geosite (ads) -> block. Demonstrates dst_domain geosite + block target.
|
|
config rule
|
|
option name 'block-ads'
|
|
option enabled '1'
|
|
option order '40'
|
|
list dst_domain 'geosite:category-ads-all'
|
|
option target 'block'
|
|
|
|
# (5) Home networks reachable via the home tunnel (uses inline ipcidr ruleset).
|
|
config rule
|
|
option name 'home-access'
|
|
option enabled '1'
|
|
option order '50'
|
|
list dst_ruleset 'home-nets' # ip-cidr ruleset
|
|
list dst_ip '10.10.10.0/24' # also inline cidr form; geoip:x allowed
|
|
option target 'direct'
|
|
option egress 'via-home' # exit through awgHome
|
|
|
|
# (6) Guest LAN + a port/proto match -> chain (shows inbound-scoped + L4 match).
|
|
config rule
|
|
option name 'guest-web'
|
|
option enabled '1'
|
|
option order '60'
|
|
list src 'iface:guest' # match by inbound interface/zone
|
|
option dst_port '80,443' # port|range|comma-list
|
|
option proto 'tcp,udp'
|
|
option target 'chain:triple'
|
|
option egress 'via-awg'
|
|
|
|
# (7) Default catch-all -> everything else through the chain. Highest order.
|
|
config rule
|
|
option name 'default'
|
|
option enabled '1'
|
|
option order '1000'
|
|
option target 'chain:triple'
|
|
option egress 'via-awg'
|
|
option kill 'closed'
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# resolver (0..N) + dns_rule (0..N) -- fully configurable DNS
|
|
# -----------------------------------------------------------------------------
|
|
# DoH resolver resolved THROUGH the proxy chain (no leak; resolved==routed).
|
|
config resolver
|
|
option name 'proxy-doh'
|
|
option type 'doh' # doh|dot|plain|local|fakeip
|
|
option address 'https://dns.quad9.net/dns-query'
|
|
option detour 'chain:triple' # resolve via this outbound
|
|
|
|
# Local resolver = the router's own dnsmasq (for direct/RU domains, ISP view).
|
|
config resolver
|
|
option name 'system-local'
|
|
option type 'local'
|
|
option address '127.0.0.1#53' # local dnsmasq
|
|
|
|
# FakeIP resolver: hand out 198.18.x placeholders, resolve real IP proxy-side.
|
|
config resolver
|
|
option name 'fake'
|
|
option type 'fakeip'
|
|
option address '198.18.0.0/15' # fakeip pool (see README NOTE)
|
|
|
|
# The DEFAULT resolver is a resolver section literally named 'default'.
|
|
config resolver 'default'
|
|
option type 'doh'
|
|
option address 'https://dns.quad9.net/dns-query'
|
|
option detour 'chain:triple'
|
|
|
|
# --- DNS routing rules (ordered) ---
|
|
# Ads domains -> blocked at DNS level.
|
|
config dns_rule
|
|
option order '10'
|
|
list match_domain 'geosite:category-ads-all'
|
|
option resolver 'block' # <resolver name>|block
|
|
|
|
# RU domains -> resolved locally (ISP/local view) to keep them direct.
|
|
config dns_rule
|
|
option order '20'
|
|
list match_domain 'geosite:category-ru'
|
|
option resolver 'system-local'
|
|
|
|
# A specific client subnet -> forced through the proxy DoH resolver.
|
|
config dns_rule
|
|
option order '30'
|
|
list match_src '192.168.11.0/24' # per-client DNS
|
|
option resolver 'proxy-doh'
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# profile (0..N) -- conditional overrides by active WAN / probe / time [T2]
|
|
# -----------------------------------------------------------------------------
|
|
# SIM mode: when the SIM interface (eth2) becomes the default WAN, re-pin the
|
|
# per-client rule's egress to a VLESS wrap (generalizes the real sim-setup.sh).
|
|
config profile
|
|
option name 'sim'
|
|
option when 'wan:eth2' # wan:<iface>|probe:<url>|time:<HH-HH>
|
|
list set 'rule.pc-triple.egress=via-chain' # k=v override
|
|
list set 'globals.dns_mode=fakeip'
|