ebpf

package
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DirectionRequest  = "request"
	DirectionResponse = "response"
)
View Source
const (
	// DirectionUnset is a convenience value to specify an unset/removed direction field
	DirectionUnset = 0xFF
	// DirectionIngress and DirectionEgress values according to field 61 in https://www.iana.org/assignments/ipfix/ipfix.xhtml
	DirectionIngress = 0
	DirectionEgress  = 1

	// InitiatorSrc and InitiatorDst values set accordingly to flows_common.h definition
	InitiatorSrc = 1
	InitiatorDst = 2

	InterfaceUnset = 0xFFFFFFFF
)

Variables

This section is empty.

Functions

func LoadNet

func LoadNet() (*ebpf.CollectionSpec, error)

LoadNet returns the embedded CollectionSpec for Net.

func LoadNetObjects

func LoadNetObjects(obj interface{}, opts *ebpf.CollectionOptions) error

LoadNetObjects loads Net and converts it into a struct.

The following types are suitable as obj argument:

*NetObjects
*NetPrograms
*NetMaps

See ebpf.CollectionSpec.LoadAndAssign documentation for details.

func LoadNetSk added in v1.5.0

func LoadNetSk() (*ebpf.CollectionSpec, error)

LoadNetSk returns the embedded CollectionSpec for NetSk.

func LoadNetSkObjects added in v1.5.0

func LoadNetSkObjects(obj interface{}, opts *ebpf.CollectionOptions) error

LoadNetSkObjects loads NetSk and converts it into a struct.

The following types are suitable as obj argument:

*NetSkObjects
*NetSkPrograms
*NetSkMaps

See ebpf.CollectionSpec.LoadAndAssign documentation for details.

func RecordGetters added in v1.6.0

func RecordGetters(name attr.Name) (attributes.Getter[*Record, attribute.KeyValue], bool)

RecordGetters returns the attributes.Getter function that returns the string value of a given attribute name. nolint:cyclop

func RecordStringGetters added in v1.7.0

func RecordStringGetters(name attr.Name) (attributes.Getter[*Record, string], bool)

Types

type FlowFetcher

type FlowFetcher struct {
}

func NewFlowFetcher

func NewFlowFetcher(_, _ int, _, _ bool) (*FlowFetcher, error)

func (*FlowFetcher) Close

func (m *FlowFetcher) Close() error

func (*FlowFetcher) LookupAndDeleteMap

func (m *FlowFetcher) LookupAndDeleteMap() map[NetFlowId][]NetFlowMetrics

func (*FlowFetcher) ReadRingBuf

func (m *FlowFetcher) ReadRingBuf() (ringbuf.Record, error)

func (*FlowFetcher) Register

func (m *FlowFetcher) Register(_ ifaces.Interface) error

type IPAddr

type IPAddr [net.IPv6len]uint8

IPAddr encodes v4 and v6 IPs with a fixed length. IPv4 addresses are encoded as IPv6 addresses with prefix ::ffff/96 as described in https://datatracker.ietf.org/doc/html/rfc4038#section-4.2 (same behavior as Go's net.IP type)

func (*IPAddr) IP

func (ia *IPAddr) IP() net.IP

IP returns the net.IP equivalent object

func (*IPAddr) IntEncodeV4

func (ia *IPAddr) IntEncodeV4() uint32

IntEncodeV4 encodes an IPv4 address as an integer (in network encoding, big endian). It assumes that the passed IP is already IPv4. Otherwise it would just encode the last 4 bytes of an IPv6 address

func (*IPAddr) MarshalJSON

func (ia *IPAddr) MarshalJSON() ([]byte, error)

type NetConnInitiatorKey added in v1.7.0

type NetConnInitiatorKey struct {
	LowIp      struct{ In6U struct{ U6Addr8 [16]uint8 } }
	HighIp     struct{ In6U struct{ U6Addr8 [16]uint8 } }
	LowIpPort  uint16
	HighIpPort uint16
}

type NetFlowId

type NetFlowId NetFlowIdT

func (*NetFlowId) DstIP

func (fi *NetFlowId) DstIP() *IPAddr

DstIP is never null. Returned as pointer for efficiency.

func (*NetFlowId) SrcIP

func (fi *NetFlowId) SrcIP() *IPAddr

SrcIP is never null. Returned as pointer for efficiency.

type NetFlowIdT

type NetFlowIdT struct {
	SrcIp             struct{ In6U struct{ U6Addr8 [16]uint8 } }
	DstIp             struct{ In6U struct{ U6Addr8 [16]uint8 } }
	EthProtocol       uint16
	SrcPort           uint16
	DstPort           uint16
	TransportProtocol uint8
	IfIndex           uint32
}

