diff --git a/config/config.go b/config/config.go index ac5f4a1e..39448b87 100644 --- a/config/config.go +++ b/config/config.go @@ -114,7 +114,7 @@ type Profile struct { type Tun struct { Enable bool `yaml:"enable" json:"enable"` Device string `yaml:"device" json:"device"` - Stack string `yaml:"stack" json:"stack"` + Stack C.TUNStack `yaml:"stack" json:"stack"` DNSHijack []netip.AddrPort `yaml:"dns-hijack" json:"dns-hijack"` AutoRoute bool `yaml:"auto-route" json:"auto-route"` AutoDetectInterface bool `yaml:"auto-detect-interface" json:"auto-detect-interface"` @@ -250,13 +250,13 @@ type RawFallbackFilter struct { } type RawTun struct { - Enable bool `yaml:"enable" json:"enable"` - Device string `yaml:"device" json:"device"` - Stack string `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"` - RedirectToTun []string `yaml:"-" json:"-"` + Enable bool `yaml:"enable" json:"enable"` + Device string `yaml:"device" json:"device"` + 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"` + RedirectToTun []string `yaml:"-" json:"-"` MTU uint32 `yaml:"mtu" json:"mtu,omitempty"` //Inet4Address []ListenPrefix `yaml:"inet4-address" json:"inet4_address,omitempty"` @@ -371,7 +371,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) { Tun: RawTun{ Enable: false, Device: "", - Stack: "gvisor", + Stack: C.TunGvisor, DNSHijack: []string{"0.0.0.0:53"}, // default hijack all dns query AutoRoute: true, AutoDetectInterface: true, diff --git a/constant/tun.go b/constant/tun.go index 10e24861..38f51155 100644 --- a/constant/tun.go +++ b/constant/tun.go @@ -7,13 +7,15 @@ import ( ) var StackTypeMapping = map[string]TUNStack{ - strings.ToUpper(TunGvisor.String()): TunGvisor, - strings.ToUpper(TunSystem.String()): TunSystem, + strings.ToLower(TunGvisor.String()): TunGvisor, + strings.ToLower(TunSystem.String()): TunSystem, + strings.ToLower(TunLWIP.String()): TunLWIP, } const ( TunGvisor TUNStack = iota TunSystem + TunLWIP ) type TUNStack int @@ -24,7 +26,7 @@ func (e *TUNStack) UnmarshalYAML(unmarshal func(any) error) error { if err := unmarshal(&tp); err != nil { return err } - mode, exist := StackTypeMapping[strings.ToUpper(tp)] + mode, exist := StackTypeMapping[strings.ToLower(tp)] if !exist { return errors.New("invalid tun stack") } @@ -41,7 +43,7 @@ func (e TUNStack) MarshalYAML() (any, error) { func (e *TUNStack) UnmarshalJSON(data []byte) error { var tp string json.Unmarshal(data, &tp) - mode, exist := StackTypeMapping[strings.ToUpper(tp)] + mode, exist := StackTypeMapping[strings.ToLower(tp)] if !exist { return errors.New("invalid tun stack") } @@ -60,6 +62,8 @@ func (e TUNStack) String() string { return "gVisor" case TunSystem: return "System" + case TunLWIP: + return "LWIP" default: return "unknown" } diff --git a/listener/sing_tun/server.go b/listener/sing_tun/server.go index ea173481..2e388440 100644 --- a/listener/sing_tun/server.go +++ b/listener/sing_tun/server.go @@ -186,7 +186,7 @@ func New(options config.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.P return } l.tunIf = tunIf - l.tunStack, err = tun.NewStack(options.Stack, tun.StackOptions{ + l.tunStack, err = tun.NewStack(strings.ToLower(options.Stack.String()), tun.StackOptions{ Context: context.TODO(), Tun: tunIf, MTU: tunOptions.MTU,