platform.go 1.6 KB

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