sing-box/experimental/libbox/platform.go

69 lines
1.6 KiB
Go
Raw Normal View History

2023-03-15 14:56:06 +08:00
//go:build linux || darwin
2022-10-25 12:55:00 +08:00
package libbox
2023-02-28 19:02:27 +08:00
import "github.com/sagernet/sing-box/option"
2022-10-25 12:55:00 +08:00
type PlatformInterface interface {
AutoDetectInterfaceControl(fd int32) error
2023-02-26 19:16:28 +08:00
OpenTun(options TunOptions) (int32, error)
2022-10-25 12:55:00 +08:00
WriteLog(message string)
UseProcFS() bool
FindConnectionOwner(ipProtocol int32, sourceAddress string, sourcePort int32, destinationAddress string, destinationPort int32) (int32, error)
PackageNameByUid(uid int32) (string, error)
UIDByPackageName(packageName string) (int32, error)
}
type TunInterface interface {
FileDescriptor() int32
Close() error
}
2023-02-28 19:02:27 +08:00
type OnDemandRuleIterator interface {
Next() OnDemandRule
HasNext() bool
}
type OnDemandRule interface {
Target() int32
DNSSearchDomainMatch() StringIterator
DNSServerAddressMatch() StringIterator
InterfaceTypeMatch() int32
SSIDMatch() StringIterator
ProbeURL() string
}
type onDemandRule struct {
option.OnDemandRule
}
func (r *onDemandRule) Target() int32 {
if r.OnDemandRule.Action == nil {
return -1
}
return int32(*r.OnDemandRule.Action)
}
func (r *onDemandRule) DNSSearchDomainMatch() StringIterator {
return newIterator(r.OnDemandRule.DNSSearchDomainMatch)
}
func (r *onDemandRule) DNSServerAddressMatch() StringIterator {
return newIterator(r.OnDemandRule.DNSServerAddressMatch)
}
func (r *onDemandRule) InterfaceTypeMatch() int32 {
if r.OnDemandRule.InterfaceTypeMatch == nil {
return -1
}
return int32(*r.OnDemandRule.InterfaceTypeMatch)
}
func (r *onDemandRule) SSIDMatch() StringIterator {
return newIterator(r.OnDemandRule.SSIDMatch)
}
func (r *onDemandRule) ProbeURL() string {
return r.OnDemandRule.ProbeURL
}