bpf

package
v0.0.0-...-a5bca4c Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2017 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DBG_CAPTURE_UNSPEC = iota
	DBG_CAPTURE_FROM_LXC
	DBG_CAPTURE_FROM_NETDEV
	DBG_CAPTURE_FROM_OVERLAY
	DBG_CAPTURE_DELIVERY
	DBG_CAPTURE_FROM_LB
	DBG_CAPTURE_AFTER_V46
	DBG_CAPTURE_AFTER_V64
)
View Source
const (
	DBG_UNSPEC = iota
	DBG_GENERIC
	DBG_LOCAL_DELIVERY
	DBG_ENCAP
	DBG_LXC_FOUND
	DBG_POLICY_DENIED
	DBG_CT_LOOKUP
	DBG_CT_MATCH
	DBG_CT_CREATED
	DBG_CT_CREATED2
	DBG_ICMP6_HANDLE
	DBG_ICMP6_REQUEST
	DBG_ICMP6_NS
	DBG_ICMP6_TIME_EXCEEDED
	DBG_CT_VERDICT
	DBG_DECAP
	DBG_PORT_MAP
	DBG_ERROR_RET
	DBG_TO_HOST
	DBG_TO_STACK
	DBG_PKT_HASH
	DBG_LB6_LOOKUP_MASTER
	DBG_LB6_LOOKUP_MASTER_FAIL
	DBG_LB6_LOOKUP_SLAVE
	DBG_LB6_LOOKUP_SLAVE_SUCCESS
	DBG_LB6_REVERSE_NAT_LOOKUP
	DBG_LB6_REVERSE_NAT
	DBG_LB4_LOOKUP_MASTER
	DBG_LB4_LOOKUP_MASTER_FAIL
	DBG_LB4_LOOKUP_SLAVE
	DBG_LB4_LOOKUP_SLAVE_SUCCESS
	DBG_LB4_REVERSE_NAT_LOOKUP
	DBG_LB4_REVERSE_NAT
	DBG_LB4_LOOPBACK_SNAT
	DBG_LB4_LOOPBACK_SNAT_REV
	DBG_CT_LOOKUP4
)
View Source
const (
	CT_NEW int = iota
	CT_ESTABLISHED
	CT_REPLY
	CT_RELATED
)

must be in sync with <bpf/lib/conntrack.h>

View Source
const (
	CILIUM_NOTIFY_UNSPEC = iota
	CILIUM_NOTIFY_DROP
	CILIUM_DBG_MSG
	CILIUM_DBG_CAPTURE
)

Must be synchronized with <bpf/lib/common.h>

View Source
const (
	EventsMapName   = "cilium_events"
	MAX_POLL_EVENTS = 32

	PERF_TYPE_HARDWARE   = 0
	PERF_TYPE_SOFTWARE   = 1
	PERF_TYPE_TRACEPOINT = 2
	PERF_TYPE_HW_CACHE   = 3
	PERF_TYPE_RAW        = 4
	PERF_TYPE_BREAKPOINT = 5

	PERF_SAMPLE_IP           = 1 << 0
	PERF_SAMPLE_TID          = 1 << 1
	PERF_SAMPLE_TIME         = 1 << 2
	PERF_SAMPLE_ADDR         = 1 << 3
	PERF_SAMPLE_READ         = 1 << 4
	PERF_SAMPLE_CALLCHAIN    = 1 << 5
	PERF_SAMPLE_ID           = 1 << 6
	PERF_SAMPLE_CPU          = 1 << 7
	PERF_SAMPLE_PERIOD       = 1 << 8
	PERF_SAMPLE_STREAM_ID    = 1 << 9
	PERF_SAMPLE_RAW          = 1 << 10
	PERF_SAMPLE_BRANCH_STACK = 1 << 11
	PERF_SAMPLE_REGS_USER    = 1 << 12
	PERF_SAMPLE_STACK_USER   = 1 << 13
	PERF_SAMPLE_WEIGHT       = 1 << 14
	PERF_SAMPLE_DATA_SRC     = 1 << 15
	PERF_SAMPLE_IDENTIFIER   = 1 << 16
	PERF_SAMPLE_TRANSACTION  = 1 << 17
	PERF_SAMPLE_REGS_INTR    = 1 << 18

	PERF_COUNT_SW_BPF_OUTPUT = 10
)
View Source
const (
	DebugCaptureLen = 20
)
View Source
const (
	DropNotifyLen = 32
)

Variables

