platform.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package libbox
  2. import (
  3. C "github.com/sagernet/sing-box/constant"
  4. "github.com/sagernet/sing-box/option"
  5. )
  6. type PlatformInterface interface {
  7. LocalDNSTransport() LocalDNSTransport
  8. UsePlatformAutoDetectInterfaceControl() bool
  9. AutoDetectInterfaceControl(fd int32) error
  10. OpenTun(options TunOptions) (int32, error)
  11. UseProcFS() bool
  12. FindConnectionOwner(ipProtocol int32, sourceAddress string, sourcePort int32, destinationAddress string, destinationPort int32) (*ConnectionOwner, error)
  13. StartDefaultInterfaceMonitor(listener InterfaceUpdateListener) error
  14. CloseDefaultInterfaceMonitor(listener InterfaceUpdateListener) error
  15. GetInterfaces() (NetworkInterfaceIterator, error)
  16. UnderNetworkExtension() bool
  17. IncludeAllNetworks() bool
  18. ReadWIFIState() *WIFIState
  19. SystemCertificates() StringIterator
  20. ClearDNSCache()
  21. SendNotification(notification *Notification) error
  22. }
  23. type ConnectionOwner struct {
  24. UserId int32
  25. UserName string
  26. ProcessPath string
  27. AndroidPackageName string
  28. }
  29. type InterfaceUpdateListener interface {
  30. UpdateDefaultInterface(interfaceName string, interfaceIndex int32, isExpensive bool, isConstrained bool)
  31. }
  32. const (
  33. InterfaceTypeWIFI = int32(C.InterfaceTypeWIFI)
  34. InterfaceTypeCellular = int32(C.InterfaceTypeCellular)
  35. InterfaceTypeEthernet = int32(C.InterfaceTypeEthernet)
  36. InterfaceTypeOther = int32(C.InterfaceTypeOther)
  37. )
  38. type NetworkInterface struct {
  39. Index int32
  40. MTU int32
  41. Name string
  42. Addresses StringIterator
  43. Flags int32
  44. Type int32
  45. DNSServer StringIterator
  46. Metered bool
  47. }
  48. type WIFIState struct {
  49. SSID string
  50. BSSID string
  51. }
  52. func NewWIFIState(wifiSSID string, wifiBSSID string) *WIFIState {
  53. return &WIFIState{wifiSSID, wifiBSSID}
  54. }
  55. type NetworkInterfaceIterator interface {
  56. Next() *NetworkInterface
  57. HasNext() bool
  58. }
  59. type Notification struct {
  60. Identifier string
  61. TypeName string
  62. TypeID int32
  63. Title string
  64. Subtitle string
  65. Body string
  66. OpenURL string
  67. }
  68. type OnDemandRule interface {
  69. Target() int32
  70. DNSSearchDomainMatch() StringIterator
  71. DNSServerAddressMatch() StringIterator
  72. InterfaceTypeMatch() int32
  73. SSIDMatch() StringIterator
  74. ProbeURL() string
  75. }
  76. type OnDemandRuleIterator interface {
  77. Next() OnDemandRule
  78. HasNext() bool
  79. }
  80. type onDemandRule struct {
  81. option.OnDemandRule
  82. }
  83. func (r *onDemandRule) Target() int32 {
  84. if r.OnDemandRule.Action == nil {
  85. return -1
  86. }
  87. return int32(*r.OnDemandRule.Action)
  88. }
  89. func (r *onDemandRule) DNSSearchDomainMatch() StringIterator {
  90. return newIterator(r.OnDemandRule.DNSSearchDomainMatch)
  91. }
  92. func (r *onDemandRule) DNSServerAddressMatch() StringIterator {
  93. return newIterator(r.OnDemandRule.DNSServerAddressMatch)
  94. }
  95. func (r *onDemandRule) InterfaceTypeMatch() int32 {
  96. if r.OnDemandRule.InterfaceTypeMatch == nil {
  97. return -1
  98. }
  99. return int32(*r.OnDemandRule.InterfaceTypeMatch)
  100. }
  101. func (r *onDemandRule) SSIDMatch() StringIterator {
  102. return newIterator(r.OnDemandRule.SSIDMatch)
  103. }
  104. func (r *onDemandRule) ProbeURL() string {
  105. return r.OnDemandRule.ProbeURL
  106. }