cilium / ebpf

ebpf-go is a pure-Go library to read, modify and load eBPF programs and attach them to various hooks in the Linux kernel.
https://ebpf-go.dev
MIT License
6.39k stars 699 forks source link

New API in Collection{Spec} for modifying global BPF variables #1542

Closed smagnani96 closed 2 weeks ago

smagnani96 commented 3 months ago

Describe the bug

-- Newbie here, text to be adjusted --

Opening this issue to discuss a possible enhancement to the library regarding the interaction with static/global variables in an eBPF program. AFAIU, the current state of the library doesn't allow to interact with such data, since the map containing these varaibles (".rodata", ".data", ".bss") are not emitted (referring to https://github.com/cilium/ebpf/blob/main/cmd/bpf2go/main.go#L367 and https://github.com/cilium/ebpf/blob/main/cmd/bpf2go/gen/output.go#L108).

Useful pointers:

  1. https://github.com/cilium/ebpf/discussions/943
  2. https://stackoverflow.com/questions/78742654/how-does-mmaped-ebpf-map-shared-between-processes-synchronizes-operations

Ongoing effort:

  1. Map.Memory and ebpf.Variable support: https://github.com/ti-mo/ebpf/tree/tb/ebpf-variables
  2. bpf2go support for ebpf.Variable: #1543 (rebased on https://github.com/ti-mo/ebpf/tree/tb/ebpf-variables plus some required hack)
lmb commented 3 months ago

cc @ti-mo PTAL

ti-mo commented 2 weeks ago

This was merged in https://github.com/cilium/ebpf/pull/1572. bpf2go work continuing in https://github.com/cilium/ebpf/pull/1543.