Skip to content

Commit 64738a7

Browse files
madeyeclaude
andcommitted
Bump version to v0.8.0 and update docs
- Version bump to 0.8.0 - Add e2e testing feature to README, docs, and Chinese translations - Update local traffic docs: fwmark/IP_BOUND_IF replaces UID-based approach - Update script usage examples with new argument format - Remove deprecated --proxy-user from CLI table, add --fwmark Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 90fb5e1 commit 64738a7

6 files changed

Lines changed: 36 additions & 62 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ members = [".", "test_servers", "e2e"]
33

44
[package]
55
name = "trans_proxy"
6-
version = "0.7.0"
6+
version = "0.8.0"
77
edition = "2021"
88
description = "Transparent proxy with upstream HTTP CONNECT and SOCKS5 proxy support (macOS pf, Linux nftables)"
99
license = "MIT"

README.md

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Designed to run on a machine acting as a side router (gateway) for other devices
2727
- **Daemon mode** — Run as a background process with PID file and log file support
2828
- **Service install** — launchd on macOS, systemd on Linux. On Linux, nftables NAT rules are automatically managed via ExecStartPre/ExecStopPost
2929
- **Async I/O** — Built on tokio with per-connection task spawning
30+
- **End-to-end tested** — Full e2e test suite exercises the real nftables/pf + proxy pipeline on both Linux and macOS
3031

3132
## Requirements
3233

@@ -184,7 +185,7 @@ sudo ./target/release/trans_proxy \
184185
| `--pid-file` | `/var/run/trans_proxy.pid` | PID file path (used with `--daemon`) |
185186
| `--log-file` | `/var/log/trans_proxy.log` (daemon) / stderr | Log file path |
186187
| `--local-traffic` | off | Also intercept traffic originating from the gateway itself (not just forwarded LAN traffic) |
187-
| `--proxy-user` | `trans_proxy` | System user for loop prevention when `--local-traffic` is enabled |
188+
| `--fwmark` | `1` | Firewall mark for loop prevention on Linux (used with `--local-traffic`) |
188189
| `--ports` | *(all TCP)* | Comma-separated list of TCP ports to redirect (e.g., `22,80,443`). When omitted, all TCP traffic is redirected |
189190
| `--install` | off | Install as a system service (launchd on macOS, systemd on Linux) |
190191
| `--uninstall` | off | Uninstall the system service |
@@ -196,9 +197,10 @@ sudo ./target/release/trans_proxy \
196197
The included scripts manage pf rules via an anchor (won't interfere with existing firewall rules).
197198

198199
```bash
199-
sudo scripts/pf_setup.sh <interface> [proxy_port] [proxy_user] [ports]
200-
sudo scripts/pf_setup.sh en0 8443 # all TCP
201-
sudo scripts/pf_setup.sh en0 8443 "" 80,443 # only ports 80,443
200+
sudo scripts/pf_setup.sh <interface> [proxy_port] [upstream_proxy] [ports]
201+
sudo scripts/pf_setup.sh en0 8443 # all TCP
202+
sudo scripts/pf_setup.sh en0 8443 "" 80,443 # only ports 80,443
203+
sudo scripts/pf_setup.sh en0 8443 127.0.0.1:1082 # all TCP + local traffic
202204

203205
# Tear down
204206
sudo scripts/pf_teardown.sh
@@ -209,9 +211,10 @@ sudo scripts/pf_teardown.sh
209211
The included scripts create a dedicated nftables table for trans_proxy.
210212

211213
```bash
212-
sudo scripts/nftables_setup.sh <interface> [proxy_port] [proxy_user] [ports]
213-
sudo scripts/nftables_setup.sh eth0 8443 # all TCP
214-
sudo scripts/nftables_setup.sh eth0 8443 "" 80,443 # only ports 80,443
214+
sudo scripts/nftables_setup.sh <interface> [proxy_port] [fwmark] [upstream_proxy] [ports]
215+
sudo scripts/nftables_setup.sh eth0 8443 # all TCP
216+
sudo scripts/nftables_setup.sh eth0 8443 "" "" 80,443 # only ports 80,443
217+
sudo scripts/nftables_setup.sh eth0 8443 1 127.0.0.1:7890 # all TCP + local traffic
215218

216219
# Tear down
217220
sudo scripts/nftables_teardown.sh
@@ -281,30 +284,10 @@ sudo ./target/release/trans_proxy \
281284

282285
#### How it works
283286

284-
Loop prevention uses UID-based exclusion: the proxy runs as a dedicated system user, and firewall rules skip traffic from that user.
287+
Loop prevention is automatic — no dedicated system user required:
285288

286-
- **Linux**: Adds an nftables OUTPUT chain with `meta skuid` exclusion
287-
- **macOS**: Adds `pass out route-to (lo0)` + `rdr on lo0` rules with `user !=` exclusion
288-
289-
#### Creating the system user
290-
291-
The proxy user must exist on the system before using `--local-traffic`.
292-
293-
**Linux:**
294-
```bash
295-
sudo useradd --system --no-create-home --shell /usr/sbin/nologin trans_proxy
296-
```
297-
298-
**macOS:**
299-
```bash
300-
# Find an unused UID (e.g., 499)
301-
sudo dscl . -create /Users/trans_proxy
302-
sudo dscl . -create /Users/trans_proxy UserShell /usr/bin/false
303-
sudo dscl . -create /Users/trans_proxy UniqueID 499
304-
sudo dscl . -create /Users/trans_proxy PrimaryGroupID 20
305-
```
306-
307-
To use a different username, pass `--proxy-user <name>`.
289+
- **Linux**: Sets `SO_MARK` (fwmark) on outbound sockets; nftables OUTPUT chain skips marked packets
290+
- **macOS**: Sets `IP_BOUND_IF` to bind outbound sockets to `lo0` when the upstream is on localhost, plus a `pass out quick` pf rule to exclude the upstream proxy destination
308291

309292
### Client Setup
310293

README_zh.md

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- **守护进程模式** — 作为后台进程运行,支持 PID 文件和日志文件
2828
- **系统服务** — macOS 使用 launchd,Linux 使用 systemd。Linux 上通过 ExecStartPre/ExecStopPost 自动管理 nftables NAT 规则
2929
- **异步 I/O** — 基于 tokio 构建,每个连接独立任务调度
30+
- **端到端测试** — 完整的端到端测试套件在 Linux 和 macOS 上运行真实的 nftables/pf + 代理流水线
3031

3132
## 系统要求
3233

@@ -184,7 +185,7 @@ sudo ./target/release/trans_proxy \
184185
| `--pid-file` | `/var/run/trans_proxy.pid` | PID 文件路径(与 `--daemon` 配合使用) |
185186
| `--log-file` | `/var/log/trans_proxy.log`(守护进程)/ stderr | 日志文件路径 |
186187
| `--local-traffic` | 关闭 | 同时拦截网关本机发出的流量(不仅仅是转发的局域网流量) |
187-
| `--proxy-user` | `trans_proxy` | 启用 `--local-traffic` 时用于防止回环的系统用户 |
188+
| `--fwmark` | `1` | Linux 上用于防止回环的防火墙标记(与 `--local-traffic` 配合使用) |
188189
| `--ports` | *(所有 TCP)* | 要重定向的 TCP 端口列表,逗号分隔(例如 `22,80,443`)。未指定时重定向所有 TCP 流量 |
189190
| `--install` | 关闭 | 安装为系统服务(macOS 使用 launchd,Linux 使用 systemd) |
190191
| `--uninstall` | 关闭 | 卸载系统服务 |
@@ -194,9 +195,10 @@ sudo ./target/release/trans_proxy \
194195
#### macOS (pf)
195196

196197
```bash
197-
sudo scripts/pf_setup.sh <interface> [proxy_port] [proxy_user] [ports]
198-
sudo scripts/pf_setup.sh en0 8443 # 所有 TCP
199-
sudo scripts/pf_setup.sh en0 8443 "" 80,443 # 仅端口 80,443
198+
sudo scripts/pf_setup.sh <interface> [proxy_port] [upstream_proxy] [ports]
199+
sudo scripts/pf_setup.sh en0 8443 # 所有 TCP
200+
sudo scripts/pf_setup.sh en0 8443 "" 80,443 # 仅端口 80,443
201+
sudo scripts/pf_setup.sh en0 8443 127.0.0.1:1082 # 所有 TCP + 本地流量
200202

201203
# 拆除配置
202204
sudo scripts/pf_teardown.sh
@@ -205,9 +207,10 @@ sudo scripts/pf_teardown.sh
205207
#### Linux (nftables)
206208

207209
```bash
208-
sudo scripts/nftables_setup.sh <interface> [proxy_port] [proxy_user] [ports]
209-
sudo scripts/nftables_setup.sh eth0 8443 # 所有 TCP
210-
sudo scripts/nftables_setup.sh eth0 8443 "" 80,443 # 仅端口 80,443
210+
sudo scripts/nftables_setup.sh <interface> [proxy_port] [fwmark] [upstream_proxy] [ports]
211+
sudo scripts/nftables_setup.sh eth0 8443 # 所有 TCP
212+
sudo scripts/nftables_setup.sh eth0 8443 "" "" 80,443 # 仅端口 80,443
213+
sudo scripts/nftables_setup.sh eth0 8443 1 127.0.0.1:7890 # 所有 TCP + 本地流量
211214

212215
# 拆除配置
213216
sudo scripts/nftables_teardown.sh
@@ -277,30 +280,10 @@ sudo ./target/release/trans_proxy \
277280

278281
#### 工作原理
279282

280-
通过基于 UID 的排除实现回环防护:代理以专用系统用户身份运行,防火墙规则跳过该用户的流量。
283+
回环防护是自动的,无需创建专用系统用户:
281284

282-
- **Linux**:添加 nftables OUTPUT 链,使用 `meta skuid` 排除
283-
- **macOS**:添加 `pass out route-to (lo0)` + `rdr on lo0` 规则,使用 `user !=` 排除
284-
285-
#### 创建系统用户
286-
287-
使用 `--local-traffic` 前,代理用户必须已存在于系统中。
288-
289-
**Linux:**
290-
```bash
291-
sudo useradd --system --no-create-home --shell /usr/sbin/nologin trans_proxy
292-
```
293-
294-
**macOS:**
295-
```bash
296-
# 找一个未使用的 UID(例如 499)
297-
sudo dscl . -create /Users/trans_proxy
298-
sudo dscl . -create /Users/trans_proxy UserShell /usr/bin/false
299-
sudo dscl . -create /Users/trans_proxy UniqueID 499
300-
sudo dscl . -create /Users/trans_proxy PrimaryGroupID 20
301-
```
302-
303-
如需使用其他用户名,请传递 `--proxy-user <name>`
285+
- **Linux**:在出站 socket 上设置 `SO_MARK`(fwmark),nftables OUTPUT 链跳过带标记的数据包
286+
- **macOS**:当上游代理在本地时,设置 `IP_BOUND_IF` 将出站 socket 绑定到 `lo0`,并通过 `pass out quick` pf 规则排除上游代理目标地址
304287

305288
### 客户端设置
306289

docs/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,10 @@ <h3>System Service</h3>
859859
<h3>Async I/O</h3>
860860
<p>Built on tokio with per-connection task spawning. Handles many concurrent connections efficiently with bidirectional relay.</p>
861861
</div>
862+
<div class="feature">
863+
<h3>E2E Tested</h3>
864+
<p>Full end-to-end test suite exercises the real nftables/pf + proxy pipeline on both Linux and macOS, covering SOCKS5, HTTP CONNECT, DNS forwarding, and port-selective redirect.</p>
865+
</div>
862866
</div>
863867
</div>
864868
</section>

docs/index_zh.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,10 @@ <h3>系统服务</h3>
859859
<h3>异步 I/O</h3>
860860
<p>基于 tokio 构建,为每个连接生成独立任务。通过双向中继高效处理大量并发连接。</p>
861861
</div>
862+
<div class="feature">
863+
<h3>端到端测试</h3>
864+
<p>完整的端到端测试套件在 Linux 和 macOS 上运行真实的 nftables/pf + 代理流水线,覆盖 SOCKS5、HTTP CONNECT、DNS 转发和端口选择性重定向。</p>
865+
</div>
862866
</div>
863867
</div>
864868
</section>

0 commit comments

Comments
 (0)