mirror of
https://github.com/tailscale/tailscale.git
synced 2025-06-07 16:28:37 +00:00
tailcfg, control/controlclient: clarify more, enforce PingRequest.URL is unique
Updates #2079 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
c61d777705
commit
333e9e75d4
@ -80,6 +80,7 @@ type Direct struct {
|
|||||||
endpoints []tailcfg.Endpoint
|
endpoints []tailcfg.Endpoint
|
||||||
everEndpoints bool // whether we've ever had non-empty endpoints
|
everEndpoints bool // whether we've ever had non-empty endpoints
|
||||||
localPort uint16 // or zero to mean auto
|
localPort uint16 // or zero to mean auto
|
||||||
|
lastPingURL string // last PingRequest.URL received, for dup suppresion
|
||||||
}
|
}
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
@ -775,7 +776,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, cb func(*netm
|
|||||||
health.GotStreamedMapResponse()
|
health.GotStreamedMapResponse()
|
||||||
}
|
}
|
||||||
|
|
||||||
if pr := resp.PingRequest; pr != nil {
|
if pr := resp.PingRequest; pr != nil && c.isUniquePingRequest(pr) {
|
||||||
go answerPing(c.logf, c.httpc, pr)
|
go answerPing(c.logf, c.httpc, pr)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1170,6 +1171,23 @@ func ipForwardingBroken(routes []netaddr.IPPrefix, state *interfaces.State) bool
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isUniquePingRequest reports whether pr contains a new PingRequest.URL
|
||||||
|
// not already handled, noting its value when returning true.
|
||||||
|
func (c *Direct) isUniquePingRequest(pr *tailcfg.PingRequest) bool {
|
||||||
|
if pr == nil || pr.URL == "" {
|
||||||
|
// Bogus.
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
if pr.URL == c.lastPingURL {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
c.lastPingURL = pr.URL
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func answerPing(logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest) {
|
func answerPing(logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest) {
|
||||||
if pr.URL == "" {
|
if pr.URL == "" {
|
||||||
logf("invalid PingRequest with no URL")
|
logf("invalid PingRequest with no URL")
|
||||||
|
@ -880,6 +880,9 @@ type DNSConfig struct {
|
|||||||
type PingRequest struct {
|
type PingRequest struct {
|
||||||
// URL is the URL to send a HEAD request to.
|
// URL is the URL to send a HEAD request to.
|
||||||
// It will be a unique URL each time. No auth headers are necessary.
|
// It will be a unique URL each time. No auth headers are necessary.
|
||||||
|
//
|
||||||
|
// If the client sees multiple PingRequests with the same URL,
|
||||||
|
// subsequent ones should be ignored.
|
||||||
URL string
|
URL string
|
||||||
|
|
||||||
// Log is whether to log about this ping in the success case.
|
// Log is whether to log about this ping in the success case.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user