diff --git a/config/config.go b/config/config.go index 33fd81fd37..f53fb69d1b 100644 --- a/config/config.go +++ b/config/config.go @@ -271,7 +271,7 @@ type RawTun struct { Stack C.TUNStack `yaml:"stack" json:"stack"` DNSHijack []string `yaml:"dns-hijack" json:"dns-hijack"` AutoRoute bool `yaml:"auto-route" json:"auto-route"` - AutoDetectInterface bool `yaml:"auto-detect-interface"` + AutoDetectInterface bool `yaml:"auto-detect-interface" json:"auto-detect-interface"` MTU uint32 `yaml:"mtu" json:"mtu,omitempty"` GSO bool `yaml:"gso" json:"gso,omitempty"` diff --git a/config/raw_tun_test.go b/config/raw_tun_test.go new file mode 100644 index 0000000000..a69aaa1d98 --- /dev/null +++ b/config/raw_tun_test.go @@ -0,0 +1,25 @@ +package config + +import ( + "encoding/json" + "testing" +) + +func TestRawTunJSONUsesMihomoAutoDetectInterfaceKey(t *testing.T) { + data, err := json.Marshal(RawTun{AutoDetectInterface: true}) + if err != nil { + t.Fatalf("marshal RawTun: %v", err) + } + + var fields map[string]any + if err := json.Unmarshal(data, &fields); err != nil { + t.Fatalf("unmarshal RawTun JSON: %v", err) + } + + if got := fields["auto-detect-interface"]; got != true { + t.Fatalf("auto-detect-interface = %v, want true", got) + } + if _, found := fields["AutoDetectInterface"]; found { + t.Fatal("unexpected Go field name in RawTun JSON") + } +}