Documentation ¶
Index ¶
- Constants
- Variables
- func HMAC1(sum *[blake2s.Size]byte, key, in0 []byte)
- func HMAC2(sum *[blake2s.Size]byte, key, in0, in1 []byte)
- func KDF1(t0 *[blake2s.Size]byte, key, input []byte)
- func KDF2(t0, t1 *[blake2s.Size]byte, key, input []byte)
- func KDF3(t0, t1, t2 *[blake2s.Size]byte, key, input []byte)
- type CookieChecker
- type CookieGenerator
- type Handshake
- type IndexTable
- func (table *IndexTable) Delete(index uint32)
- func (table *IndexTable) Init()
- func (table *IndexTable) Lookup(id uint32) IndexTableEntry
- func (table *IndexTable) NewIndexForHandshake(peer *Peer, handshake *Handshake) (uint32, error)
- func (table *IndexTable) SwapIndexForKeypair(index uint32, keypair *Keypair)
- type IndexTableEntry
- type Keypair
- type Keypairs
- type MessageCookieReply
- type MessageInitiation
- type MessageResponse
- type MessageTransport
- type Peer
- func (peer *Peer) BeginSymmetricSession() error
- func (peer *Peer) ExpireCurrentKeypairs()
- func (peer *Peer) FlushStagedPackets()
- func (peer *Peer) GetEndpoint() conn.Endpoint
- func (peer *Peer) NewTimer(expirationFunction func(*Peer)) *Timer
- func (peer *Peer) ReceivedWithKeypair(receivedKeypair *Keypair) bool
- func (peer *Peer) RoutineSequentialReceiver(maxBatchSize int)
- func (peer *Peer) RoutineSequentialSender(maxBatchSize int)
- func (peer *Peer) SendBuffers(buffers [][]byte) error
- func (peer *Peer) SendHandshakeInitiation(isRetry bool) error
- func (peer *Peer) SendHandshakeResponse() error
- func (peer *Peer) SendKeepalive() error
- func (peer *Peer) SendStagedPackets() error
- func (peer *Peer) SetEndpoint(endpoint conn.Endpoint)
- func (peer *Peer) SetKeepAliveInterval(interval time.Duration)
- func (peer *Peer) StagePackets(elems *QueueOutboundElementsContainer)
- func (peer *Peer) Start()
- func (peer *Peer) Stop()
- func (peer *Peer) String() string
- func (peer *Peer) ZeroAndFlushAll()
- type QueueHandshakeElement
- type QueueInboundElement
- type QueueInboundElementsContainer
- type QueueOutboundElement
- type QueueOutboundElementsContainer
- type SourceSink
- type Timer
- type Transport
- func (transport *Transport) BatchSize() int
- func (transport *Transport) Bind() conn.Bind
- func (transport *Transport) BindClose() error
- func (transport *Transport) BindUpdate() error
- func (transport *Transport) Close() error
- func (transport *Transport) ConsumeMessageInitiation(msg *MessageInitiation) *Peer
- func (transport *Transport) ConsumeMessageResponse(msg *MessageResponse) *Peer
- func (transport *Transport) CreateMessageInitiation(peer *Peer) (*MessageInitiation, error)
- func (transport *Transport) CreateMessageResponse(peer *Peer) (*MessageResponse, error)
- func (transport *Transport) DeleteKeypair(key *Keypair)
- func (transport *Transport) Down() error
- func (transport *Transport) GetInboundElement() *QueueInboundElement
- func (transport *Transport) GetInboundElementsContainer() *QueueInboundElementsContainer
- func (transport *Transport) GetMessageBuffer() *[MaxMessageSize]byte
- func (transport *Transport) GetOutboundElement() *QueueOutboundElement
- func (transport *Transport) GetOutboundElementsContainer() *QueueOutboundElementsContainer
- func (transport *Transport) IsUnderLoad() bool
- func (transport *Transport) LookupPeer(pk types.NoisePublicKey) *Peer
- func (transport *Transport) NewOutboundElement() *QueueOutboundElement
- func (transport *Transport) NewPeer(pk types.NoisePublicKey) (*Peer, error)
- func (transport *Transport) Peers() []types.NoisePublicKey
- func (transport *Transport) PopulatePools()
- func (transport *Transport) PutInboundElement(elem *QueueInboundElement)
- func (transport *Transport) PutInboundElementsContainer(c *QueueInboundElementsContainer)
- func (transport *Transport) PutMessageBuffer(msg *[MaxMessageSize]byte)
- func (transport *Transport) PutOutboundElement(elem *QueueOutboundElement)
- func (transport *Transport) PutOutboundElementsContainer(c *QueueOutboundElementsContainer)
- func (transport *Transport) RemoveAllPeers()
- func (transport *Transport) RemovePeer(pk types.NoisePublicKey)
- func (transport *Transport) RoutineDecryption(id int)
- func (transport *Transport) RoutineEncryption(id int)
- func (transport *Transport) RoutineHandshake(id int)
- func (transport *Transport) RoutineReadFromSourceSink()
- func (transport *Transport) RoutineReceiveIncoming(maxBatchSize int, recv conn.ReceiveFunc)
- func (transport *Transport) SendHandshakeCookie(initiatingElem *QueueHandshakeElement) error
- func (transport *Transport) SendKeepalivesToPeersWithCurrentKeypair()
- func (transport *Transport) SetPrivateKey(sk types.NoisePrivateKey)
- func (transport *Transport) Up() error
- func (transport *Transport) UpdatePort(port uint16) error
- func (transport *Transport) Wait() chan struct{}
- type WaitPool
Constants ¶
const ( RekeyAfterMessages = (1 << 60) RejectAfterMessages = (1 << 64) - (1 << 13) - 1 RekeyAfterTime = time.Second * 120 RekeyAttemptTime = time.Second * 90 RekeyTimeout = time.Second * 5 MaxTimerHandshakes = 90 / 5 /* RekeyAttemptTime / RekeyTimeout */ RekeyTimeoutJitterMaxMs = 334 RejectAfterTime = time.Second * 180 KeepaliveTimeout = time.Second * 10 CookieRefreshTime = time.Second * 120 HandshakeInitationRate = time.Second / 50 PaddingMultiple = 16 )
const ( MinMessageSize = MessageKeepaliveSize // minimum size of transport message (keepalive) MaxMessageSize = MaxSegmentSize // maximum size of transport message MaxContentSize = MaxSegmentSize - MessageTransportSize // maximum size of transport message content )
const ( UnderLoadAfterTime = time.Second // how long does the transport remain under load after detected MaxPeers = 1 << 16 // maximum number of configured peers )
const ( NoiseConstruction = "Noise_IKpsk2_25519_ChaChaPoly_BLAKE2s" NoiseIdentifier = "WireGuard v1 zx2c4 Jason@zx2c4.com" NoiseLabelMAC1 = "mac1----" NoiseLabelCookie = "cookie--" )
const ( MessageInitiationType = 1 MessageResponseType = 2 MessageCookieReplyType = 3 MessageTransportType = 4 )
const ( MessageInitiationSize = 148 // size of handshake initiation message MessageResponseSize = 92 // size of response message MessageCookieReplySize = 64 // size of cookie reply message MessageTransportHeaderSize = 16 // size of data preceding content in transport message MessageTransportSize = MessageTransportHeaderSize + poly1305.TagSize // size of empty transport MessageKeepaliveSize = MessageTransportSize // size of keepalive MessageHandshakeSize = MessageInitiationSize // size of largest handshake related message )
const ( MessageTransportOffsetReceiver = 4 MessageTransportOffsetCounter = 8 MessageTransportOffsetContent = 16 )
const ( QueueStagedSize = conn.IdealBatchSize QueueOutboundSize = 1024 QueueInboundSize = 1024 QueueHandshakeSize = 1024 MaxSegmentSize = (1 << 16) - 1 // largest possible UDP datagram PreallocatedBuffersPerPool = 0 // Disable and allow for infinite memory growth )
const DefaultMTU = 1420
Variables ¶
var ( InitialChainKey [blake2s.Size]byte InitialHash [blake2s.Size]byte ZeroNonce [chacha20poly1305.NonceSize]byte )
Functions ¶
Types ¶
type CookieChecker ¶
func (*CookieChecker) CheckMAC1 ¶
func (st *CookieChecker) CheckMAC1(msg []byte) bool
func (*CookieChecker) CheckMAC2 ¶
func (st *CookieChecker) CheckMAC2(msg, src []byte) bool
func (*CookieChecker) CreateReply ¶
func (st *CookieChecker) CreateReply( msg []byte, recv uint32, src []byte, ) (*MessageCookieReply, error)
func (*CookieChecker) Init ¶
func (st *CookieChecker) Init(pk types.NoisePublicKey)
type CookieGenerator ¶
func (*CookieGenerator) AddMacs ¶
func (st *CookieGenerator) AddMacs(msg []byte)
func (*CookieGenerator) ConsumeReply ¶
func (st *CookieGenerator) ConsumeReply(msg *MessageCookieReply) bool
func (*CookieGenerator) Init ¶
func (st *CookieGenerator) Init(pk types.NoisePublicKey)
type IndexTable ¶
func (*IndexTable) Delete ¶
func (table *IndexTable) Delete(index uint32)
func (*IndexTable) Init ¶
func (table *IndexTable) Init()
func (*IndexTable) Lookup ¶
func (table *IndexTable) Lookup(id uint32) IndexTableEntry
func (*IndexTable) NewIndexForHandshake ¶
func (table *IndexTable) NewIndexForHandshake(peer *Peer, handshake *Handshake) (uint32, error)
func (*IndexTable) SwapIndexForKeypair ¶
func (table *IndexTable) SwapIndexForKeypair(index uint32, keypair *Keypair)
type IndexTableEntry ¶
type IndexTableEntry struct {
// contains filtered or unexported fields
}
type MessageCookieReply ¶
type MessageCookieReply struct { Type uint32 Receiver uint32 Nonce [chacha20poly1305.NonceSizeX]byte Cookie [blake2s.Size128 + poly1305.TagSize]byte }
type MessageInitiation ¶
type MessageResponse ¶
type MessageTransport ¶
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
func (*Peer) BeginSymmetricSession ¶
Derives a new keypair from the current handshake state *
func (*Peer) ExpireCurrentKeypairs ¶
func (peer *Peer) ExpireCurrentKeypairs()
func (*Peer) FlushStagedPackets ¶
func (peer *Peer) FlushStagedPackets()
func (*Peer) GetEndpoint ¶ added in v0.7.1
func (*Peer) ReceivedWithKeypair ¶
func (*Peer) RoutineSequentialReceiver ¶
func (*Peer) RoutineSequentialSender ¶
func (*Peer) SendBuffers ¶
func (*Peer) SendHandshakeInitiation ¶
func (*Peer) SendHandshakeResponse ¶
func (*Peer) SendKeepalive ¶
Queues a keepalive if no packets are queued for peer
func (*Peer) SendStagedPackets ¶
func (*Peer) SetEndpoint ¶ added in v0.7.1
func (*Peer) SetKeepAliveInterval ¶ added in v0.10.0
func (*Peer) StagePackets ¶
func (peer *Peer) StagePackets(elems *QueueOutboundElementsContainer)
func (*Peer) ZeroAndFlushAll ¶
func (peer *Peer) ZeroAndFlushAll()
type QueueHandshakeElement ¶
type QueueHandshakeElement struct {
// contains filtered or unexported fields
}
type QueueInboundElement ¶
type QueueInboundElement struct {
// contains filtered or unexported fields
}
type QueueOutboundElement ¶
type QueueOutboundElement struct {
// contains filtered or unexported fields
}
type SourceSink ¶
type SourceSink interface { io.Closer // Read one or more packets from the Transport (without any additional headers). // On a successful read it returns the number of packets read, and sets // packet lengths within the sizes slice. len(sizes) must be >= len(bufs). // A nonzero offset can be used to instruct the Transport on where to begin // reading into each element of the bufs slice. Read(bufs [][]byte, sizes []int, destinations []types.NoisePublicKey, offset int) (int, error) // Write one or more packets to the transport (without any additional headers). // On a successful write it returns the number of packets written. A nonzero // offset can be used to instruct the Transport on where to begin writing from // each packet contained within the bufs slice. Write(bufs [][]byte, sources []types.NoisePublicKey, offset int) (int, error) // BatchSize returns the preferred/max number of packets that can be read or // written in a single read/write call. BatchSize must not change over the // lifetime of a Transport. BatchSize() int }
type Timer ¶
A Timer manages time-based aspects of the WireGuard protocol. Timer roughly copies the interface of the Linux kernel's struct timer_list.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
func NewTransport ¶
func (*Transport) BatchSize ¶
BatchSize returns the BatchSize for the transport as a whole which is the max of the bind batch size and the sink batch size. The batch size reported by transport is the size used to construct memory pools, and is the allowed batch size for the lifetime of the transport.
func (*Transport) BindUpdate ¶
func (*Transport) ConsumeMessageInitiation ¶
func (transport *Transport) ConsumeMessageInitiation(msg *MessageInitiation) *Peer
func (*Transport) ConsumeMessageResponse ¶
func (transport *Transport) ConsumeMessageResponse(msg *MessageResponse) *Peer
func (*Transport) CreateMessageInitiation ¶
func (transport *Transport) CreateMessageInitiation(peer *Peer) (*MessageInitiation, error)
func (*Transport) CreateMessageResponse ¶
func (transport *Transport) CreateMessageResponse(peer *Peer) (*MessageResponse, error)
func (*Transport) DeleteKeypair ¶
func (*Transport) GetInboundElement ¶
func (transport *Transport) GetInboundElement() *QueueInboundElement
func (*Transport) GetInboundElementsContainer ¶
func (transport *Transport) GetInboundElementsContainer() *QueueInboundElementsContainer
func (*Transport) GetMessageBuffer ¶
func (transport *Transport) GetMessageBuffer() *[MaxMessageSize]byte
func (*Transport) GetOutboundElement ¶
func (transport *Transport) GetOutboundElement() *QueueOutboundElement
func (*Transport) GetOutboundElementsContainer ¶
func (transport *Transport) GetOutboundElementsContainer() *QueueOutboundElementsContainer
func (*Transport) IsUnderLoad ¶
func (*Transport) LookupPeer ¶
func (transport *Transport) LookupPeer(pk types.NoisePublicKey) *Peer
func (*Transport) NewOutboundElement ¶
func (transport *Transport) NewOutboundElement() *QueueOutboundElement
func (*Transport) NewPeer ¶
func (transport *Transport) NewPeer(pk types.NoisePublicKey) (*Peer, error)
func (*Transport) Peers ¶ added in v0.12.4
func (transport *Transport) Peers() []types.NoisePublicKey
func (*Transport) PopulatePools ¶
func (transport *Transport) PopulatePools()
func (*Transport) PutInboundElement ¶
func (transport *Transport) PutInboundElement(elem *QueueInboundElement)
func (*Transport) PutInboundElementsContainer ¶
func (transport *Transport) PutInboundElementsContainer(c *QueueInboundElementsContainer)
func (*Transport) PutMessageBuffer ¶
func (transport *Transport) PutMessageBuffer(msg *[MaxMessageSize]byte)
func (*Transport) PutOutboundElement ¶
func (transport *Transport) PutOutboundElement(elem *QueueOutboundElement)
func (*Transport) PutOutboundElementsContainer ¶
func (transport *Transport) PutOutboundElementsContainer(c *QueueOutboundElementsContainer)
func (*Transport) RemoveAllPeers ¶
func (transport *Transport) RemoveAllPeers()
func (*Transport) RemovePeer ¶
func (transport *Transport) RemovePeer(pk types.NoisePublicKey)
func (*Transport) RoutineDecryption ¶
func (*Transport) RoutineEncryption ¶
Encrypts the elements in the queue * and marks them for sequential consumption (by releasing the mutex) * * Obs. One instance per core
func (*Transport) RoutineHandshake ¶
Handles incoming packets related to handshake.
func (*Transport) RoutineReadFromSourceSink ¶
func (transport *Transport) RoutineReadFromSourceSink()
func (*Transport) RoutineReceiveIncoming ¶
func (transport *Transport) RoutineReceiveIncoming(maxBatchSize int, recv conn.ReceiveFunc)
Receives incoming datagrams for the transport * * Every time the bind is updated a new routine is started for * IPv4 and IPv6 (separately)
func (*Transport) SendHandshakeCookie ¶
func (transport *Transport) SendHandshakeCookie(initiatingElem *QueueHandshakeElement) error
func (*Transport) SendKeepalivesToPeersWithCurrentKeypair ¶
func (transport *Transport) SendKeepalivesToPeersWithCurrentKeypair()
func (*Transport) SetPrivateKey ¶
func (transport *Transport) SetPrivateKey(sk types.NoisePrivateKey)