From 3672fd455b3f9c6730a8af28e666370841e676ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Kesim?= Date: Thu, 16 Jan 2020 15:36:06 +0100 Subject: [PATCH] Added documentation to ebpf.go --- GetRuntimeAddresses/ebpf/ebpf.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/GetRuntimeAddresses/ebpf/ebpf.go b/GetRuntimeAddresses/ebpf/ebpf.go index 241523a..056d295 100644 --- a/GetRuntimeAddresses/ebpf/ebpf.go +++ b/GetRuntimeAddresses/ebpf/ebpf.go @@ -69,6 +69,7 @@ import ( "unsafe" ) +// MapFD is a file descriptor representing a eBPF map type MapFD int // CreateMap creates an eBPF map from int->uint64. The file descriptor of the @@ -113,18 +114,26 @@ func (mfd MapFD) GetMap() (map[int]uint64, error) { } } +// Add puts the (key, value) into the eBPF map, only if the key does not exist +// yet in the map. It returns an error otherwise. func (mfd MapFD) Add(key int, value uint64) error { return mfd.updateElement(key, value, C.BPF_NOEXIST) } +// Change changes the value to an existing key in the eBPF map. It returns an +// error otherwise. func (mfd MapFD) Change(key int, value uint64) error { return mfd.updateElement(key, value, C.BPF_EXIST) } +// Set puts the (key, value) into the eBPF map. It will create or overwrite an +// existing entry for that key. func (mfd MapFD) Set(key int, value uint64) error { return mfd.updateElement(key, value, C.BPF_ANY) } +// updateElement is the low level wrapper to bpf_update_elem, used from Add(), +// Set() and Change(). func (mfd MapFD) updateElement(key int, value uint64, flag C.uint64_t) error { r, errno := C.bpf_update_elem(C.int(mfd),