Handle includeAllNetworks

This commit is contained in:
世界 2024-05-07 20:34:24 +08:00
parent cf2181dd3a
commit a2098c18e1
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
5 changed files with 20 additions and 1 deletions

View file

@ -82,6 +82,10 @@ func (s *platformInterfaceStub) UnderNetworkExtension() bool {
return false return false
} }
func (s *platformInterfaceStub) IncludeAllNetworks() bool {
return false
}
func (s *platformInterfaceStub) ClearDNSCache() { func (s *platformInterfaceStub) ClearDNSCache() {
} }

View file

@ -19,6 +19,7 @@ type PlatformInterface interface {
UsePlatformInterfaceGetter() bool UsePlatformInterfaceGetter() bool
GetInterfaces() (NetworkInterfaceIterator, error) GetInterfaces() (NetworkInterfaceIterator, error)
UnderNetworkExtension() bool UnderNetworkExtension() bool
IncludeAllNetworks() bool
ReadWIFIState() *WIFIState ReadWIFIState() *WIFIState
ClearDNSCache() ClearDNSCache()
} }

View file

@ -21,6 +21,7 @@ type Interface interface {
UsePlatformInterfaceGetter() bool UsePlatformInterfaceGetter() bool
Interfaces() ([]control.Interface, error) Interfaces() ([]control.Interface, error)
UnderNetworkExtension() bool UnderNetworkExtension() bool
IncludeAllNetworks() bool
ClearDNSCache() ClearDNSCache()
ReadWIFIState() adapter.WIFIState ReadWIFIState() adapter.WIFIState
process.Searcher process.Searcher

View file

@ -213,6 +213,10 @@ func (w *platformInterfaceWrapper) UnderNetworkExtension() bool {
return w.iif.UnderNetworkExtension() return w.iif.UnderNetworkExtension()
} }
func (w *platformInterfaceWrapper) IncludeAllNetworks() bool {
return w.iif.IncludeAllNetworks()
}
func (w *platformInterfaceWrapper) ClearDNSCache() { func (w *platformInterfaceWrapper) ClearDNSCache() {
w.iif.ClearDNSCache() w.iif.ClearDNSCache()
} }

View file

@ -166,6 +166,14 @@ func (t *Tun) Start() error {
} }
t.logger.Trace("creating stack") t.logger.Trace("creating stack")
t.tunIf = tunInterface t.tunIf = tunInterface
var (
forwarderBindInterface bool
includeAllNetworks bool
)
if t.platformInterface != nil {
forwarderBindInterface = true
includeAllNetworks = t.platformInterface.IncludeAllNetworks()
}
t.tunStack, err = tun.NewStack(t.stack, tun.StackOptions{ t.tunStack, err = tun.NewStack(t.stack, tun.StackOptions{
Context: t.ctx, Context: t.ctx,
Tun: tunInterface, Tun: tunInterface,
@ -174,8 +182,9 @@ func (t *Tun) Start() error {
UDPTimeout: t.udpTimeout, UDPTimeout: t.udpTimeout,
Handler: t, Handler: t,
Logger: t.logger, Logger: t.logger,
ForwarderBindInterface: t.platformInterface != nil, ForwarderBindInterface: forwarderBindInterface,
InterfaceFinder: t.router.InterfaceFinder(), InterfaceFinder: t.router.InterfaceFinder(),
IncludeAllNetworks: includeAllNetworks,
}) })
if err != nil { if err != nil {
return err return err