github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/experimental/libbox/platform.go (about) 1 package libbox 2 3 import ( 4 "github.com/inazumav/sing-box/option" 5 ) 6 7 type PlatformInterface interface { 8 UsePlatformAutoDetectInterfaceControl() bool 9 AutoDetectInterfaceControl(fd int32) error 10 OpenTun(options TunOptions) (int32, error) 11 WriteLog(message string) 12 UseProcFS() bool 13 FindConnectionOwner(ipProtocol int32, sourceAddress string, sourcePort int32, destinationAddress string, destinationPort int32) (int32, error) 14 PackageNameByUid(uid int32) (string, error) 15 UIDByPackageName(packageName string) (int32, error) 16 UsePlatformDefaultInterfaceMonitor() bool 17 StartDefaultInterfaceMonitor(listener InterfaceUpdateListener) error 18 CloseDefaultInterfaceMonitor(listener InterfaceUpdateListener) error 19 UsePlatformInterfaceGetter() bool 20 GetInterfaces() (NetworkInterfaceIterator, error) 21 UnderNetworkExtension() bool 22 ClearDNSCache() 23 } 24 25 type TunInterface interface { 26 FileDescriptor() int32 27 Close() error 28 } 29 30 type InterfaceUpdateListener interface { 31 UpdateDefaultInterface(interfaceName string, interfaceIndex int32) 32 } 33 34 type NetworkInterface struct { 35 Index int32 36 MTU int32 37 Name string 38 Addresses StringIterator 39 } 40 41 type NetworkInterfaceIterator interface { 42 Next() *NetworkInterface 43 HasNext() bool 44 } 45 46 type OnDemandRule interface { 47 Target() int32 48 DNSSearchDomainMatch() StringIterator 49 DNSServerAddressMatch() StringIterator 50 InterfaceTypeMatch() int32 51 SSIDMatch() StringIterator 52 ProbeURL() string 53 } 54 55 type OnDemandRuleIterator interface { 56 Next() OnDemandRule 57 HasNext() bool 58 } 59 60 type onDemandRule struct { 61 option.OnDemandRule 62 } 63 64 func (r *onDemandRule) Target() int32 { 65 if r.OnDemandRule.Action == nil { 66 return -1 67 } 68 return int32(*r.OnDemandRule.Action) 69 } 70 71 func (r *onDemandRule) DNSSearchDomainMatch() StringIterator { 72 return newIterator(r.OnDemandRule.DNSSearchDomainMatch) 73 } 74 75 func (r *onDemandRule) DNSServerAddressMatch() StringIterator { 76 return newIterator(r.OnDemandRule.DNSServerAddressMatch) 77 } 78 79 func (r *onDemandRule) InterfaceTypeMatch() int32 { 80 if r.OnDemandRule.InterfaceTypeMatch == nil { 81 return -1 82 } 83 return int32(*r.OnDemandRule.InterfaceTypeMatch) 84 } 85 86 func (r *onDemandRule) SSIDMatch() StringIterator { 87 return newIterator(r.OnDemandRule.SSIDMatch) 88 } 89 90 func (r *onDemandRule) ProbeURL() string { 91 return r.OnDemandRule.ProbeURL 92 }