Skip to content

Commit cb395b0

Browse files
mavenugoabhi
authored andcommitted
Updating config.toml with more configurable parameters
* Make VXLAN and Gossip port configurable * Configurable Default gateway network name * Add DataDir configuration params Signed-off-by: Madhu Venugopal <madhu@docker.com>
1 parent a2f4501 commit cb395b0

15 files changed

Lines changed: 118 additions & 51 deletions

cmd/dnet/dnet.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ func processConfig(cfg *config.Config) []config.Option {
123123
options = append(options, config.OptionKVProviderURL(dcfg.Client.Address))
124124
}
125125

126+
if cfg.Daemon.DefaultGwNetwork != "" {
127+
options = append(options, config.OptionDefaultGwNetwork(cfg.Daemon.DefaultGwNetwork))
128+
}
129+
130+
if cfg.Daemon.DataDir != "" {
131+
options = append(options, config.OptionDataDir(cfg.Daemon.DataDir))
132+
}
133+
126134
dOptions, err := startDiscovery(&cfg.Cluster)
127135
if err != nil {
128136
logrus.Infof("Skipping discovery : %s", err.Error())

config/config.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package config
22

33
import (
4-
"fmt"
54
"os"
65
"strings"
76

@@ -37,6 +36,7 @@ type DaemonCfg struct {
3736
Experimental bool
3837
DataDir string
3938
DefaultNetwork string
39+
DefaultGwNetwork string
4040
DefaultDriver string
4141
Labels []string
4242
DriverCfg map[string]interface{}
@@ -81,14 +81,12 @@ func ParseConfig(tomlCfgFile string) (*Config, error) {
8181
if !(strings.Contains(cfg.Cluster.Discovery, "etcd") || strings.Contains(cfg.Cluster.Discovery, "consul")) {
8282
cfg.Cluster.Discovery = "etcd://" + cfg.Cluster.Discovery
8383
}
84-
fmt.Printf("cluster address=%s, discovery=%s \n", cfg.Cluster.Address, cfg.Cluster.Discovery)
8584

8685
if _, ok := cfg.Scopes[datastore.GlobalScope]; !ok {
8786
kvParts := strings.SplitN(cfg.Cluster.Discovery, "://", 2)
8887
if len(kvParts) == 2 {
8988
gCfg := datastore.ScopeClientCfg{Provider: kvParts[0], Address: kvParts[1]}
9089
cfg.Scopes[datastore.GlobalScope] = &datastore.ScopeCfg{gCfg}
91-
fmt.Printf("KVStore provider=%s, address=%s\n", kvParts[0], kvParts[1])
9290
}
9391

9492
}
@@ -119,11 +117,17 @@ type Option func(c *Config)
119117
// OptionDefaultNetwork function returns an option setter for a default network
120118
func OptionDefaultNetwork(dn string) Option {
121119
return func(c *Config) {
122-
logrus.Debugf("Option DefaultNetwork: %s", dn)
123120
c.Daemon.DefaultNetwork = strings.TrimSpace(dn)
124121
}
125122
}
126123

124+
// OptionDefaultGwNetwork function returns an option setter for a default Gateway network
125+
func OptionDefaultGwNetwork(dn string) Option {
126+
return func(c *Config) {
127+
c.Daemon.DefaultGwNetwork = strings.TrimSpace(dn)
128+
}
129+
}
130+
127131
// OptionDefaultDriver function returns an option setter for default driver
128132
func OptionDefaultDriver(dd string) Option {
129133
return func(c *Config) {

config/libnetwork.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ title = "LibNetwork Configuration file"
22

33
[daemon]
44
debug = true
5-
labels = ["com.docker.network.driver.overlay.hostmode=true"]
5+
labels = ["com.docker.network.driver.overlay.hostmode=true", "com.docker.network.driver.overlay.vxlan-port=4790", "com.docker.network.driver.overlay.gossip-port=8000"]
6+
defaultGwNetwork = "dnet-gwbridge"
7+
DataDir = "/var/run/libnetwork"
68
[cluster]
7-
discovery = "etcd://localhost:2379"
8-
Address = "192.168.56.101"
9+
discovery = "etcd://192.168.56.101:3379"
10+
address = "192.168.56.101"
911
[datastore]
1012
embedded = false
1113
[datastore.client]
1214
provider = "etcd"
13-
Address = "localhost:2379"
15+
Address = "192.168.56.101:3379"
1416
[scopes]
1517
[scopes.global]
1618
[scopes.global.client]
1719
provider = "etcd"
18-
address = "localhost:2379"
20+
address = "192.168.56.101:3379"

controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ func New(cfgOptions ...config.Option) (NetworkController, error) {
191191
return nil, err
192192
}
193193

194+
c.initDefaultGwNetwork()
194195
drvRegistry, err := drvregistry.New(c.getStore(datastore.LocalScope), c.getStore(datastore.GlobalScope), c.RegisterDriver, nil, c.cfg.PluginGetter)
195196
if err != nil {
196197
return nil, err

default_gateway.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ var procGwNetwork = make(chan (bool), 1)
2929
- its deleted when an endpoint with GW joins the container
3030
*/
3131

32+
func (c *controller) initDefaultGwNetwork() {
33+
if c.cfg.Daemon.DefaultGwNetwork == "" {
34+
c.cfg.Daemon.DefaultGwNetwork = libnGWNetwork
35+
}
36+
}
37+
3238
func (sb *sandbox) setupDefaultGW() error {
3339

3440
// check if the container already has a GW endpoint
@@ -40,7 +46,7 @@ func (sb *sandbox) setupDefaultGW() error {
4046

4147
// Look for default gw network. In case of error (includes not found),
4248
// retry and create it if needed in a serialized execution.
43-
n, err := c.NetworkByName(libnGWNetwork)
49+
n, err := c.NetworkByName(sb.controller.DefaultGwNetworkName())
4450
if err != nil {
4551
if n, err = c.defaultGwNetwork(); err != nil {
4652
return err
@@ -146,15 +152,15 @@ func (sb *sandbox) needDefaultGW() bool {
146152

147153
func (sb *sandbox) getEndpointInGWNetwork() *endpoint {
148154
for _, ep := range sb.getConnectedEndpoints() {
149-
if ep.getNetwork().name == libnGWNetwork && strings.HasPrefix(ep.Name(), "gateway_") {
155+
if ep.getNetwork().name == sb.controller.DefaultGwNetworkName() && strings.HasPrefix(ep.Name(), "gateway_") {
150156
return ep
151157
}
152158
}
153159
return nil
154160
}
155161

156162
func (ep *endpoint) endpointInGWNetwork() bool {
157-
if ep.getNetwork().name == libnGWNetwork && strings.HasPrefix(ep.Name(), "gateway_") {
163+
if ep.getNetwork().name == ep.getNetwork().ctrlr.DefaultGwNetworkName() && strings.HasPrefix(ep.Name(), "gateway_") {
158164
return true
159165
}
160166
return false
@@ -178,7 +184,7 @@ func (c *controller) defaultGwNetwork() (Network, error) {
178184
procGwNetwork <- true
179185
defer func() { <-procGwNetwork }()
180186

181-
n, err := c.NetworkByName(libnGWNetwork)
187+
n, err := c.NetworkByName(c.DefaultGwNetworkName())
182188
if err != nil {
183189
if _, ok := err.(types.NotFoundError); ok {
184190
n, err = c.createGWNetwork()
@@ -187,6 +193,10 @@ func (c *controller) defaultGwNetwork() (Network, error) {
187193
return n, err
188194
}
189195

196+
func (c *controller) DefaultGwNetworkName() string {
197+
return c.cfg.Daemon.DefaultGwNetwork
198+
}
199+
190200
// Returns the endpoint which is providing external connectivity to the sandbox
191201
func (sb *sandbox) getGatewayEndpoint() *endpoint {
192202
for _, ep := range sb.getConnectedEndpoints() {

default_gateway_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ func getPlatformOption() EndpointOption {
1515

1616
func (c *controller) createGWNetwork() (Network, error) {
1717
netOption := map[string]string{
18-
bridge.BridgeName: libnGWNetwork,
18+
bridge.BridgeName: c.DefaultGwNetworkName(),
1919
bridge.EnableICC: strconv.FormatBool(false),
2020
bridge.EnableIPMasquerade: strconv.FormatBool(true),
2121
}
2222

23-
n, err := c.NewNetwork("bridge", libnGWNetwork, "",
23+
n, err := c.NewNetwork("bridge", c.DefaultGwNetworkName(), "",
2424
NetworkOptionDriverOpts(netOption),
2525
NetworkOptionEnableIPv6(false),
2626
)

default_gateway_solaris.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ func getPlatformOption() EndpointOption {
1515

1616
func (c *controller) createGWNetwork() (Network, error) {
1717
netOption := map[string]string{
18-
bridge.BridgeName: libnGWNetwork,
18+
bridge.BridgeName: c.DefaultGwNetworkName(),
1919
bridge.EnableICC: strconv.FormatBool(false),
2020
bridge.EnableIPMasquerade: strconv.FormatBool(true),
2121
}
2222

23-
n, err := c.NewNetwork("bridge", libnGWNetwork, "",
23+
n, err := c.NewNetwork("bridge", c.DefaultGwNetworkName(), "",
2424
NetworkOptionDriverOpts(netOption),
2525
NetworkOptionEnableIPv6(false),
2626
)

drivers/overlay/encryption.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ func (d *driver) checkEncryption(nid string, rIP net.IP, vxlanID uint32, isLocal
113113

114114
if add {
115115
for _, rIP := range nodes {
116-
if err := setupEncryption(lIP, aIP, rIP, vxlanID, d.secMap, d.keys); err != nil {
116+
if err := d.setupEncryption(lIP, aIP, rIP, vxlanID, d.secMap, d.keys); err != nil {
117117
logrus.Warnf("Failed to program network encryption between %s and %s: %v", lIP, rIP, err)
118118
}
119119
}
120120
} else {
121121
if len(nodes) == 0 {
122-
if err := removeEncryption(lIP, rIP, d.secMap); err != nil {
122+
if err := d.removeEncryption(lIP, rIP, d.secMap); err != nil {
123123
logrus.Warnf("Failed to remove network encryption between %s and %s: %v", lIP, rIP, err)
124124
}
125125
}
@@ -128,18 +128,18 @@ func (d *driver) checkEncryption(nid string, rIP net.IP, vxlanID uint32, isLocal
128128
return nil
129129
}
130130

131-
func setupEncryption(localIP, advIP, remoteIP net.IP, vni uint32, em *encrMap, keys []*key) error {
131+
func (d *driver) setupEncryption(localIP, advIP, remoteIP net.IP, vni uint32, em *encrMap, keys []*key) error {
132132
logrus.Debugf("Programming encryption for vxlan %d between %s and %s", vni, localIP, remoteIP)
133133
rIPs := remoteIP.String()
134134

135135
indices := make([]*spi, 0, len(keys))
136136

137-
err := programMangle(vni, true)
137+
err := programMangle(vni, d.vxlanPort, true)
138138
if err != nil {
139139
logrus.Warn(err)
140140
}
141141

142-
err = programInput(vni, true)
142+
err = programInput(vni, d.vxlanPort, true)
143143
if err != nil {
144144
logrus.Warn(err)
145145
}
@@ -171,7 +171,7 @@ func setupEncryption(localIP, advIP, remoteIP net.IP, vni uint32, em *encrMap, k
171171
return nil
172172
}
173173

174-
func removeEncryption(localIP, remoteIP net.IP, em *encrMap) error {
174+
func (d *driver) removeEncryption(localIP, remoteIP net.IP, em *encrMap) error {
175175
em.Lock()
176176
indices, ok := em.nodes[remoteIP.String()]
177177
em.Unlock()
@@ -198,7 +198,7 @@ func removeEncryption(localIP, remoteIP net.IP, em *encrMap) error {
198198
return nil
199199
}
200200

201-
func programMangle(vni uint32, add bool) (err error) {
201+
func programMangle(vni uint32, vxlanPort int, add bool) (err error) {
202202
var (
203203
p = strconv.FormatUint(uint64(vxlanPort), 10)
204204
c = fmt.Sprintf("0>>22&0x3C@12&0xFFFFFF00=%d", int(vni)<<8)
@@ -225,7 +225,7 @@ func programMangle(vni uint32, add bool) (err error) {
225225
return
226226
}
227227

228-
func programInput(vni uint32, add bool) (err error) {
228+
func programInput(vni uint32, vxlanPort int, add bool) (err error) {
229229
var (
230230
port = strconv.FormatUint(uint64(vxlanPort), 10)
231231
vniMatch = fmt.Sprintf("0>>22&0x3C@12&0xFFFFFF00=%d", int(vni)<<8)

drivers/overlay/joinleave.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
4444
return fmt.Errorf("could not find subnet for endpoint %s", eid)
4545
}
4646

47-
if s.gwIP == nil {
47+
if n.hostAccess && s.gwIP == nil {
4848
gwIP, err := jinfo.RequestAddress(s.subnetIP)
4949
if err != nil {
5050
logrus.Errorf("RequestAddress failed %s %v", s.subnetIP.String(), err)

drivers/overlay/ov_network.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
214214
// Make sure no rule is on the way from any stale secure network
215215
if !n.secure {
216216
for _, vni := range vnis {
217-
programMangle(vni, false)
218-
programInput(vni, false)
217+
programMangle(vni, d.vxlanPort, false)
218+
programInput(vni, d.vxlanPort, false)
219219
}
220220
}
221221

@@ -266,8 +266,8 @@ func (d *driver) DeleteNetwork(nid string) error {
266266

267267
if n.secure {
268268
for _, vni := range vnis {
269-
programMangle(vni, false)
270-
programInput(vni, false)
269+
programMangle(vni, d.vxlanPort, false)
270+
programInput(vni, d.vxlanPort, false)
271271
}
272272
}
273273

@@ -418,13 +418,13 @@ func populateVNITbl() {
418418
})
419419
}
420420

421-
func networkOnceInit() {
421+
func (d *driver) networkOnceInit() {
422422
populateVNITbl()
423423
if hostMode {
424424
return
425425
}
426426

427-
err := createVxlan("testvxlan", 1, 0)
427+
err := createVxlan("testvxlan", 1, d.vxlanPort, 0)
428428
if err != nil {
429429
logrus.Errorf("Failed to create testvxlan interface: %v", err)
430430
return
@@ -565,7 +565,7 @@ func (n *network) setupSubnetSandbox(s *subnet, brName, vxlanName string) error
565565
return fmt.Errorf("bridge creation in sandbox failed for subnet %q: %v", s.subnetIP.String(), err)
566566
}
567567

568-
err := createVxlan(vxlanName, n.vxlanID(s), n.maxMTU())
568+
err := createVxlan(vxlanName, n.vxlanID(s), n.driver.vxlanPort, n.maxMTU())
569569
if err != nil {
570570
return err
571571
}
@@ -665,7 +665,7 @@ func (n *network) initSandbox(restore bool) error {
665665
n.initEpoch++
666666
n.Unlock()
667667

668-
networkOnce.Do(networkOnceInit)
668+
networkOnce.Do(n.driver.networkOnceInit)
669669

670670
if !restore {
671671
if hostMode {

0 commit comments

Comments
 (0)