Skip to content

Commit d1bec3c

Browse files
mapleafgoclaude
andcommitted
feat(translator): add mixed-system-proxy extension field for sing-box set_system_proxy
Non-standard mihomo extension: when mixed-system-proxy is set to true in Clash YAML config, translates to set_system_proxy on the mixed inbound only (http inbound is not affected). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 47bf5b3 commit d1bec3c

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

translator/general.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ func translateGeneral(cfg *RawConfig, result *singboxConfig) {
2020
"listen": listen,
2121
"listen_port": cfg.MixedPort,
2222
}
23+
if cfg.MixedSystemProxy {
24+
inbound["set_system_proxy"] = true
25+
}
2326
applyInboundAuth(cfg.Authentication, inbound)
2427
result.Inbounds = append(result.Inbounds, inbound)
2528
}

translator/general_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,53 @@ func TestTranslateGeneralFindProcess(t *testing.T) {
152152
}
153153
}
154154

155+
func TestTranslateGeneralMixedSystemProxy(t *testing.T) {
156+
tests := []struct {
157+
name string
158+
enabled bool
159+
wantMixed bool
160+
}{
161+
{"enabled", true, true},
162+
{"disabled", false, false},
163+
}
164+
165+
for _, tt := range tests {
166+
t.Run(tt.name, func(t *testing.T) {
167+
cfg := &RawConfig{
168+
MixedPort: 7890,
169+
Port: 8080,
170+
MixedSystemProxy: tt.enabled,
171+
}
172+
result := &singboxConfig{}
173+
174+
translateGeneral(cfg, result)
175+
176+
for _, ib := range result.Inbounds {
177+
tag := ib["tag"].(string)
178+
got, _ := ib["set_system_proxy"].(bool)
179+
if tag == "mixed-in" && got != tt.wantMixed {
180+
t.Errorf("mixed-in set_system_proxy = %v, want %v", got, tt.wantMixed)
181+
}
182+
if tag == "http-in" && got {
183+
t.Error("http-in should never have set_system_proxy from MixedSystemProxy")
184+
}
185+
}
186+
})
187+
}
188+
}
189+
190+
func TestTranslateGeneralMixedSystemProxyOmitted(t *testing.T) {
191+
cfg := &RawConfig{MixedPort: 7890}
192+
result := &singboxConfig{}
193+
194+
translateGeneral(cfg, result)
195+
196+
ib := result.Inbounds[0]
197+
if _, ok := ib["set_system_proxy"]; ok {
198+
t.Error("set_system_proxy should be absent when MixedSystemProxy is false")
199+
}
200+
}
201+
155202
func TestTranslateGeneralInterface(t *testing.T) {
156203
cfg := &RawConfig{
157204
Interface: "eth0",

translator/types_mihomo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ type RawConfig struct {
66
RedirPort int `yaml:"redir-port" json:"redir-port"`
77
TProxyPort int `yaml:"tproxy-port" json:"tproxy-port"`
88
MixedPort int `yaml:"mixed-port" json:"mixed-port"`
9+
// Extension: not a standard mihomo field. Translates to sing-box mixed inbound set_system_proxy.
10+
MixedSystemProxy bool `yaml:"mixed-system-proxy" json:"mixed-system-proxy"`
911
Authentication []string `yaml:"authentication" json:"authentication"`
1012
AllowLan bool `yaml:"allow-lan" json:"allow-lan"`
1113
BindAddress string `yaml:"bind-address" json:"bind-address"`

0 commit comments

Comments
 (0)