tun

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2025 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMtu int = 1500
)

Variables

View Source
var File_tun_config_proto protoreflect.FileDescriptor

Functions

func DnsServers

func DnsServers(index int) ([]netip.Addr, error)

Types

type Config

type Config struct {

	// Defaults to "172.23.27.1/24". IP will be the ip address of the interface
	// Ending number determines OnLinkPrefixLength
	Ip4 string `protobuf:"bytes,1,opt,name=ip4,proto3" json:"ip4,omitempty"`
	// Defaults to "fd00::1/64". no zone.
	Ip6 string `protobuf:"bytes,2,opt,name=ip6,proto3" json:"ip6,omitempty"`
	// defaults to "vtun"
	Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
	// defaults to 8192
	Mtu uint32 `protobuf:"varint,4,opt,name=mtu,proto3" json:"mtu,omitempty"`
	// path to a dir containing four folders: amd64, x86, arm, arm64.
	// Each folder contains the wintun.dll for the corresponding platform.
	// Absolute or relative to cwd
	Path string `protobuf:"bytes,5,opt,name=path,proto3" json:"path,omitempty"`
	// If unset, dns nameserver address of the tun will be set to the next ip of
	// [ip4]. Same for dns6.
	Dns4 []string `protobuf:"bytes,6,rep,name=dns4,proto3" json:"dns4,omitempty"`
	Dns6 []string `protobuf:"bytes,7,rep,name=dns6,proto3" json:"dns6,omitempty"`
	// If set, the tun will only accept packets with the specified routes.
	StrictRoute bool `protobuf:"varint,8,opt,name=strict_route,json=strictRoute,proto3" json:"strict_route,omitempty"`
	// Only used when strict_route is set.
	Routes4 []string `protobuf:"bytes,9,rep,name=routes4,proto3" json:"routes4,omitempty"`
	Routes6 []string `protobuf:"bytes,10,rep,name=routes6,proto3" json:"routes6,omitempty"`
	// contains filtered or unexported fields
}

func (*Config) Descriptor deprecated

func (*Config) Descriptor() ([]byte, []int)

Deprecated: Use Config.ProtoReflect.Descriptor instead.

func (*Config) GetDns4

func (x *Config) GetDns4() []string

func (*Config) GetDns6

func (x *Config) GetDns6() []string

func (*Config) GetIp4

func (x *Config) GetIp4() string

func (*Config) GetIp6

func (x *Config) GetIp6() string

func (*Config) GetMtu

func (x *Config) GetMtu() uint32

func (*Config) GetName

func (x *Config) GetName() string

func (*Config) GetPath

func (x *Config) GetPath() string

func (*Config) GetRoutes4

func (x *Config) GetRoutes4() []string

func (*Config) GetRoutes6

func (x *Config) GetRoutes6() []string

func (*Config) GetStrictRoute

func (x *Config) GetStrictRoute() bool

func (*Config) ProtoMessage

func (*Config) ProtoMessage()

func (*Config) ProtoReflect

func (x *Config) ProtoReflect() protoreflect.Message

func (*Config) Reset

func (x *Config) Reset()

func (*Config) String

func (x *Config) String() string

type DefaultInterfaceChangeNotifier

type DefaultInterfaceChangeNotifier struct {
	// contains filtered or unexported fields
}

func (*DefaultInterfaceChangeNotifier) Notify

func (n *DefaultInterfaceChangeNotifier) Notify()

func (*DefaultInterfaceChangeNotifier) Register

func (*DefaultInterfaceChangeNotifier) Unregister

type DefaultInterfaceInfo

type DefaultInterfaceInfo struct {
	sync.RWMutex

	DefaultInterfaceChangeNotifier
	// contains filtered or unexported fields
}

implements i.DefaultInterfaceInfo Okay to not start.

func NewInterfaceMonitor

func NewInterfaceMonitor(tunName string) (*DefaultInterfaceInfo, error)

func (*DefaultInterfaceInfo) Close

func (t *DefaultInterfaceInfo) Close() error

func (*DefaultInterfaceInfo) DefaultDns4

func (t *DefaultInterfaceInfo) DefaultDns4() []netip.Addr

func (*DefaultInterfaceInfo) DefaultDns6

func (t *DefaultInterfaceInfo) DefaultDns6() []netip.Addr

func (*DefaultInterfaceInfo) DefaultInterface4

func (t *DefaultInterfaceInfo) DefaultInterface4() uint32

func (*DefaultInterfaceInfo) DefaultInterface6

func (t *DefaultInterfaceInfo) DefaultInterface6() uint32

func (*DefaultInterfaceInfo) DefaultInterfaceName4

func (t *DefaultInterfaceInfo) DefaultInterfaceName4() string

func (*DefaultInterfaceInfo) DefaultInterfaceName6

func (t *DefaultInterfaceInfo) DefaultInterfaceName6() string

func (*DefaultInterfaceInfo) HasGlobalIPv6

func (t *DefaultInterfaceInfo) HasGlobalIPv6() (bool, error)

func (*DefaultInterfaceInfo) Start

func (t *DefaultInterfaceInfo) Start() error

func (*DefaultInterfaceInfo) SupportIPv6

func (t *DefaultInterfaceInfo) SupportIPv6() int

type InterfaceInfo

type InterfaceInfo struct {
	Index int
	Name  string
}

func GetPrimaryPhysicalInterface

func GetPrimaryPhysicalInterface() (info *InterfaceInfo, err error)

type MonitorConfig

type MonitorConfig struct {
	// contains filtered or unexported fields
}

func (*MonitorConfig) Descriptor deprecated

func (*MonitorConfig) Descriptor() ([]byte, []int)

Deprecated: Use MonitorConfig.ProtoReflect.Descriptor instead.

func (*MonitorConfig) ProtoMessage

func (*MonitorConfig) ProtoMessage()

func (*MonitorConfig) ProtoReflect

func (x *MonitorConfig) ProtoReflect() protoreflect.Message

func (*MonitorConfig) Reset

func (x *MonitorConfig) Reset()

func (*MonitorConfig) String

func (x *MonitorConfig) String() string

type TunDevice

type TunDevice interface {
	common.Runnable
	Name() string
	ReadPacket() (*buf.Buffer, error)
	// WritePacket takes ownership of the buffer.
	// Buffer is released no matter success or not
	WritePacket(*buf.Buffer) error
}

func NewTun

func NewTun(name string) (TunDevice, error)

type TunDeviceWithInfo

type TunDeviceWithInfo interface {
	TunDevice
	IP4() netip.Addr
	IP6() netip.Addr
	DnsServers() []netip.Addr
}

func NewTun0

func NewTun0(config *TunOption) (TunDeviceWithInfo, error)

func NewTunDeviceWithInfo

func NewTunDeviceWithInfo(tunDevice TunDevice, ip4 netip.Addr,
	ip6 netip.Addr, dnsServers []netip.Addr) TunDeviceWithInfo

type TunOption

type TunOption struct {
	Ip4    netip.Prefix
	Ip6    netip.Prefix
	Name   string
	Mtu    uint32
	Dns4   []netip.Addr
	Dns6   []netip.Addr
	Route4 []netip.Prefix
	Route6 []netip.Prefix
	// path of "wintun", a dir containing dll for each architecture.
	// Absolute or relative to cwd. windows only
	Path   string
	Metric uint32
	FD     int
	// Offset is the offset of the packet in the tun device.
	Offset int32
}

Directories

Path Synopsis
internal
Package monitor provides facilities for monitoring network interface and route changes.
Package monitor provides facilities for monitoring network interface and route changes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL