Documentation
¶
Overview ¶
Package tunnel provides TUN tunnel integration for Android VpnService. It supports attaching to an existing TUN file descriptor provided by Android.
Index ¶
- Variables
- func IsAndroidTUNSupported() bool
- func ValidateFD(fd int) error
- type Tunnel
- func (t *Tunnel) Close() error
- func (t *Tunnel) GetMTU() int
- func (t *Tunnel) GetTUNFD() int
- func (t *Tunnel) GetTunnelInfo() map[string]interface{}
- func (t *Tunnel) GetUptime() time.Duration
- func (t *Tunnel) IsTunnelRunning() bool
- func (t *Tunnel) Restart() error
- func (t *Tunnel) StartTunnelFromFD(fd int, mtu int) error
- func (t *Tunnel) StartTunnelFromFDWithConfig(fd int, mtu int, cfg TunnelConfig) error
- func (t *Tunnel) StopTunnel() error
- type TunnelConfig
- type TunnelError
Constants ¶
This section is empty.
Variables ¶
var ( ErrTunnelAlreadyRunning = &TunnelError{Op: "start", Err: errors.New("tunnel already running")} ErrTunnelNotRunning = &TunnelError{Op: "stop", Err: errors.New("tunnel not running")} ErrInvalidFD = &TunnelError{Op: "attach", Err: errors.New("invalid TUN file descriptor")} ErrTun2socksNotFound = &TunnelError{Op: "startup", Err: errors.New("tun2socks binary not found")} ErrPlatformNotSupported = &TunnelError{Op: "init", Err: errors.New("TUN tunnel not supported on this platform")} )
Predefined errors
Functions ¶
func IsAndroidTUNSupported ¶
func IsAndroidTUNSupported() bool
IsAndroidTUNSupported returns true if Android TUN backend is supported
Types ¶
type Tunnel ¶
type Tunnel struct {
// contains filtered or unexported fields
}
Tunnel represents a TUN tunnel instance
func (*Tunnel) GetTunnelInfo ¶
GetTunnelInfo returns information about the running tunnel
func (*Tunnel) IsTunnelRunning ¶
IsTunnelRunning returns true if tunnel is currently running
func (*Tunnel) StartTunnelFromFD ¶
StartTunnelFromFD starts a TUN tunnel using an existing TUN file descriptor. This is the main entry point for Android VpnService integration.
Parameters:
- fd: TUN file descriptor from Android VpnService.protect()
- mtu: MTU for the TUN interface (use 0 for default 1500)
Returns error if tunnel fails to start. Does NOT kill the process on failure.
func (*Tunnel) StartTunnelFromFDWithConfig ¶
func (t *Tunnel) StartTunnelFromFDWithConfig(fd int, mtu int, cfg TunnelConfig) error
StartTunnelFromFDWithConfig starts tunnel with full configuration
func (*Tunnel) StopTunnel ¶
StopTunnel stops the TUN tunnel gracefully
type TunnelConfig ¶
type TunnelConfig struct {
// TUN file descriptor from Android VpnService
FD int
// MTU for the TUN interface (default: 1500)
MTU int
// Path to tun2socks binary (optional, uses embedded if empty)
Tun2socksPath string
// SOCKS5 server address (default: 127.0.0.1:1080)
Socks5Addr string
// DNS server address (default: 8.8.8.8:53)
DNS string
// Enable verbose logging
Verbose bool
}
TunnelConfig holds tunnel configuration
type TunnelError ¶
TunnelError represents tunnel-related errors
func (*TunnelError) Error ¶
func (e *TunnelError) Error() string
func (*TunnelError) Unwrap ¶
func (e *TunnelError) Unwrap() error