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

initialize messageCounter to 2 instead of verifying later #1156

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions connection_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func NewConnectionState(l *logrus.Logger, cipher string, certState *CertState, i
window: b,
myCert: certState.Certificate,
}
// always start the counter from 2, as packet 1 and packet 2 are handshake packets.
ci.messageCounter.Add(2)

return ci
}
Expand Down
11 changes: 0 additions & 11 deletions handshake_ix.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nebula

import (
"fmt"
"time"

"github.com/flynn/noise"
Expand Down Expand Up @@ -47,7 +46,6 @@ func ixHandshakeStage0(f *Interface, hh *HandshakeHostInfo) bool {
}

h := header.Encode(make([]byte, header.Len), header.Version, header.Handshake, header.HandshakeIXPSK0, 0, 1)
ci.messageCounter.Add(1)

msg, _, _, err := ci.H.WriteMessage(h, hsBytes)
if err != nil {
Expand Down Expand Up @@ -322,10 +320,6 @@ func ixHandshakeStage1(f *Interface, addr *udp.Addr, via *ViaSender, packet []by
}

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

hostinfo.remotes.ResetBlockedRemotes()

Expand Down Expand Up @@ -468,11 +462,6 @@ 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)
Expand Down
Loading