Skip to content

Commit bffc462

Browse files
committed
VXLAN UDP Port configuration support
This PR chnages allow user to configure VxLAN UDP port number. By default we use 4789 port number. But this commit will allow user to configure port number during swarm init. VxLAN port can't be modified after swarm init. Signed-off-by: selansen <elango.siva@docker.com>
1 parent d7b6174 commit bffc462

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ RUN go get -d github.com/gogo/protobuf/protoc-gen-gogo && \
77
git reset --hard 30cf7ac33676b5786e78c746683f0d4cd64fa75b && \
88
go install
99

10-
RUN go get github.com/golang/lint/golint \
10+
RUN go get golang.org/x/lint/golint \
1111
golang.org/x/tools/cmd/cover \
1212
github.com/mattn/goveralls \
1313
github.com/gordonklaus/ineffassign \

drivers/overlay/encryption.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"strconv"
1414

15+
"github.com/docker/libnetwork/drivers/overlay/overlayutils"
1516
"github.com/docker/libnetwork/iptables"
1617
"github.com/docker/libnetwork/ns"
1718
"github.com/docker/libnetwork/types"
@@ -200,7 +201,7 @@ func removeEncryption(localIP, remoteIP net.IP, em *encrMap) error {
200201

201202
func programMangle(vni uint32, add bool) (err error) {
202203
var (
203-
p = strconv.FormatUint(uint64(vxlanPort), 10)
204+
p = strconv.FormatUint(uint64(overlayutils.GetVxlanUDPPort()), 10)
204205
c = fmt.Sprintf("0>>22&0x3C@12&0xFFFFFF00=%d", int(vni)<<8)
205206
m = strconv.FormatUint(uint64(r), 10)
206207
chain = "OUTPUT"
@@ -227,7 +228,7 @@ func programMangle(vni uint32, add bool) (err error) {
227228

228229
func programInput(vni uint32, add bool) (err error) {
229230
var (
230-
port = strconv.FormatUint(uint64(vxlanPort), 10)
231+
port = strconv.FormatUint(uint64(overlayutils.GetVxlanUDPPort()), 10)
231232
vniMatch = fmt.Sprintf("0>>22&0x3C@12&0xFFFFFF00=%d", int(vni)<<8)
232233
plainVxlan = []string{"-p", "udp", "--dport", port, "-m", "u32", "--u32", vniMatch, "-j"}
233234
ipsecVxlan = append([]string{"-m", "policy", "--dir", "in", "--pol", "ipsec"}, plainVxlan...)

drivers/overlay/ov_utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66
"syscall"
77

8+
"github.com/docker/libnetwork/drivers/overlay/overlayutils"
89
"github.com/docker/libnetwork/netutils"
910
"github.com/docker/libnetwork/ns"
1011
"github.com/docker/libnetwork/osl"
@@ -61,7 +62,7 @@ func createVxlan(name string, vni uint32, mtu int) error {
6162
LinkAttrs: netlink.LinkAttrs{Name: name, MTU: mtu},
6263
VxlanId: int(vni),
6364
Learning: true,
64-
Port: vxlanPort,
65+
Port: int(overlayutils.GetVxlanUDPPort()),
6566
Proxy: true,
6667
L3miss: true,
6768
L2miss: true,

drivers/overlay/overlay.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const (
2525
vethLen = 7
2626
vxlanIDStart = 256
2727
vxlanIDEnd = (1 << 24) - 1
28-
vxlanPort = 4789
2928
vxlanEncap = 50
3029
secureOption = "encrypted"
3130
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Package overlayutils provides utility functions for overlay networks
2+
package overlayutils
3+
4+
import (
5+
"fmt"
6+
"sync"
7+
)
8+
9+
var (
10+
vxlanUDPPort uint32
11+
mutex sync.Mutex
12+
)
13+
14+
func init() {
15+
vxlanUDPPort = 4789
16+
}
17+
18+
// ConfigVxlanUDPPort configures vxlan udp port number.
19+
func ConfigVxlanUDPPort(vxlanPort uint32) error {
20+
mutex.Lock()
21+
defer mutex.Unlock()
22+
// if the value comes as 0 by any reason we set it to default value 4789
23+
if vxlanPort == 0 {
24+
vxlanPort = 4789
25+
}
26+
if vxlanPort < 1024 || vxlanPort > 49151 {
27+
return fmt.Errorf("ConfigVxlanUDPPort Vxlan UDP port number is not in valid range %d", vxlanPort)
28+
}
29+
vxlanUDPPort = vxlanPort
30+
31+
return nil
32+
}
33+
34+
// GetVxlanUDPPort returns Vxlan UDP port number
35+
func GetVxlanUDPPort() uint32 {
36+
mutex.Lock()
37+
defer mutex.Unlock()
38+
return vxlanUDPPort
39+
}

0 commit comments

Comments
 (0)