gtuntap

package
v0.0.0-...-bad6181 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iface

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

func New

func New(deviceType string, name string, mtu int, deviceIPNet net.IPNet) *Iface

New creates new TUN/TAP device. On macOS, Name is not customizable.

func (*Iface) Close

func (i *Iface) Close() error

func (*Iface) DeleteNetRoute

func (i *Iface) DeleteNetRoute(destNet net.IPNet) error

func (*Iface) DestIP

func (i *Iface) DestIP() net.IP

func (*Iface) DeviceIPNet

func (i *Iface) DeviceIPNet() net.IPNet

func (*Iface) Name

func (i *Iface) Name() string

Name returns device name. On macOS, it is generated by system, but not from `name` param of `New(...)` function.

func (*Iface) Read

func (i *Iface) Read(pkt []byte) (int, error)

func (*Iface) ServeByConn

func (i *Iface) ServeByConn(conn io.ReadWriteCloser) error

ServeByConn starts VPN after accept `.vpn` stream.

func (*Iface) ServeByDeviceData

func (i *Iface) ServeByDeviceData(openRWC OpenRWC) (bool, error)

ServeByDeviceData starts VPN after device accepted IP packet. 只有从虚拟网卡中读到数据,才去建立`.vpn` stream,并进行交换

func (*Iface) SudoAddNetRoute

func (i *Iface) SudoAddNetRoute(destNet net.IPNet) error

SudoAddNetRoute add `net` type route, all traffic sent to destNet will be forward to current TUN/TAP device.

func (*Iface) SudoSetup

func (i *Iface) SudoSetup() error

SudoSetup starts a TUN/TAP device.

Notice: 1、如果程序退出,即使是强行结束进程,TUN设备、ifconfig所自动创建的临时路由、通过route命令创建的TUN设备相关的临时路由,都会被系统自动清除。macOS下亲测如此

func (*Iface) Write

func (i *Iface) Write(pkt []byte) (int, error)

type OpenRWC

type OpenRWC = func() (io.ReadWriteCloser, error)

type PacketIP

type PacketIP []byte

func NewPacketIP

func NewPacketIP(size int) PacketIP

func (PacketIP) GetDestinationIP

func (p PacketIP) GetDestinationIP() net.IP

func (PacketIP) GetSourceIP

func (p PacketIP) GetSourceIP() net.IP

Jump to

Keyboard shortcuts

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