tstest/natlab/vnet: flush and sync pcap file after every packet

So that we can view the pcap as we debug interactively.

Updates #13038

Signed-off-by: Maisem Ali <maisem@tailscale.com>
pull/13264/head
Maisem Ali 3 months ago committed by Maisem Ali
parent 978306565d
commit 31b5239a2f

@ -21,6 +21,15 @@ type pcapWriter struct {
w *pcapgo.NgWriter 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 { func (p *pcapWriter) WritePacket(ci gopacket.CaptureInfo, data []byte) error {
if p == nil { if p == nil {
return nil return nil
@ -30,7 +39,11 @@ func (p *pcapWriter) WritePacket(ci gopacket.CaptureInfo, data []byte) error {
if p.w == nil { if p.w == nil {
return io.ErrClosedPipe 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) { func (p *pcapWriter) AddInterface(i pcapgo.NgInterface) (int, error) {

Loading…
Cancel
Save