Skip to content

Commit

Permalink
bpf: unconditionally assume map name support
Browse files Browse the repository at this point in the history
For Cilium v1.14, the minimum required kernel version is 4.19.57 [1].
Thus we can now unconditionally assume support for map names which are
available in version >= 4.15.

[1] https://docs.cilium.io/en/latest/operations/system_requirements/#base-requirements

For #22116

Signed-off-by: Tobias Klauser <tobias@cilium.io>
  • Loading branch information
tklauser committed Mar 13, 2023
1 parent 7628b19 commit 9152558
Showing 1 changed file with 11 additions and 40 deletions.
51 changes: 11 additions & 40 deletions pkg/bpf/bpf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"path"
"path/filepath"
"runtime"
"sync"
"syscall"
"unsafe"

Expand All @@ -25,8 +24,6 @@ import (
"github.com/cilium/cilium/pkg/metrics"
"github.com/cilium/cilium/pkg/option"
"github.com/cilium/cilium/pkg/spanstat"
"github.com/cilium/cilium/pkg/version"
"github.com/cilium/cilium/pkg/versioncheck"
)

// CreateMap creates a Map of type mapType, with key size keySize, a value size of
Expand All @@ -49,49 +46,30 @@ func CreateMap(mapType MapType, keySize, valueSize, maxEntries, flags, innerID u
}

func createMap(mapType MapType, keySize, valueSize, maxEntries, flags, innerID uint32, fullPath string) (int, syscall.Errno) {
kernelVersionCheckOnce.Do(func() {
if k, err := version.GetKernelVersion(); err == nil {
hasMapNameSupport = isMinVersion(k)
}
})

var (
uba unsafe.Pointer
ubaSize uintptr
)

if hasMapNameSupport {
var name [16]byte
if p := path.Base(fullPath); len(p) > 15 {
copy(name[:], p[:15]) // save last element for '\0'
} else {
copy(name[:], p)
}
u := ubaMapName{
ubaCommon: ubaCommon{
mapType: uint32(mapType),
keySize: keySize,
valueSize: valueSize,
maxEntries: maxEntries,
mapFlags: flags,
innerID: innerID,
},
mapName: name,
}
uba = unsafe.Pointer(&u)
ubaSize = unsafe.Sizeof(u)
var name [16]byte
if p := path.Base(fullPath); len(p) > 15 {
copy(name[:], p[:15]) // save last element for '\0'
} else {
u := ubaCommon{
copy(name[:], p)
}
u := ubaMapName{
ubaCommon: ubaCommon{
mapType: uint32(mapType),
keySize: keySize,
valueSize: valueSize,
maxEntries: maxEntries,
mapFlags: flags,
innerID: innerID,
}
uba = unsafe.Pointer(&u)
ubaSize = unsafe.Sizeof(u)
},
mapName: name,
}
uba = unsafe.Pointer(&u)
ubaSize = unsafe.Sizeof(u)

var duration *spanstat.SpanStat
if option.Config.MetricsConfig.BPFSyscallDurationEnabled {
Expand Down Expand Up @@ -130,13 +108,6 @@ type ubaMapName struct {
mapName [16]byte
}

var (
kernelVersionCheckOnce sync.Once
hasMapNameSupport bool

isMinVersion = versioncheck.MustCompile(">=4.15.0")
)

// This struct must be in sync with union bpf_attr's anonymous struct used by
// BPF_MAP_*_ELEM commands
type bpfAttrMapOpElem struct {
Expand Down

0 comments on commit 9152558

Please sign in to comment.