Skip to content

Commit 1b426cc

Browse files
committed
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 tailscale#2642 Change-Id: Ia9eae1677e8b3fe6f457a59e44896a335d95d547 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
1 parent 8d0ed1c commit 1b426cc

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

wgengine/netstack/netstack.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"io"
1313
"log"
1414
"net"
15+
"os"
1516
"os/exec"
1617
"runtime"
1718
"strconv"
@@ -45,7 +46,9 @@ import (
4546
"tailscale.com/wgengine/magicsock"
4647
)
4748

48-
const debugNetstack = false
49+
const debugPackets = false
50+
51+
var debugNetstack, _ = strconv.ParseBool(os.Getenv("TS_DEBUG_NETSTACK"))
4952

5053
// Impl contains the state for the netstack implementation,
5154
// and implements wgengine.FakeImpl to act as a userspace network
@@ -356,7 +359,7 @@ func (ns *Impl) injectOutbound() {
356359
full = append(full, hdrNetwork.View()...)
357360
full = append(full, hdrTransport.View()...)
358361
full = append(full, pkt.Data().AsRange().AsView()...)
359-
if debugNetstack {
362+
if debugPackets {
360363
ns.logf("[v2] packet Write out: % x", full)
361364
}
362365
if err := ns.tundev.InjectOutbound(full); err != nil {
@@ -461,7 +464,7 @@ func (ns *Impl) injectInbound(p *packet.Parsed, t *tstun.Wrapper) filter.Respons
461464
case 6:
462465
pn = header.IPv6ProtocolNumber
463466
}
464-
if debugNetstack {
467+
if debugPackets {
465468
ns.logf("[v2] packet in (from %v): % x", p.Src, p.Buffer())
466469
}
467470
vv := buffer.View(append([]byte(nil), p.Buffer()...)).ToVectorisedView()
@@ -560,6 +563,9 @@ func (ns *Impl) forwardTCP(client *gonet.TCPConn, clientRemoteIP netaddr.IP, wq
560563
go func() {
561564
select {
562565
case <-notifyCh:
566+
if debugNetstack {
567+
ns.logf("[v2] netstack: forwardTCP notifyCh fired; canceling context for %s", dialAddrStr)
568+
}
563569
case <-done:
564570
}
565571
cancel()

0 commit comments

Comments
 (0)