Compare commits

...

1 Commits

Author SHA1 Message Date
Kristoffer Dalby
8b72318669 ipn/ipnlocal: return old hwaddrs if missing
If we previously knew of macaddresses of a node, and they
suddenly goes to zero, ignore them and return the previous
hardware addresses.

Updates tailscale/corp#25168

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
2025-03-11 12:49:22 +01:00
2 changed files with 27 additions and 1 deletions

View File

@@ -360,7 +360,7 @@ func handleC2NPostureIdentityGet(b *LocalBackend, w http.ResponseWriter, r *http
// and looks good in client metrics, remove this parameter and always report MAC
// addresses.
if r.FormValue("hwaddrs") == "true" {
res.IfaceHardwareAddrs, err = posture.GetHardwareAddrs()
res.IfaceHardwareAddrs, err = b.getHardwareAddrs()
if err != nil {
b.logf("c2n: GetHardwareAddrs returned error: %v", err)
}

View File

@@ -78,6 +78,7 @@ import (
"tailscale.com/net/tsdial"
"tailscale.com/paths"
"tailscale.com/portlist"
"tailscale.com/posture"
"tailscale.com/syncs"
"tailscale.com/tailcfg"
"tailscale.com/taildrop"
@@ -403,6 +404,12 @@ type LocalBackend struct {
// notified about.
lastNotifiedDriveShares *views.SliceView[*drive.Share, drive.ShareView]
// lastKnownHardwareAddrs is a list of the previous known hardware addrs.
// Previously known hwaddrs are kept to work around an issue on Windows
// where all addresses might disappear.
// http://go/corp/25168
lastKnownHardwareAddrs syncs.AtomicValue[[]string]
// outgoingFiles keeps track of Taildrop outgoing files keyed to their OutgoingFile.ID
outgoingFiles map[string]*ipn.OutgoingFile
@@ -7456,6 +7463,25 @@ func (b *LocalBackend) resetDialPlan() {
}
}
// getHardwareAddrs returns the hardware addresses for the machine. If the list
// of hardware addresses is empty, it will return the previously known hardware
// addresses. Both the current, and previously known hardware addresses might be
// empty.
func (b *LocalBackend) getHardwareAddrs() ([]string, error) {
addrs, err := posture.GetHardwareAddrs()
if err != nil {
return nil, err
}
if len(addrs) == 0 {
b.logf("getHardwareAddrs: got empty list of hwaddrs, returning previous list")
return b.lastKnownHardwareAddrs.Load(), nil
}
b.lastKnownHardwareAddrs.Store(addrs)
return addrs, nil
}
// resetForProfileChangeLockedOnEntry resets the backend for a profile change.
//
// b.mu must held on entry. It is released on exit.