wgengine/netstack: add env knob to turn on netstack debug logs

Except for the super verbose packet-level dumps. Keep those disabled
by default with a const.

Updates #2642

Change-Id: Ia9eae1677e8b3fe6f457a59e44896a335d95d547
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/3680/head
Brad Fitzpatrick 3 years ago committed by Brad Fitzpatrick
parent 8d0ed1c9ba
commit 1b426cc232

@ -12,6 +12,7 @@ import (
"io" "io"
"log" "log"
"net" "net"
"os"
"os/exec" "os/exec"
"runtime" "runtime"
"strconv" "strconv"
@ -45,7 +46,9 @@ import (
"tailscale.com/wgengine/magicsock" "tailscale.com/wgengine/magicsock"
) )
const debugNetstack = false const debugPackets = false
var debugNetstack, _ = strconv.ParseBool(os.Getenv("TS_DEBUG_NETSTACK"))
// Impl contains the state for the netstack implementation, // Impl contains the state for the netstack implementation,
// and implements wgengine.FakeImpl to act as a userspace network // and implements wgengine.FakeImpl to act as a userspace network
@ -356,7 +359,7 @@ func (ns *Impl) injectOutbound() {
full = append(full, hdrNetwork.View()...) full = append(full, hdrNetwork.View()...)
full = append(full, hdrTransport.View()...) full = append(full, hdrTransport.View()...)
full = append(full, pkt.Data().AsRange().AsView()...) full = append(full, pkt.Data().AsRange().AsView()...)
if debugNetstack { if debugPackets {
ns.logf("[v2] packet Write out: % x", full) ns.logf("[v2] packet Write out: % x", full)
} }
if err := ns.tundev.InjectOutbound(full); err != nil { if err := ns.tundev.InjectOutbound(full); err != nil {
@ -461,7 +464,7 @@ func (ns *Impl) injectInbound(p *packet.Parsed, t *tstun.Wrapper) filter.Respons
case 6: case 6:
pn = header.IPv6ProtocolNumber pn = header.IPv6ProtocolNumber
} }
if debugNetstack { if debugPackets {
ns.logf("[v2] packet in (from %v): % x", p.Src, p.Buffer()) ns.logf("[v2] packet in (from %v): % x", p.Src, p.Buffer())
} }
vv := buffer.View(append([]byte(nil), p.Buffer()...)).ToVectorisedView() vv := buffer.View(append([]byte(nil), p.Buffer()...)).ToVectorisedView()
@ -560,6 +563,9 @@ func (ns *Impl) forwardTCP(client *gonet.TCPConn, clientRemoteIP netaddr.IP, wq
go func() { go func() {
select { select {
case <-notifyCh: case <-notifyCh:
if debugNetstack {
ns.logf("[v2] netstack: forwardTCP notifyCh fired; canceling context for %s", dialAddrStr)
}
case <-done: case <-done:
} }
cancel() cancel()

Loading…
Cancel
Save