mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Consolidate sniffer program logic
Avoid action at a distance where both `snifferArgs` and `snifferProg` must stay in sync. PiperOrigin-RevId: 346341231
This commit is contained in:
committed by
gVisor bot
parent
9c198e5df4
commit
5ea6419478
@@ -265,12 +265,36 @@ func TestWithDUT(ctx context.Context, t *testing.T, mkDevice func(*dockerutil.Co
|
||||
t.Fatalf("failed to marshal %v into json: %s", dutTestNets, err)
|
||||
}
|
||||
|
||||
snifferProg := "tcpdump"
|
||||
baseSnifferArgs := []string{
|
||||
"tcpdump",
|
||||
"-vvv",
|
||||
"--absolute-tcp-sequence-numbers",
|
||||
"--packet-buffered",
|
||||
// Disable DNS resolution.
|
||||
"-n",
|
||||
}
|
||||
if tshark {
|
||||
snifferProg = "tshark"
|
||||
baseSnifferArgs = []string{
|
||||
"tshark",
|
||||
"-V",
|
||||
"-o", "tcp.check_checksum:TRUE",
|
||||
"-o", "udp.check_checksum:TRUE",
|
||||
// Disable buffering.
|
||||
"-l",
|
||||
// Disable DNS resolution.
|
||||
"-n",
|
||||
}
|
||||
}
|
||||
for _, n := range dutTestNets {
|
||||
_, err := testbenchContainer.ExecProcess(ctx, dockerutil.ExecOpts{}, snifferArgs(n.LocalDevName)...)
|
||||
snifferArgs := append(baseSnifferArgs, "-i", n.LocalDevName)
|
||||
if !tshark {
|
||||
snifferArgs = append(
|
||||
snifferArgs,
|
||||
"-w",
|
||||
filepath.Join(testOutputDir, fmt.Sprintf("%s.pcap", n.LocalDevName)),
|
||||
)
|
||||
}
|
||||
_, err := testbenchContainer.ExecProcess(ctx, dockerutil.ExecOpts{}, snifferArgs...)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to start exec a sniffer on %s: %s", n.LocalDevName, err)
|
||||
}
|
||||
@@ -292,7 +316,7 @@ func TestWithDUT(ctx context.Context, t *testing.T, mkDevice func(*dockerutil.Co
|
||||
// any packets. On linux tests killing it immediately can
|
||||
// sometimes result in partial pcaps.
|
||||
time.Sleep(1 * time.Second)
|
||||
if logs, err := testbenchContainer.Exec(ctx, dockerutil.ExecOpts{}, "killall", snifferProg); err != nil {
|
||||
if logs, err := testbenchContainer.Exec(ctx, dockerutil.ExecOpts{}, "killall", baseSnifferArgs[0]); err != nil {
|
||||
t.Errorf("failed to kill all sniffers: %s, logs: %s", err, logs)
|
||||
}
|
||||
})
|
||||
@@ -549,24 +573,3 @@ func mountTempDirectory(t *testing.T, runOpts *dockerutil.RunOpts, hostDirTempla
|
||||
})
|
||||
return tmpDir, nil
|
||||
}
|
||||
|
||||
// snifferArgs returns the correct command line to run sniffer on the testbench.
|
||||
func snifferArgs(devName string) []string {
|
||||
if tshark {
|
||||
// Run tshark in the test bench unbuffered, without DNS resolution, just
|
||||
// on the interface with the test packets.
|
||||
return []string{
|
||||
"tshark", "-V", "-l", "-n", "-i", devName,
|
||||
"-o", "tcp.check_checksum:TRUE",
|
||||
"-o", "udp.check_checksum:TRUE",
|
||||
}
|
||||
}
|
||||
// Run tcpdump in the test bench unbuffered, without DNS resolution, just
|
||||
// on the interface with the test packets.
|
||||
return []string{
|
||||
"tcpdump",
|
||||
"-S", "-vvv", "-U", "-n",
|
||||
"-i", devName,
|
||||
"-w", filepath.Join(testOutputDir, fmt.Sprintf("%s.pcap", devName)),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user