Skip to content

Commit 232fa1a

Browse files
committed
feat: add object to describe eBPF program
1 parent 6ededbf commit 232fa1a

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

thorlog/v3/ebpf.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package thorlog
2+
3+
import (
4+
"time"
5+
)
6+
7+
// EBPFProgram describes an eBPF program attached to a specific endpoint in the kernel.
8+
//
9+
// To use eBPF nomenclature: This struct describes an eBPF link and its corresponding program.
10+
//
11+
// eBPF programs can be attached to a wide range of things; the LinkType contains what sort of object
12+
// the program is attached to, and AttachTarget contains what specific object it is attached to.
13+
//
14+
// EBPFProgram has a content that contains the (kernel translated) instructions,
15+
// provided that the kernel does not hide them due to the kernel.kptr_restrict sysctl.
16+
type EBPFProgram struct {
17+
LogObjectHeader
18+
19+
// Tag is a hash calculated from the program instructions
20+
// TODO: discuss: Should this be something like "bytecode_checksum"? It's possibly more understandable for users; on the other hand, "tag" is the kernel name for this.
21+
Tag string `textlog:"tag" json:"tag"`
22+
// User that loaded the eBPF program
23+
User string `textlog:"user" json:"user"`
24+
// Program name
25+
Name string `textlog:"name" json:"name"`
26+
// Size of the loaded program.
27+
//
28+
// This relates to instructions that have already been rewritten by the kernel;
29+
// as such, it does not have to be the exact size of the instructions that were passed
30+
// when the program was loaded.
31+
Size uint64 `textlog:"size" json:"size"`
32+
// Maps used by this program
33+
Maps []string `json:"maps"`
34+
// Functions declared by this program
35+
Functions []string `json:"functions"`
36+
// Timestamp when this program was loaded
37+
LoadTime time.Time `textlog:"load_time" json:"load_time"`
38+
// RAM locked by this eBPF program
39+
MemoryLocked uint64 `json:"memory_locked"`
40+
// Type of object the eBPF program is attached to (kprobe, syscall, tracepoint, ...)
41+
LinkType string `textlog:"link_type" json:"link_type"`
42+
// eBPF program type, i.e. whether this is a program for packet inspection / kprobe / tracepoint / ...
43+
ProgramType string `json:"program_type"`
44+
// The object the eBPF program is attached to.
45+
//
46+
// Depending on the LinkType, different fields will be present in this struct.
47+
AttachTarget EBPFAttachTarget `textlog:",expand" json:"attach_target"`
48+
// Content contains extracts from the kernel translated instructions that are
49+
// relevant for matches on this program.
50+
Content *SparseData `json:"content,omitempty"`
51+
}
52+
53+
// EBPFAttachTarget describes the target that a BPF program is attached to.
54+
type EBPFAttachTarget struct {
55+
// uprobe / tracepoint / cgroup specific; the path of the hooked ELF / tracepoint / cgroup, respectively
56+
Path string `textlog:"path,omitempty" json:"path,omitempty"`
57+
// uprobe specific; the PID of the hooked process, or nothing if the probe is for all processes
58+
Pid uint32 `textlog:"pid,omitempty" json:"pid,omitempty"`
59+
// uprobe / kprobe specific; the symbols that are hooked
60+
Symbols StringList `textlog:"symbol,omitempty" json:"symbols,omitempty"`
61+
// netkit / TCX / XDP specific; Network interface that the eBPF is attached to
62+
Interface string `textlog:"interface,omitempty" json:"interface,omitempty"`
63+
// netns / tracing / perf event specific; ID of the object attached to
64+
ObjectId int64 `textlog:"object_id,omitempty" json:"object_id,omitempty"`
65+
// netfilter specific; Protocol family (IPv4 or IPv6)
66+
Protocol string `textlog:"protocol,omitempty" json:"protocol,omitempty"`
67+
// netfilter specific; Hook (prerouting, postrouting, forward, local in, or local out)
68+
Hook string `textlog:"hook,omitempty" json:"hook,omitempty"`
69+
// netfilter specific; Priority (lower is executed earlier)
70+
Priority int `textlog:"priority,omitempty" json:"priority,omitempty"`
71+
}
72+
73+
func (EBPFProgram) reportable() {}
74+
75+
const typeEbpfProgram = "eBPF program"
76+
77+
func init() { AddLogObjectType(typeEbpfProgram, &EBPFProgram{}) }
78+
79+
func NewEBPFProgram() *EBPFProgram {
80+
return &EBPFProgram{
81+
LogObjectHeader: LogObjectHeader{
82+
Type: typeEbpfProgram,
83+
},
84+
}
85+
}

0 commit comments

Comments
 (0)