From 3739cf22b0eb400898cc092daa15fcb5b88bc0ea Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 18 Apr 2021 20:48:24 -0700 Subject: [PATCH] tailcfg, control/controlclient: allow empty MapResponse.Domain (mapver17) Signed-off-by: Brad Fitzpatrick --- control/controlclient/map.go | 6 +++++- control/controlclient/map_test.go | 20 ++++++++++++++++++++ tailcfg/tailcfg.go | 6 ++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/control/controlclient/map.go b/control/controlclient/map.go index 06205c640..e24954290 100644 --- a/control/controlclient/map.go +++ b/control/controlclient/map.go @@ -38,6 +38,7 @@ type mapSession struct { lastParsedPacketFilter []filter.Match collectServices bool previousPeers []*tailcfg.Node // for delta-purposes + lastDomain string // netMapBuilding is non-nil during a netmapForResponse call, // containing the value to be returned, once fully populated. @@ -96,6 +97,9 @@ func (ms *mapSession) netmapForResponse(resp *tailcfg.MapResponse) *netmap.Netwo if v, ok := resp.CollectServices.Get(); ok { ms.collectServices = v } + if resp.Domain != "" { + ms.lastDomain = resp.Domain + } nm := &netmap.NetworkMap{ SelfNode: resp.Node, @@ -108,7 +112,7 @@ func (ms *mapSession) netmapForResponse(resp *tailcfg.MapResponse) *netmap.Netwo Peers: resp.Peers, User: resp.Node.User, UserProfiles: make(map[tailcfg.UserID]tailcfg.UserProfile), - Domain: resp.Domain, + Domain: ms.lastDomain, DNS: *ms.lastDNSConfig, Hostinfo: resp.Node.Hostinfo, PacketFilter: ms.lastParsedPacketFilter, diff --git a/control/controlclient/map_test.go b/control/controlclient/map_test.go index a0abc8989..81c74ab18 100644 --- a/control/controlclient/map_test.go +++ b/control/controlclient/map_test.go @@ -256,4 +256,24 @@ func TestNetmapForResponse(t *testing.T) { }) wantCollect(true) }) + t.Run("implicit_domain", func(t *testing.T) { + ms := newTestMapSession(t) + var nm *netmap.NetworkMap + want := func(v string) { + t.Helper() + if nm.Domain != v { + t.Errorf("netmap.Domain = %q; want %q", nm.Domain, v) + } + } + nm = ms.netmapForResponse(&tailcfg.MapResponse{ + Node: new(tailcfg.Node), + Domain: "foo.com", + }) + want("foo.com") + + nm = ms.netmapForResponse(&tailcfg.MapResponse{ + Node: new(tailcfg.Node), + }) + want("foo.com") + }) } diff --git a/tailcfg/tailcfg.go b/tailcfg/tailcfg.go index dfd44fe0f..29ddc1b7b 100644 --- a/tailcfg/tailcfg.go +++ b/tailcfg/tailcfg.go @@ -39,7 +39,8 @@ // 14: 2021-04-07: client understands DNSConfig.Routes and DNSConfig.Resolvers // 15: 2021-04-12: client treats nil MapResponse.DNSConfig as meaning unchanged // 16: 2021-04-15: client understands Node.Online, MapResponse.OnlineChange -const CurrentMapRequestVersion = 16 +// 17: 2021-04-18: MapResponse.Domain empty means unchanged +const CurrentMapRequestVersion = 17 type StableID string @@ -939,7 +940,8 @@ type MapResponse struct { // "foo@gmail.com" (for siloed users on shared email // providers). Its exact form should not be depended on; new // forms are coming later. - Domain string + // If empty, the value is unchanged. + Domain string `json:",omitempty"` // CollectServices reports whether this node's Tailnet has // requested that info about services be included in HostInfo.