Documentation
¶
Index ¶
- Constants
- Variables
- func BroadcastAddr(inet4Address []netip.Prefix) netip.Addr
- func CalculateInterfaceName(name string) (tunName string)
- func HasNextAddress(prefix netip.Prefix, count int) bool
- func PacketDestination(packet []byte) netip.Addr
- func PacketFillHeader(packet []byte, ipVersion int)
- func PacketIPVersion(packet []byte) int
- type AutoRedirect
- type AutoRedirectOptions
- type DarwinTUN
- type DefaultInterfaceMonitor
- type DefaultInterfaceMonitorOptions
- type DefaultInterfaceUpdateCallback
- type DirectRouteContext
- type DirectRouteDestination
- type DirectRouteMapping
- type DirectRouteSession
- type Handler
- type LinuxTUN
- type NativeTun
- func (t *NativeTun) BatchRead(buffers [][]byte, offset int, readN []int) (n int, err error)
- func (t *NativeTun) BatchSize() int
- func (t *NativeTun) BatchWrite(buffers [][]byte, offset int) error
- func (t *NativeTun) Close() error
- func (t *NativeTun) FrontHeadroom() int
- func (t *NativeTun) Read(p []byte) (n int, err error)
- func (t *NativeTun) TXChecksumOffload() bool
- func (t *NativeTun) Write(p []byte) (n int, err error)
- type NetworkUpdateCallback
- type NetworkUpdateMonitor
- type Options
- func (o *Options) BuildAndroidRules(packageManager PackageManager, errorHandler E.Handler)
- func (o *Options) BuildAutoRouteRanges(underNetworkExtension bool) ([]netip.Prefix, error)
- func (o *Options) ExcludedRanges() (uidRanges []ranges.Range[uint32])
- func (o *Options) Inet4GatewayAddr() netip.Addr
- func (o *Options) Inet6GatewayAddr() netip.Addr
- type PackageManager
- type PackageManagerCallback
- type PackageManagerOptions
- type PacketHandler
- type Session
- type Stack
- type StackOptions
- type System
- type TCPNat
- type TCPSession
- type Tun
- type WinTun
Constants ¶
View Source
const ( DefaultAutoRedirectInputMark = 0x2023 DefaultAutoRedirectOutputMark = 0x2024 )
View Source
const ( DefaultIPRoute2TableIndex = 2022 DefaultIPRoute2RuleIndex = 9000 )
View Source
const FlagAndroidVPNUpdate = 1 << iota
View Source
const PacketOffset = 0
View Source
const ProtocolRedirect = "redirect"
View Source
const WithGVisor = false
Variables ¶
View Source
var ( ErrDrop = E.New("drop by rule") ErrReset = E.New("reset by rule") )
View Source
var ErrGVisorNotIncluded = E.New(`gVisor is not included in this build, rebuild with -tags with_gvisor`)
View Source
var ErrIncludeAllNetworks = E.New("`system` and `mixed` stack are not available when `includeAllNetworks` is enabled. See https://github.com/SagerNet/sing-tun/issues/25")
View Source
var ErrNetlinkBanned = E.New(
"netlink socket in Android is banned by Google, " +
"use the root or system (ADB) user to run sing-box, " +
"or switch to the sing-box Android graphical interface client",
)
View Source
var ErrNoRoute = E.New("no route to internet")
View Source
var ErrTooManySegments = E.New("too many segments")
Functions ¶
func CalculateInterfaceName ¶
func PacketDestination ¶ added in v0.4.6
func PacketFillHeader ¶ added in v0.4.6
func PacketIPVersion ¶ added in v0.4.6
Types ¶
type AutoRedirect ¶ added in v0.4.1
func NewAutoRedirect ¶ added in v0.4.1
func NewAutoRedirect(options AutoRedirectOptions) (AutoRedirect, error)
type AutoRedirectOptions ¶ added in v0.4.1
type AutoRedirectOptions struct {
TunOptions *Options
Context context.Context
Handler Handler
Logger logger.Logger
NetworkMonitor NetworkUpdateMonitor
InterfaceFinder control.InterfaceFinder
TableName string
DisableNFTables bool
CustomRedirectPort func() int
RouteAddressSet *[]*netipx.IPSet
RouteExcludeAddressSet *[]*netipx.IPSet
}
type DefaultInterfaceMonitor ¶
type DefaultInterfaceMonitor interface {
Start() error
Close() error
DefaultInterface() *control.Interface
OverrideAndroidVPN() bool
AndroidVPNEnabled() bool
RegisterCallback(callback DefaultInterfaceUpdateCallback) *list.Element[DefaultInterfaceUpdateCallback]
UnregisterCallback(element *list.Element[DefaultInterfaceUpdateCallback])
}
func NewDefaultInterfaceMonitor ¶
func NewDefaultInterfaceMonitor(networkMonitor NetworkUpdateMonitor, logger logger.Logger, options DefaultInterfaceMonitorOptions) (DefaultInterfaceMonitor, error)
type DefaultInterfaceMonitorOptions ¶
type DefaultInterfaceMonitorOptions struct {
InterfaceFinder control.InterfaceFinder
OverrideAndroidVPN bool
UnderNetworkExtension bool
}
type DirectRouteContext ¶ added in v0.4.8
type DirectRouteDestination ¶ added in v0.4.8
type DirectRouteMapping ¶ added in v0.4.8
type DirectRouteMapping struct {
// contains filtered or unexported fields
}
func NewDirectRouteMapping ¶ added in v0.4.8
func NewDirectRouteMapping(timeout time.Duration) *DirectRouteMapping
func (*DirectRouteMapping) Lookup ¶ added in v0.4.8
func (m *DirectRouteMapping) Lookup(session DirectRouteSession, constructor func(timeout time.Duration) (DirectRouteDestination, error)) (DirectRouteDestination, error)
type DirectRouteSession ¶ added in v0.4.8
type Handler ¶
type Handler interface {
PrepareConnection(
network string,
source M.Socksaddr,
destination M.Socksaddr,
routeContext DirectRouteContext,
timeout time.Duration,
) (DirectRouteDestination, error)
N.TCPConnectionHandler
PacketHandler
E.Handler
}
type NativeTun ¶
type NativeTun struct {
// contains filtered or unexported fields
}
func (*NativeTun) BatchWrite ¶ added in v0.2.0
func (*NativeTun) FrontHeadroom ¶ added in v0.2.0
func (*NativeTun) TXChecksumOffload ¶ added in v0.2.0
type NetworkUpdateCallback ¶
type NetworkUpdateCallback = func()
type NetworkUpdateMonitor ¶
type NetworkUpdateMonitor interface {
Start() error
Close() error
RegisterCallback(callback NetworkUpdateCallback) *list.Element[NetworkUpdateCallback]
UnregisterCallback(element *list.Element[NetworkUpdateCallback])
}
func NewNetworkUpdateMonitor ¶
func NewNetworkUpdateMonitor(logger logger.Logger) (NetworkUpdateMonitor, error)
type Options ¶
type Options struct {
Name string
Inet4Address []netip.Prefix
Inet6Address []netip.Prefix
MTU uint32
GSO bool
AutoRoute bool
Inet4Gateway netip.Addr
Inet6Gateway netip.Addr
DNSServers []netip.Addr
IPRoute2TableIndex int
IPRoute2RuleIndex int
AutoRedirectMarkMode bool
AutoRedirectInputMark uint32
AutoRedirectOutputMark uint32
ExcludeMPTCP bool
Inet4LoopbackAddress []netip.Addr
Inet6LoopbackAddress []netip.Addr
StrictRoute bool
Inet4RouteAddress []netip.Prefix
Inet6RouteAddress []netip.Prefix
Inet4RouteExcludeAddress []netip.Prefix
Inet6RouteExcludeAddress []netip.Prefix
IncludeInterface []string
ExcludeInterface []string
IncludeUID []ranges.Range[uint32]
ExcludeUID []ranges.Range[uint32]
ExcludeSrcPort []ranges.Range[uint16]
ExcludeDstPort []ranges.Range[uint16]
IncludeAndroidUser []int
IncludePackage []string
ExcludePackage []string
InterfaceMonitor DefaultInterfaceMonitor
FileDescriptor int
Logger logger.Logger
// For library usages.
EXP_DisableDNSHijack bool
// For darwin tun
EXP_RecvMsgX bool
EXP_SendMsgX bool
// contains filtered or unexported fields
}
func (*Options) BuildAndroidRules ¶
func (o *Options) BuildAndroidRules(packageManager PackageManager, errorHandler E.Handler)
func (*Options) BuildAutoRouteRanges ¶ added in v0.2.0
func (*Options) ExcludedRanges ¶
func (*Options) Inet4GatewayAddr ¶ added in v0.4.1
func (*Options) Inet6GatewayAddr ¶ added in v0.4.1
type PackageManager ¶
type PackageManager interface {
Start() error
Close() error
IDByPackage(packageName string) (uint32, bool)
PackageByID(id uint32) (string, bool)
}
func NewPackageManager ¶
func NewPackageManager(options PackageManagerOptions) (PackageManager, error)
type PackageManagerCallback ¶
type PackageManagerOptions ¶ added in v0.4.1
type PackageManagerOptions struct {
Callback PackageManagerCallback
// Logger is the logger to log errors
// optional
Logger logger.Logger
}
type PacketHandler ¶ added in v0.4.6
type Stack ¶
func NewGVisor ¶
func NewGVisor( options StackOptions, ) (Stack, error)
func NewMixed ¶ added in v0.1.11
func NewMixed( options StackOptions, ) (Stack, error)
func NewSystem ¶
func NewSystem(options StackOptions) (Stack, error)
type StackOptions ¶
type TCPNat ¶
type TCPNat struct {
// contains filtered or unexported fields
}
func (*TCPNat) LookupBack ¶
func (n *TCPNat) LookupBack(port uint16) *TCPSession
type TCPSession ¶
type Tun ¶
type Tun interface {
io.ReadWriter
Close() error
}
Source Files
¶
- monitor.go
- monitor_linux.go
- monitor_linux_default.go
- monitor_shared.go
- packages.go
- packages_stub.go
- redirect.go
- redirect_iptables.go
- redirect_linux.go
- redirect_nftables.go
- redirect_nftables_exprs.go
- redirect_nftables_rules.go
- redirect_nftables_rules_openwrt.go
- redirect_server.go
- route_direct.go
- stack.go
- stack_gvisor_stub.go
- stack_system.go
- stack_system_nat.go
- stack_system_nonwindows.go
- stack_system_packet.go
- tun.go
- tun_linux.go
- tun_linux_flags.go
- tun_linux_offload.go
- tun_linux_offload_errors.go
- tun_nondarwin.go
- tun_rules.go
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
fdbased_darwin
Package fdbased provides the implementation of data-link layer endpoints backed by boundary-preserving file descriptors (e.g., TUN devices, seqpacket/datagram sockets).
|
Package fdbased provides the implementation of data-link layer endpoints backed by boundary-preserving file descriptors (e.g., TUN devices, seqpacket/datagram sockets). |
|
gtcpip/checksum
Package checksum provides the implementation of the encoding and decoding of network protocol headers.
|
Package checksum provides the implementation of the encoding and decoding of network protocol headers. |
|
gtcpip/header
Package header provides the implementation of the encoding and decoding of network protocol headers.
|
Package header provides the implementation of the encoding and decoding of network protocol headers. |
|
gtcpip/seqnum
Package seqnum defines the types and methods for TCP sequence numbers such that they fit in 32-bit words and work properly when overflows occur.
|
Package seqnum defines the types and methods for TCP sequence numbers such that they fit in 32-bit words and work properly when overflows occur. |
Click to show internal directories.
Click to hide internal directories.