github.com/rawahars/moby@v24.0.4+incompatible/libnetwork/drivers/overlay/overlayutils/utils.go (about) 1 // Package overlayutils provides utility functions for overlay networks 2 package overlayutils 3 4 import ( 5 "fmt" 6 "sync" 7 ) 8 9 var ( 10 mutex sync.RWMutex 11 vxlanUDPPort = defaultVXLANUDPPort 12 ) 13 14 const defaultVXLANUDPPort uint32 = 4789 15 16 // ConfigVXLANUDPPort configures the VXLAN UDP port (data path port) number. 17 // If no port is set, the default (4789) is returned. Valid port numbers are 18 // between 1024 and 49151. 19 func ConfigVXLANUDPPort(vxlanPort uint32) error { 20 if vxlanPort == 0 { 21 vxlanPort = defaultVXLANUDPPort 22 } 23 // IANA procedures for each range in detail 24 // The Well Known Ports, aka the System Ports, from 0-1023 25 // The Registered Ports, aka the User Ports, from 1024-49151 26 // The Dynamic Ports, aka the Private Ports, from 49152-65535 27 // So we can allow range between 1024 to 49151 28 if vxlanPort < 1024 || vxlanPort > 49151 { 29 return fmt.Errorf("VXLAN UDP port number is not in valid range (1024-49151): %d", vxlanPort) 30 } 31 mutex.Lock() 32 vxlanUDPPort = vxlanPort 33 mutex.Unlock() 34 return nil 35 } 36 37 // VXLANUDPPort returns Vxlan UDP port number 38 func VXLANUDPPort() uint32 { 39 mutex.RLock() 40 defer mutex.RUnlock() 41 return vxlanUDPPort 42 }