control/controlclient,net/tstun,wgengine/magicsock: fix handling of zero keys in TSMP (#20508)

Updates tailscale/corp#45042

Signed-off-by: Claus Lensbøl <claus@tailscale.com>
This commit is contained in:
Claus Lensbøl
2026-07-17 14:02:53 -04:00
committed by GitHub
parent c1edf7f458
commit 82a381e54b
6 changed files with 121 additions and 49 deletions
+5
View File
@@ -200,6 +200,11 @@ func (ms *mapSession) Close() {
var ErrChangeQueueClosed = errors.New("change queue closed")
func (ms *mapSession) updateDiscoForNode(id tailcfg.NodeID, key key.NodePublic, discoKey key.DiscoPublic, lastSeen time.Time, online bool) error {
if discoKey.IsZero() {
ms.logf("[v1] controlclient: received zero disco key update from nodeID %v", id)
return nil
}
ms.cqmu.Lock()
if ms.changeQueueClosed {
+23 -12
View File
@@ -629,7 +629,7 @@ func TestUpdateDiscoForNode(t *testing.T) {
name string
initialOnline bool
initialLastSeen time.Time
updateDiscoKey bool
updateDiscoKey func() key.DiscoPublic
updateOnline bool
updateLastSeen time.Time
wantUpdate bool
@@ -639,7 +639,7 @@ func TestUpdateDiscoForNode(t *testing.T) {
name: "newer_key_not_online",
initialOnline: true,
initialLastSeen: time.Unix(1, 0),
updateDiscoKey: true,
updateDiscoKey: key.NewDisco().Public,
updateOnline: false,
updateLastSeen: time.Now(),
wantUpdate: true,
@@ -649,7 +649,7 @@ func TestUpdateDiscoForNode(t *testing.T) {
name: "newer_key_online",
initialOnline: true,
initialLastSeen: time.Unix(1, 0),
updateDiscoKey: true,
updateDiscoKey: key.NewDisco().Public,
updateOnline: true,
updateLastSeen: time.Now(),
wantUpdate: true,
@@ -659,7 +659,7 @@ func TestUpdateDiscoForNode(t *testing.T) {
name: "older_key_not_online",
initialOnline: false,
initialLastSeen: time.Now(),
updateDiscoKey: true,
updateDiscoKey: key.NewDisco().Public,
updateOnline: false,
updateLastSeen: time.Unix(1, 0),
wantUpdate: false,
@@ -669,7 +669,7 @@ func TestUpdateDiscoForNode(t *testing.T) {
name: "older_key_online",
initialOnline: false,
initialLastSeen: time.Now(),
updateDiscoKey: true,
updateDiscoKey: key.NewDisco().Public,
updateOnline: true,
updateLastSeen: time.Unix(1, 0),
wantUpdate: true,
@@ -679,7 +679,7 @@ func TestUpdateDiscoForNode(t *testing.T) {
name: "same_newer_key_not_online",
initialOnline: true,
initialLastSeen: time.Unix(1, 0),
updateDiscoKey: false,
updateDiscoKey: nil,
updateOnline: false,
updateLastSeen: time.Now(),
wantUpdate: false,
@@ -689,7 +689,7 @@ func TestUpdateDiscoForNode(t *testing.T) {
name: "same_newer_key_online",
initialOnline: true,
initialLastSeen: time.Unix(1, 0),
updateDiscoKey: false,
updateDiscoKey: nil,
updateOnline: true,
updateLastSeen: time.Now(),
wantUpdate: false,
@@ -699,7 +699,7 @@ func TestUpdateDiscoForNode(t *testing.T) {
name: "same_older_key_not_online",
initialOnline: false,
initialLastSeen: time.Now(),
updateDiscoKey: false,
updateDiscoKey: nil,
updateOnline: false,
updateLastSeen: time.Unix(1, 0),
wantUpdate: false,
@@ -709,7 +709,7 @@ func TestUpdateDiscoForNode(t *testing.T) {
name: "same_older_key_online",
initialOnline: false,
initialLastSeen: time.Now(),
updateDiscoKey: false,
updateDiscoKey: nil,
updateOnline: true,
updateLastSeen: time.Unix(1, 0),
wantUpdate: true,
@@ -718,12 +718,23 @@ func TestUpdateDiscoForNode(t *testing.T) {
{
name: "no_initial_last_seen",
initialOnline: false,
updateDiscoKey: true,
updateDiscoKey: key.NewDisco().Public,
updateOnline: false,
updateLastSeen: time.Now(),
wantUpdate: true,
wantKeyChanged: true,
},
{
name: "zero_key",
initialOnline: false,
updateDiscoKey: func() key.DiscoPublic {
return key.DiscoPublic{}
},
updateOnline: false,
updateLastSeen: time.Now(),
wantUpdate: false,
wantKeyChanged: false,
},
}
for _, tt := range tests {
@@ -755,8 +766,8 @@ func TestUpdateDiscoForNode(t *testing.T) {
}
newKey := oldKey.Public()
if tt.updateDiscoKey {
newKey = key.NewDisco().Public()
if tt.updateDiscoKey != nil {
newKey = tt.updateDiscoKey()
}
ms.updateDiscoForNode(node.ID, node.Key, newKey, tt.updateLastSeen, tt.updateOnline)