2022-10-25 04:55:00 +00:00
|
|
|
package libbox
|
|
|
|
|
2023-04-18 06:04:09 +00:00
|
|
|
import (
|
|
|
|
"github.com/sagernet/sing-box/option"
|
|
|
|
)
|
2023-02-28 11:02:27 +00:00
|
|
|
|
2022-10-25 04:55:00 +00:00
|
|
|
type PlatformInterface interface {
|
2023-04-21 09:04:55 +00:00
|
|
|
UsePlatformAutoDetectInterfaceControl() bool
|
2022-10-25 04:55:00 +00:00
|
|
|
AutoDetectInterfaceControl(fd int32) error
|
2023-02-26 11:16:28 +00:00
|
|
|
OpenTun(options TunOptions) (int32, error)
|
2022-10-25 04:55:00 +00: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)
|
2023-04-18 06:04:09 +00:00
|
|
|
UsePlatformDefaultInterfaceMonitor() bool
|
|
|
|
StartDefaultInterfaceMonitor(listener InterfaceUpdateListener) error
|
|
|
|
CloseDefaultInterfaceMonitor(listener InterfaceUpdateListener) error
|
|
|
|
UsePlatformInterfaceGetter() bool
|
|
|
|
GetInterfaces() (NetworkInterfaceIterator, error)
|
2023-06-07 13:01:29 +00:00
|
|
|
UnderNetworkExtension() bool
|
2024-05-07 12:34:24 +00:00
|
|
|
IncludeAllNetworks() bool
|
2023-11-24 12:58:07 +00:00
|
|
|
ReadWIFIState() *WIFIState
|
2023-08-24 13:52:38 +00:00
|
|
|
ClearDNSCache()
|
2024-10-18 01:58:03 +00:00
|
|
|
ReportDeprecated(feature DeprecatedNote)
|
2022-10-25 04:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type TunInterface interface {
|
|
|
|
FileDescriptor() int32
|
|
|
|
Close() error
|
|
|
|
}
|
2023-02-28 11:02:27 +00:00
|
|
|
|
2023-04-18 06:04:09 +00:00
|
|
|
type InterfaceUpdateListener interface {
|
|
|
|
UpdateDefaultInterface(interfaceName string, interfaceIndex int32)
|
|
|
|
}
|
|
|
|
|
|
|
|
type NetworkInterface struct {
|
|
|
|
Index int32
|
|
|
|
MTU int32
|
|
|
|
Name string
|
|
|
|
Addresses StringIterator
|
|
|
|
}
|
|
|
|
|
2023-11-24 12:58:07 +00:00
|
|
|
type WIFIState struct {
|
|
|
|
SSID string
|
|
|
|
BSSID string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewWIFIState(wifiSSID string, wifiBSSID string) *WIFIState {
|
|
|
|
return &WIFIState{wifiSSID, wifiBSSID}
|
|
|
|
}
|
|
|
|
|
2023-04-18 06:04:09 +00:00
|
|
|
type NetworkInterfaceIterator interface {
|
|
|
|
Next() *NetworkInterface
|
2023-02-28 11:02:27 +00:00
|
|
|
HasNext() bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type OnDemandRule interface {
|
|
|
|
Target() int32
|
|
|
|
DNSSearchDomainMatch() StringIterator
|
|
|
|
DNSServerAddressMatch() StringIterator
|
|
|
|
InterfaceTypeMatch() int32
|
|
|
|
SSIDMatch() StringIterator
|
|
|
|
ProbeURL() string
|
|
|
|
}
|
|
|
|
|
2023-04-18 06:04:09 +00:00
|
|
|
type OnDemandRuleIterator interface {
|
|
|
|
Next() OnDemandRule
|
|
|
|
HasNext() bool
|
|
|
|
}
|
|
|
|
|
2023-02-28 11:02:27 +00:00
|
|
|
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
|
|
|
|
}
|