github.com/dylandreimerink/gobpfld@v0.6.1-0.20220205171531-e79c330ad608/kernelsupport/program.go (about) 1 package kernelsupport 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 // ProgramSupport is a flagset that describes which programs types are supported 9 type ProgramSupport uint64 10 11 // TODO add comments 12 const ( 13 // 3.19 14 KFeatProgSocketFilter ProgramSupport = 1 << iota 15 // 4.1 16 KFeatProgKProbe 17 // 4.1 18 KFeatProgSchedCLS 19 // 4.1 20 KFeatProgSchedACT 21 // 4.7 22 KFeatProgTracepoint 23 // 4.8 24 KFeatProgXDP 25 // 4.9 26 KFeatProgPerfEvent 27 // 4.10 28 KFeatProgCGroupSKB 29 // 4.10 30 KFeatProgCGroupSocket 31 // 4.10 32 KFeatProgLWTIn 33 KFeatProgLWTOut 34 KFeatProgLWTXmit 35 // 4.13 36 KFeatProgSocketOps 37 // 4.14 38 KFeatProgSKSKB 39 // 4.15 40 KFeatProgCGroupDevice 41 // 4.17 42 KFeatProgSKMsg 43 // 4.17 44 KFeatProgRawTracepoint 45 // 4.17 46 KFeatProgCGroupSocketAddr 47 // 4.18 48 KFeatProgLWTSeg6Local 49 // 4.18 50 KFeatProgLIRCMode2 51 // 4.19 52 KFeatProgSKReusePort 53 // 4.20 54 KFeatProgFlowDissector 55 // 5.2 56 KFeatProgCGroupSysctl 57 // 5.2 58 KFeatProgRawTracepointWritable 59 // 5.3 60 KFeatProgCgroupSocketOpt 61 // 5.5 62 KFeatProgTracing 63 // 5.6 64 KFeatProgStructOps 65 // 5.6 66 KFeatProgExt 67 // 5.7 68 KFeatProgLSM 69 // 5.9 70 KFeatProgSKLookup 71 72 // An end marker for enumeration, not an actual feature flag 73 kFeatProgMax //nolint:revive // leading k is used to stay consistent with exported vars 74 ) 75 76 // Has returns true if 'ps' has all the specified flags 77 func (ps ProgramSupport) Has(flags ProgramSupport) bool { 78 return ps&flags == flags 79 } 80 81 var programSupportToString = map[ProgramSupport]string{ 82 KFeatProgSocketFilter: "Socket filter", 83 KFeatProgKProbe: "KProbe", 84 KFeatProgSchedCLS: "TC classifier", 85 KFeatProgSchedACT: "TC action", 86 KFeatProgTracepoint: "Tracepoint", 87 KFeatProgXDP: "XDP", 88 KFeatProgPerfEvent: "Perf event", 89 KFeatProgCGroupSKB: "CGroup SKB", 90 KFeatProgCGroupSocket: "CGroup Socket", 91 KFeatProgLWTIn: "LWT in", 92 KFeatProgLWTOut: "LWT out", 93 KFeatProgLWTXmit: "LWT xmit", 94 KFeatProgSocketOps: "Socket operations", 95 KFeatProgSKSKB: "SK SKB", 96 KFeatProgCGroupDevice: "CGroup device", 97 KFeatProgSKMsg: "SK messag", 98 KFeatProgRawTracepoint: "Raw tracepoint", 99 KFeatProgCGroupSocketAddr: "CGroup socket addr", 100 KFeatProgLWTSeg6Local: "LWT seg6 local", 101 KFeatProgLIRCMode2: "LIRC mode2", 102 KFeatProgSKReusePort: "SK reuse port", 103 KFeatProgFlowDissector: "Flow dissector", 104 KFeatProgCGroupSysctl: "CGroup sysctl", 105 KFeatProgRawTracepointWritable: "Raw tracepoint writable", 106 KFeatProgCgroupSocketOpt: "Cgroup socket options", 107 KFeatProgTracing: "Tracing", 108 KFeatProgStructOps: "Struct operations", 109 KFeatProgExt: "Extentsion", 110 KFeatProgLSM: "LSM", 111 KFeatProgSKLookup: "SK lookup", 112 } 113 114 func (ps ProgramSupport) String() string { 115 var progs []string 116 for i := ProgramSupport(1); i < kFeatProgMax; i = i << 1 { 117 // If this flag is set 118 if ps&i > 0 { 119 progStr := programSupportToString[i] 120 if progStr == "" { 121 progStr = fmt.Sprintf("missing program str(%d)", i) 122 } 123 progs = append(progs, progStr) 124 } 125 } 126 127 if len(progs) == 0 { 128 return "No support" 129 } 130 131 if len(progs) == 1 { 132 return progs[0] 133 } 134 135 return strings.Join(progs, ", ") 136 }