-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathkerno.h
More file actions
165 lines (136 loc) · 5.52 KB
/
Copy pathkerno.h
File metadata and controls
165 lines (136 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 Optiqor contributors.
//
// kerno.h — Shared definitions for all Kerno eBPF programs.
//
// Every event struct defined here MUST match the corresponding Go struct
// in the loader (internal/bpf/*.go) exactly — same field order, same sizes.
// Use explicit-width types (__u32, __u64, etc.) and pack where needed.
#ifndef __KERNO_H__
#define __KERNO_H__
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_core_read.h>
// ─── Constants ──────────────────────────────────────────────────────────────
#define TASK_COMM_LEN 16
#define MAX_ENTRIES 8192
#define RINGBUF_SIZE (256 * 1024) // 256 KB per ring buffer
// ─── Severity levels (matches Go Severity type) ────────────────────────────
#define SEVERITY_INFO 0
#define SEVERITY_WARNING 1
#define SEVERITY_CRITICAL 2
// ─── Event types (discriminator for union-style processing) ────────────────
#define EVENT_SYSCALL_LATENCY 1
#define EVENT_TCP_MONITOR 2
#define EVENT_OOM_KILL 3
#define EVENT_DISK_IO 4
#define EVENT_SCHED_DELAY 5
#define EVENT_FD_TRACK 6
#define EVENT_FILE_AUDIT 7
// ─── Syscall Latency Event ─────────────────────────────────────────────────
struct syscall_event {
__u64 timestamp_ns;
__u64 latency_ns;
__u64 cgroup_id;
__u32 pid;
__u32 tid;
__u32 syscall_nr;
__u32 ret;
char comm[TASK_COMM_LEN];
};
// ─── TCP Monitor Event ─────────────────────────────────────────────────────
// TCP event subtypes.
#define TCP_EVENT_CONNECT 1
#define TCP_EVENT_CLOSE 2
#define TCP_EVENT_RETRANSMIT 3
#define TCP_EVENT_RTT 4
struct tcp_event {
__u64 timestamp_ns;
__u64 cgroup_id;
__u32 pid;
__u32 saddr; // IPv4 source address (network byte order)
__u32 daddr; // IPv4 destination address (network byte order)
__u16 sport;
__u16 dport;
__u16 family; // AF_INET or AF_INET6
__u8 event_type; // TCP_EVENT_* subtype
__u8 state; // TCP state for state change events
__u32 rtt_us; // smoothed RTT in microseconds (for RTT events)
__u32 retransmits; // total retransmit count
char comm[TASK_COMM_LEN];
__u8 _pad[4];
};
// ─── OOM Kill Event ────────────────────────────────────────────────────────
struct oom_event {
__u64 timestamp_ns;
__u64 cgroup_id;
__u64 total_pages;
__u64 rss_pages;
__u32 pid;
__u32 triggered_pid; // PID that triggered the OOM killer
__s32 oom_score;
__u32 _pad;
char comm[TASK_COMM_LEN];
};
// ─── Disk I/O Event ────────────────────────────────────────────────────────
struct disk_event {
__u64 timestamp_ns;
__u64 latency_ns;
__u64 sector;
__u32 dev; // device number (MKDEV)
__u32 pid;
__u64 nr_bytes; // widened to __u64: merged/discard requests can exceed 8 MiB
__u8 op; // 'R' = read, 'W' = write, 'S' = sync
__u8 _pad[7]; // re-pad to keep struct size a multiple of 8
char comm[TASK_COMM_LEN];
};
// ─── Scheduler Delay Event ─────────────────────────────────────────────────
struct sched_event {
__u64 timestamp_ns;
__u64 runq_delay_ns;
__u64 cgroup_id;
__u32 pid;
__u32 cpu;
char comm[TASK_COMM_LEN];
};
// ─── File Descriptor Track Event ───────────────────────────────────────────
#define FD_OP_OPEN 1
#define FD_OP_CLOSE 2
struct fd_event {
__u64 timestamp_ns;
__u64 cgroup_id;
__u32 pid;
__s32 fd;
__u8 op; // FD_OP_OPEN or FD_OP_CLOSE
__u8 _pad[7];
char comm[TASK_COMM_LEN];
};
// ─── File Audit Event ──────────────────────────────────────────────────────
#define MAX_FILENAME_LEN 256
struct file_event {
__u64 timestamp_ns;
__u64 cgroup_id;
__u32 pid;
__u32 uid;
__u32 flags;
__u32 _pad;
char comm[TASK_COMM_LEN];
char filename[MAX_FILENAME_LEN];
};
// ─── Helper macros ─────────────────────────────────────────────────────────
// Declare a BPF ring buffer map with the given name.
#define KERNO_RINGBUF(name) \
struct { \
__uint(type, BPF_MAP_TYPE_RINGBUF); \
__uint(max_entries, RINGBUF_SIZE); \
} name SEC(".maps")
// Declare a BPF hash map.
#define KERNO_HASH(name, key_type, val_type, max) \
struct { \
__uint(type, BPF_MAP_TYPE_HASH); \
__uint(max_entries, max); \
__type(key, key_type); \
__type(value, val_type); \
} name SEC(".maps")
#endif // __KERNO_H__