fix(server): 走隧道/拒绝的域名规则也开 reverse_mapping
用户规则(可配置分流)里 action==proxy/reject 的域名规则,此前不触发 dns.reverse_mapping(只有 direct 域名规则触发)。而应用自行解析域名后按 IP 发起连接,路由层只剩 IP,无反向映射则 domain 规则永不命中——走隧道/拒绝的 域名规则会静默失效。 translateUserRules 把 hasDomainDirect 扩成 hasDomainRule:任意 action 的 域名类规则(domain/domain_suffix/domain_keyword)都置真、都开 reverse_mapping。 direct 专属的 ip_cidr→route_exclude_address(extraExclude)那条线不变。 这也是把私有服务分流(PANGOLIN_PRIVATE_SPLIT_DOMAINS)改用用户规则表达的 前置修复——否则一条"走隧道"用户规则替代 private-split 会连不上。 回归测试 TestBuildConfigProxyDomainEnablesReverseMapping:唯一一条走隧道/拒绝 域名规则(privateSplit 关、无 direct 域名规则)必须开 reverse_mapping。go test ./... 全绿。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A79VtQA1BwTuQN1ThpvYpo
This commit is contained in:
@@ -358,6 +358,32 @@ func TestBuildConfigUserRules(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// 回归钉:走隧道/拒绝的域名规则也必须开 reverse_mapping。应用自行解析域名后按 IP
|
||||
// 发起连接,路由层只剩 IP,无反向映射则 domain 规则永不命中、该规则静默失效。
|
||||
// 旧实现只为 action==direct 的域名规则开 reverse_mapping,走隧道/拒绝会漏 → 本测试
|
||||
// 用**唯一一条走隧道域名规则**(无任何 direct 域名规则、privateSplit 关)钉死修复。
|
||||
func TestBuildConfigProxyDomainEnablesReverseMapping(t *testing.T) {
|
||||
for _, action := range []string{"proxy", "reject"} {
|
||||
node := testNode()
|
||||
p := routing.Default()
|
||||
p.Rules = []routing.Rule{
|
||||
{Type: "domain_suffix", Value: "example.com", Action: action, Enabled: true},
|
||||
}
|
||||
// SplitCN 关 + 不给 PrivateSplitDomains → reverse_mapping 只可能由该域名规则触发。
|
||||
raw, err := BuildClientConfig(node, "dp", "k", ClientConfigOpts{Profile: p})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var cfg map[string]any
|
||||
if err := json.Unmarshal(raw, &cfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cfg["dns"].(map[string]any)["reverse_mapping"] != true {
|
||||
t.Fatalf("action=%s domain rule must enable reverse_mapping", action)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildConfigGlobalMode(t *testing.T) {
|
||||
p := routing.Default()
|
||||
p.Mode = "global"
|
||||
|
||||
Reference in New Issue
Block a user