github.com/dylandreimerink/gobpfld@v0.6.1-0.20220205171531-e79c330ad608/kernelsupport/api.go (about) 1 package kernelsupport 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 // APISupport is a flagset which describes which features related to the bpf syscall API are supported 9 type APISupport uint64 10 11 // TODO add comments 12 const ( 13 // KFeatAPIBasic includes: map create, map lookup, map update, map delete, map getnext 14 // prog load 15 KFeatAPIBasic APISupport = 1 << iota 16 KFeatAPIMapGetNextNull 17 KFeatAPIMapNumaCreate 18 KFeatAPIMapSyscallRW 19 KFeatAPIMapName 20 KFeatAPIMapLookupAndDelete 21 KFeatAPIMapZeroSeed 22 KFeatAPIMapLock 23 KFeatAPIMapBPFRW 24 KFeatAPIMapFreeze 25 KFeatAPIMapMMap 26 KFeatAPIMapBatchOps 27 // 4.4 OBJ_PIN and OBJ_GET 28 KFeatAPIObjPinGet 29 // 4.10 PROG_ATTACH and PROG_DETACH 30 KFeatAPIProgramAttachDetach 31 // 4.12 32 KFeatAPIProgramTestRun 33 // 4.13 34 KFeatAPIProgramGetNextID 35 // 4.13 36 KFeatAPIMapGetNextID 37 // 4.13 38 KFeatAPIProgramGetFDByID 39 // 4.13 40 KFeatAPIMapGetFDByID 41 // 4.13 42 KFeatAPIObjectGetInfoByFD 43 // 4.15 44 KFeatAPIProgramQuery 45 // 4.17 46 KFeatAPIRawTracepointOpen 47 // 4.18 48 KFeatAPIBTFLoad 49 // 4.18 50 KFeatAPIBTFGetFDByID 51 // 4.18 52 KFeatAPITaskFDQuery 53 // 5.4 54 KFeatAPIBTFGetNextID 55 // 5.7 56 KFeatAPILinkCreate 57 // 5.7 58 KFeatAPILinkUpdate 59 // 5.8 60 KFeatAPILinkGetFDByID 61 // 5.8 62 KFeatAPILinkGetNextID 63 // 5.8 64 KFeatAPIEnableStats 65 // 5.8 66 KFeatAPIIterCreate 67 // 5.9 68 KFeatAPILinkDetach 69 // 5.10 70 KFeatAPIProgBindMap 71 72 // An end marker for enumeration, not an actual feature flag 73 kFeatAPIMax //nolint:revive // leading k is used to stay consistent with exported vars 74 ) 75 76 // Has returns true if 'as' has all the specified flags 77 func (as APISupport) Has(flags APISupport) bool { 78 return as&flags == flags 79 } 80 81 var apiSupportToString = map[APISupport]string{ 82 KFeatAPIBasic: "Map create, map lookup, map update, map getnext, prog load", 83 KFeatAPIMapGetNextNull: "Map get next null", 84 KFeatAPIMapNumaCreate: "Map NUMA create", 85 KFeatAPIMapSyscallRW: "Map syscall R/W", 86 KFeatAPIMapName: "Map name", 87 KFeatAPIMapLookupAndDelete: "Map lookup and delete", 88 KFeatAPIMapZeroSeed: "Map zero seed", 89 KFeatAPIMapLock: "Map lock", 90 KFeatAPIMapBPFRW: "Map BPF R/W", 91 KFeatAPIMapFreeze: "Map freeze", 92 KFeatAPIMapMMap: "Map MMap", 93 KFeatAPIMapBatchOps: "Map batch ops", 94 KFeatAPIObjPinGet: "Object pin/get", 95 KFeatAPIProgramAttachDetach: "Program attach/detach", 96 KFeatAPIProgramTestRun: "Program test run", 97 KFeatAPIProgramGetNextID: "Program get next ID", 98 KFeatAPIMapGetNextID: "Map get next ID", 99 KFeatAPIProgramGetFDByID: "Program get FD by ID", 100 KFeatAPIMapGetFDByID: "Map get FD by ID", 101 KFeatAPIObjectGetInfoByFD: "Object get info by FD", 102 KFeatAPIProgramQuery: "Program query", 103 KFeatAPIRawTracepointOpen: "Raw tracepoint open", 104 KFeatAPIBTFLoad: "BTF load", 105 KFeatAPIBTFGetFDByID: "BTF get FD by ID", 106 KFeatAPITaskFDQuery: "Task FD query", 107 KFeatAPIBTFGetNextID: "BTF get next ID", 108 KFeatAPILinkCreate: "Link create", 109 KFeatAPILinkUpdate: "Link update", 110 KFeatAPILinkGetFDByID: "Link get FD by ID", 111 KFeatAPILinkGetNextID: "Link get next ID", 112 KFeatAPIEnableStats: "Enable stats", 113 KFeatAPIIterCreate: "Iterator create", 114 KFeatAPILinkDetach: "Link detach", 115 KFeatAPIProgBindMap: "Prog bind map", 116 } 117 118 func (as APISupport) String() string { 119 var apis []string 120 for i := APISupport(1); i < kFeatAPIMax; i = i << 1 { 121 // If this flag is set 122 if as&i > 0 { 123 apiStr := apiSupportToString[i] 124 if apiStr == "" { 125 apiStr = fmt.Sprintf("missing api str(%d)", i) 126 } 127 apis = append(apis, apiStr) 128 } 129 } 130 131 if len(apis) == 0 { 132 return "No support" 133 } 134 135 if len(apis) == 1 { 136 return apis[0] 137 } 138 139 return strings.Join(apis, ", ") 140 }