2025-10-07 15:40:11 +08:00
|
|
|
package adapter
|
|
|
|
|
|
|
|
|
|
import (
|
2026-04-23 05:52:14 +08:00
|
|
|
"net/netip"
|
|
|
|
|
|
2025-10-07 15:40:11 +08:00
|
|
|
"github.com/sagernet/sing-box/option"
|
|
|
|
|
"github.com/sagernet/sing-tun"
|
|
|
|
|
"github.com/sagernet/sing/common/logger"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type PlatformInterface interface {
|
|
|
|
|
Initialize(networkManager NetworkManager) error
|
|
|
|
|
|
|
|
|
|
UsePlatformAutoDetectInterfaceControl() bool
|
|
|
|
|
AutoDetectInterfaceControl(fd int) error
|
|
|
|
|
|
|
|
|
|
UsePlatformInterface() bool
|
|
|
|
|
OpenInterface(options *tun.Options, platformOptions option.TunPlatformOptions) (tun.Tun, error)
|
2026-07-13 19:12:05 +08:00
|
|
|
ProcessPlatformOptions(options option.TunPlatformOptions) error
|
2025-10-07 15:40:11 +08:00
|
|
|
|
|
|
|
|
UsePlatformDefaultInterfaceMonitor() bool
|
|
|
|
|
CreateDefaultInterfaceMonitor(logger logger.Logger) tun.DefaultInterfaceMonitor
|
|
|
|
|
|
|
|
|
|
UsePlatformNetworkInterfaces() bool
|
|
|
|
|
NetworkInterfaces() ([]NetworkInterface, error)
|
|
|
|
|
|
|
|
|
|
UnderNetworkExtension() bool
|
|
|
|
|
NetworkExtensionIncludeAllNetworks() bool
|
|
|
|
|
|
|
|
|
|
ClearDNSCache()
|
|
|
|
|
RequestPermissionForWIFIState() error
|
|
|
|
|
ReadWIFIState() WIFIState
|
|
|
|
|
|
|
|
|
|
UsePlatformConnectionOwnerFinder() bool
|
|
|
|
|
FindConnectionOwner(request *FindConnectionOwnerRequest) (*ConnectionOwner, error)
|
|
|
|
|
|
2025-12-07 11:24:45 +08:00
|
|
|
UsePlatformWIFIMonitor() bool
|
|
|
|
|
|
2025-10-07 15:40:11 +08:00
|
|
|
UsePlatformNotification() bool
|
|
|
|
|
SendNotification(notification *Notification) error
|
2026-04-23 05:52:14 +08:00
|
|
|
|
|
|
|
|
MyInterfaceAddress() []netip.Addr
|
2026-03-05 00:15:37 +08:00
|
|
|
|
|
|
|
|
UsePlatformNeighborResolver() bool
|
|
|
|
|
StartNeighborMonitor(listener NeighborUpdateListener) error
|
|
|
|
|
CloseNeighborMonitor(listener NeighborUpdateListener) error
|
2026-05-28 18:42:58 +08:00
|
|
|
|
|
|
|
|
UsePlatformShell() bool
|
|
|
|
|
CheckPlatformShell() error
|
|
|
|
|
OpenShellSession(user *PlatformUser, command string, env []string, term string, rows int32, cols int32) (ShellSession, error)
|
|
|
|
|
LookupUser(username string) (*PlatformUser, error)
|
|
|
|
|
LookupSFTPServer() (string, error)
|
|
|
|
|
ReadSystemSSHHostKey() ([]byte, error)
|
2026-06-02 11:29:06 +08:00
|
|
|
TailscaleHostname() string
|
2026-07-08 00:10:00 +08:00
|
|
|
|
|
|
|
|
UsePlatformBridge() bool
|
|
|
|
|
CreateBridge(options BridgeOptions) (BridgeSession, error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type BridgeOptions struct {
|
|
|
|
|
BridgeName string
|
|
|
|
|
MTU uint32
|
|
|
|
|
Inet4Port netip.Addr
|
|
|
|
|
Inet6Port netip.Addr
|
|
|
|
|
Interface string
|
|
|
|
|
RuleIndex int
|
|
|
|
|
RouteTable int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type BridgeSession interface {
|
|
|
|
|
FileDescriptor() int
|
|
|
|
|
Name() string
|
|
|
|
|
Inet6Active() bool
|
|
|
|
|
SetEgress(interfaceName string) error
|
|
|
|
|
Close() error
|
2026-05-28 18:42:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PlatformUser struct {
|
|
|
|
|
Username string
|
|
|
|
|
Uid int
|
|
|
|
|
Gid int
|
|
|
|
|
HomeDir string
|
|
|
|
|
Shell string
|
|
|
|
|
Groups []int
|
2025-10-07 15:40:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type FindConnectionOwnerRequest struct {
|
|
|
|
|
IpProtocol int32
|
|
|
|
|
SourceAddress string
|
|
|
|
|
SourcePort int32
|
|
|
|
|
DestinationAddress string
|
|
|
|
|
DestinationPort int32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ConnectionOwner struct {
|
2026-03-23 18:33:03 +08:00
|
|
|
ProcessID uint32
|
|
|
|
|
UserId int32
|
|
|
|
|
UserName string
|
|
|
|
|
ProcessPath string
|
|
|
|
|
AndroidPackageNames []string
|
2025-10-07 15:40:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Notification struct {
|
|
|
|
|
Identifier string
|
|
|
|
|
TypeName string
|
|
|
|
|
TypeID int32
|
|
|
|
|
Title string
|
|
|
|
|
Subtitle string
|
|
|
|
|
Body string
|
|
|
|
|
OpenURL string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type SystemProxyStatus struct {
|
|
|
|
|
Available bool
|
|
|
|
|
Enabled bool
|
|
|
|
|
}
|