You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for eBPF linked lists in KernelScript. Introduce list declaration syntax, operations (push_front, push_back, pop_front, pop_back), and automatic struct modifications for list elements.
KernelScript provides seamless support for eBPF linked lists with Python-like syntax. Lists automatically handle the complex BPF linked list infrastructure while providing a simple, type-safe interface.
2304
+
2305
+
#### 5.6.1 List Declaration Syntax
2306
+
2307
+
Lists use a simplified syntax compared to maps - no flags or pinning allowed:
2308
+
2309
+
```kernelscript
2310
+
// Basic list declaration
2311
+
var my_list : list<StructType>
2312
+
2313
+
// Lists can only contain struct types
2314
+
struct PacketInfo {
2315
+
src_ip: u32,
2316
+
dst_ip: u32,
2317
+
size: u16,
2318
+
}
2319
+
2320
+
var packet_queue : list<PacketInfo>
2321
+
```
2322
+
2323
+
**List Constraints:**
2324
+
- ✅ Only struct types are allowed as list elements
2325
+
- ❌ Lists cannot be pinned (no `pin` keyword)
2326
+
- ❌ Lists cannot have flags (no `@flags()`)
2327
+
- ❌ Primitive types like `u32`, `str`, etc. are not allowed
2328
+
2329
+
#### 5.6.2 List Operations
2330
+
2331
+
KernelScript provides four core list operations that map directly to eBPF linked list functions:
2332
+
2333
+
```kernelscript
2334
+
struct EventData {
2335
+
timestamp: u64,
2336
+
event_type: u32,
2337
+
}
2338
+
2339
+
var event_list : list<EventData>
2340
+
2341
+
@helper
2342
+
fn process_events() {
2343
+
var event = EventData {
2344
+
timestamp: bpf_ktime_get_ns(),
2345
+
event_type: 1,
2346
+
}
2347
+
2348
+
// Add elements
2349
+
event_list.push_back(event) // Add to end of list
2350
+
event_list.push_front(event) // Add to beginning of list
2351
+
2352
+
// Remove and return elements
2353
+
var latest = event_list.pop_front() // Remove from beginning
2354
+
var oldest = event_list.pop_back() // Remove from end
2355
+
2356
+
// Check for null (empty list)
2357
+
if (latest != null) {
2358
+
// Process the event
2359
+
if (latest->event_type == 1) {
2360
+
// Handle event
2361
+
}
2362
+
}
2363
+
}
2364
+
```
2365
+
2366
+
#### 5.6.3 Generated eBPF Code
2367
+
2368
+
The compiler automatically generates the necessary BPF linked list infrastructure:
2369
+
2370
+
##### 1. Helper Function Declarations
2371
+
```c
2372
+
/* BPF list helper functions are automatically declared */
0 commit comments