wg

package module
v0.0.0-...-f611d03 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: MIT Imports: 24 Imported by: 1

Documentation

Overview

Package pointc helps with the creation and usage of userland wireguard networks.

Index

Constants

View Source
const (
	// WireguardHeaderSize is the size of a wireguard header. The MTU needed for the [Netstack] is <actual hardware MTU> - [WireguardHeaderSize].
	WireguardHeaderSize = 80
	// DefaultMTU is the default MTU as specified from wireguard-go
	DefaultMTU = device.DefaultMTU
	// DefaultBatchSize is the default number of packets read/written from the [tun.Device] in one operation.
	DefaultBatchSize = conn.IdealBatchSize
	// DefaultChannelSize is the size of the packet queue for the underlaying [channel.Endpoint]
	DefaultChannelSize = 8 * DefaultBatchSize
)

Variables

This section is empty.

Functions

func OptionBind

func OptionBind(b Bind) option

OptionBind sets the Bind in the options struct. If this is not specified DefaultBind will be used.

func OptionCloser

func OptionCloser(closer func() error) option

OptionCloser adds a closer function to the [options] struct. Closer functions are called to gracefully close resources when needed.

func OptionConfig

func OptionConfig(cfg wgapi.Configurable) option

OptionConfig specifies a wireguard config to load before the interface is brought up.

func OptionDevice

func OptionDevice(d Device) option

OptionDevice specifies the Device in the options struct.

func OptionErr

func OptionErr(e error) option

OptionErr causes New to fail with the given error

func OptionLogger

func OptionLogger(l *wglog.Logger) option

OptionLogger adds a logger to the options struct.

func OptionNetDevice

func OptionNetDevice(p **Net) option

OptionNetDevice initializes a userspace networking stack. Note: The pointer *p becomes valid and usable only if the New function successfully completes without returning an error. In case of errors, *p should not be considered reliable.

func OptionNop

func OptionNop() option

OptionNop is an option function that does nothing. Useful as a placeholder.

Types

type Bind

type Bind = conn.Bind

func DefaultBind

func DefaultBind() Bind

DefaultBind is the default wireguard UDP listener..

type Device

type Device = tun.Device

type Dialer

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

Dialer handles dialing with a given local address

func (*Dialer) DialTCP

func (d *Dialer) DialTCP(ctx context.Context, addr *net.TCPAddr) (net.Conn, error)

DialTCP initiates a TCP connection with a remote TCP listener.

func (*Dialer) DialUDP

func (d *Dialer) DialUDP(addr *net.UDPAddr) (net.PacketConn, error)

DialUDP dials a UDP network.

type Net

type Net Netstack

Net handles the application level dialing/listening.

func (*Net) Dialer

func (n *Net) Dialer(laddr net.IP, port uint16) *Dialer

Dialer creates a new dialer with a specified local address.

func (*Net) Listen

func (n *Net) Listen(addr *net.TCPAddr) (net.Listener, error)

Listen listens with the TCP protocol on the given address.

func (*Net) ListenPacket

func (n *Net) ListenPacket(addr *net.UDPAddr) (net.PacketConn, error)

ListenPacket listens with the UDP protocol on the given address

type Netstack

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

Netstack is a wireguard device that takes the raw packets communicated through wireguard and turns them into meaningful TCP/UDP connections.

func NewDefaultNetstack

func NewDefaultNetstack() (*Netstack, error)

NewDefaultNetstack calls NewNetstack with the default values.

func NewNetstack

func NewNetstack(mtu int, batchSize int, channelSize int) (*Netstack, error)

NewNetstack creates a new wireguard network stack.

func (*Netstack) BatchSize

func (d *Netstack) BatchSize() int

BatchSize implements tun.Device.BatchSize and returns the configured BatchSize

func (*Netstack) Close

func (d *Netstack) Close() error

Close closes the network stack rendering it unusable in the future.

func (*Netstack) Events

func (d *Netstack) Events() <-chan tun.Event

Events implements tun.Device.Events

func (*Netstack) File

func (d *Netstack) File() *os.File

File implements tun.Device.File and always returns nil

func (*Netstack) MTU

func (d *Netstack) MTU() (int, error)

MTU implements tun.Device.MTU and returns the configured MTU

func (*Netstack) Name

func (d *Netstack) Name() (string, error)

Name implements tun.Device.Name and always returns "point-c"

func (*Netstack) Net

func (d *Netstack) Net() *Net

Net allows using the device similar to the net package.

func (*Netstack) Read

func (d *Netstack) Read(buf [][]byte, sizes []int, offset int) (n int, err error)

Read will always read exactly one packet at a time.

func (*Netstack) Write

func (d *Netstack) Write(buf [][]byte, offset int) (int, error)

Write will write all packets given to it to the underlaying netstack.

type TCPIPError

type TCPIPError struct{ Err tcpip.Error }

TCPIPError turn a tcpip.Error into a normal error.

func (*TCPIPError) Error

func (err *TCPIPError) Error() string

type Wireguard

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

Wireguard handles configuring and closing a wireguard client/server.

func New

func New(opts ...option) (_ *Wireguard, err error)

New allows the creating of a new wireguard interface.

func (*Wireguard) Close

func (c *Wireguard) Close() (err error)

Close closes the wireguard server/client, rendering it unusable in the future.

func (*Wireguard) GetConfig

func (c *Wireguard) GetConfig() (wgapi.IPC, error)

GetConfig gets the raw config from an IPC get=1 operation.

func (*Wireguard) SetConfig

func (c *Wireguard) SetConfig(cfg wgapi.Configurable) error

SetConfig performs an IPC set=1 operation.

Directories

Path Synopsis
Package wgapi helps with communicating with the userspace wireguard module.
Package wgapi helps with communicating with the userspace wireguard module.
wgconfig
Package wgconfig has examples for simple client and server configuration.
Package wgconfig has examples for simple client and server configuration.
wgevents Module

Jump to

Keyboard shortcuts

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