Skip to content

Commit 77250a3

Browse files
authored
ipn/ipnlocal, types: plumb tailnet display name cap through to network profile (tailscale#17045)
Updates tailscale/corp#30456 Signed-off-by: Nick O'Neill <nick@tailscale.com>
1 parent f1ded84 commit 77250a3

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

ipn/ipnlocal/local.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,12 +1650,18 @@ func (b *LocalBackend) SetControlClientStatus(c controlclient.Client, st control
16501650
prefsChanged = true
16511651
}
16521652

1653+
// If the tailnet's display name has changed, update prefs.
1654+
if st.NetMap != nil && st.NetMap.TailnetDisplayName() != b.pm.CurrentProfile().NetworkProfile().DisplayName {
1655+
prefsChanged = true
1656+
}
1657+
16531658
// Perform all mutations of prefs based on the netmap here.
16541659
if prefsChanged {
16551660
// Prefs will be written out if stale; this is not safe unless locked or cloned.
16561661
if err := b.pm.SetPrefs(prefs.View(), ipn.NetworkProfile{
16571662
MagicDNSName: curNetMap.MagicDNSSuffix(),
16581663
DomainName: curNetMap.DomainName(),
1664+
DisplayName: curNetMap.TailnetDisplayName(),
16591665
}); err != nil {
16601666
b.logf("Failed to save new controlclient state: %v", err)
16611667
}
@@ -1716,6 +1722,7 @@ func (b *LocalBackend) SetControlClientStatus(c controlclient.Client, st control
17161722
if err := b.pm.SetPrefs(p, ipn.NetworkProfile{
17171723
MagicDNSName: st.NetMap.MagicDNSSuffix(),
17181724
DomainName: st.NetMap.DomainName(),
1725+
DisplayName: st.NetMap.TailnetDisplayName(),
17191726
}); err != nil {
17201727
b.logf("Failed to save new controlclient state: %v", err)
17211728
}
@@ -6185,6 +6192,7 @@ func (b *LocalBackend) resolveExitNode() (changed bool) {
61856192
if err := b.pm.SetPrefs(prefs.View(), ipn.NetworkProfile{
61866193
MagicDNSName: nm.MagicDNSSuffix(),
61876194
DomainName: nm.DomainName(),
6195+
DisplayName: nm.TailnetDisplayName(),
61886196
}); err != nil {
61896197
b.logf("failed to save exit node changes: %v", err)
61906198
}

ipn/ipnlocal/node_backend.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ func (nb *nodeBackend) NetworkProfile() ipn.NetworkProfile {
168168
// These are ok to call with nil netMap.
169169
MagicDNSName: nb.netMap.MagicDNSSuffix(),
170170
DomainName: nb.netMap.DomainName(),
171+
DisplayName: nb.netMap.TailnetDisplayName(),
171172
}
172173
}
173174

ipn/prefs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,7 @@ type WindowsUserID string
988988
type NetworkProfile struct {
989989
MagicDNSName string
990990
DomainName string
991+
DisplayName string
991992
}
992993

993994
// RequiresBackfill returns whether this object does not have all the data

types/netmap/netmap.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,22 @@ func (nm *NetworkMap) DomainName() string {
252252
return nm.Domain
253253
}
254254

255+
// TailnetDisplayName returns the admin-editable name contained in
256+
// NodeAttrTailnetDisplayName. If the capability is not present it
257+
// returns an empty string.
258+
func (nm *NetworkMap) TailnetDisplayName() string {
259+
if nm == nil || !nm.SelfNode.Valid() {
260+
return ""
261+
}
262+
263+
tailnetDisplayNames, err := tailcfg.UnmarshalNodeCapViewJSON[string](nm.SelfNode.CapMap(), tailcfg.NodeAttrTailnetDisplayName)
264+
if err != nil || len(tailnetDisplayNames) == 0 {
265+
return ""
266+
}
267+
268+
return tailnetDisplayNames[0]
269+
}
270+
255271
// HasSelfCapability reports whether nm.SelfNode contains capability c.
256272
//
257273
// It exists to satisify an unused (as of 2025-01-04) interface in the logknob package.

0 commit comments

Comments
 (0)