github.com/metacubex/mihomo@v1.18.5/listener/sing_tun/server_android.go (about) 1 package sing_tun 2 3 import ( 4 "github.com/metacubex/mihomo/log" 5 tun "github.com/metacubex/sing-tun" 6 "github.com/sagernet/netlink" 7 "golang.org/x/sys/unix" 8 "runtime" 9 ) 10 11 func (l *Listener) buildAndroidRules(tunOptions *tun.Options) error { 12 packageManager, err := tun.NewPackageManager(l.handler) 13 if err != nil { 14 return err 15 } 16 err = packageManager.Start() 17 if err != nil { 18 return err 19 } 20 l.packageManager = packageManager 21 tunOptions.BuildAndroidRules(packageManager, l.handler) 22 return nil 23 } 24 25 func (h *ListenerHandler) OnPackagesUpdated(packages int, sharedUsers int) { 26 return 27 } 28 29 func (l *Listener) openAndroidHotspot(tunOptions tun.Options) { 30 if runtime.GOOS == "android" && tunOptions.AutoRoute { 31 priority := 9000 32 if len(tunOptions.ExcludedRanges()) > 0 { 33 priority++ 34 } 35 if tunOptions.InterfaceMonitor.AndroidVPNEnabled() { 36 priority++ 37 } 38 it := netlink.NewRule() 39 it.Priority = priority 40 it.IifName = tunOptions.Name 41 it.Table = 254 //main 42 it.Family = unix.AF_INET 43 it.SuppressPrefixlen = 0 44 err := netlink.RuleAdd(it) 45 if err != nil { 46 log.Warnln("[TUN] add AndroidHotspot rule error") 47 } 48 } 49 }