Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
## 亮点 / Highlights

- 🛡️ **改不坏**:每次改动先预览、分级;倒计时内不确认就自动回滚,断电也会回滚;完整历史,随时退回。
- ⚡ **快**:普通流量始终走硬件加速(MT7986 PPE + WED),分流、按域名选线路都不影响卸载。
- ⚡ **快**:普通流量始终走硬件加速(MT7986 PPE + WED),分流、按域名选线路、单口多拨都不影响卸载。
- 🪶 **小**:没有空转的守护进程;DDNS、证书、体检都是按需运行的短命令。
- 🧩 **全**:多线、IPv6、选择性代理、反向代理、去广告、设备管理,一个网页里全部可配。
- 🤖 **为 agent 设计**:配置即代码,命令输出 JSON,作用域 API token,自带 agent skill。
Expand All @@ -51,7 +51,7 @@

| 模块 | 功能 |
|---|---|
| **网络** | PPPoE(1500 MTU)/ DHCP / 静态,多线故障切换与负载均衡;策略路由(按设备 / 网段 / **域名**);双线 IPv6,运营商换前缀自动恢复;访客 / IoT 网络、VLAN;**主路由 / 旁路由 / 纯 AP** 三种模式 |
| **网络** | PPPoE(1500 MTU)/ DHCP / 静态;**多拨**(单口多拨每条会话独立 MAC、多口多拨、拨号顺序),多线故障切换与负载均衡;策略路由(按设备 / 网段 / **域名**,设备的 IPv4 + IPv6 都能固定到一条线);双线 IPv6,运营商换前缀自动恢复;访客 / IoT 网络、VLAN;**主路由 / 旁路由 / 纯 AP** 三种模式 |
| **WiFi** | 多 SSID、WPA2/3、访客隔离;组播转单播、802.11v 频段引导、射频健康与自愈;定时开关 |
| **DNS / DHCP** | 静态分配、本地记录、DNS 分流、DoT;**去广告**;DNS 主导权(拦截设备私自 DoH / DoT) |
| **防火墙** | 端口转发、IPv6 入站、通信规则(含时间段)、硬件 / 软件卸载;默认拒绝公网入站 |
Expand Down Expand Up @@ -84,6 +84,8 @@ wget -O install.sh https://github.com/Cd1s/mini-router/releases/latest/download/
mr plan # 看会改什么(也可以直接在网页里改)
mr apply --confirm 120 # 应用;120 秒内不 mr confirm 就自动回滚
mr confirm
mr -c new.yaml apply --confirm 120 # 改一份副本再应用:先快照在用的配置,回滚完整
mr wan mac wan2 # 多拨:给同一网口上的第二条 PPPoE 生成固定 MAC(写进 wan[].mac)
mr set 'wifi.steering.enabled=true' # 按路径改配置,保留注释
mr doctor # 体检;--heal 一键修复
mr status · mr history · mr rollback N · mr ddns status · mr edge status # JSON 输出
Expand All @@ -105,7 +107,7 @@ mkdir -p ~/.claude/skills && cp -r skills/mini-router ~/.claude/skills/
- `sudo ./tools/ci.sh`(Linux):单元测试,用真实的 `nft` / `dnsmasq` / `hostapd` / `sing-box` 校验生成的配置,
并在网络命名空间里跑防火墙、多线、代理、反向代理的端到端测试。
- 网页本地调试:`python3 tools/mock/mockapi.py 8088`
- 从源码构建:`./tools/release.sh v0.3.0 out/release`;AX6000 固件:`build/m3/`。
- 从源码构建:`./tools/release.sh v0.3.1 out/release`;AX6000 固件:`build/m3/`。

## License

Expand Down
4 changes: 4 additions & 0 deletions docs/modules/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ dhcpcd 钩子把每条 WAN 的前缀记在 `/run/mini-router/wan/<名>.pd6`,
flowtable(PPE 不做 IPv6 NAT);源地址本就在 `via` 前缀里的照常硬件加速。DDNS `ipv6: mac:` 对被策略固定到某条 WAN 的设备
优先发布该 WAN 前缀里的地址。

