Skip to content

Commit

Permalink
ensure messageCounter is set before handshake is complete (#1154)
Browse files Browse the repository at this point in the history
Ensure we set messageCounter to 2 before the handshake is marked as
complete.
  • Loading branch information
wadey committed Jun 3, 2024
1 parent a92056a commit d9cae9e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions handshake_ix.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nebula

import (
"fmt"
"time"

"github.com/flynn/noise"
Expand Down Expand Up @@ -321,7 +322,11 @@ func ixHandshakeStage1(f *Interface, addr *udp.Addr, via *ViaSender, packet []by
}

f.connectionManager.AddTrafficWatch(hostinfo.localIndexId)
hostinfo.ConnectionState.messageCounter.Store(2)
prev := hostinfo.ConnectionState.messageCounter.Swap(2)
if prev > 2 {
panic(fmt.Errorf("invalid state: messageCounter > 2 before handshake complete: %v", prev))
}

hostinfo.remotes.ResetBlockedRemotes()

return
Expand Down Expand Up @@ -463,12 +468,15 @@ func ixHandshakeStage2(f *Interface, addr *udp.Addr, via *ViaSender, hh *Handsha
// Build up the radix for the firewall if we have subnets in the cert
hostinfo.CreateRemoteCIDR(remoteCert)

prev := hostinfo.ConnectionState.messageCounter.Swap(2)
if prev > 2 {
panic(fmt.Errorf("invalid state: messageCounter > 2 before handshake complete: %v", prev))
}

// Complete our handshake and update metrics, this will replace any existing tunnels for this vpnIp
f.handshakeManager.Complete(hostinfo, f)
f.connectionManager.AddTrafficWatch(hostinfo.localIndexId)

hostinfo.ConnectionState.messageCounter.Store(2)

if f.l.Level >= logrus.DebugLevel {
hostinfo.logger(f.l).Debugf("Sending %d stored packets", len(hh.packetStore))
}
Expand Down

0 comments on commit d9cae9e

Please sign in to comment.