fix: tun stack shown
This commit is contained in:
parent
2c236387b7
commit
77a3c1c3ae
@ -114,7 +114,7 @@ type Profile struct {
|
|||||||
type Tun struct {
|
type Tun struct {
|
||||||
Enable bool `yaml:"enable" json:"enable"`
|
Enable bool `yaml:"enable" json:"enable"`
|
||||||
Device string `yaml:"device" json:"device"`
|
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"`
|
DNSHijack []netip.AddrPort `yaml:"dns-hijack" json:"dns-hijack"`
|
||||||
AutoRoute bool `yaml:"auto-route" json:"auto-route"`
|
AutoRoute bool `yaml:"auto-route" json:"auto-route"`
|
||||||
AutoDetectInterface bool `yaml:"auto-detect-interface" json:"auto-detect-interface"`
|
AutoDetectInterface bool `yaml:"auto-detect-interface" json:"auto-detect-interface"`
|
||||||
@ -252,7 +252,7 @@ type RawFallbackFilter struct {
|
|||||||
type RawTun struct {
|
type RawTun struct {
|
||||||
Enable bool `yaml:"enable" json:"enable"`
|
Enable bool `yaml:"enable" json:"enable"`
|
||||||
Device string `yaml:"device" json:"device"`
|
Device string `yaml:"device" json:"device"`
|
||||||
Stack string `yaml:"stack" json:"stack"`
|
Stack C.TUNStack `yaml:"stack" json:"stack"`
|
||||||
DNSHijack []string `yaml:"dns-hijack" json:"dns-hijack"`
|
DNSHijack []string `yaml:"dns-hijack" json:"dns-hijack"`
|
||||||
AutoRoute bool `yaml:"auto-route" json:"auto-route"`
|
AutoRoute bool `yaml:"auto-route" json:"auto-route"`
|
||||||
AutoDetectInterface bool `yaml:"auto-detect-interface"`
|
AutoDetectInterface bool `yaml:"auto-detect-interface"`
|
||||||
@ -371,7 +371,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
|
|||||||
Tun: RawTun{
|
Tun: RawTun{
|
||||||
Enable: false,
|
Enable: false,
|
||||||
Device: "",
|
Device: "",
|
||||||
Stack: "gvisor",
|
Stack: C.TunGvisor,
|
||||||
DNSHijack: []string{"0.0.0.0:53"}, // default hijack all dns query
|
DNSHijack: []string{"0.0.0.0:53"}, // default hijack all dns query
|
||||||
AutoRoute: true,
|
AutoRoute: true,
|
||||||
AutoDetectInterface: true,
|
AutoDetectInterface: true,
|
||||||
|
@ -7,13 +7,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var StackTypeMapping = map[string]TUNStack{
|
var StackTypeMapping = map[string]TUNStack{
|
||||||
strings.ToUpper(TunGvisor.String()): TunGvisor,
|
strings.ToLower(TunGvisor.String()): TunGvisor,
|
||||||
strings.ToUpper(TunSystem.String()): TunSystem,
|
strings.ToLower(TunSystem.String()): TunSystem,
|
||||||
|
strings.ToLower(TunLWIP.String()): TunLWIP,
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TunGvisor TUNStack = iota
|
TunGvisor TUNStack = iota
|
||||||
TunSystem
|
TunSystem
|
||||||
|
TunLWIP
|
||||||
)
|
)
|
||||||
|
|
||||||
type TUNStack int
|
type TUNStack int
|
||||||
@ -24,7 +26,7 @@ func (e *TUNStack) UnmarshalYAML(unmarshal func(any) error) error {
|
|||||||
if err := unmarshal(&tp); err != nil {
|
if err := unmarshal(&tp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
mode, exist := StackTypeMapping[strings.ToUpper(tp)]
|
mode, exist := StackTypeMapping[strings.ToLower(tp)]
|
||||||
if !exist {
|
if !exist {
|
||||||
return errors.New("invalid tun stack")
|
return errors.New("invalid tun stack")
|
||||||
}
|
}
|
||||||
@ -41,7 +43,7 @@ func (e TUNStack) MarshalYAML() (any, error) {
|
|||||||
func (e *TUNStack) UnmarshalJSON(data []byte) error {
|
func (e *TUNStack) UnmarshalJSON(data []byte) error {
|
||||||
var tp string
|
var tp string
|
||||||
json.Unmarshal(data, &tp)
|
json.Unmarshal(data, &tp)
|
||||||
mode, exist := StackTypeMapping[strings.ToUpper(tp)]
|
mode, exist := StackTypeMapping[strings.ToLower(tp)]
|
||||||
if !exist {
|
if !exist {
|
||||||
return errors.New("invalid tun stack")
|
return errors.New("invalid tun stack")
|
||||||
}
|
}
|
||||||
@ -60,6 +62,8 @@ func (e TUNStack) String() string {
|
|||||||
return "gVisor"
|
return "gVisor"
|
||||||
case TunSystem:
|
case TunSystem:
|
||||||
return "System"
|
return "System"
|
||||||
|
case TunLWIP:
|
||||||
|
return "LWIP"
|
||||||
default:
|
default:
|
||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ func New(options config.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.P
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
l.tunIf = tunIf
|
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(),
|
Context: context.TODO(),
|
||||||
Tun: tunIf,
|
Tun: tunIf,
|
||||||
MTU: tunOptions.MTU,
|
MTU: tunOptions.MTU,
|
||||||
|
Reference in New Issue
Block a user