Skip to content

Commit

Permalink
chore: allow config table-index for tun
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Mar 24, 2024
1 parent d2ae94f commit 5af7f4e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ type RawTun struct {
EndpointIndependentNat bool `yaml:"endpoint-independent-nat" json:"endpoint_independent_nat,omitempty"`
UDPTimeout int64 `yaml:"udp-timeout" json:"udp_timeout,omitempty"`
FileDescriptor int `yaml:"file-descriptor" json:"file-descriptor"`
TableIndex int `yaml:"table-index" json:"table-index"`
}

type RawTuicServer struct {
Expand Down Expand Up @@ -1448,6 +1449,7 @@ func parseTun(rawTun RawTun, general *General) error {
EndpointIndependentNat: rawTun.EndpointIndependentNat,
UDPTimeout: rawTun.UDPTimeout,
FileDescriptor: rawTun.FileDescriptor,
TableIndex: rawTun.TableIndex,
}

return nil
Expand Down
4 changes: 4 additions & 0 deletions hub/route/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type tunSchema struct {
EndpointIndependentNat *bool `yaml:"endpoint-independent-nat" json:"endpoint-independent-nat,omitempty"`
UDPTimeout *int64 `yaml:"udp-timeout" json:"udp-timeout,omitempty"`
FileDescriptor *int `yaml:"file-descriptor" json:"file-descriptor"`
TableIndex *int `yaml:"table-index" json:"table-index"`
}

type tuicServerSchema struct {
Expand Down Expand Up @@ -209,6 +210,9 @@ func pointerOrDefaultTun(p *tunSchema, def LC.Tun) LC.Tun {
if p.FileDescriptor != nil {
def.FileDescriptor = *p.FileDescriptor
}
if p.TableIndex != nil {
def.TableIndex = *p.TableIndex
}
}
return def
}
Expand Down
1 change: 1 addition & 0 deletions listener/config/tun.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ type Tun struct {
EndpointIndependentNat bool `yaml:"endpoint-independent-nat" json:"endpoint-independent-nat,omitempty"`
UDPTimeout int64 `yaml:"udp-timeout" json:"udp-timeout,omitempty"`
FileDescriptor int `yaml:"file-descriptor" json:"file-descriptor"`
TableIndex int `yaml:"table-index" json:"table-index"`
}
2 changes: 2 additions & 0 deletions listener/inbound/tun.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type TunOption struct {
EndpointIndependentNat bool `inbound:"endpoint_independent_nat,omitempty"`
UDPTimeout int64 `inbound:"udp_timeout,omitempty"`
FileDescriptor int `inbound:"file-descriptor,omitempty"`
TableIndex int `inbound:"table-index,omitempty"`
}

func (o TunOption) Equal(config C.InboundConfig) bool {
Expand Down Expand Up @@ -118,6 +119,7 @@ func NewTun(options *TunOption) (*Tun, error) {
EndpointIndependentNat: options.EndpointIndependentNat,
UDPTimeout: options.UDPTimeout,
FileDescriptor: options.FileDescriptor,
TableIndex: options.TableIndex,
},
}, nil
}
Expand Down
3 changes: 2 additions & 1 deletion listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,8 @@ func hasTunConfigChange(tunConf *LC.Tun) bool {
LastTunConf.StrictRoute != tunConf.StrictRoute ||
LastTunConf.EndpointIndependentNat != tunConf.EndpointIndependentNat ||
LastTunConf.UDPTimeout != tunConf.UDPTimeout ||
LastTunConf.FileDescriptor != tunConf.FileDescriptor {
LastTunConf.FileDescriptor != tunConf.FileDescriptor ||
LastTunConf.TableIndex != tunConf.TableIndex {
return true
}

Expand Down
6 changes: 5 additions & 1 deletion listener/sing_tun/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
} else {
udpTimeout = int64(sing.UDPTimeout.Seconds())
}
tableIndex := options.TableIndex
if tableIndex == 0 {
tableIndex = 2022
}
includeUID := uidToRange(options.IncludeUID)
if len(options.IncludeUIDRange) > 0 {
var err error
Expand Down Expand Up @@ -225,7 +229,7 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
ExcludePackage: options.ExcludePackage,
FileDescriptor: options.FileDescriptor,
InterfaceMonitor: defaultInterfaceMonitor,
TableIndex: 2022,
TableIndex: tableIndex,
}

err = l.buildAndroidRules(&tunOptions)
Expand Down

0 comments on commit 5af7f4e

Please sign in to comment.