2018-10-26 22:51:34 -04:00
|
|
|
// Package overlayutils provides utility functions for overlay networks
|
|
|
|
package overlayutils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
vxlanUDPPort uint32
|
|
|
|
mutex sync.Mutex
|
|
|
|
)
|
|
|
|
|
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-13 18:44:42 -05:00
|
|
|
// ConfigVXLANUDPPort configures vxlan udp port number.
|
|
|
|
func ConfigVXLANUDPPort(vxlanPort uint32) error {
|
2018-10-26 22:51:34 -04:00
|
|
|
mutex.Lock()
|
|
|
|
defer mutex.Unlock()
|
|
|
|
// if the value comes as 0 by any reason we set it to default value 4789
|
|
|
|
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 {
|
|
|
|
return fmt.Errorf("ConfigVxlanUDPPort Vxlan UDP port number is not in valid range %d", vxlanPort)
|
|
|
|
}
|
|
|
|
vxlanUDPPort = vxlanPort
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-11-13 18:44:42 -05:00
|
|
|
// VXLANUDPPort returns Vxlan UDP port number
|
|
|
|
func VXLANUDPPort() uint32 {
|
2018-10-26 22:51:34 -04:00
|
|
|
mutex.Lock()
|
|
|
|
defer mutex.Unlock()
|
|
|
|
return vxlanUDPPort
|
|
|
|
}
|