chore: allow config table-index for tun

https://github.com/MetaCubeX/mihomo/issues/1128
This commit is contained in:
wwqgtxx 2024-03-24 21:31:52 +08:00
parent d2ae94f20b
commit 5af7f4e847
6 changed files with 16 additions and 2 deletions

View File

@ -265,6 +265,7 @@ type RawTun struct {
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"` FileDescriptor int `yaml:"file-descriptor" json:"file-descriptor"`
TableIndex int `yaml:"table-index" json:"table-index"`
} }
type RawTuicServer struct { type RawTuicServer struct {
@ -1448,6 +1449,7 @@ func parseTun(rawTun RawTun, general *General) error {
EndpointIndependentNat: rawTun.EndpointIndependentNat, EndpointIndependentNat: rawTun.EndpointIndependentNat,
UDPTimeout: rawTun.UDPTimeout, UDPTimeout: rawTun.UDPTimeout,
FileDescriptor: rawTun.FileDescriptor, FileDescriptor: rawTun.FileDescriptor,
TableIndex: rawTun.TableIndex,
} }
return nil return nil

View File

@ -91,6 +91,7 @@ type tunSchema struct {
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"` FileDescriptor *int `yaml:"file-descriptor" json:"file-descriptor"`
TableIndex *int `yaml:"table-index" json:"table-index"`
} }
type tuicServerSchema struct { type tuicServerSchema struct {
@ -209,6 +210,9 @@ func pointerOrDefaultTun(p *tunSchema, def LC.Tun) LC.Tun {
if p.FileDescriptor != nil { if p.FileDescriptor != nil {
def.FileDescriptor = *p.FileDescriptor def.FileDescriptor = *p.FileDescriptor
} }
if p.TableIndex != nil {
def.TableIndex = *p.TableIndex
}
} }
return def return def
} }

View File

@ -49,4 +49,5 @@ type Tun struct {
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"` FileDescriptor int `yaml:"file-descriptor" json:"file-descriptor"`
TableIndex int `yaml:"table-index" json:"table-index"`
} }

View File

@ -40,6 +40,7 @@ type TunOption struct {
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"` FileDescriptor int `inbound:"file-descriptor,omitempty"`
TableIndex int `inbound:"table-index,omitempty"`
} }
func (o TunOption) Equal(config C.InboundConfig) bool { func (o TunOption) Equal(config C.InboundConfig) bool {
@ -118,6 +119,7 @@ func NewTun(options *TunOption) (*Tun, error) {
EndpointIndependentNat: options.EndpointIndependentNat, EndpointIndependentNat: options.EndpointIndependentNat,
UDPTimeout: options.UDPTimeout, UDPTimeout: options.UDPTimeout,
FileDescriptor: options.FileDescriptor, FileDescriptor: options.FileDescriptor,
TableIndex: options.TableIndex,
}, },
}, nil }, nil
} }

View File

@ -823,7 +823,8 @@ func hasTunConfigChange(tunConf *LC.Tun) bool {
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 { LastTunConf.FileDescriptor != tunConf.FileDescriptor ||
LastTunConf.TableIndex != tunConf.TableIndex {
return true return true
} }

View File

@ -112,6 +112,10 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
} else { } else {
udpTimeout = int64(sing.UDPTimeout.Seconds()) udpTimeout = int64(sing.UDPTimeout.Seconds())
} }
tableIndex := options.TableIndex
if tableIndex == 0 {
tableIndex = 2022
}
includeUID := uidToRange(options.IncludeUID) includeUID := uidToRange(options.IncludeUID)
if len(options.IncludeUIDRange) > 0 { if len(options.IncludeUIDRange) > 0 {
var err error var err error
@ -225,7 +229,7 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
ExcludePackage: options.ExcludePackage, ExcludePackage: options.ExcludePackage,
FileDescriptor: options.FileDescriptor, FileDescriptor: options.FileDescriptor,
InterfaceMonitor: defaultInterfaceMonitor, InterfaceMonitor: defaultInterfaceMonitor,
TableIndex: 2022, TableIndex: tableIndex,
} }
err = l.buildAndroidRules(&tunOptions) err = l.buildAndroidRules(&tunOptions)