platform.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package libbox
  2. import "github.com/sagernet/sing-box/option"
  3. type PlatformInterface interface {
  4. AutoDetectInterfaceControl(fd int32) error
  5. OpenTun(options TunOptions) (int32, error)
  6. WriteLog(message string)
  7. UseProcFS() bool
  8. FindConnectionOwner(ipProtocol int32, sourceAddress string, sourcePort int32, destinationAddress string, destinationPort int32) (int32, error)
  9. PackageNameByUid(uid int32) (string, error)
  10. UIDByPackageName(packageName string) (int32, error)
  11. }
  12. type TunInterface interface {
  13. FileDescriptor() int32
  14. Close() error
  15. }
  16. type OnDemandRuleIterator interface {
  17. Next() OnDemandRule
  18. HasNext() bool
  19. }
  20. type OnDemandRule interface {
  21. Target() int32
  22. DNSSearchDomainMatch() StringIterator
  23. DNSServerAddressMatch() StringIterator
  24. InterfaceTypeMatch() int32
  25. SSIDMatch() StringIterator
  26. ProbeURL() string
  27. }
  28. type onDemandRule struct {
  29. option.OnDemandRule
  30. }
  31. func (r *onDemandRule) Target() int32 {
  32. if r.OnDemandRule.Action == nil {
  33. return -1
  34. }
  35. return int32(*r.OnDemandRule.Action)
  36. }
  37. func (r *onDemandRule) DNSSearchDomainMatch() StringIterator {
  38. return newIterator(r.OnDemandRule.DNSSearchDomainMatch)
  39. }
  40. func (r *onDemandRule) DNSServerAddressMatch() StringIterator {
  41. return newIterator(r.OnDemandRule.DNSServerAddressMatch)
  42. }
  43. func (r *onDemandRule) InterfaceTypeMatch() int32 {
  44. if r.OnDemandRule.InterfaceTypeMatch == nil {
  45. return -1
  46. }
  47. return int32(*r.OnDemandRule.InterfaceTypeMatch)
  48. }
  49. func (r *onDemandRule) SSIDMatch() StringIterator {
  50. return newIterator(r.OnDemandRule.SSIDMatch)
  51. }
  52. func (r *onDemandRule) ProbeURL() string {
  53. return r.OnDemandRule.ProbeURL
  54. }