From b663ab46858000e846459b0be5c35f0cdf96b70d Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 4 Jun 2020 08:26:05 -0700 Subject: [PATCH] cmd/derper: treat self-connection connection watch as no-op Updates #388 --- cmd/derper/derper.go | 2 +- derp/derp_server.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/derper/derper.go b/cmd/derper/derper.go index de63482fb..edbd68462 100644 --- a/cmd/derper/derper.go +++ b/cmd/derper/derper.go @@ -44,7 +44,7 @@ var ( logCollection = flag.String("logcollection", "", "If non-empty, logtail collection to log to") runSTUN = flag.Bool("stun", false, "also run a STUN server") meshPSKFile = flag.String("mesh-psk-file", defaultMeshPSKFile(), "if non-empty, path to file containing the mesh pre-shared key file. It should contain some hex string; whitespace is trimmed.") - meshWith = flag.String("mesh-with", "", "optional comma-separated list of hostnames to mesh with; the server's own hostname can be in the list, in which case it's ignored if its DNS resolves to an IP on the machine") + meshWith = flag.String("mesh-with", "", "optional comma-separated list of hostnames to mesh with; the server's own hostname can be in the list") ) type config struct { diff --git a/derp/derp_server.go b/derp/derp_server.go index a95a7702d..7fabf1013 100644 --- a/derp/derp_server.go +++ b/derp/derp_server.go @@ -259,6 +259,13 @@ func (s *Server) addWatcher(c *sclient) { panic("invariant: addWatcher called without permissions") } + if c.key == s.publicKey { + // We're connecting to ourself. Do nothing. + // TODO(bradfitz): have client notice and disconnect + // so an idle TCP connection isn't kept open. + return + } + s.mu.Lock() defer s.mu.Unlock()