packet

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package packet contains types and methods that transform WireGuard packets.

Index

Constants

View Source
const (
	WireGuardMessageTypeHandshakeInitiation  = 1
	WireGuardMessageTypeHandshakeResponse    = 2
	WireGuardMessageTypeHandshakeCookieReply = 3
	WireGuardMessageTypeData                 = 4

	WireGuardMessageLengthHandshakeInitiation  = 148
	WireGuardMessageLengthHandshakeResponse    = 92
	WireGuardMessageLengthHandshakeCookieReply = 64
)

Variables

View Source
var (
	ErrPacketSize    = errors.New("packet is too big or too small to be processed")
	ErrPayloadLength = errors.New("payload length field value is out of range")
)

Functions

This section is empty.

Types

type Handler

type Handler interface {
	// Headroom returns the amount of extra space required in read/write buffers besides the payload.
	Headroom() Headroom

	// EncryptZeroCopy encrypts a WireGuard packet and returns a swgp packet without copying or incurring any allocations.
	//
	// The WireGuard packet starts at buf[wgPacketStart] and its length is specified by wgPacketLength.
	// The returned swgp packet starts at buf[swgpPacketStart] and its length is specified by swgpPacketLength.
	//
	// buf must have at least FrontOverhead() bytes before and RearOverhead() bytes after the WireGuard packet.
	// In other words, start must not be less than FrontOverhead(), len(buf) must not be less than start + length + RearOverhead().
	EncryptZeroCopy(buf []byte, wgPacketStart, wgPacketLength int) (swgpPacketStart, swgpPacketLength int, err error)

	// DecryptZeroCopy decrypts a swgp packet and returns a WireGuard packet without copying or incurring any allocations.
	//
	// The swgp packet starts at buf[swgpPacketStart] and its length is specified by swgpPacketLength.
	// The returned WireGuard packet starts at buf[wgPacketStart] and its length is specified by wgPacketLength.
	DecryptZeroCopy(buf []byte, swgpPacketStart, swgpPacketLength int) (wgPacketStart, wgPacketLength int, err error)
}

Handler encrypts WireGuard packets and decrypts swgp packets.

func NewParanoidHandler

func NewParanoidHandler(psk []byte) (Handler, error)

NewParanoidHandler creates a "paranoid" handler that uses the given PSK to encrypt and decrypt packets.

func NewZeroOverheadHandler

func NewZeroOverheadHandler(psk []byte) (Handler, error)

NewZeroOverheadHandler creates a zero-overhead handler that uses the given PSK to encrypt and decrypt packets.

type HandlerErr added in v1.2.0

type HandlerErr struct {
	Err     error
	Message string
}

func (*HandlerErr) Error added in v1.2.0

func (e *HandlerErr) Error() string

func (*HandlerErr) Unwrap added in v1.2.0

func (e *HandlerErr) Unwrap() error

type Headroom added in v1.5.0

type Headroom struct {
	// Front is the minimum space required at the beginning of the buffer before payload.
	Front int

	// Rear is the minimum space required at the end of the buffer after payload.
	Rear int
}

Headroom reports the amount of extra space required in read/write buffers besides the payload.

Jump to

Keyboard shortcuts

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