Added documentation to ebpf.go
This commit is contained in:
parent
3c7f976acc
commit
3672fd455b
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user