VXLAN port configuration - late review comments update

Some review comments came in very late after merging
	#2282. This PR addresses those review comments.

Signed-off-by: selansen <elango.siva@docker.com>
This commit is contained in:
selansen 2018-11-13 18:44:42 -05:00
parent 077ccabc45
commit 56ca280b27
3 changed files with 11 additions and 9 deletions

View File

@ -201,7 +201,7 @@ func removeEncryption(localIP, remoteIP net.IP, em *encrMap) error {
func programMangle(vni uint32, add bool) (err error) {
var (
p = strconv.FormatUint(uint64(overlayutils.GetVxlanUDPPort()), 10)
p = strconv.FormatUint(uint64(overlayutils.VXLANUDPPort()), 10)
c = fmt.Sprintf("0>>22&0x3C@12&0xFFFFFF00=%d", int(vni)<<8)
m = strconv.FormatUint(uint64(r), 10)
chain = "OUTPUT"
@ -228,7 +228,7 @@ func programMangle(vni uint32, add bool) (err error) {
func programInput(vni uint32, add bool) (err error) {
var (
port = strconv.FormatUint(uint64(overlayutils.GetVxlanUDPPort()), 10)
port = strconv.FormatUint(uint64(overlayutils.VXLANUDPPort()), 10)
vniMatch = fmt.Sprintf("0>>22&0x3C@12&0xFFFFFF00=%d", int(vni)<<8)
plainVxlan = []string{"-p", "udp", "--dport", port, "-m", "u32", "--u32", vniMatch, "-j"}
ipsecVxlan = append([]string{"-m", "policy", "--dir", "in", "--pol", "ipsec"}, plainVxlan...)

View File

@ -62,7 +62,7 @@ func createVxlan(name string, vni uint32, mtu int) error {
LinkAttrs: netlink.LinkAttrs{Name: name, MTU: mtu},
VxlanId: int(vni),
Learning: true,
Port: int(overlayutils.GetVxlanUDPPort()),
Port: int(overlayutils.VXLANUDPPort()),
Proxy: true,
L3miss: true,
L2miss: true,

View File

@ -11,17 +11,19 @@ var (
mutex sync.Mutex
)
const defaultVXLANUDPPort = 4789
func init() {
vxlanUDPPort = 4789
vxlanUDPPort = defaultVXLANUDPPort
}
// ConfigVxlanUDPPort configures vxlan udp port number.
func ConfigVxlanUDPPort(vxlanPort uint32) error {
// 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 = 4789
vxlanPort = defaultVXLANUDPPort
}
// IANA procedures for each range in detail
// The Well Known Ports, aka the System Ports, from 0-1023
@ -36,8 +38,8 @@ func ConfigVxlanUDPPort(vxlanPort uint32) error {
return nil
}
// GetVxlanUDPPort returns Vxlan UDP port number
func GetVxlanUDPPort() uint32 {
// VXLANUDPPort returns Vxlan UDP port number
func VXLANUDPPort() uint32 {
mutex.Lock()
defer mutex.Unlock()
return vxlanUDPPort