Skip to content

Commit

Permalink
feat: introduce enum string api
Browse files Browse the repository at this point in the history
This adds the Name() method to MapType, BPFAttachType and BPFProgType,
which relies on libbpf_bpf_map_type_str(), libbpf_bpf_attach_type_str()
and libbpf_bpf_prog_type_str() respectively.
  • Loading branch information
geyslan committed Sep 4, 2023
1 parent 021248d commit d1e69fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions map-common.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func (t MapType) String() string {
return str
}

func (t MapType) Name() string {
return C.GoString(C.libbpf_bpf_map_type_str(C.enum_bpf_map_type(t)))
}

//
// MapFlag
//
Expand Down
10 changes: 9 additions & 1 deletion prog-common.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func (t BPFProgType) String() string {
return str
}

func (t BPFProgType) Name() string {
return C.GoString(C.libbpf_bpf_prog_type_str(C.enum_bpf_prog_type(t)))
}

//
// BPFAttachType
//
Expand Down Expand Up @@ -197,12 +201,16 @@ var bpfAttachTypeToString = map[BPFAttachType]string{
func (t BPFAttachType) String() string {
str, ok := bpfAttachTypeToString[t]
if !ok {
return "Unspecified"
return "BPFAttachType unspecified"
}

return str
}

func (t BPFAttachType) Name() string {
return C.GoString(C.libbpf_bpf_attach_type_str(C.enum_bpf_attach_type(t)))
}

//
// BPFCgroupIterOrder
//
Expand Down

0 comments on commit d1e69fb

Please sign in to comment.