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

feat: add option to speedtest to dump a pcap of network traffic#11848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
feat: add option to speedtest to dump a pcap of network traffic
  • Loading branch information
@coadler
coadler committedJan 26, 2024
commit02d25def3c7b39d024904c36adfb5c8b3d1f3ada
23 changes: 23 additions & 0 deletionscli/speedtest.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,13 @@ package cli
import (
"context"
"fmt"
"os"
"time"

"github.com/jedib0t/go-pretty/v6/table"
"golang.org/x/xerrors"
tsspeedtest "tailscale.com/net/speedtest"
"tailscale.com/wgengine/capture"

"cdr.dev/slog"
"cdr.dev/slog/sloggers/sloghuman"
Expand All@@ -21,6 +23,7 @@ func (r *RootCmd) speedtest() *clibase.Cmd {
direct bool
duration time.Duration
direction string
pcapFile string
)
client := new(codersdk.Client)
cmd := &clibase.Cmd{
Expand DownExpand Up@@ -63,6 +66,7 @@ func (r *RootCmd) speedtest() *clibase.Cmd {
return err
}
defer conn.Close()

if direct {
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
Expand DownExpand Up@@ -95,6 +99,19 @@ func (r *RootCmd) speedtest() *clibase.Cmd {
} else {
conn.AwaitReachable(ctx)
}

if pcapFile != "" {
s := capture.New()
conn.InstallCaptureHook(s.LogPacket)
f, err := os.OpenFile(pcapFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer f.Close()
unregister := s.RegisterOutput(f)
defer unregister()
}

var tsDir tsspeedtest.Direction
switch direction {
case "up":
Expand DownExpand Up@@ -146,6 +163,12 @@ func (r *RootCmd) speedtest() *clibase.Cmd {
Default: tsspeedtest.DefaultDuration.String(),
Value: clibase.DurationOf(&duration),
},
{
Description: "Specifies a file to write a network capture to.",
Flag: "pcap-file",
Default: "",
Value: clibase.StringOf(&pcapFile),
},
}
return cmd
}
7 changes: 7 additions & 0 deletionstailnet/conn.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,6 +30,7 @@ import (
tslogger "tailscale.com/types/logger"
"tailscale.com/types/netlogtype"
"tailscale.com/wgengine"
"tailscale.com/wgengine/capture"
"tailscale.com/wgengine/magicsock"
"tailscale.com/wgengine/netstack"
"tailscale.com/wgengine/router"
Expand DownExpand Up@@ -310,6 +311,12 @@ type Conn struct {
trafficStats *connstats.Statistics
}

func (c *Conn) InstallCaptureHook(f capture.Callback) {
c.mutex.Lock()
defer c.mutex.Unlock()
c.wireguardEngine.InstallCaptureHook(f)
}

func (c *Conn) MagicsockSetDebugLoggingEnabled(enabled bool) {
c.magicConn.SetDebugLoggingEnabled(enabled)
}
Expand Down

[8]ページ先頭

©2009-2026 Movatter.jp