-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable.go
48 lines (38 loc) · 937 Bytes
/
table.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package wbpf
import (
"fmt"
"github.com/cilium/ebpf"
)
var (
ErrTableNotFound = fmt.Errorf("table not found")
ErrIncorrectTableType = fmt.Errorf("incorrect table type")
ErrTableIsNil = fmt.Errorf("table is nil")
)
type UpdateFlag uint32
const (
UpdateAny UpdateFlag = iota
// UpdateNoExist creates a new element.
UpdateNoExist UpdateFlag = 1 << (iota - 1)
// UpdateExist updates an existing element.
UpdateExist
// UpdateLock updates elements under bpf_spin_lock.
UpdateLock
)
type Table struct {
*ebpf.Map
info *ebpf.MapInfo
mod *Module
}
func (t *Table) TableType() ebpf.MapType { return t.info.Type }
func (t *Table) TableName() string { return t.info.Name }
func (f UpdateFlag) ToMapUpdateFlag() ebpf.MapUpdateFlags {
switch f {
case UpdateNoExist:
return ebpf.UpdateNoExist
case UpdateExist:
return ebpf.UpdateExist
case UpdateLock:
return ebpf.UpdateLock
}
return ebpf.UpdateAny
}