type NetFlowMetrics

type NetFlowMetrics NetFlowMetricsT

func (*NetFlowMetrics) Accumulate

func (fm *NetFlowMetrics) Accumulate(src *NetFlowMetrics)

type NetFlowMetricsT

type NetFlowMetricsT struct {
	Packets         uint32
	Bytes           uint64
	StartMonoTimeNs uint64
	EndMonoTimeNs   uint64
	Flags           uint16
	IfaceDirection  uint8
	Initiator       uint8
	Errno           uint8
}

type NetFlowRecordT

type NetFlowRecordT struct {
	Id      NetFlowId
	Metrics NetFlowMetrics
}

func ReadFrom

func ReadFrom(reader io.Reader) (NetFlowRecordT, error)

ReadFrom reads a Record from a binary source, in LittleEndian order

type NetMapSpecs

type NetMapSpecs struct {
	AggregatedFlows *ebpf.MapSpec `ebpf:"aggregated_flows"`
	ConnInitiators  *ebpf.MapSpec `ebpf:"conn_initiators"`
	DirectFlows     *ebpf.MapSpec `ebpf:"direct_flows"`
	FlowDirections  *ebpf.MapSpec `ebpf:"flow_directions"`
}

NetMapSpecs contains maps before they are loaded into the kernel.

It can be passed ebpf.CollectionSpec.Assign.

type NetMaps

type NetMaps struct {
	AggregatedFlows *ebpf.Map `ebpf:"aggregated_flows"`
	ConnInitiators  *ebpf.Map `ebpf:"conn_initiators"`
	DirectFlows     *ebpf.Map `ebpf:"direct_flows"`
	FlowDirections  *ebpf.Map `ebpf:"flow_directions"`
}

NetMaps contains all maps after they have been loaded into the kernel.

It can be passed to LoadNetObjects or ebpf.CollectionSpec.LoadAndAssign.

func (*NetMaps) Close

func (m *NetMaps) Close() error

type NetObjects

type NetObjects struct {
	NetPrograms
	NetMaps
}

NetObjects contains all objects after they have been loaded into the kernel.

It can be passed to LoadNetObjects or ebpf.CollectionSpec.LoadAndAssign.

func (*NetObjects) Close

func (o *NetObjects) Close() error

type NetProgramSpecs

type NetProgramSpecs struct {
	EgressFlowParse  *ebpf.ProgramSpec `ebpf:"egress_flow_parse"`
	IngressFlowParse *ebpf.ProgramSpec `ebpf:"ingress_flow_parse"`
}

NetSpecs contains programs before they are loaded into the kernel.

It can be passed ebpf.CollectionSpec.Assign.

type NetPrograms

type NetPrograms struct {
	EgressFlowParse  *ebpf.Program `ebpf:"egress_flow_parse"`
	IngressFlowParse *ebpf.Program `ebpf:"ingress_flow_parse"`
}

NetPrograms contains all programs after they have been loaded into the kernel.

It can be passed to LoadNetObjects or ebpf.CollectionSpec.LoadAndAssign.

func (*NetPrograms) Close

func (p *NetPrograms) Close() error

type NetSkConnInitiatorKey added in v1.7.0

type NetSkConnInitiatorKey struct {
	LowIp      struct{ In6U struct{ U6Addr8 [16]uint8 } }
	HighIp     struct{ In6U struct{ U6Addr8 [16]uint8 } }
	LowIpPort  uint16
	HighIpPort uint16
}

type NetSkFlowId added in v1.5.0

type NetSkFlowId NetSkFlowIdT

type NetSkFlowIdT added in v1.5.0

type NetSkFlowIdT struct {
	SrcIp             struct{ In6U struct{ U6Addr8 [16]uint8 } }
	DstIp             struct{ In6U struct{ U6Addr8 [16]uint8 } }
	EthProtocol       uint16
	SrcPort           uint16
	DstPort           uint16
	TransportProtocol uint8
	IfIndex           uint32
}

type NetSkFlowMetrics added in v1.5.0

type NetSkFlowMetrics NetSkFlowMetricsT

type NetSkFlowMetricsT added in v1.5.0

type NetSkFlowMetricsT struct {
	Packets         uint32
	Bytes           uint64
	StartMonoTimeNs uint64
	EndMonoTimeNs   uint64
	Flags           uint16
	IfaceDirection  uint8
	Initiator       uint8
	Errno           uint8
}

type NetSkFlowRecordT added in v1.5.0

type NetSkFlowRecordT struct {
	Id      NetSkFlowId
	Metrics NetSkFlowMetrics
}

