Skip to content

Commit

Permalink
tstest/natlab/vnet: flush and sync pcap file after every packet
Browse files Browse the repository at this point in the history
So that we can view the pcap as we debug interactively.

Updates tailscale#13038

Signed-off-by: Maisem Ali <maisem@tailscale.com>
  • Loading branch information
Maisem Ali authored and maisem committed Aug 24, 2024
1 parent 9783065 commit 31b5239
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tstest/natlab/vnet/pcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ type pcapWriter struct {
w *pcapgo.NgWriter
}

func do(fs ...func() error) error {
for _, f := range fs {
if err := f(); err != nil {
return err
}
}
return nil
}

func (p *pcapWriter) WritePacket(ci gopacket.CaptureInfo, data []byte) error {
if p == nil {
return nil
Expand All @@ -30,7 +39,11 @@ func (p *pcapWriter) WritePacket(ci gopacket.CaptureInfo, data []byte) error {
if p.w == nil {
return io.ErrClosedPipe
}
return p.w.WritePacket(ci, data)
return do(
func() error { return p.w.WritePacket(ci, data) },
p.w.Flush,
p.f.Sync,
)
}

func (p *pcapWriter) AddInterface(i pcapgo.NgInterface) (int, error) {
Expand Down

0 comments on commit 31b5239

Please sign in to comment.