wireguard

package module
v0.0.0-...-7da6457 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2016 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CounterBitsTotal     = 2048
	BitsPerInt           = strconv.IntSize
	CounterRedundantBits = BitsPerInt
	CounterWindowSize    = CounterBitsTotal - BitsPerInt
)
View Source
const (
	RekeyAfterMessages   = ^uint64(0) - 0xffff
	RejectAfterMessages  = ^uint64(0) - CounterWindowSize - 1
	RekeyTimeout         = time.Duration(5) * time.Second
	RekeyAfterTime       = time.Duration(120) * time.Second
	RejectAfterTime      = time.Duration(180) * time.Second
	InitiationsPerSecond = time.Second / 50
	MaxPeersPerDevice    = ^uint16(0)
)

Variables

View Source
var ErrHostUnreachable = errors.New("Host unreachable")
View Source
var ErrNoKey = errors.New("No Key")

Functions

This section is empty.

Types

type Interface

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

An Interface communicates encrypted packets with peers.

func NewInterface

func NewInterface(c InterfaceConfig) (*Interface, error)

func (*Interface) AddPeer

func (f *Interface) AddPeer(p *Peer) error

AddPeer adds a peer to the interface configuration. If the peer, identified by its public key, already exists, then all configuration will be replaced with the new fields.

func (*Interface) Close

func (f *Interface) Close() error

Close shuts down the interface.

func (*Interface) GetPeers

func (f *Interface) GetPeers() []*Peer

GetPeers retrieves a list of all peers known to the interface.

func (*Interface) RemovePeer

func (f *Interface) RemovePeer(pubkey []byte) error

RemovePeer removes the peer identified with the public key pubkey from the interface configuration.

func (*Interface) Run

func (f *Interface) Run() error

Run starts the interface and blocks until it is closed.

func (*Interface) SetPeers

func (f *Interface) SetPeers(peers []*Peer) error

SetPeers replaces all of the peers that the interface is configured for with a new list.

func (*Interface) SetPresharedKey

func (f *Interface) SetPresharedKey(k []byte) error

SetPresharedKey changes the pre-shared key for the interface.

func (*Interface) SetPrivateKey

func (f *Interface) SetPrivateKey(k []byte) error

SetPrivateKey changes the private key for the interface. It is safe to call while the interface is running.

type InterfaceConfig

type InterfaceConfig struct {
	// Outside is the connection that will be used to send and receive encrypted
	// packets with peers. It will be closed if Close is called on the Interface.
	Outside UDPConn

	// Inside is the interface that will be used to read plaintext packets
	// destined for peers and write decrypted packets received from peers. Each
	// Read must return a single IP packet to send to a peer, and each Write
	// will provide a single received IP packet.
	Inside io.ReadWriter

	// PrivateKey holds the static Curve25519 private key for the interface. If
	// set, it must be exactly 32 random bytes.
	PrivateKey []byte

	// PresharedKey holds an optional pre-shared key to use during handshakes.
	// If set, it must be exactly 32 random bytes.
	PresharedKey []byte

	// Peers is the initial set of peers that the interface will communicate
	// with.
	Peers []*Peer
}

An InterfaceConfig is the configuration used to create an interface.

type PacketQueue

type PacketQueue struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*PacketQueue) Append

func (pq *PacketQueue) Append(v []byte)

func (*PacketQueue) BoundedAppend

func (pq *PacketQueue) BoundedAppend(v []byte, maxSize int)

func (*PacketQueue) Len

func (pq *PacketQueue) Len() int

func (*PacketQueue) Peek

func (pq *PacketQueue) Peek() []byte

func (*PacketQueue) Pop

func (pq *PacketQueue) Pop() (v []byte)

func (*PacketQueue) Steal

func (pq *PacketQueue) Steal() *PacketQueue

type Peer

type Peer struct {
	// PublicKey is the static Curve25519 public key of the peer. It must be
	// exactly 32 bytes.
	PublicKey []byte

	// AllowedIPs is the list of IP networks that will be routed to and accepted
	// from the peer.
	AllowedIPs []*net.IPNet

	// Endpoint is the network address that packets destined for the peer will
	// be sent to. If it is nil, packets destined for this peer will not be
	// routable until an incoming handshake is received.
	Endpoint *net.UDPAddr

	// PersistentKeepaliveInterval, if non-zero, is the number of seconds
	// between keep-alive packets sent to the peer.
	PersistentKeepaliveInterval int

	// LastHandshake is the timestamp of the last successful handshake with the
	// peer. This field is read-only.
	LastHandshake time.Time

	// RxBytes is the number of bytes received from the peer. This field is
	// read-only.
	RxBytes int64

	// TxBytes is the number of bytes transmitted to the peer. This field is
	// read-only.
	TxBytes int64
}

A Peer is a remote endpoint that can be communicated with via an Interface.

type RouteTable

type RouteTable struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewRouteTable

func NewRouteTable() RouteTable

NewRouteTable creates a new routing table that handles both IPv4/IPv6 routes.

func (RouteTable) Clear

func (rt RouteTable) Clear()

Clear sets the routing table to be empty.

func (RouteTable) Insert

func (rt RouteTable) Insert(r *net.IPNet, p *peer) error

Insert inserts the entry into the routing table. If a previous entry exists, it is replaced.

func (RouteTable) Lookup

func (rt RouteTable) Lookup(ip net.IP) (p *peer, err error)

Lookup returns the peer matching the longest prefix match for the given ip.

func (RouteTable) LookupFromPacket

func (rt RouteTable) LookupFromPacket(packet []byte) (p *peer, err error)

func (RouteTable) Remove

func (rt RouteTable) Remove(r *net.IPNet) error

Remove deletes the entry from the routing table.

func (RouteTable) RemoveByPeer

func (rt RouteTable) RemoveByPeer(p *peer) error

RemoveByPeer deletes all entries associated with the given peer.

type UDPConn

type UDPConn interface {
	ReadFromUDP(b []byte) (int, *net.UDPAddr, error)
	WriteToUDP(b []byte, addr *net.UDPAddr) (int, error)
	Close() error
}

Directories

Path Synopsis
internal
skip32
Package skip32 implements the Skip32 blockcipher SKIP32 is a 32-bit block cipher based on SKIPJACK, written by Greg Rose of QUALCOMM Australia.
Package skip32 implements the Skip32 blockcipher SKIP32 is a 32-bit block cipher based on SKIPJACK, written by Greg Rose of QUALCOMM Australia.
t

Jump to

Keyboard shortcuts

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