mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-01-07 09:53:58 +08:00
chore: fix sing-tun's BuildAndroidRules
This commit is contained in:
parent
afd5e48adc
commit
110e0014d1
@ -257,6 +257,20 @@ type RawTun struct {
|
|||||||
AutoRoute bool `yaml:"auto-route" json:"auto-route"`
|
AutoRoute bool `yaml:"auto-route" json:"auto-route"`
|
||||||
AutoDetectInterface bool `yaml:"auto-detect-interface"`
|
AutoDetectInterface bool `yaml:"auto-detect-interface"`
|
||||||
RedirectToTun []string `yaml:"-" json:"-"`
|
RedirectToTun []string `yaml:"-" json:"-"`
|
||||||
|
|
||||||
|
MTU uint32 `yaml:"mtu" json:"mtu,omitempty"`
|
||||||
|
//Inet4Address []ListenPrefix `yaml:"inet4-address" json:"inet4_address,omitempty"`
|
||||||
|
Inet6Address []ListenPrefix `yaml:"inet6-address" json:"inet6_address,omitempty"`
|
||||||
|
StrictRoute bool `yaml:"strict-route" json:"strict_route,omitempty"`
|
||||||
|
IncludeUID []uint32 `yaml:"include-uid" json:"include_uid,omitempty"`
|
||||||
|
IncludeUIDRange []string `yaml:"include-uid-range" json:"include_uid_range,omitempty"`
|
||||||
|
ExcludeUID []uint32 `yaml:"exclude-uid" json:"exclude_uid,omitempty"`
|
||||||
|
ExcludeUIDRange []string `yaml:"exclude-uid-range" json:"exclude_uid_range,omitempty"`
|
||||||
|
IncludeAndroidUser []int `yaml:"include-android-user" json:"include_android_user,omitempty"`
|
||||||
|
IncludePackage []string `yaml:"include-package" json:"include_package,omitempty"`
|
||||||
|
ExcludePackage []string `yaml:"exclude-package" json:"exclude_package,omitempty"`
|
||||||
|
EndpointIndependentNat bool `yaml:"endpoint-independent-nat" json:"endpoint_independent_nat,omitempty"`
|
||||||
|
UDPTimeout int64 `yaml:"udp-timeout" json:"udp_timeout,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RawConfig struct {
|
type RawConfig struct {
|
||||||
@ -361,6 +375,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
|
|||||||
DNSHijack: []string{"0.0.0.0:53"}, // default hijack all dns query
|
DNSHijack: []string{"0.0.0.0:53"}, // default hijack all dns query
|
||||||
AutoRoute: false,
|
AutoRoute: false,
|
||||||
AutoDetectInterface: false,
|
AutoDetectInterface: false,
|
||||||
|
Inet6Address: []ListenPrefix{ListenPrefix(netip.MustParsePrefix("fdfe:dcba:9876::1/126"))},
|
||||||
},
|
},
|
||||||
EBpf: EBpf{
|
EBpf: EBpf{
|
||||||
RedirectToTun: []string{},
|
RedirectToTun: []string{},
|
||||||
@ -1132,8 +1147,20 @@ func parseTun(rawTun RawTun, general *General, dnsCfg *DNS) (*Tun, error) {
|
|||||||
AutoRoute: rawTun.AutoRoute,
|
AutoRoute: rawTun.AutoRoute,
|
||||||
AutoDetectInterface: rawTun.AutoDetectInterface,
|
AutoDetectInterface: rawTun.AutoDetectInterface,
|
||||||
RedirectToTun: rawTun.RedirectToTun,
|
RedirectToTun: rawTun.RedirectToTun,
|
||||||
Inet4Address: []ListenPrefix{ListenPrefix(tunAddressPrefix)},
|
|
||||||
Inet6Address: []ListenPrefix{ListenPrefix(netip.MustParsePrefix("fdfe:dcba:9876::1/126"))},
|
MTU: rawTun.MTU,
|
||||||
|
Inet4Address: []ListenPrefix{ListenPrefix(tunAddressPrefix)},
|
||||||
|
Inet6Address: rawTun.Inet6Address,
|
||||||
|
StrictRoute: rawTun.StrictRoute,
|
||||||
|
IncludeUID: rawTun.IncludeUID,
|
||||||
|
IncludeUIDRange: rawTun.IncludeUIDRange,
|
||||||
|
ExcludeUID: rawTun.ExcludeUID,
|
||||||
|
ExcludeUIDRange: rawTun.ExcludeUIDRange,
|
||||||
|
IncludeAndroidUser: rawTun.IncludeAndroidUser,
|
||||||
|
IncludePackage: rawTun.IncludePackage,
|
||||||
|
ExcludePackage: rawTun.ExcludePackage,
|
||||||
|
EndpointIndependentNat: rawTun.EndpointIndependentNat,
|
||||||
|
UDPTimeout: rawTun.UDPTimeout,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package sing_tun
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -25,19 +26,31 @@ var InterfaceName = "Meta"
|
|||||||
type Listener struct {
|
type Listener struct {
|
||||||
closed bool
|
closed bool
|
||||||
options config.Tun
|
options config.Tun
|
||||||
handler tun.Handler
|
handler *ListenerHandler
|
||||||
|
|
||||||
tunIf tun.Tun
|
tunIf tun.Tun
|
||||||
tunStack tun.Stack
|
tunStack tun.Stack
|
||||||
|
|
||||||
networkUpdateMonitor tun.NetworkUpdateMonitor
|
networkUpdateMonitor tun.NetworkUpdateMonitor
|
||||||
defaultInterfaceMonitor tun.DefaultInterfaceMonitor
|
defaultInterfaceMonitor tun.DefaultInterfaceMonitor
|
||||||
|
packageManager tun.PackageManager
|
||||||
|
}
|
||||||
|
|
||||||
|
func CalculateInterfaceName(name string) (tunName string) {
|
||||||
|
if runtime.GOOS == "darwin" {
|
||||||
|
tunName = "utun"
|
||||||
|
} else if name != "" {
|
||||||
|
tunName = name
|
||||||
|
} else {
|
||||||
|
tunName = "tun"
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(options config.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.PacketAdapter) (l *Listener, err error) {
|
func New(options config.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.PacketAdapter) (l *Listener, err error) {
|
||||||
tunName := options.Device
|
tunName := options.Device
|
||||||
if tunName == "" {
|
if tunName == "" {
|
||||||
tunName = tun.CalculateInterfaceName(InterfaceName)
|
tunName = CalculateInterfaceName(InterfaceName)
|
||||||
}
|
}
|
||||||
tunMTU := options.MTU
|
tunMTU := options.MTU
|
||||||
if tunMTU == 0 {
|
if tunMTU == 0 {
|
||||||
@ -157,9 +170,11 @@ func New(options config.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.P
|
|||||||
TableIndex: 2022,
|
TableIndex: 2022,
|
||||||
}
|
}
|
||||||
|
|
||||||
//if C.IsAndroid {
|
err = l.buildAndroidRules(&tunOptions)
|
||||||
// t.tunOptions.BuildAndroidRules(t.router.PackageManager(), t)
|
if err != nil {
|
||||||
//}
|
err = E.Cause(err, "build android rules")
|
||||||
|
return
|
||||||
|
}
|
||||||
tunIf, err := tun.Open(tunOptions)
|
tunIf, err := tun.Open(tunOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = E.Cause(err, "configure tun interface")
|
err = E.Cause(err, "configure tun interface")
|
||||||
@ -229,6 +244,7 @@ func (l *Listener) Close() {
|
|||||||
l.tunIf,
|
l.tunIf,
|
||||||
l.defaultInterfaceMonitor,
|
l.defaultInterfaceMonitor,
|
||||||
l.networkUpdateMonitor,
|
l.networkUpdateMonitor,
|
||||||
|
l.packageManager,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
listener/sing_tun/server_android.go
Normal file
23
listener/sing_tun/server_android.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package sing_tun
|
||||||
|
|
||||||
|
import (
|
||||||
|
tun "github.com/sagernet/sing-tun"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (l *Listener) buildAndroidRules(tunOptions *tun.Options) error {
|
||||||
|
packageManager, err := tun.NewPackageManager(l.handler)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = packageManager.Start()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
l.packageManager = packageManager
|
||||||
|
tunOptions.BuildAndroidRules(packageManager, l.handler)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ListenerHandler) OnPackagesUpdated(packages int, sharedUsers int) {
|
||||||
|
return
|
||||||
|
}
|
11
listener/sing_tun/server_other.go
Normal file
11
listener/sing_tun/server_other.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
//go:build !android
|
||||||
|
|
||||||
|
package sing_tun
|
||||||
|
|
||||||
|
import (
|
||||||
|
tun "github.com/sagernet/sing-tun"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (l *Listener) buildAndroidRules(tunOptions *tun.Options) error {
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user