让一条 WAN 只给一台设备用(IPv4 和 IPv6):局域网里每台设备都会拿到两条线的前缀、自己挑源地址,所以在固定那台设备的策略
后面再加一条 `{name: others-v6-via-wan, src: "::/0", via: wan, nat6: true}`——其余设备的 IPv6 都走 wan,用了另一条线前缀的
被转换成 wan 的前缀(IPv4 本来就走默认 WAN)。策略按配置顺序匹配,排在前面的设备不受影响。

#### 断线兜底(fallback)

`via` 的 WAN 断线(PPPoE 掉线)或健康检测失败时,它的路由表里没有默认路由,打了标记的流量会落到 main 表,
Expand Down
6 changes: 5 additions & 1 deletion examples/router.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ wan:

multiwan: # no health check / balancing (mode off); only the PPPoE dial order
dial_order: [wan2, wan] # the ISP's DDNS follows the session that connected last: wan
dial_restore: "04:30" # wan2 redialled on its own: redial wan at 04:30 to restore the order
dial_restore: now # wan2 redialled on its own: redial wan at once (the ISP DDNS must stay on wan)

policy_routes:
- name: desktop-via-wan2
Expand All @@ -54,6 +54,10 @@ policy_routes:
table: 102
mark: "0x102"
nat6: true # its IPv6 from wan's prefix too leaves wan2 (NPTv6 to wan2's prefix)
- name: others-v6-via-wan # wan2 is desktop's alone, IPv6 too: every other device's IPv6 leaves wan,
src: "::/0" # a source in wan2's prefix translated into wan's (IPv4 already takes wan)
via: wan
nat6: true