This section is empty.

Functions

func CreateMap

func CreateMap(mapType int, keySize, valueSize, maxEntries uint32) (int, error)

CreateMap creates a Map of type mapType, with key size keySize, a value size of valueSize and the maximum amount of entries of maxEntries. mapType should be one of the bpf_map_type in "uapi/linux/bpf.h"

func CtInfo

func CtInfo(arg1 uint32, arg2 uint32) string

func CtState

func CtState(state int32) string

func DeleteElement

func DeleteElement(fd int, key unsafe.Pointer) error

DeleteElement deletes the map element with the given key.

func Dissect

func Dissect(dissect bool, data []byte)

func DropReason

func DropReason(reason uint8) string

func GetMapPrefix

func GetMapPrefix() string

func GetMapRoot

func GetMapRoot() string

func GetNextKey

func GetNextKey(fd int, key, nextKey unsafe.Pointer) error

GetNextKey stores, in nextKey, the next key after the key of the map in fd.

func LookupElement

func LookupElement(fd int, key, value unsafe.Pointer) error

LookupElement looks up for the map value stored in fd with the given key. The value is stored in the value unsafe.Pointer.

func MapPath

func MapPath(name string) string

func MapPrefixPath

func MapPrefixPath() string

func MountFS

func MountFS() error

func ObjGet

func ObjGet(pathname string) (int, error)

ObjGet reads the pathname and returns the map's fd read.

func ObjPin

func ObjPin(fd int, pathname string) error

ObjPin stores the map's fd in pathname.

func OpenOrCreateMap

func OpenOrCreateMap(path string, mapType int, keySize, valueSize, maxEntries uint32) (int, bool, error)

func SetMapPrefix

func SetMapPrefix(path string)

func SetMapRoot

func SetMapRoot(path string)

func UpdateElement

func UpdateElement(fd int, key, value unsafe.Pointer, flags uint64) error

UpdateElement updates the map in fd with the given value in the given key. The flags can have the following values (if you include "uapi/linux/bpf.h"): C.BPF_ANY to create new element or update existing; C.BPF_NOEXIST to create new element if it didn't exist; C.BPF_EXIST to update existing element.

Types

type DebugCapture

type DebugCapture struct {
	Type    uint8
	SubType uint8
	Source  uint16
	Hash    uint32
	Len     uint32
	OrigLen uint32
	Arg1    uint32
}

func (*DebugCapture) Dump

func (n *DebugCapture) Dump(dissect bool, data []byte, prefix string)

type DebugMsg

type DebugMsg struct {
	Type    uint8
	SubType uint8
	Source  uint16
	Hash    uint32
	Arg1    uint32
	Arg2    uint32
}

func (*DebugMsg) Dump

func (n *DebugMsg) Dump(data []byte, prefix string)

type DropNotify

type DropNotify struct {
	Type     uint8
	SubType  uint8
	Source   uint16
	Hash     uint32
	OrigLen  uint32
	CapLen   uint32
	SrcLabel uint32
	DstLabel uint32
	DstID    uint32
	Ifindex  uint32
}

func (*DropNotify) Dump

func (n *DropNotify) Dump(dissect bool, data []byte, prefix string)

type DumpCallback

type DumpCallback func(key MapKey, value MapValue)

type DumpParser

type DumpParser func(key []byte, value []byte) (MapKey, MapValue, error)

type EPoll

type EPoll struct {
	// contains filtered or unexported fields
}

func (*EPoll) AddFD

func (ep *EPoll) AddFD(fd int, events uint32) error

func (*EPoll) Close

func (ep *EPoll) Close()

func (*EPoll) Poll

func (ep *EPoll) Poll(timeout int) (int, error)

type EventMap

type EventMap struct {
	// contains filtered or unexported fields
}

func (*EventMap) Close

func (e *EventMap) Close()

func (*EventMap) Update

func (e *EventMap) Update(ev *PerfEvent) error

type LostFunc

type LostFunc func(msg *PerfEventLost, cpu int)

type Map

type Map struct {
	MapInfo
	// contains filtered or unexported fields
}

func NewMap

func NewMap(name string, mapType MapType, keySize int, valueSize int, maxEntries int) *Map

func OpenMap

func OpenMap(name string) (*Map, error)

func (*Map) Close

func (m *Map) Close() error

func (*Map) DeepCopy

func (m *Map) DeepCopy() *Map

func (*Map) Delete

func (m *Map) Delete(key MapKey) error

