Ver Fonte

Merge pull request #2300 from selansen/master

 VXLAN port configuration - late review comments update
Flavio Crisciani há 6 anos atrás
pai
commit
7667c0a4b2

+ 2 - 2
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...)

+ 1 - 1
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,

+ 8 - 6
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