firewall:
offload: hardware
Expand Down
1 change: 1 addition & 0 deletions mr/mod_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
func devConfig(t *testing.T) *Config {
t.Helper()
c := testConfig(t)
c.Policy = c.Policy[:1] // the home config's first policy only: the cases number theirs from 1
c.Devices = []Device{
{Name: "office-pc", MACs: []string{"02:00:00:00:10:01"}, IP: "192.168.1.70", Type: "pc", Owner: "Alice"},
{Name: "kid-tablet", MACs: []string{"AA:BB:CC:00:00:21", "aa:bb:cc:00:00:22"}, IP: "192.168.1.121"},
Expand Down
4 changes: 2 additions & 2 deletions mr/mod_net_dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func dialEnv(t *testing.T) (c *Config, now *time.Time, sleeps *int, onSleep *fun

func TestDialValidate(t *testing.T) {
c := testConfig(t)
if m := c.MultiWAN; strings.Join(m.DialOrder, ",") != "wan2,wan" || m.DialWait != 0 || m.dialWait() != 30*time.Second || m.DialRestore != "04:30" || m.Enabled() {
if m := c.MultiWAN; strings.Join(m.DialOrder, ",") != "wan2,wan" || m.DialWait != 0 || m.dialWait() != 30*time.Second || m.DialRestore != "now" || m.Enabled() {
t.Fatalf("home config: %+v", m)
}
for _, tc := range []struct {
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestDialRestore(t *testing.T) {

// HH:MM: nothing now; crond at 04:30 router time (+03, not the example's: sync-public rewrites that;
// now is 11:00 there)
c.System.Timezone = "<+03>-3"
c.System.Timezone, c.MultiWAN.DialRestore = "<+03>-3", "04:30"
dialOnUp(c, "wan2")
if len(spawned) != 0 {
t.Errorf("HH:MM spawned %v", spawned)
Expand Down
3 changes: 2 additions & 1 deletion mr/mod_net_domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
func domainTestConfig(t *testing.T) *Config {
t.Helper()
c := testConfig(t)
c.Policy = c.Policy[:1] // the home config's first policy only: the cases number theirs from 1
f := filepath.Join(t.TempDir(), "video.domains")
os.WriteFile(f, []byte("# comment\nvideo.example.org\n\nstatic.example.com # below example.com\n+.Img.Example.NET.\n"), 0644)
c.Policy = append(c.Policy,
Expand Down Expand Up @@ -188,7 +189,7 @@ func TestNetPolicyDomainsLongList(t *testing.T) {
// The proxy's dnsmasq fills the same sets, except for names it answers with fake IPs.
func TestNetPolicyDomainsProxyDNS(t *testing.T) {
c := proxyTestConfig(t)
c.Policy = append(c.Policy, Policy{Name: "video", Domains: []string{"video.example.org", "claude.ai", "openai.com"}, Via: "wan2"})
c.Policy = append(c.Policy[:1], Policy{Name: "video", Domains: []string{"video.example.org", "claude.ai", "openai.com"}, Via: "wan2"})
c.defaults()
mustValid(t, c)
f := renderMap(t, c)
Expand Down
4 changes: 3 additions & 1 deletion mr/mod_net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ func TestDelegatedPrefixesFromWANEvent(t *testing.T) {
// what the dhcpcd hook recorded per WAN; garbage in the record never reaches nft.
func TestPD6Script(t *testing.T) {
c := testConfig(t)
c.Policy = c.Policy[:1] // the home config's wan2 policy only (its others-v6-via-wan adds pd6_0 / npt6*_1)
old := wanRunDir
wanRunDir = t.TempDir()
t.Cleanup(func() { wanRunDir = old })
Expand All @@ -528,7 +529,7 @@ func TestPD6Script(t *testing.T) {
// nat6 (#108): validation, no chains without it, fallback: drop covers every source.
func TestNetPolicyNAT6(t *testing.T) {
c := testConfig(t)
c.Policy = append(c.Policy,
c.Policy = append(c.Policy[:1],
Policy{Name: "v4only", Src: "192.168.1.9", Via: "wan2", NAT6: true},
Policy{Name: "wan-no-pd", MAC: "aa:bb:cc:dd:ee:ff", Via: "wan", NAT6: true})
c.WAN[0].IPv6PD = false
Expand All @@ -540,6 +541,7 @@ func TestNetPolicyNAT6(t *testing.T) {
}
}
c = testConfig(t)
c.Policy = c.Policy[:1] // without the home config's others-v6-via-wan (nat6 too)
c.Policy[0].Fallback = "drop"
nft := renderNft(c, allExist)
wantSubs(t, "nft", nft, `iifname "br-lan" ether saddr 02:c3:06:d6:7f:8a meta nfproto ipv6 oifname "pppoe-wan" counter drop comment "fallback:desktop-via-wan2"`)
Expand Down
6 changes: 3 additions & 3 deletions tools/ci.d/sys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ ok "service settings"

# 3. crontab
C=$L/etc/crontabs/root
# home: no schedules, but the DDNS check, the dial-order restore and the certificate renewal
[ "$(grep -c '^[^#]' "$H/etc/crontabs/root")" = 3 ] && grep -q ' /usr/sbin/mr ddns sync --cron$' "$H/etc/crontabs/root" &&
grep -qx '30 4 \* \* \* /usr/sbin/mr wan dial-restore' "$H/etc/crontabs/root" &&
# home: no schedules, but the DDNS check and the certificate renewal (its dial-order restore is `now`: no cron)
[ "$(grep -c '^[^#]' "$H/etc/crontabs/root")" = 2 ] && grep -q ' /usr/sbin/mr ddns sync --cron$' "$H/etc/crontabs/root" &&
! grep -q 'dial-restore' "$H/etc/crontabs/root" &&
grep -q ' /usr/sbin/mr edge renew --cron$' "$H/etc/crontabs/root" || fail "home crontab: $(cat "$H/etc/crontabs/root")"
grep -qx 'crond' "$L/etc/mini-router/gen/services" || fail "lab: crond not enabled"
grep -qx 'crond' "$H/etc/mini-router/gen/services" || fail "home: crond not enabled"
Expand Down
Loading