mirror of
https://github.com/slackhq/nebula.git
synced 2026-08-16 01:27:04 +02:00
stop trying to interpret TCP, reorder via message counter and hostinfo-creation-order
This commit is contained in:
@@ -14,6 +14,16 @@ import (
|
||||
|
||||
const ReplayWindow = 8192
|
||||
|
||||
// sessionEpoch hands out a receiver-local ordinal to every ConnectionState as
|
||||
// it is created. The RX staging sort (overlay/batch) orders packets by
|
||||
// (epoch, message counter). A re-handshake never rekeys an existing tunnel; it
|
||||
// brings up a whole new hostinfo (and ConnectionState) with its own counter
|
||||
// space starting near zero, while the old tunnel keeps decrypting in-flight
|
||||
// packets until it is torn down. During that cutover one flush batch can hold
|
||||
// packets from both tunnels, and the epoch is what keeps the old tunnel's
|
||||
// packets sorted ahead of the new tunnel's.
|
||||
var sessionEpoch atomic.Uint64
|
||||
|
||||
type ConnectionState struct {
|
||||
eKey noiseutil.CipherState
|
||||
dKey noiseutil.CipherState
|
||||
@@ -24,6 +34,8 @@ type ConnectionState struct {
|
||||
window *Bits
|
||||
decryptLock sync.Mutex
|
||||
writeLock sync.Mutex
|
||||
// epoch is this session's sessionEpoch ordinal. Immutable after creation.
|
||||
epoch uint64
|
||||
}
|
||||
|
||||
// newConnectionStateFromResult builds a fully-populated ConnectionState from a
|
||||
@@ -38,6 +50,7 @@ func newConnectionStateFromResult(r *handshake.Result) *ConnectionState {
|
||||
eKey: noiseutil.NewCipherState(r.EKey, r.Cipher),
|
||||
dKey: noiseutil.NewCipherState(r.DKey, r.Cipher),
|
||||
window: NewBits(ReplayWindow),
|
||||
epoch: sessionEpoch.Add(1),
|
||||
}
|
||||
ci.messageCounter.Add(r.MessageIndex)
|
||||
for i := uint64(1); i <= r.MessageIndex; i++ {
|
||||
|
||||
Reference in New Issue
Block a user