From 0a42b0a72666c46846b8aa5a70c9843540d80fd2 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 24 Jul 2020 23:05:04 +0200 Subject: [PATCH] ipn: add OSVersion, DeviceModel fields to Prefs and propagate to Hostinfos Needed for Android. Signed-off-by: Elias Naur --- ipn/local.go | 20 ++++++++++++++------ ipn/prefs.go | 6 ++++++ ipn/prefs_test.go | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ipn/local.go b/ipn/local.go index d4868405b..9b5087b1b 100644 --- a/ipn/local.go +++ b/ipn/local.go @@ -353,9 +353,7 @@ func (b *LocalBackend) Start(opts Options) error { b.serverURL = b.prefs.ControlURL hostinfo.RoutableIPs = append(hostinfo.RoutableIPs, b.prefs.AdvertiseRoutes...) hostinfo.RequestTags = append(hostinfo.RequestTags, b.prefs.AdvertiseTags...) - if b.prefs.Hostname != "" { - hostinfo.Hostname = b.prefs.Hostname - } + applyPrefsToHostinfo(hostinfo, b.prefs) b.notify = opts.Notify b.netMap = nil @@ -734,9 +732,7 @@ func (b *LocalBackend) SetPrefs(new *Prefs) { oldHi := b.hostinfo newHi := oldHi.Clone() newHi.RoutableIPs = append([]wgcfg.CIDR(nil), b.prefs.AdvertiseRoutes...) - if h := new.Hostname; h != "" { - newHi.Hostname = h - } + applyPrefsToHostinfo(newHi, new) b.hostinfo = newHi hostInfoChanged := !oldHi.Equal(newHi) b.mu.Unlock() @@ -943,6 +939,18 @@ func wgCIDRToNetaddr(cidrs []wgcfg.CIDR) (ret []netaddr.IPPrefix) { return ret } +func applyPrefsToHostinfo(hi *tailcfg.Hostinfo, prefs *Prefs) { + if h := prefs.Hostname; h != "" { + hi.Hostname = h + } + if v := prefs.OSVersion; v != "" { + hi.OSVersion = v + } + if m := prefs.DeviceModel; m != "" { + hi.DeviceModel = m + } +} + // enterState transitions the backend into newState, updating internal // state and propagating events out as needed. // diff --git a/ipn/prefs.go b/ipn/prefs.go index c10ffbdba..50759e1bd 100644 --- a/ipn/prefs.go +++ b/ipn/prefs.go @@ -54,6 +54,10 @@ type Prefs struct { // Hostname is the hostname to use for identifying the node. If // not set, os.Hostname is used. Hostname string + // OSVersion overrides tailcfg.Hostinfo's OSVersion. + OSVersion string + // DeviceModel overrides tailcfg.Hostinfo's DeviceModel. + DeviceModel string // NotepadURLs is a debugging setting that opens OAuth URLs in // notepad.exe on Windows, rather than loading them in a browser. @@ -138,6 +142,8 @@ func (p *Prefs) Equals(p2 *Prefs) bool { p.NoSNAT == p2.NoSNAT && p.NetfilterMode == p2.NetfilterMode && p.Hostname == p2.Hostname && + p.OSVersion == p2.OSVersion && + p.DeviceModel == p2.DeviceModel && compareIPNets(p.AdvertiseRoutes, p2.AdvertiseRoutes) && compareStrings(p.AdvertiseTags, p2.AdvertiseTags) && p.Persist.Equals(p2.Persist) diff --git a/ipn/prefs_test.go b/ipn/prefs_test.go index c869cfd4d..4f75095dc 100644 --- a/ipn/prefs_test.go +++ b/ipn/prefs_test.go @@ -24,7 +24,7 @@ func fieldsOf(t reflect.Type) (fields []string) { func TestPrefsEqual(t *testing.T) { tstest.PanicOnLog() - prefsHandles := []string{"ControlURL", "RouteAll", "AllowSingleHosts", "CorpDNS", "WantRunning", "ShieldsUp", "AdvertiseTags", "Hostname", "NotepadURLs", "DisableDERP", "AdvertiseRoutes", "NoSNAT", "NetfilterMode", "Persist"} + prefsHandles := []string{"ControlURL", "RouteAll", "AllowSingleHosts", "CorpDNS", "WantRunning", "ShieldsUp", "AdvertiseTags", "Hostname", "OSVersion", "DeviceModel", "NotepadURLs", "DisableDERP", "AdvertiseRoutes", "NoSNAT", "NetfilterMode", "Persist"} if have := fieldsOf(reflect.TypeOf(Prefs{})); !reflect.DeepEqual(have, prefsHandles) { t.Errorf("Prefs.Equal check might be out of sync\nfields: %q\nhandled: %q\n", have, prefsHandles)