Feat: support set tun file-descriptor in config file

Co-authored-by: DuFoxit <DuFoxit@users.noreply.github.com>
This commit is contained in:
wwqgtxx 2023-03-15 23:43:58 +08:00
parent 520cc807d6
commit 998d407d44
6 changed files with 12 additions and 1 deletions

View File

@ -218,6 +218,7 @@ type RawTun struct {
ExcludePackage []string `yaml:"exclude-package" json:"exclude_package,omitempty"` ExcludePackage []string `yaml:"exclude-package" json:"exclude_package,omitempty"`
EndpointIndependentNat bool `yaml:"endpoint-independent-nat" json:"endpoint_independent_nat,omitempty"` EndpointIndependentNat bool `yaml:"endpoint-independent-nat" json:"endpoint_independent_nat,omitempty"`
UDPTimeout int64 `yaml:"udp-timeout" json:"udp_timeout,omitempty"` UDPTimeout int64 `yaml:"udp-timeout" json:"udp_timeout,omitempty"`
FileDescriptor int `yaml:"file-descriptor" json:"file-descriptor"`
} }
type RawTuicServer struct { type RawTuicServer struct {
@ -1239,6 +1240,7 @@ func parseTun(rawTun RawTun, general *General) error {
ExcludePackage: rawTun.ExcludePackage, ExcludePackage: rawTun.ExcludePackage,
EndpointIndependentNat: rawTun.EndpointIndependentNat, EndpointIndependentNat: rawTun.EndpointIndependentNat,
UDPTimeout: rawTun.UDPTimeout, UDPTimeout: rawTun.UDPTimeout,
FileDescriptor: rawTun.FileDescriptor,
} }
return nil return nil

View File

@ -80,6 +80,7 @@ type tunSchema struct {
ExcludePackage *[]string `yaml:"exclude-package" json:"exclude-package,omitempty"` ExcludePackage *[]string `yaml:"exclude-package" json:"exclude-package,omitempty"`
EndpointIndependentNat *bool `yaml:"endpoint-independent-nat" json:"endpoint-independent-nat,omitempty"` EndpointIndependentNat *bool `yaml:"endpoint-independent-nat" json:"endpoint-independent-nat,omitempty"`
UDPTimeout *int64 `yaml:"udp-timeout" json:"udp-timeout,omitempty"` UDPTimeout *int64 `yaml:"udp-timeout" json:"udp-timeout,omitempty"`
FileDescriptor *int `yaml:"file-descriptor" json:"file-descriptor"`
} }
type tuicServerSchema struct { type tuicServerSchema struct {
@ -169,6 +170,9 @@ func pointerOrDefaultTun(p *tunSchema, def LC.Tun) LC.Tun {
if p.UDPTimeout != nil { if p.UDPTimeout != nil {
def.UDPTimeout = *p.UDPTimeout def.UDPTimeout = *p.UDPTimeout
} }
if p.FileDescriptor != nil {
def.FileDescriptor = *p.FileDescriptor
}
} }
return def return def
} }

View File

@ -95,4 +95,5 @@ type Tun struct {
ExcludePackage []string `yaml:"exclude-package" json:"exclude-package,omitempty"` ExcludePackage []string `yaml:"exclude-package" json:"exclude-package,omitempty"`
EndpointIndependentNat bool `yaml:"endpoint-independent-nat" json:"endpoint-independent-nat,omitempty"` EndpointIndependentNat bool `yaml:"endpoint-independent-nat" json:"endpoint-independent-nat,omitempty"`
UDPTimeout int64 `yaml:"udp-timeout" json:"udp-timeout,omitempty"` UDPTimeout int64 `yaml:"udp-timeout" json:"udp-timeout,omitempty"`
FileDescriptor int `yaml:"file-descriptor" json:"file-descriptor"`
} }

View File

@ -33,6 +33,7 @@ type TunOption struct {
ExcludePackage []string `inbound:"exclude_package,omitempty"` ExcludePackage []string `inbound:"exclude_package,omitempty"`
EndpointIndependentNat bool `inbound:"endpoint_independent_nat,omitempty"` EndpointIndependentNat bool `inbound:"endpoint_independent_nat,omitempty"`
UDPTimeout int64 `inbound:"udp_timeout,omitempty"` UDPTimeout int64 `inbound:"udp_timeout,omitempty"`
FileDescriptor int `inbound:"file-descriptor,omitempty"`
} }
func (o TunOption) Equal(config C.InboundConfig) bool { func (o TunOption) Equal(config C.InboundConfig) bool {
@ -96,6 +97,7 @@ func NewTun(options *TunOption) (*Tun, error) {
ExcludePackage: options.ExcludePackage, ExcludePackage: options.ExcludePackage,
EndpointIndependentNat: options.EndpointIndependentNat, EndpointIndependentNat: options.EndpointIndependentNat,
UDPTimeout: options.UDPTimeout, UDPTimeout: options.UDPTimeout,
FileDescriptor: options.FileDescriptor,
}, },
}, nil }, nil
} }

View File

@ -821,7 +821,8 @@ func hasTunConfigChange(tunConf *LC.Tun) bool {
LastTunConf.MTU != tunConf.MTU || LastTunConf.MTU != tunConf.MTU ||
LastTunConf.StrictRoute != tunConf.StrictRoute || LastTunConf.StrictRoute != tunConf.StrictRoute ||
LastTunConf.EndpointIndependentNat != tunConf.EndpointIndependentNat || LastTunConf.EndpointIndependentNat != tunConf.EndpointIndependentNat ||
LastTunConf.UDPTimeout != tunConf.UDPTimeout { LastTunConf.UDPTimeout != tunConf.UDPTimeout ||
LastTunConf.FileDescriptor != tunConf.FileDescriptor {
return true return true
} }

View File

@ -212,6 +212,7 @@ func New(options LC.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapte
IncludeAndroidUser: options.IncludeAndroidUser, IncludeAndroidUser: options.IncludeAndroidUser,
IncludePackage: options.IncludePackage, IncludePackage: options.IncludePackage,
ExcludePackage: options.ExcludePackage, ExcludePackage: options.ExcludePackage,
FileDescriptor: options.FileDescriptor,
InterfaceMonitor: defaultInterfaceMonitor, InterfaceMonitor: defaultInterfaceMonitor,
TableIndex: 2022, TableIndex: 2022,
} }