From 90555c5cb2d6d60a129a0572213b2f74ec716149 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 10 Aug 2022 14:52:02 -0700 Subject: [PATCH] tailcfg, control/controlclient: add PingRequest.URLIsNoise [capver 38] Change-Id: I19bb63b6d99e96b2f9fd2c440afcc31d38137ded Signed-off-by: Brad Fitzpatrick --- control/controlclient/direct.go | 21 +++++++++++++++------ tailcfg/tailcfg.go | 7 ++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 1c9892a35..06346bebc 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -885,7 +885,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, readOnly bool if pr := resp.PingRequest; pr != nil && c.isUniquePingRequest(pr) { metricMapResponsePings.Add(1) - go answerPing(c.logf, c.httpc, pr, c.pinger) + go c.answerPing(pr) } if u := resp.PopBrowserURL; u != "" && u != sess.lastPopBrowserURL { sess.lastPopBrowserURL = u @@ -1203,21 +1203,30 @@ func (c *Direct) isUniquePingRequest(pr *tailcfg.PingRequest) bool { return true } -func answerPing(logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest, pinger Pinger) { +func (c *Direct) answerPing(pr *tailcfg.PingRequest) { + httpc := c.httpc + if pr.URLIsNoise { + nc, err := c.getNoiseClient() + if err != nil { + c.logf("failed to get noise client for ping request: %v", err) + return + } + httpc = nc.Client + } if pr.URL == "" { - logf("invalid PingRequest with no URL") + c.logf("invalid PingRequest with no URL") return } if pr.Types == "" { - answerHeadPing(logf, c, pr) + answerHeadPing(c.logf, httpc, pr) return } for _, t := range strings.Split(pr.Types, ",") { switch pt := tailcfg.PingType(t); pt { case tailcfg.PingTSMP, tailcfg.PingDisco, tailcfg.PingICMP, tailcfg.PingPeerAPI: - go doPingerPing(logf, c, pr, pinger, pt) + go doPingerPing(c.logf, httpc, pr, c.pinger, pt) default: - logf("unsupported ping request type: %q", t) + c.logf("unsupported ping request type: %q", t) } } } diff --git a/tailcfg/tailcfg.go b/tailcfg/tailcfg.go index ede343979..5d0f40f16 100644 --- a/tailcfg/tailcfg.go +++ b/tailcfg/tailcfg.go @@ -72,7 +72,8 @@ type CapabilityVersion int // 34: 2022-08-02: client understands CapabilityFileSharingTarget // 36: 2022-08-02: added PeersChangedPatch.{Key,DiscoKey,Online,LastSeen,KeyExpiry,Capabilities} // 37: 2022-08-09: added Debug.{SetForceBackgroundSTUN,SetRandomizeClientPort}; Debug are sticky -const CurrentCapabilityVersion CapabilityVersion = 37 +// 38: 2022-08-11: added PingRequest.URLIsNoise +const CurrentCapabilityVersion CapabilityVersion = 38 type StableID string @@ -1151,6 +1152,10 @@ type PingRequest struct { // If Types and IP are defined, then URL is the URL to send a POST request to. URL string + // URLIsNoise, if true, means that the client should hit URL over the Noise + // transport instead of TLS. + URLIsNoise bool `json:",omitempty"` + // Log is whether to log about this ping in the success case. // For failure cases, the client will log regardless. Log bool `json:",omitempty"`