type NetSkMapSpecs added in v1.5.0

type NetSkMapSpecs struct {
	AggregatedFlows *ebpf.MapSpec `ebpf:"aggregated_flows"`
	ConnInitiators  *ebpf.MapSpec `ebpf:"conn_initiators"`
	DirectFlows     *ebpf.MapSpec `ebpf:"direct_flows"`
	FlowDirections  *ebpf.MapSpec `ebpf:"flow_directions"`
}

NetSkMapSpecs contains maps before they are loaded into the kernel.

It can be passed ebpf.CollectionSpec.Assign.

type NetSkMaps added in v1.5.0

type NetSkMaps struct {
	AggregatedFlows *ebpf.Map `ebpf:"aggregated_flows"`
	ConnInitiators  *ebpf.Map `ebpf:"conn_initiators"`
	DirectFlows     *ebpf.Map `ebpf:"direct_flows"`
	FlowDirections  *ebpf.Map `ebpf:"flow_directions"`
}

NetSkMaps contains all maps after they have been loaded into the kernel.

It can be passed to LoadNetSkObjects or ebpf.CollectionSpec.LoadAndAssign.

func (*NetSkMaps) Close added in v1.5.0

func (m *NetSkMaps) Close() error

type NetSkObjects added in v1.5.0

type NetSkObjects struct {
	NetSkPrograms
	NetSkMaps
}

NetSkObjects contains all objects after they have been loaded into the kernel.

It can be passed to LoadNetSkObjects or ebpf.CollectionSpec.LoadAndAssign.

func (*NetSkObjects) Close added in v1.5.0

func (o *NetSkObjects) Close() error

type NetSkProgramSpecs added in v1.5.0

type NetSkProgramSpecs struct {
	SocketHttpFilter *ebpf.ProgramSpec `ebpf:"socket__http_filter"`
}

NetSkSpecs contains programs before they are loaded into the kernel.

It can be passed ebpf.CollectionSpec.Assign.

type NetSkPrograms added in v1.5.0

type NetSkPrograms struct {
	SocketHttpFilter *ebpf.Program `ebpf:"socket__http_filter"`
}

NetSkPrograms contains all programs after they have been loaded into the kernel.

It can be passed to LoadNetSkObjects or ebpf.CollectionSpec.LoadAndAssign.

func (*NetSkPrograms) Close added in v1.5.0

func (p *NetSkPrograms) Close() error

type NetSkSpecs added in v1.5.0

type NetSkSpecs struct {
	NetSkProgramSpecs
	NetSkMapSpecs
}

NetSkSpecs contains maps and programs before they are loaded into the kernel.

It can be passed ebpf.CollectionSpec.Assign.

type NetSpecs

type NetSpecs struct {
	NetProgramSpecs
	NetMapSpecs
}

NetSpecs contains maps and programs before they are loaded into the kernel.

It can be passed ebpf.CollectionSpec.Assign.

type Record

type Record struct {
	NetFlowRecordT

	// Attrs of the flow record: source/destination, Interface, Beyla IP, etc...
	Attrs RecordAttrs
}

Record contains accumulated metrics from a flow, with extra metadata that is added from the user space REMINDER: any attribute here must be also added to the functions RecordGetters and getDefinitions in pkg/internal/export/metric/definitions.go

func NewRecord

func NewRecord(
	key NetFlowId,
	metrics NetFlowMetrics,
) *Record

type RecordAttrs added in v1.4.0

type RecordAttrs struct {
	// SrcName and DstName might be set from several sources along the processing/decoration pipeline:
	// - K8s entity
	// - Host name
	// - IP
	SrcName string
	DstName string

	Interface string
	// BeylaIP provides information about the source of the flow (the Agent that traced it)
	BeylaIP  string
	Metadata map[attr.Name]string
}

type SockFlowFetcher added in v1.5.0

type SockFlowFetcher struct{}

func NewSockFlowFetcher added in v1.5.0

func NewSockFlowFetcher(_, _ int) (*SockFlowFetcher, error)

func (*SockFlowFetcher) Close added in v1.5.0

func (s *SockFlowFetcher) Close() error

func (*SockFlowFetcher) LookupAndDeleteMap added in v1.5.0

func (s *SockFlowFetcher) LookupAndDeleteMap() map[NetFlowId][]NetFlowMetrics

func (*SockFlowFetcher) ReadRingBuf added in v1.5.0

func (s *SockFlowFetcher) ReadRingBuf() (ringbuf.Record, error)

func (*SockFlowFetcher) Register added in v1.5.0

func (s *SockFlowFetcher) Register(_ ifaces.Interface) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL