Skip to content

Commit ae8789d

Browse files
committed
[wip] devices: annotate new bpf functions
Link to cilium/ebpf analogs. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent 3dfc84e commit ae8789d

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

devices/ebpf_linux.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ func bpf(cmd uintptr, attr unsafe.Pointer, size uintptr) (uintptr, error) {
2424
}
2525

2626
// bpfProgLoad loads a BPF_PROG_TYPE_CGROUP_DEVICE program and returns its fd.
27+
//
28+
// It is roughly equivalent to [github.com/cilium/ebpf/internal/sys.ProgLoad],
29+
// and the "retry with verifier log" is taken from [github.com/cilium/ebpf.NewProgram].
2730
func bpfProgLoad(insns asm.Instructions, license string) (int, error) {
2831
buf := bytes.NewBuffer(make([]byte, 0, insns.Size()))
2932
if err := insns.Marshal(buf, nativeEndian); err != nil {
@@ -84,6 +87,8 @@ func bpfProgLoad(insns asm.Instructions, license string) (int, error) {
8487
}
8588

8689
// bpfProgGetFdByID returns the fd for the BPF program with the given ID.
90+
//
91+
// It is roughly equivalent to [github.com/cilium/ebpf/internal/sys.ProgGetFdById].
8792
func bpfProgGetFdByID(id uint32) (int, error) {
8893
// The kernel zero-fills the rest of bpf_attr beyond the size we pass.
8994
attr := struct{ id uint32 }{id}
@@ -96,6 +101,8 @@ func bpfProgGetFdByID(id uint32) (int, error) {
96101

97102
// bpfProgAttach attaches progFd to cgroupFd with the given flags. If replaceFd
98103
// is >= 0, its fd is set in replaceBpfFd (for BPF_F_REPLACE semantics).
104+
//
105+
// It is roughly equivalent to [github.com/cilium/ebpf/link.RawAttachProgram].
99106
func bpfProgAttach(cgroupFd, progFd int, attachFlags uint32, replaceFd int) error {
100107
attr := struct {
101108
targetFd uint32
@@ -117,6 +124,8 @@ func bpfProgAttach(cgroupFd, progFd int, attachFlags uint32, replaceFd int) erro
117124
}
118125

119126
// bpfProgDetach detaches progFd from cgroupFd.
127+
//
128+
// It is roughly equivalent to [github.com/cilium/ebpf/link.RawDetachProgram].
120129
func bpfProgDetach(cgroupFd, progFd int) error {
121130
// The kernel zero-fills the rest of bpf_attr beyond the size we pass.
122131
attr := struct {

0 commit comments

Comments
 (0)