Files
sing-box-extended-mirror/experimental/libbox/platform.go
T

152 lines
3.8 KiB
Go
Raw Normal View History

2022-10-25 12:55:00 +08:00
package libbox
2026-05-13 22:37:05 +08:00
import C "github.com/sagernet/sing-box/constant"
2023-02-28 19:02:27 +08:00
2022-10-25 12:55:00 +08:00
type PlatformInterface interface {
2025-03-16 14:50:44 +08:00
LocalDNSTransport() LocalDNSTransport
UsePlatformAutoDetectInterfaceControl() bool
2022-10-25 12:55:00 +08:00
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
UseProcFS() bool
2026-01-04 02:53:33 +08:00
FindConnectionOwner(ipProtocol int32, sourceAddress string, sourcePort int32, destinationAddress string, destinationPort int32) (*ConnectionOwner, error)
2023-04-18 14:04:09 +08:00
StartDefaultInterfaceMonitor(listener InterfaceUpdateListener) error
CloseDefaultInterfaceMonitor(listener InterfaceUpdateListener) error
GetInterfaces() (NetworkInterfaceIterator, error)
2023-06-07 21:01:29 +08:00
UnderNetworkExtension() bool
2024-05-07 20:34:24 +08:00
IncludeAllNetworks() bool
ReadWIFIState() *WIFIState
ClearDNSCache()
2024-11-06 12:51:53 +08:00
SendNotification(notification *Notification) error
2026-08-14 20:45:41 +08:00
CancelNotification(identifier string, typeID int32) error
StartNeighborMonitor(listener NeighborUpdateListener) error
CloseNeighborMonitor(listener NeighborUpdateListener) error
RegisterMyInterface(name string)
2026-05-28 18:42:58 +08:00
UsePlatformShell() bool
CheckPlatformShell() error
OpenShellSession(user *PlatformUser, command string, environ StringIterator, term string, rows int32, cols int32) (ShellSession, error)
LookupUser(username string) (*PlatformUser, error)
LookupSFTPServer() (string, error)
ReadSystemSSHHostKey() (string, error)
TailscaleHostname() string
2026-07-08 00:10:00 +08:00
UsePlatformBridge() bool
CreateBridge(options *BridgeOptions) (BridgeSession, error)
}
type BridgeOptions struct {
BridgeName string
MTU int32
Inet4Port string
Inet6Port string
Interface string
RuleIndex int32
RouteTable int32
}
type BridgeSession interface {
FileDescriptor() int32
Name() string
Inet6Active() bool
SetEgress(interfaceName string) error
Close() error
2026-05-28 18:42:58 +08:00
}
type PlatformUser struct {
Username string
Uid int32
Gid int32
HomeDir string
Shell string
groups []int32
}
func (u *PlatformUser) SetGroups(groups Int32Iterator) {
u.groups = iteratorToArray[int32](groups)
}
func (u *PlatformUser) Groups() Int32Iterator {
return newIterator(u.groups)
}
type NeighborUpdateListener interface {
UpdateNeighborTable(entries NeighborEntryIterator)
2022-10-25 12:55:00 +08:00
}
2026-01-04 02:53:33 +08:00
type ConnectionOwner struct {
2026-03-23 18:33:03 +08:00
UserId int32
UserName string
ProcessPath string
androidPackageNames []string
}
func (c *ConnectionOwner) SetAndroidPackageNames(names StringIterator) {
c.androidPackageNames = iteratorToArray[string](names)
}
func (c *ConnectionOwner) AndroidPackageNames() StringIterator {
return newIterator(c.androidPackageNames)
2026-01-04 02:53:33 +08:00
}
2023-04-18 14:04:09 +08:00
type InterfaceUpdateListener interface {
2024-11-11 16:23:45 +08:00
UpdateDefaultInterface(interfaceName string, interfaceIndex int32, isExpensive bool, isConstrained bool)
UpdateNetworkPath(networkPath string)
2023-04-18 14:04:09 +08:00
}
2024-11-11 16:23:45 +08:00
const (
2024-11-13 19:05:28 +08:00
InterfaceTypeWIFI = int32(C.InterfaceTypeWIFI)
InterfaceTypeCellular = int32(C.InterfaceTypeCellular)
InterfaceTypeEthernet = int32(C.InterfaceTypeEthernet)
InterfaceTypeOther = int32(C.InterfaceTypeOther)
2024-11-11 16:23:45 +08:00
)
2023-04-18 14:04:09 +08:00
type NetworkInterface struct {
Index int32
MTU int32
Name string
Addresses StringIterator
2024-10-29 15:28:58 +08:00
Flags int32
2024-11-11 16:23:45 +08:00
2024-11-13 19:05:28 +08:00
Type int32
2024-11-11 16:23:45 +08:00
DNSServer StringIterator
2026-08-13 12:54:50 +08:00
Gateway StringIterator
2024-11-11 16:23:45 +08:00
Metered bool
2023-04-18 14:04:09 +08:00
}
type WIFIState struct {
SSID string
BSSID string
}
func NewWIFIState(wifiSSID string, wifiBSSID string) *WIFIState {
return &WIFIState{wifiSSID, wifiBSSID}
}
2023-04-18 14:04:09 +08:00
type NetworkInterfaceIterator interface {
Next() *NetworkInterface
2023-02-28 19:02:27 +08:00
HasNext() bool
}
2024-11-06 12:51:53 +08:00
type Notification struct {
Identifier string
TypeName string
TypeID int32
Title string
Subtitle string
Body string
OpenURL string
}
2023-02-28 19:02:27 +08:00
type OnDemandRule interface {
Target() int32
DNSSearchDomainMatch() StringIterator
DNSServerAddressMatch() StringIterator
InterfaceTypeMatch() int32
SSIDMatch() StringIterator
ProbeURL() string
}
2023-04-18 14:04:09 +08:00
type OnDemandRuleIterator interface {
Next() OnDemandRule
HasNext() bool
}