From 56ca280b273219592d11306256c6e3704c381f60 Mon Sep 17 00:00:00 2001 From: selansen Date: Tue, 13 Nov 2018 18:44:42 -0500 Subject: [PATCH] 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 --- libnetwork/drivers/overlay/encryption.go | 4 ++-- libnetwork/drivers/overlay/ov_utils.go | 2 +- libnetwork/drivers/overlay/overlayutils/utils.go | 14 ++++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/libnetwork/drivers/overlay/encryption.go b/libnetwork/drivers/overlay/encryption.go index 38fd710b9c..d71f81bdf0 100644 --- a/libnetwork/drivers/overlay/encryption.go +++ b/libnetwork/drivers/overlay/encryption.go @@ -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...) diff --git a/libnetwork/drivers/overlay/ov_utils.go b/libnetwork/drivers/overlay/ov_utils.go index 69e691d0ec..7338ea9e47 100644 --- a/libnetwork/drivers/overlay/ov_utils.go +++ b/libnetwork/drivers/overlay/ov_utils.go @@ -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, diff --git a/libnetwork/drivers/overlay/overlayutils/utils.go b/libnetwork/drivers/overlay/overlayutils/utils.go index a2a7387113..c59d74502f 100644 --- a/libnetwork/drivers/overlay/overlayutils/utils.go +++ b/libnetwork/drivers/overlay/overlayutils/utils.go @@ -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