mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-01-30 04:36:54 +00:00
Do not set address sets to routes on Apple platforms
Network Extension was observed to stop for unknown reasons
This commit is contained in:
parent
9b73222314
commit
e64cf3b7df
|
@ -66,10 +66,6 @@ func (s *platformInterfaceStub) OpenTun(options *tun.Options, platformOptions op
|
||||||
return nil, os.ErrInvalid
|
return nil, os.ErrInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *platformInterfaceStub) UpdateRouteOptions(options *tun.Options, platformInterface option.TunPlatformOptions) error {
|
|
||||||
return os.ErrInvalid
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *platformInterfaceStub) UsePlatformDefaultInterfaceMonitor() bool {
|
func (s *platformInterfaceStub) UsePlatformDefaultInterfaceMonitor() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ type PlatformInterface interface {
|
||||||
UsePlatformAutoDetectInterfaceControl() bool
|
UsePlatformAutoDetectInterfaceControl() bool
|
||||||
AutoDetectInterfaceControl(fd int32) error
|
AutoDetectInterfaceControl(fd int32) error
|
||||||
OpenTun(options TunOptions) (int32, error)
|
OpenTun(options TunOptions) (int32, error)
|
||||||
UpdateRouteOptions(options TunOptions) error
|
|
||||||
WriteLog(message string)
|
WriteLog(message string)
|
||||||
UseProcFS() bool
|
UseProcFS() bool
|
||||||
FindConnectionOwner(ipProtocol int32, sourceAddress string, sourcePort int32, destinationAddress string, destinationPort int32) (int32, error)
|
FindConnectionOwner(ipProtocol int32, sourceAddress string, sourcePort int32, destinationAddress string, destinationPort int32) (int32, error)
|
||||||
|
|
|
@ -13,7 +13,6 @@ type Interface interface {
|
||||||
UsePlatformAutoDetectInterfaceControl() bool
|
UsePlatformAutoDetectInterfaceControl() bool
|
||||||
AutoDetectInterfaceControl(fd int) error
|
AutoDetectInterfaceControl(fd int) error
|
||||||
OpenTun(options *tun.Options, platformOptions option.TunPlatformOptions) (tun.Tun, error)
|
OpenTun(options *tun.Options, platformOptions option.TunPlatformOptions) (tun.Tun, error)
|
||||||
UpdateRouteOptions(options *tun.Options, platformOptions option.TunPlatformOptions) error
|
|
||||||
CreateDefaultInterfaceMonitor(logger logger.Logger) tun.DefaultInterfaceMonitor
|
CreateDefaultInterfaceMonitor(logger logger.Logger) tun.DefaultInterfaceMonitor
|
||||||
Interfaces() ([]adapter.NetworkInterface, error)
|
Interfaces() ([]adapter.NetworkInterface, error)
|
||||||
UnderNetworkExtension() bool
|
UnderNetworkExtension() bool
|
||||||
|
|
|
@ -174,20 +174,6 @@ func (w *platformInterfaceWrapper) OpenTun(options *tun.Options, platformOptions
|
||||||
return tun.New(*options)
|
return tun.New(*options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *platformInterfaceWrapper) UpdateRouteOptions(options *tun.Options, platformOptions option.TunPlatformOptions) error {
|
|
||||||
if len(options.IncludeUID) > 0 || len(options.ExcludeUID) > 0 {
|
|
||||||
return E.New("android: unsupported uid options")
|
|
||||||
}
|
|
||||||
if len(options.IncludeAndroidUser) > 0 {
|
|
||||||
return E.New("android: unsupported android_user option")
|
|
||||||
}
|
|
||||||
routeRanges, err := options.BuildAutoRouteRanges(true)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return w.iif.UpdateRouteOptions(&tunOptions{options, routeRanges, platformOptions})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *platformInterfaceWrapper) CreateDefaultInterfaceMonitor(logger logger.Logger) tun.DefaultInterfaceMonitor {
|
func (w *platformInterfaceWrapper) CreateDefaultInterfaceMonitor(logger logger.Logger) tun.DefaultInterfaceMonitor {
|
||||||
return &platformDefaultInterfaceMonitor{
|
return &platformDefaultInterfaceMonitor{
|
||||||
platformInterfaceWrapper: w,
|
platformInterfaceWrapper: w,
|
||||||
|
|
|
@ -305,7 +305,7 @@ func (t *Inbound) Start(stage adapter.StartStage) error {
|
||||||
if t.tunOptions.Name == "" {
|
if t.tunOptions.Name == "" {
|
||||||
t.tunOptions.Name = tun.CalculateInterfaceName("")
|
t.tunOptions.Name = tun.CalculateInterfaceName("")
|
||||||
}
|
}
|
||||||
if t.platformInterface == nil || runtime.GOOS != "android" {
|
if t.platformInterface == nil {
|
||||||
t.routeAddressSet = common.FlatMap(t.routeRuleSet, adapter.RuleSet.ExtractIPSet)
|
t.routeAddressSet = common.FlatMap(t.routeRuleSet, adapter.RuleSet.ExtractIPSet)
|
||||||
for _, routeRuleSet := range t.routeRuleSet {
|
for _, routeRuleSet := range t.routeRuleSet {
|
||||||
ipSets := routeRuleSet.ExtractIPSet()
|
ipSets := routeRuleSet.ExtractIPSet()
|
||||||
|
@ -421,41 +421,7 @@ func (t *Inbound) Start(stage adapter.StartStage) error {
|
||||||
func (t *Inbound) updateRouteAddressSet(it adapter.RuleSet) {
|
func (t *Inbound) updateRouteAddressSet(it adapter.RuleSet) {
|
||||||
t.routeAddressSet = common.FlatMap(t.routeRuleSet, adapter.RuleSet.ExtractIPSet)
|
t.routeAddressSet = common.FlatMap(t.routeRuleSet, adapter.RuleSet.ExtractIPSet)
|
||||||
t.routeExcludeAddressSet = common.FlatMap(t.routeExcludeRuleSet, adapter.RuleSet.ExtractIPSet)
|
t.routeExcludeAddressSet = common.FlatMap(t.routeExcludeRuleSet, adapter.RuleSet.ExtractIPSet)
|
||||||
if t.autoRedirect != nil {
|
t.autoRedirect.UpdateRouteAddressSet()
|
||||||
t.autoRedirect.UpdateRouteAddressSet()
|
|
||||||
} else {
|
|
||||||
tunOptions := t.tunOptions
|
|
||||||
for _, ipSet := range t.routeAddressSet {
|
|
||||||
for _, prefix := range ipSet.Prefixes() {
|
|
||||||
if prefix.Addr().Is4() {
|
|
||||||
tunOptions.Inet4RouteAddress = append(tunOptions.Inet4RouteAddress, prefix)
|
|
||||||
} else {
|
|
||||||
tunOptions.Inet6RouteAddress = append(tunOptions.Inet6RouteAddress, prefix)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, ipSet := range t.routeExcludeAddressSet {
|
|
||||||
for _, prefix := range ipSet.Prefixes() {
|
|
||||||
if prefix.Addr().Is4() {
|
|
||||||
tunOptions.Inet4RouteExcludeAddress = append(tunOptions.Inet4RouteExcludeAddress, prefix)
|
|
||||||
} else {
|
|
||||||
tunOptions.Inet6RouteExcludeAddress = append(tunOptions.Inet6RouteExcludeAddress, prefix)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if t.platformInterface != nil {
|
|
||||||
err := t.platformInterface.UpdateRouteOptions(&tunOptions, t.platformOptions)
|
|
||||||
if err != nil {
|
|
||||||
t.logger.Error("update route addresses: ", err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
err := t.tunIf.UpdateRouteOptions(tunOptions)
|
|
||||||
if err != nil {
|
|
||||||
t.logger.Error("update route addresses: ", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
t.logger.Info("updated route addresses")
|
|
||||||
}
|
|
||||||
t.routeAddressSet = nil
|
t.routeAddressSet = nil
|
||||||
t.routeExcludeAddressSet = nil
|
t.routeExcludeAddressSet = nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue