2018-10-26 22:51:34 -04:00
|
|
|
// Package overlayutils provides utility functions for overlay networks
|
|
|
|
package overlayutils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2018-11-22 15:29:20 -05:00
|
|
|
mutex sync.RWMutex
|
2018-10-26 22:51:34 -04:00
|
|
|
vxlanUDPPort uint32
|
|
|
|
)
|
|
|
|
|
2018-11-13 18:44:42 -05:00
|
|
|
const defaultVXLANUDPPort = 4789
|
|
|
|
|
2018-10-26 22:51:34 -04:00
|
|
|
func init() {
|
2018-11-13 18:44:42 -05:00
|
|
|
vxlanUDPPort = defaultVXLANUDPPort
|
2018-10-26 22:51:34 -04:00
|
|
|
}
|
|
|
|
|
2018-11-22 15:40:36 -05:00
|
|
|
// ConfigVXLANUDPPort configures the VXLAN UDP port (data path port) number.
|
|
|
|
// If no port is set, the default (4789) is returned. Valid port numbers are
|
|
|
|
// between 1024 and 49151.
|
2018-11-13 18:44:42 -05:00
|
|
|
func ConfigVXLANUDPPort(vxlanPort uint32) error {
|
2018-10-26 22:51:34 -04:00
|
|
|
if vxlanPort == 0 {
|
2018-11-13 18:44:42 -05:00
|
|
|
vxlanPort = defaultVXLANUDPPort
|
2018-10-26 22:51:34 -04:00
|
|
|
}
|
|
|
|
// IANA procedures for each range in detail
|
|
|
|
// The Well Known Ports, aka the System Ports, from 0-1023
|
|
|
|
// The Registered Ports, aka the User Ports, from 1024-49151
|
|
|
|
// The Dynamic Ports, aka the Private Ports, from 49152-65535
|
|
|
|
// So we can allow range between 1024 to 49151
|
|
|
|
if vxlanPort < 1024 || vxlanPort > 49151 {
|
2018-11-22 15:40:36 -05:00
|
|
|
return fmt.Errorf("VXLAN UDP port number is not in valid range (1024-49151): %d", vxlanPort)
|
2018-10-26 22:51:34 -04:00
|
|
|
}
|
2018-11-22 15:29:20 -05:00
|
|
|
mutex.Lock()
|
2018-10-26 22:51:34 -04:00
|
|
|
vxlanUDPPort = vxlanPort
|
2018-11-22 15:29:20 -05:00
|
|
|
mutex.Unlock()
|
2018-10-26 22:51:34 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-11-13 18:44:42 -05:00
|
|
|
// VXLANUDPPort returns Vxlan UDP port number
|
|
|
|
func VXLANUDPPort() uint32 {
|
2018-11-22 15:29:20 -05:00
|
|
|
mutex.RLock()
|
|
|
|
defer mutex.RUnlock()
|
2018-10-26 22:51:34 -04:00
|
|
|
return vxlanUDPPort
|
|
|
|
}
|