Skip to content

Commit

Permalink
nodemap: add validation to check that node map max is at least 16384.
Browse files Browse the repository at this point in the history
This is the constant default size prior to adding the flag.
There's not much reason to lower this value so to avoid edge cases we'll just say that this is the lower bound.

Signed-off-by: Tom Hadlaw <tom.hadlaw@isovalent.com>
  • Loading branch information
tommyp1ckles committed Mar 15, 2024
1 parent 3fcc2fb commit bbc4154
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/maps/nodemap/cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package nodemap

import (
"fmt"

"github.com/cilium/cilium/pkg/bpf"
"github.com/cilium/cilium/pkg/hive/cell"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -31,7 +33,11 @@ var defaultConfig = Config{
NodeMapMax: DefaultMaxEntries,
}

func newNodeMap(lifecycle cell.Lifecycle, conf Config) bpf.MapOut[Map] {
func newNodeMap(lifecycle cell.Lifecycle, conf Config) (bpf.MapOut[Map], error) {
if conf.NodeMapMax < DefaultMaxEntries {
return bpf.MapOut[Map]{}, fmt.Errorf("creating node map: bpf-node-map-max cannot be less than %d (%d)",
DefaultMaxEntries, conf.NodeMapMax)
}
nodeMap := newMap(MapName, conf)

lifecycle.Append(cell.Hook{
Expand All @@ -43,5 +49,5 @@ func newNodeMap(lifecycle cell.Lifecycle, conf Config) bpf.MapOut[Map] {
},
})

return bpf.NewMapOut(Map(nodeMap))
return bpf.NewMapOut(Map(nodeMap)), nil
}

0 comments on commit bbc4154

Please sign in to comment.