Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum string API #372

Merged
merged 6 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 42 additions & 32 deletions map-common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,37 @@ import (
type MapType uint32

const (
MapTypeUnspec MapType = iota
MapTypeHash
MapTypeArray
MapTypeProgArray
MapTypePerfEventArray
MapTypePerCPUHash
MapTypePerCPUArray
MapTypeStackTrace
MapTypeCgroupArray
MapTypeLRUHash
MapTypeLRUPerCPUHash
MapTypeLPMTrie
MapTypeArrayOfMaps
MapTypeHashOfMaps
MapTypeDevMap
MapTypeSockMap
MapTypeCPUMap
MapTypeXSKMap
MapTypeSockHash
MapTypeCgroupStorage
MapTypeReusePortSockArray
MapTypePerCPUCgroupStorage
MapTypeQueue
MapTypeStack
MapTypeSKStorage
MapTypeDevmapHash
MapTypeStructOps
MapTypeRingbuf
MapTypeInodeStorage
MapTypeTaskStorage
MapTypeBloomFilter
MapTypeUnspec MapType = C.BPF_MAP_TYPE_UNSPEC
MapTypeHash MapType = C.BPF_MAP_TYPE_HASH
MapTypeArray MapType = C.BPF_MAP_TYPE_ARRAY
MapTypeProgArray MapType = C.BPF_MAP_TYPE_PROG_ARRAY
MapTypePerfEventArray MapType = C.BPF_MAP_TYPE_PERF_EVENT_ARRAY
MapTypePerCPUHash MapType = C.BPF_MAP_TYPE_PERCPU_HASH
MapTypePerCPUArray MapType = C.BPF_MAP_TYPE_PERCPU_ARRAY
MapTypeStackTrace MapType = C.BPF_MAP_TYPE_STACK_TRACE
MapTypeCgroupArray MapType = C.BPF_MAP_TYPE_CGROUP_ARRAY
MapTypeLRUHash MapType = C.BPF_MAP_TYPE_LRU_HASH
MapTypeLRUPerCPUHash MapType = C.BPF_MAP_TYPE_LRU_PERCPU_HASH
MapTypeLPMTrie MapType = C.BPF_MAP_TYPE_LPM_TRIE
MapTypeArrayOfMaps MapType = C.BPF_MAP_TYPE_ARRAY_OF_MAPS
MapTypeHashOfMaps MapType = C.BPF_MAP_TYPE_HASH_OF_MAPS
MapTypeDevMap MapType = C.BPF_MAP_TYPE_DEVMAP
MapTypeSockMap MapType = C.BPF_MAP_TYPE_SOCKMAP
MapTypeCPUMap MapType = C.BPF_MAP_TYPE_CPUMAP
MapTypeXSKMap MapType = C.BPF_MAP_TYPE_XSKMAP
MapTypeSockHash MapType = C.BPF_MAP_TYPE_SOCKHASH
MapTypeCgroupStorage MapType = C.BPF_MAP_TYPE_CGROUP_STORAGE
MapTypeReusePortSockArray MapType = C.BPF_MAP_TYPE_REUSEPORT_SOCKARRAY
MapTypePerCPUCgroupStorage MapType = C.BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE
MapTypeQueue MapType = C.BPF_MAP_TYPE_QUEUE
MapTypeStack MapType = C.BPF_MAP_TYPE_STACK
MapTypeSKStorage MapType = C.BPF_MAP_TYPE_SK_STORAGE
MapTypeDevmapHash MapType = C.BPF_MAP_TYPE_DEVMAP_HASH
MapTypeStructOps MapType = C.BPF_MAP_TYPE_STRUCT_OPS
MapTypeRingbuf MapType = C.BPF_MAP_TYPE_RINGBUF
MapTypeInodeStorage MapType = C.BPF_MAP_TYPE_INODE_STORAGE
MapTypeTaskStorage MapType = C.BPF_MAP_TYPE_TASK_STORAGE
MapTypeBloomFilter MapType = C.BPF_MAP_TYPE_BLOOM_FILTER
)

var mapTypeToString = map[MapType]string{
Expand Down Expand Up @@ -86,7 +86,17 @@ var mapTypeToString = map[MapType]string{
}

func (t MapType) String() string {
return mapTypeToString[t]
str, ok := mapTypeToString[t]
if !ok {
// MapTypeUnspec must exist in mapTypeToString to avoid infinite recursion.
return BPFProgTypeUnspec.String()
}

return str
}

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

//
Expand Down
Loading
Loading