|
@@ -6,6 +6,7 @@ import (
|
|
"github.com/slackhq/nebula/firewall"
|
|
"github.com/slackhq/nebula/firewall"
|
|
"github.com/slackhq/nebula/header"
|
|
"github.com/slackhq/nebula/header"
|
|
"github.com/slackhq/nebula/iputil"
|
|
"github.com/slackhq/nebula/iputil"
|
|
|
|
+ "github.com/slackhq/nebula/noiseutil"
|
|
"github.com/slackhq/nebula/udp"
|
|
"github.com/slackhq/nebula/udp"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -256,6 +257,11 @@ func (f *Interface) SendVia(viaIfc interface{},
|
|
) {
|
|
) {
|
|
via := viaIfc.(*HostInfo)
|
|
via := viaIfc.(*HostInfo)
|
|
relay := relayIfc.(*Relay)
|
|
relay := relayIfc.(*Relay)
|
|
|
|
+
|
|
|
|
+ if noiseutil.EncryptLockNeeded {
|
|
|
|
+ // NOTE: for goboring AESGCMTLS we need to lock because of the nonce check
|
|
|
|
+ via.ConnectionState.writeLock.Lock()
|
|
|
|
+ }
|
|
c := via.ConnectionState.messageCounter.Add(1)
|
|
c := via.ConnectionState.messageCounter.Add(1)
|
|
|
|
|
|
out = header.Encode(out, header.Version, header.Message, header.MessageRelay, relay.RemoteIndex, c)
|
|
out = header.Encode(out, header.Version, header.Message, header.MessageRelay, relay.RemoteIndex, c)
|
|
@@ -264,6 +270,9 @@ func (f *Interface) SendVia(viaIfc interface{},
|
|
// Authenticate the header and payload, but do not encrypt for this message type.
|
|
// Authenticate the header and payload, but do not encrypt for this message type.
|
|
// The payload consists of the inner, unencrypted Nebula header, as well as the end-to-end encrypted payload.
|
|
// The payload consists of the inner, unencrypted Nebula header, as well as the end-to-end encrypted payload.
|
|
if len(out)+len(ad)+via.ConnectionState.eKey.Overhead() > cap(out) {
|
|
if len(out)+len(ad)+via.ConnectionState.eKey.Overhead() > cap(out) {
|
|
|
|
+ if noiseutil.EncryptLockNeeded {
|
|
|
|
+ via.ConnectionState.writeLock.Unlock()
|
|
|
|
+ }
|
|
via.logger(f.l).
|
|
via.logger(f.l).
|
|
WithField("outCap", cap(out)).
|
|
WithField("outCap", cap(out)).
|
|
WithField("payloadLen", len(ad)).
|
|
WithField("payloadLen", len(ad)).
|
|
@@ -285,6 +294,9 @@ func (f *Interface) SendVia(viaIfc interface{},
|
|
|
|
|
|
var err error
|
|
var err error
|
|
out, err = via.ConnectionState.eKey.EncryptDanger(out, out, nil, c, nb)
|
|
out, err = via.ConnectionState.eKey.EncryptDanger(out, out, nil, c, nb)
|
|
|
|
+ if noiseutil.EncryptLockNeeded {
|
|
|
|
+ via.ConnectionState.writeLock.Unlock()
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
via.logger(f.l).WithError(err).Info("Failed to EncryptDanger in sendVia")
|
|
via.logger(f.l).WithError(err).Info("Failed to EncryptDanger in sendVia")
|
|
return
|
|
return
|
|
@@ -313,8 +325,10 @@ func (f *Interface) sendNoMetrics(t header.MessageType, st header.MessageSubType
|
|
out = out[header.Len:]
|
|
out = out[header.Len:]
|
|
}
|
|
}
|
|
|
|
|
|
- //TODO: enable if we do more than 1 tun queue
|
|
|
|
- //ci.writeLock.Lock()
|
|
|
|
|
|
+ if noiseutil.EncryptLockNeeded {
|
|
|
|
+ // NOTE: for goboring AESGCMTLS we need to lock because of the nonce check
|
|
|
|
+ ci.writeLock.Lock()
|
|
|
|
+ }
|
|
c := ci.messageCounter.Add(1)
|
|
c := ci.messageCounter.Add(1)
|
|
|
|
|
|
//l.WithField("trace", string(debug.Stack())).Error("out Header ", &Header{Version, t, st, 0, hostinfo.remoteIndexId, c}, p)
|
|
//l.WithField("trace", string(debug.Stack())).Error("out Header ", &Header{Version, t, st, 0, hostinfo.remoteIndexId, c}, p)
|
|
@@ -335,8 +349,9 @@ func (f *Interface) sendNoMetrics(t header.MessageType, st header.MessageSubType
|
|
|
|
|
|
var err error
|
|
var err error
|
|
out, err = ci.eKey.EncryptDanger(out, out, p, c, nb)
|
|
out, err = ci.eKey.EncryptDanger(out, out, p, c, nb)
|
|
- //TODO: see above note on lock
|
|
|
|
- //ci.writeLock.Unlock()
|
|
|
|
|
|
+ if noiseutil.EncryptLockNeeded {
|
|
|
|
+ ci.writeLock.Unlock()
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
hostinfo.logger(f.l).WithError(err).
|
|
hostinfo.logger(f.l).WithError(err).
|
|
WithField("udpAddr", remote).WithField("counter", c).
|
|
WithField("udpAddr", remote).WithField("counter", c).
|