func (*Map) DeleteAll

func (m *Map) DeleteAll() error

Delete all entries of a map by traversing the map and deleting individual entries. Note that if entries are added while the taversal is in progress, such entries may survive the deletion process.

func (*Map) Dump

func (m *Map) Dump(parser DumpParser, cb DumpCallback) error

func (*Map) GetFd

func (m *Map) GetFd() int

func (*Map) Lookup

func (m *Map) Lookup(key MapKey) (MapValue, error)

func (*Map) Open

func (m *Map) Open() error

func (*Map) OpenOrCreate

func (m *Map) OpenOrCreate() (bool, error)

func (*Map) Update

func (m *Map) Update(key MapKey, value MapValue) error

type MapInfo

type MapInfo struct {
	MapType    MapType
	KeySize    uint32
	ValueSize  uint32
	MaxEntries uint32
	Flags      uint32
}

func GetMapInfo

func GetMapInfo(pid int, fd int) (*MapInfo, error)

type MapKey

type MapKey interface {
	// Returns pointer to start of key
	GetKeyPtr() unsafe.Pointer

	// Allocates a new value matching the key type
	NewValue() MapValue
}

type MapType

type MapType int
const (
	MapTypeUnspec MapType = iota
	MapTypeHash
	MapTypeArray
	MapTypeProgArray
	MapTypePerfEventArray
	MapTypePerCPUHash
	MapTypePerCPUArray
	MapTypeStackTrace
	MapTypeCgroupArray
	MapTypeLRUHash
	MapTypeLRUPerCPUHash
	MapTypeLPMTrie
)

This enumeration must be in sync with <linux/bpf.h>

func (MapType) String

func (t MapType) String() string

type MapValue

type MapValue interface {
	// Returns pointer to start of value
	GetValuePtr() unsafe.Pointer
}

type PerCpuEvents

type PerCpuEvents struct {
	Cpus     int
	Npages   int
	Pagesize int
	// contains filtered or unexported fields
}

func NewPerCpuEvents

func NewPerCpuEvents(config *PerfEventConfig) (*PerCpuEvents, error)

func (*PerCpuEvents) CloseAll

func (e *PerCpuEvents) CloseAll() error

func (*PerCpuEvents) Poll

func (e *PerCpuEvents) Poll(timeout int) (int, error)

func (*PerCpuEvents) ReadAll

func (e *PerCpuEvents) ReadAll(receive ReceiveFunc, lost LostFunc) error

func (*PerCpuEvents) Stats

func (e *PerCpuEvents) Stats() (uint64, uint64)

type PerfEvent

type PerfEvent struct {
	Fd int
	// contains filtered or unexported fields
}

func PerfEventOpen

func PerfEventOpen(config *PerfEventConfig, pid int, cpu int, groupFD int, flags int) (*PerfEvent, error)

func (*PerfEvent) Close

func (e *PerfEvent) Close()

func (*PerfEvent) Disable

func (e *PerfEvent) Disable() error

func (*PerfEvent) Enable

func (e *PerfEvent) Enable() error

func (*PerfEvent) Mmap

func (e *PerfEvent) Mmap(pagesize int, npages int) error

func (*PerfEvent) Read

func (e *PerfEvent) Read(receive ReceiveFunc, lostFn LostFunc) error

type PerfEventConfig

type PerfEventConfig struct {
	NumCpus      int
	NumPages     int
	MapName      string
	Type         int
	Config       int
	SampleType   int
	WakeupEvents int
}

func DefaultPerfEventConfig

func DefaultPerfEventConfig() *PerfEventConfig

type PerfEventHeader

type PerfEventHeader struct {
	Type      uint32
	Misc      uint16
	TotalSize uint16
}

Matching 'struct perf_event_header in <linux/perf_event.h>

type PerfEventLost

type PerfEventLost struct {
	PerfEventHeader
	Id   uint64
	Lost uint64
}

Matching 'struct perf_event_lost in kernel sources

type PerfEventSample

type PerfEventSample struct {
	PerfEventHeader
	Size uint32
	// contains filtered or unexported fields
}

Matching 'struct perf_event_sample in kernel sources

func (*PerfEventSample) DataCopy

func (e *PerfEventSample) DataCopy() []byte

func (*PerfEventSample) DataDirect

func (e *PerfEventSample) DataDirect() []byte

type ReceiveFunc

type ReceiveFunc func(msg *PerfEventSample, cpu int)

Jump to

Keyboard shortcuts

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