Skip to content

Commit

Permalink
Merge pull request moby#2302 from thaJeztah/vxlan_locking
Browse files Browse the repository at this point in the history
Use sync.RWMutex for VXLANUDPPort
  • Loading branch information
Flavio Crisciani authored Jan 3, 2019
2 parents e50e15f + 6f59dce commit 2bea082
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions drivers/overlay/overlayutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

var (
mutex sync.RWMutex
vxlanUDPPort uint32
mutex sync.Mutex
)

const defaultVXLANUDPPort = 4789
Expand All @@ -19,8 +19,6 @@ func init() {

// ConfigVXLANUDPPort configures vxlan udp port number.
func ConfigVXLANUDPPort(vxlanPort uint32) error {
mutex.Lock()
defer mutex.Unlock()
// if the value comes as 0 by any reason we set it to default value 4789
if vxlanPort == 0 {
vxlanPort = defaultVXLANUDPPort
Expand All @@ -33,14 +31,15 @@ func ConfigVXLANUDPPort(vxlanPort uint32) error {
if vxlanPort < 1024 || vxlanPort > 49151 {
return fmt.Errorf("ConfigVxlanUDPPort Vxlan UDP port number is not in valid range %d", vxlanPort)
}
mutex.Lock()
vxlanUDPPort = vxlanPort

mutex.Unlock()
return nil
}

// VXLANUDPPort returns Vxlan UDP port number
func VXLANUDPPort() uint32 {
mutex.Lock()
defer mutex.Unlock()
mutex.RLock()
defer mutex.RUnlock()
return vxlanUDPPort
}

0 comments on commit 2bea082

Please sign in to comment.