Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure messageCounter is set before handshake is complete #1154

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading