Skip to content

Commit

Permalink
Add strict mode API
Browse files Browse the repository at this point in the history
  • Loading branch information
javierhonduco committed Apr 28, 2022
1 parent 64458ba commit f0722d3
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion libbpfgo.go
Expand Up @@ -328,6 +328,41 @@ func NewModuleFromFile(bpfObjPath string) (*Module, error) {
})
}

// LibbpfStrictMode is an enum as defined in https://elixir.bootlin.com/linux/v5.17.5/source/tools/lib/bpf/libbpf_legacy.h#L23
type LibbpfStrictMode uint32

const (
LibbpfStrictModeAll LibbpfStrictMode = C.LIBBPF_STRICT_ALL
LibbpfStrictModeNone LibbpfStrictMode = C.LIBBPF_STRICT_NONE
LibbpfStrictModeCleanPtrs LibbpfStrictMode = C.LIBBPF_STRICT_CLEAN_PTRS
LibbpfStrictModeDirectErrs LibbpfStrictMode = C.LIBBPF_STRICT_DIRECT_ERRS
LibbpfStrictModeSecName LibbpfStrictMode = C.LIBBPF_STRICT_SEC_NAME
LibbpfStrictModeNoObjectList LibbpfStrictMode = C.LIBBPF_STRICT_NO_OBJECT_LIST
LibbpfStrictModeAutoRlimitMemlock LibbpfStrictMode = C.LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK
)

func (b LibbpfStrictMode) String() (str string) {
x := map[LibbpfStrictMode]string{
LibbpfStrictModeAll: "LIBBPF_STRICT_ALL",
LibbpfStrictModeNone: "LIBBPF_STRICT_NONE",
LibbpfStrictModeCleanPtrs: "LIBBPF_STRICT_CLEAN_PTRS",
LibbpfStrictModeDirectErrs: "LIBBPF_STRICT_DIRECT_ERRS",
LibbpfStrictModeSecName: "LIBBPF_STRICT_SEC_NAME",
LibbpfStrictModeNoObjectList: "LIBBPF_STRICT_NO_OBJECT_LIST",
LibbpfStrictModeAutoRlimitMemlock: "LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK",
}

str, ok := x[b]
if !ok {
str = LibbpfStrictModeNone.String()
}
return str
}

func SetStrictMode(mode LibbpfStrictMode) {
C.libbpf_set_strict_mode(uint32(mode))
}

func NewModuleFromFileArgs(args NewModuleArgs) (*Module, error) {
C.set_print_fn()
if err := bumpMemlockRlimit(); err != nil {
Expand Down Expand Up @@ -787,7 +822,7 @@ func (b *BPFMap) DeleteKeyBatch(keys unsafe.Pointer, count uint32) error {
ElemFlags: C.BPF_ANY,
Flags: C.BPF_ANY,
}

errC := C.bpf_map_delete_batch(b.fd, keys, &countC, bpfMapBatchOptsToC(opts))
if errC != 0 {
sc := syscall.Errno(-errC)
Expand Down

0 comments on commit f0722d3

Please sign in to comment.