Documentation ¶
Overview ¶
Package wg helps with the creation and usage of userland wireguard networks.
Index ¶
- Constants
- Variables
- type Bind
- type Device
- type Dialer
- type Net
- type Netstack
- func (d *Netstack) BatchSize() int
- func (d *Netstack) Close() error
- func (d *Netstack) Events() <-chan tun.Event
- func (d *Netstack) File() *os.File
- func (d *Netstack) MTU() (int, error)
- func (d *Netstack) Name() (string, error)
- func (d *Netstack) Net() *Net
- func (d *Netstack) Read(buf [][]byte, sizes []int, offset int) (n int, err error)
- func (d *Netstack) Write(buf [][]byte, offset int) (int, error)
- type Option
- type TCPIPError
- type Wireguard
Constants ¶
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 ¶
var DefaultBind = defaultBind
DefaultBind is the default wireguard UDP listener.
var (
ErrNoDeviceSpecified = errors.New("no device specified")
)
var SetStackOptions = func(s *stack.Stack, ep *channel.Endpoint, id *tcpip.NICID) error { // Wireguard-go does this var enableSACK tcpip.TCPSACKEnabled = true if err := s.SetTransportProtocolOption(tcp.ProtocolNumber, &enableSACK); err != nil { return &TCPIPError{Err: err} } *id = tcpip.NICID(s.UniqueID()) if err := s.CreateNICWithOptions(*id, ep, stack.NICOptions{Name: ""}); err != nil { return &TCPIPError{Err: err} } return nil }
Functions ¶
This section is empty.
Types ¶
type Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
Dialer handles dialing with a given local address
type Net ¶
type Net Netstack
Net handles the application level dialing/listening.
func (*Net) ListenPacket ¶
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 ¶
NewDefaultNetstack calls NewNetstack with the default values.
func NewNetstack ¶
NewNetstack creates a new wireguard network stack.
func (*Netstack) BatchSize ¶
BatchSize implements tun.Device.BatchSize and returns the configured BatchSize
func (*Netstack) Events ¶
Events implements tun.Device.Events
func (*Netstack) File ¶
File implements tun.Device.File and always returns nil
func (*Netstack) MTU ¶
MTU implements tun.Device.MTU and returns the configured MTU
func (*Netstack) Name ¶
Name implements tun.Device.Name and always returns "point-c"
type Option ¶
type Option func(*options) error
func OptionBind ¶
OptionBind sets the Bind in the [options] struct. If this is not specified DefaultBind will be used.
func OptionCloser ¶
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 ¶
OptionDevice specifies the Device in the [options] struct.
func OptionLogger ¶
OptionLogger adds a logger to the [options] struct.
func OptionNetDevice ¶
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.
type TCPIPError ¶
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 (*Wireguard) Close ¶
Close closes the wireguard server/client, rendering it unusable in the future.