github.com/cilium/cilium@v1.16.2/pkg/monitor/datapath_recorder.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package monitor
     5  
     6  import (
     7  	"bufio"
     8  	"fmt"
     9  	"os"
    10  )
    11  
    12  const (
    13  	// RecorderCaptureLen is the amount of data in the RecorderCapture message
    14  	RecorderCaptureLen = 24
    15  )
    16  
    17  // RecorderCapture is the message format of a pcap capture in the bpf ring buffer
    18  type RecorderCapture struct {
    19  	Type     uint8
    20  	SubType  uint8
    21  	RuleID   uint16
    22  	Reserved uint32
    23  	TimeBoot uint64
    24  	CapLen   uint32
    25  	Len      uint32
    26  	// data
    27  }
    28  
    29  // DumpInfo prints a summary of the recorder notify messages.
    30  func (n *RecorderCapture) DumpInfo(data []byte) {
    31  	buf := bufio.NewWriter(os.Stdout)
    32  	dir := "egress"
    33  	if n.SubType == 1 {
    34  		dir = "ingress"
    35  	}
    36  	fmt.Fprintf(buf, "Recorder capture: dir:%s rule:%d ts:%d caplen:%d len:%d\n",
    37  		dir, int(n.RuleID), int(n.TimeBoot), int(n.CapLen), int(n.Len))
    38  	buf.Flush()
    39  	Dissect(true, data[RecorderCaptureLen:])
    40  	fmt.Fprintf(buf, "----\n")
    41  	buf.Flush()
    42  }