Documentation
¶
Index ¶
- Constants
- Variables
- func BroadcastAddr(inet4Address []netip.Prefix) netip.Addr
- func BuildICMPError(packet []byte, errorType ICMPError, source netip.Addr, mtu uint32, ...) ([]byte, bool)
- func CalculateInterfaceName(name string) (tunName string)
- func GSOSplit(in []byte, options GSOOptions, outBufs [][]byte, sizes []int, outOffset int) (int, error)
- func HasNextAddress(prefix netip.Prefix, count int) bool
- func IPTransportProtocol(packet []byte) (uint8, bool)
- func IsRecoverableReadError(err error) bool
- func PacketDestination(packet []byte) netip.Addr
- func PacketFillHeader(packet []byte, ipVersion int)
- func PacketIPVersion(packet []byte) int
- type AutoRedirect
- type AutoRedirectHandler
- type AutoRedirectOptions
- type DarwinTUN
- type DefaultInterfaceMonitor
- type DefaultInterfaceMonitorOptions
- type DefaultInterfaceUpdateCallback
- type FlowAction
- type FlowCloseReason
- type FlowHandle
- type FlowTracker
- type FlowVerdict
- type ForwardDispatcher
- type ForwardFrameMeta
- type ForwardStage
- type ForwardWriteback
- type GSOOptions
- type GSOType
- type Go
- func (s *Go) Close() error
- func (s *Go) DialTCP(ctx context.Context, source netip.Addr, destination netip.AddrPort) (*GoConn, error)
- func (s *Go) DialUDP(local netip.AddrPort, destination netip.AddrPort) (*GoUDPConn, error)
- func (s *Go) HasEndpoint(protocol uint8, local, remote netip.AddrPort) bool
- func (s *Go) ListenTCP(local netip.AddrPort) (*GoListener, error)
- func (s *Go) ListenUDP(local netip.AddrPort) (*GoUDPConn, error)
- func (s *Go) ResetNetwork()
- func (s *Go) Start() error
- type GoConn
- func (c *GoConn) Close() error
- func (c *GoConn) CloseRead() error
- func (c *GoConn) CloseWrite() error
- func (c *GoConn) FrontHeadroom() int
- func (c *GoConn) HandshakeFailure(err error) error
- func (c *GoConn) HandshakeSuccess() error
- func (c *GoConn) InitializeReadWaiter(options N.ReadWaitOptions) bool
- func (c *GoConn) LocalAddr() net.Addr
- func (c *GoConn) NeedHandshakeForRead() bool
- func (c *GoConn) NeedHandshakeForWrite() bool
- func (c *GoConn) Read(p []byte) (int, error)
- func (c *GoConn) RemoteAddr() net.Addr
- func (c *GoConn) SetDeadline(t time.Time) error
- func (c *GoConn) SetKeepAlive(keepalive bool) error
- func (c *GoConn) SetKeepAliveConfig(config net.KeepAliveConfig) error
- func (c *GoConn) SetKeepAlivePeriod(d time.Duration) error
- func (c *GoConn) SetLinger(sec int) error
- func (c *GoConn) SetNoDelay(noDelay bool) error
- func (c *GoConn) SetReadBuffer(size int) error
- func (c *GoConn) SetReadDeadline(t time.Time) error
- func (c *GoConn) SetWriteBuffer(size int) error
- func (c *GoConn) SetWriteDeadline(t time.Time) error
- func (c *GoConn) Splice(owner SpliceSocket, options SpliceOptions) bool
- func (c *GoConn) WaitReadBuffer() (*buf.Buffer, error)
- func (c *GoConn) Write(p []byte) (int, error)
- func (c *GoConn) WriteBuffer(buffer *buf.Buffer) error
- func (c *GoConn) WriterMTU() int
- type GoListener
- type GoPacketConn
- func (w *GoPacketConn) Close() error
- func (w *GoPacketConn) CloseFlow()
- func (w *GoPacketConn) CreatePacketBatchWriter() (N.PacketBatchWriter, bool)
- func (w *GoPacketConn) FrontHeadroom() int
- func (w *GoPacketConn) HandshakeFailure(err error) error
- func (w *GoPacketConn) HandshakeSuccess() error
- func (w *GoPacketConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error
- func (w *GoPacketConn) WritePacketBatch(buffers []*buf.Buffer, destinations []M.Socksaddr) error
- type GoUDPConn
- func (c *GoUDPConn) Close() error
- func (c *GoUDPConn) InitializeReadWaiter(options N.ReadWaitOptions) bool
- func (c *GoUDPConn) LocalAddr() net.Addr
- func (c *GoUDPConn) Read(p []byte) (int, error)
- func (c *GoUDPConn) ReadFrom(p []byte) (int, net.Addr, error)
- func (c *GoUDPConn) ReadFromUDPAddrPort(p []byte) (int, netip.AddrPort, error)
- func (c *GoUDPConn) ReadPacket(buffer *buf.Buffer) (M.Socksaddr, error)
- func (c *GoUDPConn) RemoteAddr() net.Addr
- func (c *GoUDPConn) SetDeadline(t time.Time) error
- func (c *GoUDPConn) SetReadBuffer(size int) error
- func (c *GoUDPConn) SetReadDeadline(t time.Time) error
- func (c *GoUDPConn) SetWriteBuffer(size int) error
- func (c *GoUDPConn) SetWriteDeadline(t time.Time) error
- func (c *GoUDPConn) WaitReadPacket() (*buf.Buffer, M.Socksaddr, error)
- func (c *GoUDPConn) Write(p []byte) (int, error)
- func (c *GoUDPConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error
- func (c *GoUDPConn) WriteTo(p []byte, addr net.Addr) (int, error)
- func (c *GoUDPConn) WriteToUDPAddrPort(p []byte, addr netip.AddrPort) (int, error)
- type Handler
- type ICMPError
- type LinuxTUN
- type MemoryPressure
- type MemoryTun
- func (t *MemoryTun) Close() error
- func (t *MemoryTun) MTU() int
- func (t *MemoryTun) Name() (string, error)
- func (t *MemoryTun) NewOutboundQueue(handler func(packets []*buf.Buffer)) *OutboundQueue
- func (t *MemoryTun) Read(p []byte) (int, error)
- func (t *MemoryTun) Start() error
- func (t *MemoryTun) UpdateMTU(mtu int)
- func (t *MemoryTun) UpdateRouteOptions(tunOptions Options) error
- func (t *MemoryTun) Write(p []byte) (int, error)
- func (t *MemoryTun) WritePackets(packets [][]byte) (int, error)
- type MemoryTunOptions
- type NATFiltering
- type NATMapping
- type NativeTun
- func (t *NativeTun) BatchRead(buffers [][]byte, offset int, readN []int) (int, error)
- func (t *NativeTun) BatchSize() int
- func (t *NativeTun) BatchWrite(buffers [][]byte, offset int) (int, error)
- func (t *NativeTun) Close() error
- func (t *NativeTun) FrontHeadroom() int
- func (t *NativeTun) Name() (string, error)
- func (t *NativeTun) Read(p []byte) (n int, err error)
- func (t *NativeTun) Start() error
- func (t *NativeTun) TXChecksumOffload() bool
- func (t *NativeTun) UpdateRouteOptions(tunOptions Options) error
- func (t *NativeTun) Write(p []byte) (n int, err error)
- type NetworkUpdateCallback
- type NetworkUpdateMonitor
- type Options
- func (o *Options) BuildAndroidRules(packageManager PackageManager)
- func (o *Options) BuildAutoRouteRanges(underNetworkExtension bool) ([]netip.Prefix, error)
- func (o *Options) DNSModeOrDefault() string
- func (o *Options) DNSServerAddress() ([]netip.Addr, error)
- func (o *Options) ExcludedRanges() (uidRanges []ranges.Range[uint32])
- func (o *Options) Inet4DNSAddress() ([]netip.Addr, error)
- func (o *Options) Inet4GatewayAddr() netip.Addr
- func (o *Options) Inet6DNSAddress() ([]netip.Addr, error)
- func (o *Options) Inet6GatewayAddr() netip.Addr
- type OutboundQueue
- type PackageManager
- type PackageManagerCallback
- type PackageManagerOptions
- type PacketNAT
- type Port
- type PortWithSelectorRange
- type ReadRetry
- type RedirectServer
- type Return
- type Session
- type SpliceOptions
- type SplicePacketOptions
- type SpliceSocket
- type Stack
- type StackOptions
- type System
- type TCPNat
- type TCPSession
- type Tun
- type UDPEgressConn
- func (c *UDPEgressConn) Close() error
- func (c *UDPEgressConn) LocalAddr() net.Addr
- func (c *UDPEgressConn) ReadFromUDPAddrPort(buffer []byte) (int, netip.AddrPort, error)
- func (c *UDPEgressConn) SetDeadline(t time.Time) error
- func (c *UDPEgressConn) SetReadDeadline(t time.Time) error
- func (c *UDPEgressConn) SetWriteDeadline(t time.Time) error
- func (c *UDPEgressConn) WriteToUDPAddrPort(buffer []byte, destination netip.AddrPort) (int, error)
- type UDPEgressPool
- type UDPEgressPoolOptions
- type UDPNat
- func (s *UDPNat) Close() error
- func (s *UDPNat) NewPacket(bufferSlices [][]byte, source M.Socksaddr, destination M.Socksaddr, ...)
- func (s *UDPNat) NewPacketBatch(buffers []*buf.Buffer, sources []M.Socksaddr, destination M.Socksaddr, ...)
- func (s *UDPNat) Purge()
- func (s *UDPNat) PurgeExpired()
- func (s *UDPNat) Start() error
- type UDPNatConn
- func (c *UDPNatConn) Close() error
- func (c *UDPNatConn) CreatePacketBatchReadWaiter() (N.PacketBatchReadWaiter, bool)
- func (c *UDPNatConn) CreatePacketBatchWriter() (N.PacketBatchWriter, bool)
- func (c *UDPNatConn) InitializeReadWaiter(options N.ReadWaitOptions) (needCopy bool)
- func (c *UDPNatConn) LocalAddr() net.Addr
- func (c *UDPNatConn) ReadPacket(buffer *buf.Buffer) (addr M.Socksaddr, err error)
- func (c *UDPNatConn) RemoteAddr() net.Addr
- func (c *UDPNatConn) SetDeadline(t time.Time) error
- func (c *UDPNatConn) SetReadDeadline(t time.Time) error
- func (c *UDPNatConn) SetTimeout(timeout time.Duration) bool
- func (c *UDPNatConn) SetWriteDeadline(t time.Time) error
- func (c *UDPNatConn) Splice(owner SpliceSocket, options SplicePacketOptions) bool
- func (c *UDPNatConn) Timeout() time.Duration
- func (c *UDPNatConn) Upstream() any
- func (c *UDPNatConn) WaitReadPacket() (buffer *buf.Buffer, destination M.Socksaddr, err error)
- func (c *UDPNatConn) WaitReadPackets() (buffers []*buf.Buffer, destinations []M.Socksaddr, err error)
- func (c *UDPNatConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error
- type UDPNatOptions
- type UDPNatPrepareFunc
- type WinTun
Constants ¶
const ( DefaultAutoRedirectInputMark = 0x2023 DefaultAutoRedirectOutputMark = 0x2024 DefaultAutoRedirectResetMark = 0x2025 DefaultAutoRedirectTProxyMark = 0x2026 DefaultAutoRedirectNFQueue = 100 DefaultAutoRedirectInputMarkAndroid = 0x400000 DefaultAutoRedirectOutputMarkAndroid = 0x200000 DefaultAutoRedirectResetMarkAndroid = 0x600000 DefaultAutoRedirectTProxyMarkAndroid = 0x800000 )
const ( DefaultIPRoute2TableIndex = 2022 DefaultIPRoute2RuleIndex = 9000 DefaultIPRoute2AutoRedirectFallbackRuleIndex = 32768 )
const ( DNSModeDisabled = "disabled" DNSModeNative = "native" DNSModeHijack = "hijack" )
const FlagAndroidVPNUpdate = 1 << iota
const PacketOffset = 0
const WithGVisor = false
Variables ¶
var ErrGVisorNotIncluded = E.New(`gVisor is not included in this build, rebuild with -tags with_gvisor`)
var ErrIncludeAllNetworks = E.New("`system` and `mixed` stack are not available when `includeAllNetworks` is enabled. See https://github.com/SagerNet/sing-tun/issues/25")
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",
)
var ErrNoRoute = E.New("no route to internet")
var ErrTooManySegments = errors.New("too many segments")
ErrTooManySegments is returned by Device.Read() when segmentation overflows the length of supplied buffers. This error should not cause reads to cease.
Functions ¶
func BuildICMPError ¶
func CalculateInterfaceName ¶
func GSOSplit ¶
func GSOSplit(in []byte, options GSOOptions, outBufs [][]byte, sizes []int, outOffset int) (int, error)
GSOSplit splits packets from 'in' into outBufs[<index>][outOffset:], writing the size of each element into sizes. It returns the number of buffers populated, and/or an error. Callers may pass an 'in' slice that overlaps with the first element of outBuffers, i.e. &in[0] may be equal to &outBufs[0][outOffset]. GSONone is a valid options.GSOType regardless of the value of options.NeedsCsum. Length of each outBufs element must be greater than or equal to the length of 'in', otherwise output may be silently truncated.
func IPTransportProtocol ¶
func IsRecoverableReadError ¶
func PacketDestination ¶
func PacketFillHeader ¶
func PacketIPVersion ¶
Types ¶
type AutoRedirect ¶
func NewAutoRedirect ¶
func NewAutoRedirect(options AutoRedirectOptions) (AutoRedirect, error)
type AutoRedirectHandler ¶
type AutoRedirectHandler interface {
JudgeFlow(network uint8, source netip.AddrPort, destination netip.AddrPort, firstPacket []byte) FlowVerdict
N.TCPConnectionHandlerEx
}
type AutoRedirectOptions ¶
type AutoRedirectOptions struct {
TunOptions *Options
Context context.Context
Handler AutoRedirectHandler
Logger logger.Logger
NetworkMonitor NetworkUpdateMonitor
InterfaceFinder control.InterfaceFinder
TableName string
DisableNFTables bool
CustomRedirectPort func() int
CustomRedirectListenerFD func() (int, error)
RouteAddressSet func() (include []netip.Prefix, exclude []netip.Prefix, err error)
AndroidVPNService bool
}
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])
RegisterMyInterface(interfaceName string)
MyInterfaces() []string
}
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 FlowAction ¶
type FlowAction uint8
const ( ActionAccept FlowAction = iota ActionFlow ActionReject ActionDrop ActionBypass ActionHijackDNS )
type FlowCloseReason ¶
type FlowCloseReason uint8
const ( FlowCloseReset FlowCloseReason = iota FlowCloseFinished FlowCloseTimeout )
func (FlowCloseReason) String ¶
func (r FlowCloseReason) String() string
type FlowHandle ¶
type FlowHandle interface {
CloseFlow()
}
type FlowTracker ¶
type FlowTracker interface {
AttachFlow(handle FlowHandle)
CountForward(n int)
CountReverse(n int)
FlowEstablished()
CloseFlow(reason FlowCloseReason)
}
type FlowVerdict ¶
type FlowVerdict struct {
Action FlowAction
Port Port
Destination netip.AddrPort
UDPTimeout time.Duration
NewTracker func() FlowTracker
}
type ForwardDispatcher ¶
type ForwardDispatcher struct {
// contains filtered or unexported fields
}
func NewForwardDispatcher ¶
func NewForwardDispatcher(handler Handler, writeback ForwardWriteback, logger logger.Logger, udpTimeout time.Duration, icmpTimeout time.Duration) *ForwardDispatcher
func (*ForwardDispatcher) Close ¶
func (d *ForwardDispatcher) Close()
func (*ForwardDispatcher) NewStage ¶
func (d *ForwardDispatcher) NewStage(writeback ForwardWriteback) *ForwardStage
func (*ForwardDispatcher) ResetNetwork ¶
func (d *ForwardDispatcher) ResetNetwork()
type ForwardFrameMeta ¶
type ForwardFrameMeta struct {
// contains filtered or unexported fields
}
type ForwardStage ¶
type ForwardStage struct {
// contains filtered or unexported fields
}
func (*ForwardStage) Dispatch ¶
func (s *ForwardStage) Dispatch(packet []byte) bool
func (*ForwardStage) DispatchParsed ¶
func (s *ForwardStage) DispatchParsed(packet []byte, meta ForwardFrameMeta, parsed *forwardPacket) bool
func (*ForwardStage) Flush ¶
func (s *ForwardStage) Flush()
type ForwardWriteback ¶
type GSOOptions ¶
type GSOOptions struct {
// GSOType represents the type of segmentation offload.
GSOType GSOType
// HdrLen is the sum of the layer 3 and 4 header lengths. This field may be
// zero when GSOType == GSONone.
HdrLen uint16
// CsumStart is the head byte index of the packet data to be checksummed,
// i.e. the start of the TCP or UDP header.
CsumStart uint16
// CsumOffset is the offset from CsumStart where the 2-byte checksum value
// should be placed.
CsumOffset uint16
// GSOSize is the size of each segment exclusive of HdrLen. The tail segment
// may be smaller than this value.
GSOSize uint16
// NeedsCsum may be set where GSOType == GSONone. When set, the checksum
// at CsumStart + CsumOffset must be a partial checksum, i.e. the
// pseudo-header sum.
NeedsCsum bool
}
GSOOptions is loosely modeled after struct virtio_net_hdr from the VIRTIO specification. It is a common representation of GSO metadata that can be applied to support packet GSO across tun.Device implementations.
type Go ¶
type Go struct {
// contains filtered or unexported fields
}
func NewGo ¶
func NewGo(options StackOptions) (*Go, error)
func (*Go) HasEndpoint ¶
func (*Go) ResetNetwork ¶
func (s *Go) ResetNetwork()
type GoConn ¶
type GoConn struct {
// contains filtered or unexported fields
}
func (*GoConn) CloseWrite ¶
func (*GoConn) FrontHeadroom ¶
func (*GoConn) HandshakeFailure ¶
func (*GoConn) HandshakeSuccess ¶
func (*GoConn) InitializeReadWaiter ¶
func (c *GoConn) InitializeReadWaiter(options N.ReadWaitOptions) bool
func (*GoConn) NeedHandshakeForRead ¶
func (*GoConn) NeedHandshakeForWrite ¶
func (*GoConn) RemoteAddr ¶
func (*GoConn) SetKeepAlive ¶
func (*GoConn) SetKeepAliveConfig ¶
func (c *GoConn) SetKeepAliveConfig(config net.KeepAliveConfig) error
func (*GoConn) SetNoDelay ¶
func (*GoConn) SetReadBuffer ¶
func (*GoConn) SetWriteBuffer ¶
func (*GoConn) Splice ¶
func (c *GoConn) Splice(owner SpliceSocket, options SpliceOptions) bool
type GoListener ¶
type GoListener struct {
// contains filtered or unexported fields
}
func (*GoListener) AcceptTCP ¶
func (l *GoListener) AcceptTCP() (*GoConn, error)
func (*GoListener) Addr ¶
func (l *GoListener) Addr() net.Addr
func (*GoListener) Close ¶
func (l *GoListener) Close() error
func (*GoListener) SetDeadline ¶
func (l *GoListener) SetDeadline(t time.Time) error
type GoPacketConn ¶
type GoPacketConn struct {
// contains filtered or unexported fields
}
func (*GoPacketConn) Close ¶
func (w *GoPacketConn) Close() error
func (*GoPacketConn) CloseFlow ¶
func (w *GoPacketConn) CloseFlow()
func (*GoPacketConn) CreatePacketBatchWriter ¶
func (w *GoPacketConn) CreatePacketBatchWriter() (N.PacketBatchWriter, bool)
func (*GoPacketConn) FrontHeadroom ¶
func (w *GoPacketConn) FrontHeadroom() int
func (*GoPacketConn) HandshakeFailure ¶
func (w *GoPacketConn) HandshakeFailure(err error) error
func (*GoPacketConn) HandshakeSuccess ¶
func (w *GoPacketConn) HandshakeSuccess() error
func (*GoPacketConn) WritePacket ¶
func (*GoPacketConn) WritePacketBatch ¶
type GoUDPConn ¶
type GoUDPConn struct {
// contains filtered or unexported fields
}
func (*GoUDPConn) InitializeReadWaiter ¶
func (c *GoUDPConn) InitializeReadWaiter(options N.ReadWaitOptions) bool
func (*GoUDPConn) ReadFromUDPAddrPort ¶
func (*GoUDPConn) ReadPacket ¶
func (*GoUDPConn) RemoteAddr ¶
func (*GoUDPConn) SetReadBuffer ¶
func (*GoUDPConn) SetWriteBuffer ¶
func (*GoUDPConn) WaitReadPacket ¶
func (*GoUDPConn) WritePacket ¶
type Handler ¶
type Handler interface {
JudgeFlow(network uint8, source netip.AddrPort, destination netip.AddrPort, firstPacket []byte) FlowVerdict
NewDNSPacket(payload []byte, source M.Socksaddr, destination M.Socksaddr, writer N.PacketWriter)
N.TCPConnectionHandlerEx
N.UDPConnectionHandlerEx
}
type MemoryPressure ¶
type MemoryPressure uint8
const ( MemoryPressureNone MemoryPressure = iota MemoryPressureWarning MemoryPressureCritical )
type MemoryTun ¶
type MemoryTun struct {
// contains filtered or unexported fields
}
func NewMemoryTun ¶
func NewMemoryTun(options MemoryTunOptions) *MemoryTun
func (*MemoryTun) NewOutboundQueue ¶
func (t *MemoryTun) NewOutboundQueue(handler func(packets []*buf.Buffer)) *OutboundQueue
func (*MemoryTun) UpdateRouteOptions ¶
type MemoryTunOptions ¶
type NATFiltering ¶
type NATFiltering uint8
const ( NATFilteringEndpointIndependent NATFiltering = iota NATFilteringAddressDependent NATFilteringAddressAndPortDependent )
type NATMapping ¶
type NATMapping uint8
const ( NATMappingEndpointIndependent NATMapping = iota NATMappingAddressDependent NATMappingAddressAndPortDependent )
type NativeTun ¶
type NativeTun struct {
// contains filtered or unexported fields
}
func (*NativeTun) BatchWrite ¶
func (*NativeTun) FrontHeadroom ¶
func (*NativeTun) TXChecksumOffload ¶
func (*NativeTun) UpdateRouteOptions ¶
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
NetNs string
Inet4Address []netip.Prefix
Inet6Address []netip.Prefix
MTU uint32
GSO bool
MultiQueue bool
AutoRoute bool
InterfaceScope bool
Inet4Gateway netip.Addr
Inet6Gateway netip.Addr
DNSMode string
DNSAddress []netip.Addr
IPRoute2TableIndex int
IPRoute2RuleIndex int
IPRoute2AutoRedirectFallbackRuleIndex int
AutoRedirectMarkMode bool
AutoRedirectInputMark uint32
AutoRedirectOutputMark uint32
AutoRedirectResetMark uint32
AutoRedirectTProxyMark uint32
AutoRedirectNFQueue uint16
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
BridgeInterface []string
IncludeUID []ranges.Range[uint32]
ExcludeUID []ranges.Range[uint32]
IncludeAndroidUser []int
IncludePackage []string
ExcludePackage []string
IncludeMACAddress []net.HardwareAddr
ExcludeMACAddress []net.HardwareAddr
InterfaceFinder control.InterfaceFinder
InterfaceMonitor DefaultInterfaceMonitor
FileDescriptor int
Logger logger.Logger
// For library usages.
EXP_DisableDNSHijack bool
EXP_ExternalConfiguration bool
// Safe at every MTU: the darwin pending packet limit is derived from the utun control socket
// receive buffer.
EXP_MultiPendingPackets bool
// Do not enable. In netif mode (every utun handed out by Network Extension) utun_pkt_input
// returns ENOSPC without freeing the mbuf once 512 packets are queued
// (net.utun.max_pending_input), leaking one mbuf per rejected write until reboot; sendmsg_x
// pushes the write rate past the netif drain rate (about 500k to 700k packets per second on an
// M4 Pro) and reproduces the device-wide network loss, writev stays below it by its own cost.
EXP_SendMsgX bool
// contains filtered or unexported fields
}
func (*Options) BuildAndroidRules ¶
func (o *Options) BuildAndroidRules(packageManager PackageManager)
func (*Options) BuildAutoRouteRanges ¶
func (*Options) DNSModeOrDefault ¶
func (*Options) ExcludedRanges ¶
func (*Options) Inet4GatewayAddr ¶
func (*Options) Inet6GatewayAddr ¶
type OutboundQueue ¶
type OutboundQueue struct {
// contains filtered or unexported fields
}
func (*OutboundQueue) Close ¶
func (q *OutboundQueue) Close() error
func (*OutboundQueue) WriteBuffers ¶
func (q *OutboundQueue) WriteBuffers(buffers []*buf.Buffer)
type PackageManager ¶
type PackageManager interface {
Start() error
Close() error
IDByPackage(packageName string) (uint32, bool)
PackageByID(id uint32) (string, bool)
PackagesByID(id uint32) ([]string, bool)
}
func NewPackageManager ¶
func NewPackageManager(options PackageManagerOptions) (PackageManager, error)
type PackageManagerCallback ¶
type PackageManagerOptions ¶
type PackageManagerOptions struct {
Callback PackageManagerCallback
// Logger is the logger to log errors
// optional
Logger logger.Logger
}
type PortWithSelectorRange ¶
type RedirectServer ¶
type RedirectServer struct {
// contains filtered or unexported fields
}
func NewRedirectServer ¶
func NewRedirectServer(ctx context.Context, handler N.TCPConnectionHandlerEx, logger logger.Logger, listenAddress netip.Addr) *RedirectServer
func (*RedirectServer) Close ¶
func (s *RedirectServer) Close() error
func (*RedirectServer) ListenerFileDescriptor ¶
func (s *RedirectServer) ListenerFileDescriptor() (int, error)
func (*RedirectServer) Port ¶
func (s *RedirectServer) Port() uint16
func (*RedirectServer) SetExternalTransparent ¶
func (s *RedirectServer) SetExternalTransparent()
func (*RedirectServer) Start ¶
func (s *RedirectServer) Start() error
type SpliceOptions ¶
type SplicePacketOptions ¶
type SplicePacketOptions struct {
SpliceOptions
Timeout time.Duration
NAT PacketNAT
Cached []*N.PacketBuffer
Offload N.PacketOffload
FrontHeadroom int
RearHeadroom int
}
type SpliceSocket ¶
type Stack ¶
func NewGVisor ¶
func NewGVisor( options StackOptions, ) (Stack, error)
func NewMixed ¶
func NewMixed( options StackOptions, ) (Stack, error)
func NewSystem ¶
func NewSystem(options StackOptions) (Stack, error)
type StackOptions ¶
type StackOptions struct {
Context context.Context
Tun Tun
TunOptions Options
UDPTimeout time.Duration
ICMPTimeout time.Duration
UDPMapping NATMapping
UDPFiltering NATFiltering
UDPNATMax uint32
Handler Handler
Logger logger.Logger
ForwarderBindInterface bool
IncludeAllNetworks bool
InterfaceFinder control.InterfaceFinder
MemoryPressure func() MemoryPressure
TCPCongestionControl string
}
type System ¶
type System struct {
// contains filtered or unexported fields
}
func (*System) ResetNetwork ¶
func (s *System) ResetNetwork()
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 UDPEgressConn ¶
type UDPEgressConn struct {
// contains filtered or unexported fields
}
func NewUDPEgressConn ¶
func NewUDPEgressConn(anchor *net.UDPConn, pool *UDPEgressPool) *UDPEgressConn
func (*UDPEgressConn) Close ¶
func (c *UDPEgressConn) Close() error
func (*UDPEgressConn) LocalAddr ¶
func (c *UDPEgressConn) LocalAddr() net.Addr
func (*UDPEgressConn) ReadFromUDPAddrPort ¶
func (*UDPEgressConn) SetDeadline ¶
func (c *UDPEgressConn) SetDeadline(t time.Time) error
func (*UDPEgressConn) SetReadDeadline ¶
func (c *UDPEgressConn) SetReadDeadline(t time.Time) error
func (*UDPEgressConn) SetWriteDeadline ¶
func (c *UDPEgressConn) SetWriteDeadline(t time.Time) error
func (*UDPEgressConn) WriteToUDPAddrPort ¶
type UDPEgressPool ¶
type UDPEgressPool struct {
// contains filtered or unexported fields
}
func NewUDPEgressPool ¶
func NewUDPEgressPool(options UDPEgressPoolOptions) *UDPEgressPool
func (*UDPEgressPool) Close ¶
func (p *UDPEgressPool) Close()
func (*UDPEgressPool) LookupEgress ¶
func (p *UDPEgressPool) LookupEgress(destination netip.AddrPort) *net.UDPConn
func (*UDPEgressPool) ReceiveEgress ¶
func (*UDPEgressPool) SetEgressPort ¶
func (p *UDPEgressPool) SetEgressPort(port uint16) bool
type UDPEgressPoolOptions ¶
type UDPEgressPoolOptions struct {
Logger logger.Logger
Network string
Control control.Func
InterfaceFinder control.InterfaceFinder
InterfaceMonitor DefaultInterfaceMonitor
IsExempt func() bool
}
type UDPNat ¶
type UDPNat struct {
// contains filtered or unexported fields
}
func NewUDPNat ¶
func NewUDPNat(options UDPNatOptions) *UDPNat
func (*UDPNat) NewPacketBatch ¶
func (*UDPNat) PurgeExpired ¶
func (s *UDPNat) PurgeExpired()
type UDPNatConn ¶
type UDPNatConn struct {
// contains filtered or unexported fields
}
func (*UDPNatConn) Close ¶
func (c *UDPNatConn) Close() error
func (*UDPNatConn) CreatePacketBatchReadWaiter ¶
func (c *UDPNatConn) CreatePacketBatchReadWaiter() (N.PacketBatchReadWaiter, bool)
func (*UDPNatConn) CreatePacketBatchWriter ¶
func (c *UDPNatConn) CreatePacketBatchWriter() (N.PacketBatchWriter, bool)
func (*UDPNatConn) InitializeReadWaiter ¶
func (c *UDPNatConn) InitializeReadWaiter(options N.ReadWaitOptions) (needCopy bool)
func (*UDPNatConn) LocalAddr ¶
func (c *UDPNatConn) LocalAddr() net.Addr
func (*UDPNatConn) ReadPacket ¶
func (*UDPNatConn) RemoteAddr ¶
func (c *UDPNatConn) RemoteAddr() net.Addr
func (*UDPNatConn) SetDeadline ¶
func (c *UDPNatConn) SetDeadline(t time.Time) error
func (*UDPNatConn) SetReadDeadline ¶
func (c *UDPNatConn) SetReadDeadline(t time.Time) error
func (*UDPNatConn) SetTimeout ¶
func (c *UDPNatConn) SetTimeout(timeout time.Duration) bool
func (*UDPNatConn) SetWriteDeadline ¶
func (c *UDPNatConn) SetWriteDeadline(t time.Time) error
func (*UDPNatConn) Splice ¶
func (c *UDPNatConn) Splice(owner SpliceSocket, options SplicePacketOptions) bool
func (*UDPNatConn) Timeout ¶
func (c *UDPNatConn) Timeout() time.Duration
func (*UDPNatConn) Upstream ¶
func (c *UDPNatConn) Upstream() any
func (*UDPNatConn) WaitReadPacket ¶
func (*UDPNatConn) WaitReadPackets ¶
func (*UDPNatConn) WritePacket ¶
type UDPNatOptions ¶
type UDPNatOptions struct {
Handler N.UDPConnectionHandlerEx
Prepare UDPNatPrepareFunc
Timeout time.Duration
Mapping NATMapping
Filtering NATFiltering
MaxSize uint32
InterfaceFinder control.InterfaceFinder
}
type UDPNatPrepareFunc ¶
Source Files
¶
- flow.go
- flow_dispatch.go
- flow_dns.go
- flow_mtu.go
- flow_nat.go
- flow_parse.go
- flow_reject.go
- flow_rewrite.go
- icmp_error.go
- monitor.go
- monitor_linux.go
- monitor_linux_default.go
- monitor_shared.go
- netns_linux.go
- nfqueue_linux.go
- packages.go
- packages_stub.go
- redirect.go
- redirect_iptables.go
- redirect_linux.go
- redirect_nftables.go
- redirect_nftables_docker.go
- redirect_nftables_exprs.go
- redirect_nftables_rules.go
- redirect_nftables_rules_openwrt.go
- redirect_route_linux.go
- redirect_route_vpnservice_stub.go
- redirect_server.go
- stack.go
- stack_go.go
- stack_go_conn.go
- stack_go_conn_options.go
- stack_go_dial.go
- stack_go_engine.go
- stack_go_io.go
- stack_go_io_linux.go
- stack_go_io_memory.go
- stack_go_listen.go
- stack_go_memory.go
- stack_go_memory_arena.go
- stack_go_memory_linux.go
- stack_go_profile_default.go
- stack_go_ring.go
- stack_go_socket_linux.go
- stack_go_socket_unix.go
- stack_go_splice.go
- stack_go_tcp_ack.go
- stack_go_tcp_bbr.go
- stack_go_tcp_cong.go
- stack_go_tcp_cubic.go
- stack_go_tcp_input.go
- stack_go_tcp_output.go
- stack_go_tcp_rate.go
- stack_go_udp.go
- stack_go_udp_socket.go
- stack_go_wheel.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_memory.go
- tun_memory_queue.go
- tun_nondarwin.go
- tun_offload.go
- tun_offload_errors.go
- tun_offload_linux.go
- tun_read_error.go
- tun_rules.go
- udp_egress.go
- udp_egress_conn.go
- udp_nat.go
- udp_nat_cleanup.go
Directories
¶
| Path | Synopsis |
|---|---|
|
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. |
|
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. |
|
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. |
|
internal
|
|