mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-27 10:47:35 +00:00
derp: add a debug option to verbosely log drops to a destination.
Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
909c165382
commit
37c19970b3
@ -16,6 +16,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -24,6 +25,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go4.org/mem"
|
||||||
"golang.org/x/crypto/nacl/box"
|
"golang.org/x/crypto/nacl/box"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
"tailscale.com/disco"
|
"tailscale.com/disco"
|
||||||
@ -35,6 +37,25 @@ import (
|
|||||||
|
|
||||||
var debug, _ = strconv.ParseBool(os.Getenv("DERP_DEBUG_LOGS"))
|
var debug, _ = strconv.ParseBool(os.Getenv("DERP_DEBUG_LOGS"))
|
||||||
|
|
||||||
|
// verboseDropKeys is the set of destination public keys that should
|
||||||
|
// verbosely log whenever DERP drops a packet.
|
||||||
|
var verboseDropKeys = map[key.Public]bool{}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
keys := os.Getenv("TS_DEBUG_VERBOSE_DROPS")
|
||||||
|
if keys == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, keyStr := range strings.Split(keys, ",") {
|
||||||
|
k, err := key.NewPublicFromHexMem(mem.S(keyStr))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("ignoring invalid debug key %q: %v", keyStr, err)
|
||||||
|
} else {
|
||||||
|
verboseDropKeys[k] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
perClientSendQueueDepth = 32 // packets buffered for sending
|
perClientSendQueueDepth = 32 // packets buffered for sending
|
||||||
writeTimeout = 2 * time.Second
|
writeTimeout = 2 * time.Second
|
||||||
@ -53,14 +74,14 @@ type Server struct {
|
|||||||
// before failing when writing to a client.
|
// before failing when writing to a client.
|
||||||
WriteTimeout time.Duration
|
WriteTimeout time.Duration
|
||||||
|
|
||||||
privateKey key.Private
|
privateKey key.Private
|
||||||
publicKey key.Public
|
publicKey key.Public
|
||||||
logf logger.Logf
|
logf logger.Logf
|
||||||
memSys0 uint64 // runtime.MemStats.Sys at start (or early-ish)
|
memSys0 uint64 // runtime.MemStats.Sys at start (or early-ish)
|
||||||
meshKey string
|
meshKey string
|
||||||
|
limitedLogf logger.Logf
|
||||||
|
|
||||||
// Counters:
|
// Counters:
|
||||||
_ [pad32bit]byte
|
|
||||||
packetsSent, bytesSent expvar.Int
|
packetsSent, bytesSent expvar.Int
|
||||||
packetsRecv, bytesRecv expvar.Int
|
packetsRecv, bytesRecv expvar.Int
|
||||||
packetsRecvByKind metrics.LabelMap
|
packetsRecvByKind metrics.LabelMap
|
||||||
@ -141,6 +162,7 @@ func NewServer(privateKey key.Private, logf logger.Logf) *Server {
|
|||||||
privateKey: privateKey,
|
privateKey: privateKey,
|
||||||
publicKey: privateKey.Public(),
|
publicKey: privateKey.Public(),
|
||||||
logf: logf,
|
logf: logf,
|
||||||
|
limitedLogf: logger.RateLimitedFn(logf, 30*time.Second, 5, 100),
|
||||||
packetsRecvByKind: metrics.LabelMap{Label: "kind"},
|
packetsRecvByKind: metrics.LabelMap{Label: "kind"},
|
||||||
packetsDroppedReason: metrics.LabelMap{Label: "reason"},
|
packetsDroppedReason: metrics.LabelMap{Label: "reason"},
|
||||||
clients: map[key.Public]*sclient{},
|
clients: map[key.Public]*sclient{},
|
||||||
@ -624,6 +646,12 @@ func (c *sclient) sendPkt(dst *sclient, p pkt) error {
|
|||||||
case <-dst.sendQueue:
|
case <-dst.sendQueue:
|
||||||
s.packetsDropped.Add(1)
|
s.packetsDropped.Add(1)
|
||||||
s.packetsDroppedQueueHead.Add(1)
|
s.packetsDroppedQueueHead.Add(1)
|
||||||
|
if verboseDropKeys[dstKey] {
|
||||||
|
// Generate a full string including src and dst, so
|
||||||
|
// the limiter kicks in once per src.
|
||||||
|
msg := fmt.Sprintf("tail drop %s -> %s", p.src.ShortString(), dstKey.ShortString())
|
||||||
|
c.s.limitedLogf(msg)
|
||||||
|
}
|
||||||
if debug {
|
if debug {
|
||||||
c.logf("dropping packet from client %x queue head", dstKey)
|
c.logf("dropping packet from client %x queue head", dstKey)
|
||||||
}
|
}
|
||||||
@ -635,6 +663,12 @@ func (c *sclient) sendPkt(dst *sclient, p pkt) error {
|
|||||||
// this case to keep reader unblocked.
|
// this case to keep reader unblocked.
|
||||||
s.packetsDropped.Add(1)
|
s.packetsDropped.Add(1)
|
||||||
s.packetsDroppedQueueTail.Add(1)
|
s.packetsDroppedQueueTail.Add(1)
|
||||||
|
if verboseDropKeys[dstKey] {
|
||||||
|
// Generate a full string including src and dst, so
|
||||||
|
// the limiter kicks in once per src.
|
||||||
|
msg := fmt.Sprintf("head drop %s -> %s", p.src.ShortString(), dstKey.ShortString())
|
||||||
|
c.s.limitedLogf(msg)
|
||||||
|
}
|
||||||
if debug {
|
if debug {
|
||||||
c.logf("dropping packet from client %x queue tail", dstKey)
|
c.logf("dropping packet from client %x queue tail", dstKey)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user