Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/maps/encrypt: allocate BPF map in MapCreate only if EnableIPSec is set #10189

Merged
merged 1 commit into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion daemon/datapath.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func (d *Daemon) initMaps() error {
}

func setupIPSec() (int, uint8, error) {
if option.Config.EncryptNode == false {
if !option.Config.EncryptNode {
ipsec.DeleteIPsecEncryptRoute()
}

Expand Down
27 changes: 16 additions & 11 deletions pkg/maps/encrypt/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package encrypt

import (
"fmt"
"sync"
"unsafe"

"github.com/cilium/cilium/pkg/bpf"
Expand Down Expand Up @@ -74,21 +75,25 @@ const (
)

var (
// Encrypt represents the BPF map for sockets
encryptMap = bpf.NewMap(MapName,
bpf.MapTypeArray,
&EncryptKey{},
int(unsafe.Sizeof(EncryptKey{})),
&EncryptValue{},
int(unsafe.Sizeof(EncryptValue{})),
MaxEntries,
0, 0,
bpf.ConvertKeyValue,
).WithCache()
once sync.Once
encryptMap *bpf.Map
)

// MapCreate will create an encrypt map
func MapCreate() error {
once.Do(func() {
encryptMap = bpf.NewMap(MapName,
bpf.MapTypeArray,
&EncryptKey{},
int(unsafe.Sizeof(EncryptKey{})),
&EncryptValue{},
int(unsafe.Sizeof(EncryptValue{})),
MaxEntries,
0, 0,
bpf.ConvertKeyValue,
).WithCache()
})

_, err := encryptMap.OpenOrCreate()
return err
}
Expand Down