github.com/dylandreimerink/gobpfld@v0.6.1-0.20220205171531-e79c330ad608/kernelsupport/misc.go (about) 1 package kernelsupport 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 // MiscSupport is a flagset that describes features that don't neatly fit into any other category 9 type MiscSupport uint64 10 11 const ( 12 // KFeatMiscXSKRingFlags indicates that the kernel version has flags in AF_XDP rings 13 // https://github.com/torvalds/linux/commit/77cd0d7b3f257fd0e3096b4fdcff1a7d38e99e10 14 KFeatMiscXSKRingFlags MiscSupport = iota 15 // KFeatBTFFuncScope indicates that the kernel doesn't require BTF FUNC types to have a vlen of 0. 16 // Since kernel 5.6, the scope of functions is encoded in vlen. 17 // https://github.com/cilium/ebpf/issues/43 18 // https://github.com/llvm/llvm-project/commit/fbb64aa69835c8e3e9efe0afc8a73058b5a0fb3c 19 KFeatBTFFuncScope 20 // KFeatGlobalData indicates that the kernel supports global data sections. 21 // https://lwn.net/Articles/784936/ 22 // https://github.com/torvalds/linux/commit/d8eca5bbb2be9bc7546f9e733786fa2f1a594c67 23 KFeatGlobalData 24 kFeatMiscMax //nolint:revive // leading k is used to stay consistent with exported vars 25 ) 26 27 // Has returns true if 'as' has all the specified flags 28 func (ms MiscSupport) Has(flags MiscSupport) bool { 29 return ms&flags == flags 30 } 31 32 var miscSupportToString = map[MiscSupport]string{ 33 KFeatMiscXSKRingFlags: "XSK ring flags", 34 } 35 36 func (ms MiscSupport) String() string { 37 var miscFeats []string 38 for i := MiscSupport(1); i < kFeatMiscMax; i = i << 1 { 39 // If this flag is set 40 if ms&i > 0 { 41 miscStr := miscSupportToString[i] 42 if miscStr == "" { 43 miscStr = fmt.Sprintf("missing attach str(%d)", i) 44 } 45 miscFeats = append(miscFeats, miscStr) 46 } 47 } 48 49 if len(miscFeats) == 0 { 50 return "No support" 51 } 52 53 if len(miscFeats) == 1 { 54 return miscFeats[0] 55 } 56 57 return strings.Join(miscFeats, ", ") 58 }