Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pkg/ipmasq/ipmasq.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/fsnotify/fsnotify"
"k8s.io/apimachinery/pkg/util/yaml"

"github.com/cilium/cilium/pkg/lock"
"github.com/cilium/cilium/pkg/logging"
"github.com/cilium/cilium/pkg/logging/logfields"
)
Expand Down Expand Up @@ -88,6 +89,8 @@ type IPMasqMap interface {

// IPMasqAgent represents a state of the ip-masq-agent
type IPMasqAgent struct {
lock lock.Mutex

configPath string
masqLinkLocalIPv4 bool
masqLinkLocalIPv6 bool
Expand All @@ -113,6 +116,9 @@ func NewIPMasqAgent(configPath string, ipMasqMap IPMasqMap) *IPMasqAgent {
// Start starts the ip-masq-agent goroutine which tracks the config file and
// updates the BPF map accordingly.
func (a *IPMasqAgent) Start() error {
a.lock.Lock()
defer a.lock.Unlock()

watcher, err := fsnotify.NewWatcher()
if err != nil {
return fmt.Errorf("failed to create fsnotify watcher: %w", err)
Expand All @@ -130,7 +136,7 @@ func (a *IPMasqAgent) Start() error {
if err := a.restore(); err != nil {
log.WithError(err).Warn("Failed to restore")
}
if err := a.Update(); err != nil {
if err := a.update(); err != nil {
log.WithError(err).Warn("Failed to update")
}

Expand Down Expand Up @@ -175,8 +181,14 @@ func (a *IPMasqAgent) Stop() {
a.watcher.Close()
}

// Update updates the ipmasq BPF map entries with ones from the config file.
func (a *IPMasqAgent) Update() error {
a.lock.Lock()
defer a.lock.Unlock()
return a.update()
}

// Update updates the ipmasq BPF map entries with ones from the config file.
func (a *IPMasqAgent) update() error {
isEmpty, err := a.readConfig()
if err != nil {
return err
Expand Down
Loading