11# box4linux workspace
22
3- Linux-native control plane (phase 2) lives in:
3+ Linux-native control plane lives in:
44- ` cmd/boxctl `
55- ` lib/common.sh `
66- ` lib/config.sh `
77- ` lib/supervisor/ `
88- ` lib/firewall/ `
99- ` systemd/ `
1010- ` tests/integration/ `
11+ - ` packaging/arch/ `
1112
1213Android reference artifacts are kept untouched in ` box-reference/ ` .
1314
@@ -26,60 +27,106 @@ Android reference artifacts are kept untouched in `box-reference/`.
2627 - ` ./cmd/boxctl firewall dry-run `
27284 . Run integration checks:
2829 - ` ./tests/integration/test_phase2.sh `
29- - ` sudo ./tests/integration/test_real_kernel.sh ` (skips automatically when root/CAP_SYS_ADMIN/CAP_NET_ADMIN or backend tooling is unavailable)
30+ - ` sudo ./tests/integration/test_real_kernel.sh `
3031
31- ## Systemd units
32+ ## Arch Package Build/Install
3233
33- - ` systemd/box.service `
34- - ` systemd/box-firewall.service `
34+ Build package from repo root:
35+ - ` cd packaging/arch && makepkg --noconfirm -f `
3536
36- Copy/symlink these to your systemd unit path and ensure ` boxctl ` is installed as ` /usr/bin/boxctl ` .
37+ Install package:
38+ - ` sudo pacman -U ./box4linux-*.pkg.tar.zst `
3739
38- ## Phase 3 notes
40+ Installed layout:
41+ - ` /usr/bin/boxctl `
42+ - ` /usr/lib/box4linux/cmd/boxctl `
43+ - ` /usr/lib/box4linux/lib/... `
44+ - ` /etc/box/box.toml `
45+ - ` /usr/lib/systemd/system/box.service `
46+ - ` /usr/lib/systemd/system/box-firewall.service `
47+ - ` /usr/share/doc/box4linux/ `
48+
49+ Config upgrade behavior:
50+ - Package marks ` /etc/box/box.toml ` as backup config.
51+ - Local edits are preserved across upgrades.
52+ - New template versions land as ` .pacnew ` when needed.
53+
54+ ## Service Lifecycle (Packaged Install)
55+
56+ Use helper script from package docs:
57+ - ` sudo /usr/share/doc/box4linux/systemd-lifecycle.sh enable `
58+ - ` sudo /usr/share/doc/box4linux/systemd-lifecycle.sh status `
59+ - ` sudo /usr/share/doc/box4linux/systemd-lifecycle.sh disable `
60+
61+ Manual equivalent:
62+ - ` sudo systemctl daemon-reload `
63+ - ` sudo systemctl enable --now box.service box-firewall.service `
64+ - ` sudo systemctl disable --now box-firewall.service box.service `
65+
66+ ## Packaged Operational Quickstart
67+
68+ 1 . Verify command and units:
69+ - ` boxctl service status --json `
70+ - ` boxctl firewall status --json `
71+ 2 . Preview firewall operations:
72+ - ` boxctl firewall dry-run `
73+ 3 . Start runtime:
74+ - ` sudo systemctl start box.service `
75+ 4 . Renew firewall policy safely:
76+ - ` sudo systemctl reload box-firewall.service `
77+
78+ ## CI/Release Flow
79+
80+ Workflow file: ` .github/workflows/ci.yml `
81+
82+ On push/PR:
83+ - ` bash -n ` checks on shell scripts
84+ - ` shellcheck ` when available
85+ - mock integration: ` ./tests/integration/test_phase2.sh `
86+ - privileged integration: ` sudo ./tests/integration/test_real_kernel.sh ` (suite prints ` SKIP ` when capabilities/tooling are unavailable)
87+ - Arch package build in Arch container
88+ - package smoke test: ` ./tests/integration/test_arch_package_smoke.sh <pkg> `
89+
90+ On tags (` v* ` ):
91+ - built package artifact is published to GitHub Releases
92+
93+ ## Phase 3 Notes
3994
4095- Supported cores: ` mihomo ` , ` sing-box `
41- - Core overlay mutators render runtime configs under ` /run/box/rendered ` (or dev fallback).
96+ - Runtime overlays rendered under ` /run/box/rendered ` (or dev fallback)
4297- Firewall backends:
43- - ` iptables ` : parity path with staged apply/rollback
44- - ` nftables ` : MVP parity path with staged apply/rollback
45- - Supported modes on both backends: ` tun ` , ` tproxy ` , ` redirect ` , ` mixed ` , ` enhance ` .
46- - DNS strategy handling: ` tproxy ` , ` redirect ` , ` disable ` .
47- - Tailscale coexistence defaults to ` dns_coexist_mode=preserve_tailnet ` .
48- - Coexistence mode semantics:
49- - ` preserve_tailnet ` : apply tailscale bypass (` tailscale0 ` , ` 100.64.0.0/10 ` ) and MagicDNS resolver exclusion (` 100.100.100.100:53 ` ).
50- - ` strict_box ` : do not add tailscale bypass/MagicDNS exclusion rules; still never delete non-BOX routes/rules.
51- - Tailscale safeguards include:
52- - bypass ` tailscale0 `
53- - bypass ` 100.64.0.0/10 ` and preserve ` fd7a:115c:a1e0::/48 ` by not touching ip6tables in this backend
54- - bypass ` 100.100.100.100:53 ` (MagicDNS resolver)
55- - preserve table ` 52 ` / fwmark ` 0x80000/0xff0000 ` ownership
56- - Route convergence: renew/reapply prunes stale BOX fwmark rules for the same fwmark+table (any old pref) and installs exactly one rule with current ` route_pref ` .
57- - ` enable|renew|disable ` paths are idempotent and lock-protected.
58- - ` boxctl firewall dry-run ` prints intended backend operations without applying.
59- - ` BOX_TRACE_COMMANDS=1 ` logs external command execution with ` component ` , ` action ` , and command string.
60- - ` boxctl firewall status --json ` is side-effect free and includes stable diagnostics:
61- - ` backend ` / ` backend_selected `
62- - ` backend_available `
63- - ` mode `
64- - ` dns_hijack_mode `
65- - ` dns_coexist_mode `
66- - ` dns_coexist_mode_active `
67- - ` cap_ipv4 ` , ` cap_ipv6 ` , ` cap_tproxy `
68- - ` dry_run_supported `
69- - ` last_error `
70-
71- ## Backend capability notes
98+ - ` iptables ` (mature path)
99+ - ` nftables ` (MVP parity)
100+ - Supported modes on both backends: ` tun ` , ` tproxy ` , ` redirect ` , ` mixed ` , ` enhance `
101+ - DNS strategies: ` tproxy ` , ` redirect ` , ` disable `
102+ - Coexistence modes:
103+ - ` preserve_tailnet ` (default): apply tailscale and MagicDNS bypasses
104+ - ` strict_box ` : skip tailscale/MagicDNS bypass insertion
105+ - Route convergence: renew/reapply prunes stale BOX fwmark rules and enforces one current ` route_pref ` rule
106+ - Idempotent + lock-protected: ` enable|renew|disable `
107+ - ` BOX_TRACE_COMMANDS=1 ` logs external command executions with component/action context
108+ - ` boxctl firewall status --json ` exposes stable diagnostics (backend, capabilities, coexist fields, errors)
109+
110+ ## Backend Capability Notes
72111
73112- ` iptables ` :
74113 - ` cap_ipv4=true `
75- - ` cap_ipv6=false ` (no ip6tables graph yet )
114+ - ` cap_ipv6=false ` (full ip6tables graph pending )
76115- ` nftables ` :
77116 - ` cap_ipv4=true `
78- - ` cap_ipv6=false ` (full IPv6 interception/hijack graph still pending)
117+ - ` cap_ipv6=false ` (full IPv6 interception/hijack graph pending)
118+
119+ ## Rollback/Uninstall
120+
121+ Safe uninstall (keeps config backups/data unless manually removed):
122+ - ` sudo pacman -R box4linux `
123+
124+ Optional manual purge of local state:
125+ - ` sudo rm -rf /etc/box /var/lib/box /run/box /var/log/box `
79126
80127## Remaining TODO
81128
82- - Full UID/GID/interface/MAC policy graph in firewall (currently placeholder stage) .
83- - Full kernel-capability probing for nft/iptables modules across all distro variants .
129+ - Full UID/GID/interface/MAC policy graph in firewall.
130+ - Full IPv6 interception/hijack parity .
84131- API-based reload hooks for ` mihomo ` and ` sing-box ` .
85- - Explicit IPv6 tailnet bypass/interception parity for both backends .
132+ - Broader kernel-capability probing across distro variants .
0 commit comments