Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc14e92

Browse files
authored
feat: add option to speedtest to dump a pcap of network traffic (#11848)
1 parentb2bc3ff commitbc14e92

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

‎cli/speedtest.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package cli
33
import (
44
"context"
55
"fmt"
6+
"os"
67
"time"
78

89
"github.com/jedib0t/go-pretty/v6/table"
910
"golang.org/x/xerrors"
1011
tsspeedtest"tailscale.com/net/speedtest"
12+
"tailscale.com/wgengine/capture"
1113

1214
"cdr.dev/slog"
1315
"cdr.dev/slog/sloggers/sloghuman"
@@ -21,6 +23,7 @@ func (r *RootCmd) speedtest() *clibase.Cmd {
2123
directbool
2224
duration time.Duration
2325
directionstring
26+
pcapFilestring
2427
)
2528
client:=new(codersdk.Client)
2629
cmd:=&clibase.Cmd{
@@ -63,6 +66,7 @@ func (r *RootCmd) speedtest() *clibase.Cmd {
6366
returnerr
6467
}
6568
deferconn.Close()
69+
6670
ifdirect {
6771
ticker:=time.NewTicker(time.Second)
6872
deferticker.Stop()
@@ -95,6 +99,19 @@ func (r *RootCmd) speedtest() *clibase.Cmd {
9599
}else {
96100
conn.AwaitReachable(ctx)
97101
}
102+
103+
ifpcapFile!="" {
104+
s:=capture.New()
105+
conn.InstallCaptureHook(s.LogPacket)
106+
f,err:=os.OpenFile(pcapFile,os.O_WRONLY|os.O_CREATE|os.O_TRUNC,0o644)
107+
iferr!=nil {
108+
returnerr
109+
}
110+
deferf.Close()
111+
unregister:=s.RegisterOutput(f)
112+
deferunregister()
113+
}
114+
98115
vartsDir tsspeedtest.Direction
99116
switchdirection {
100117
case"up":
@@ -146,6 +163,12 @@ func (r *RootCmd) speedtest() *clibase.Cmd {
146163
Default:tsspeedtest.DefaultDuration.String(),
147164
Value:clibase.DurationOf(&duration),
148165
},
166+
{
167+
Description:"Specifies a file to write a network capture to.",
168+
Flag:"pcap-file",
169+
Default:"",
170+
Value:clibase.StringOf(&pcapFile),
171+
},
149172
}
150173
returncmd
151174
}

‎cli/testdata/coder_speedtest_--help.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ OPTIONS:
1414
Specifies whether to run in reverse mode where the client receives and
1515
the server sends.
1616

17+
--pcap-file string
18+
Specifies a file to write a network capture to.
19+
1720
-t, --time duration (default: 5s)
1821
Specifies the duration to monitor traffic.
1922

‎docs/cli/speedtest.md

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎tailnet/conn.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
tslogger"tailscale.com/types/logger"
3131
"tailscale.com/types/netlogtype"
3232
"tailscale.com/wgengine"
33+
"tailscale.com/wgengine/capture"
3334
"tailscale.com/wgengine/magicsock"
3435
"tailscale.com/wgengine/netstack"
3536
"tailscale.com/wgengine/router"
@@ -310,6 +311,12 @@ type Conn struct {
310311
trafficStats*connstats.Statistics
311312
}
312313

314+
func (c*Conn)InstallCaptureHook(f capture.Callback) {
315+
c.mutex.Lock()
316+
deferc.mutex.Unlock()
317+
c.wireguardEngine.InstallCaptureHook(f)
318+
}
319+
313320
func (c*Conn)MagicsockSetDebugLoggingEnabled(enabledbool) {
314321
c.magicConn.SetDebugLoggingEnabled(enabled)
315322
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp