Skip to content

Commit a55f96f

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

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

thorlog/v3/ebpf.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 AttachedTo contains what specific object it is attached to.
13+
//
14+
// EbpfProgram has an attached 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+
// Attached to what sort of object (kprobe, syscall, tracepoint, ...)
41+
LinkType string `textlog:"link_type" json:"link_type"`
42+
// EBPF program type, whether this is a program for packet inspection / kprobe / tracepoint / ...
43+
ProgramType string `json:"program_type"`
44+
// Attached to which object
45+
AttachedTo AttachTarget `textlog:",expand" json:"attached_to"`
46+
// Content contains extracts from the kernel translated instructions that are
47+
// relevant for matches on this program.
48+
Content *SparseData `json:"content,omitempty"`
49+
}
50+
51+
// AttachTarget describes the target that a BPF program is attached to.
52+
// This is highly dependent on EbpfProgram.LinkType.
53+
type AttachTarget struct {
54+
// uprobe / tracepoint / cgroup specific; the path of the hooked ELF / tracepoint / cgroup
55+
Path string `textlog:"path,omitempty" json:"path,omitempty"`
56+
// uprobe specific; the PID of the hooked process, or nothing if the probe is for all processes
57+
Pid uint32 `textlog:"pid,omitempty" json:"pid,omitempty"`
58+
// uprobe / kprobe specific; the symbols that are hooked
59+
Symbols StringList `textlog:"symbol,omitempty" json:"symbols,omitempty"`
60+
// netkit / TCX / XDP specific; Network interface that the eBPF is attached to
61+
Interface string `textlog:"interface,omitempty" json:"interface,omitempty"`
62+
// netns / tracing / perf event specific; ID of the object attached to
63+
ObjectId int64 `textlog:"object_id,omitempty" json:"object_id,omitempty"`
64+
// netfilter specific; Protocol family (IPv4 or IPv6)
65+
Protocol string `textlog:"protocol,omitempty" json:"protocol,omitempty"`
66+
// netfilter specific; Hook (prerouting, postrouting, forward, local in, or local out)
67+
Hook string `textlog:"hook,omitempty" json:"hook,omitempty"`
68+
// netfilter specific; Priority (lower is executed earlier)
69+
Priority int `textlog:"priority,omitempty" json:"priority,omitempty"`
70+
}
71+
72+
func (EbpfProgram) reportable() {}
73+
74+
const typeEbpfProgram = "eBPF program"
75+
76+
func init() { AddLogObjectType(typeEbpfProgram, &EbpfProgram{}) }
77+
78+
func NewEbpfProgram() *EbpfProgram {
79+
return &EbpfProgram{
80+
LogObjectHeader: LogObjectHeader{
81+
Type: typeEbpfProgram,
82+
},
83+
}
84+
}

0 commit comments

Comments
 (0)