|
@@ -4,7 +4,6 @@ import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
"net"
|
|
"net"
|
|
- "strconv"
|
|
|
|
"strings"
|
|
"strings"
|
|
"sync"
|
|
"sync"
|
|
|
|
|
|
@@ -62,6 +61,7 @@ type NetworkInfo interface {
|
|
IpamInfo() ([]*IpamInfo, []*IpamInfo)
|
|
IpamInfo() ([]*IpamInfo, []*IpamInfo)
|
|
DriverOptions() map[string]string
|
|
DriverOptions() map[string]string
|
|
Scope() string
|
|
Scope() string
|
|
|
|
+ IPv6Enabled() bool
|
|
Internal() bool
|
|
Internal() bool
|
|
}
|
|
}
|
|
|
|
|
|
@@ -466,7 +466,7 @@ func (n *network) UnmarshalJSON(b []byte) (err error) {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-// NetworkOption is a option setter function type used to pass varios options to
|
|
|
|
|
|
+// NetworkOption is an option setter function type used to pass various options to
|
|
// NewNetwork method. The various setter functions of type NetworkOption are
|
|
// NewNetwork method. The various setter functions of type NetworkOption are
|
|
// provided by libnetwork, they look like NetworkOptionXXXX(...)
|
|
// provided by libnetwork, they look like NetworkOptionXXXX(...)
|
|
type NetworkOption func(n *network)
|
|
type NetworkOption func(n *network)
|
|
@@ -475,9 +475,17 @@ type NetworkOption func(n *network)
|
|
// in a Dictionary of Key-Value pair
|
|
// in a Dictionary of Key-Value pair
|
|
func NetworkOptionGeneric(generic map[string]interface{}) NetworkOption {
|
|
func NetworkOptionGeneric(generic map[string]interface{}) NetworkOption {
|
|
return func(n *network) {
|
|
return func(n *network) {
|
|
- n.generic = generic
|
|
|
|
- if _, ok := generic[netlabel.EnableIPv6]; ok {
|
|
|
|
- n.enableIPv6 = generic[netlabel.EnableIPv6].(bool)
|
|
|
|
|
|
+ if n.generic == nil {
|
|
|
|
+ n.generic = make(map[string]interface{})
|
|
|
|
+ }
|
|
|
|
+ if val, ok := generic[netlabel.EnableIPv6]; ok {
|
|
|
|
+ n.enableIPv6 = val.(bool)
|
|
|
|
+ }
|
|
|
|
+ if val, ok := generic[netlabel.Internal]; ok {
|
|
|
|
+ n.internal = val.(bool)
|
|
|
|
+ }
|
|
|
|
+ for k, v := range generic {
|
|
|
|
+ n.generic[k] = v
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -489,14 +497,25 @@ func NetworkOptionPersist(persist bool) NetworkOption {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// NetworkOptionEnableIPv6 returns an option setter to explicitly configure IPv6
|
|
|
|
+func NetworkOptionEnableIPv6(enableIPv6 bool) NetworkOption {
|
|
|
|
+ return func(n *network) {
|
|
|
|
+ if n.generic == nil {
|
|
|
|
+ n.generic = make(map[string]interface{})
|
|
|
|
+ }
|
|
|
|
+ n.enableIPv6 = enableIPv6
|
|
|
|
+ n.generic[netlabel.EnableIPv6] = enableIPv6
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
// NetworkOptionInternalNetwork returns an option setter to config the network
|
|
// NetworkOptionInternalNetwork returns an option setter to config the network
|
|
// to be internal which disables default gateway service
|
|
// to be internal which disables default gateway service
|
|
func NetworkOptionInternalNetwork() NetworkOption {
|
|
func NetworkOptionInternalNetwork() NetworkOption {
|
|
return func(n *network) {
|
|
return func(n *network) {
|
|
- n.internal = true
|
|
|
|
if n.generic == nil {
|
|
if n.generic == nil {
|
|
n.generic = make(map[string]interface{})
|
|
n.generic = make(map[string]interface{})
|
|
}
|
|
}
|
|
|
|
+ n.internal = true
|
|
n.generic[netlabel.Internal] = true
|
|
n.generic[netlabel.Internal] = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -525,13 +544,6 @@ func NetworkOptionDriverOpts(opts map[string]string) NetworkOption {
|
|
}
|
|
}
|
|
// Store the options
|
|
// Store the options
|
|
n.generic[netlabel.GenericData] = opts
|
|
n.generic[netlabel.GenericData] = opts
|
|
- // Decode and store the endpoint options of libnetwork interest
|
|
|
|
- if val, ok := opts[netlabel.EnableIPv6]; ok {
|
|
|
|
- var err error
|
|
|
|
- if n.enableIPv6, err = strconv.ParseBool(val); err != nil {
|
|
|
|
- log.Warnf("Failed to parse %s' value: %s (%s)", netlabel.EnableIPv6, val, err.Error())
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -692,7 +704,7 @@ func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoi
|
|
ep.id = stringid.GenerateRandomID()
|
|
ep.id = stringid.GenerateRandomID()
|
|
|
|
|
|
// Initialize ep.network with a possibly stale copy of n. We need this to get network from
|
|
// Initialize ep.network with a possibly stale copy of n. We need this to get network from
|
|
- // store. But once we get it from store we will have the most uptodate copy possible.
|
|
|
|
|
|
+ // store. But once we get it from store we will have the most uptodate copy possibly.
|
|
ep.network = n
|
|
ep.network = n
|
|
ep.locator = n.getController().clusterHostID()
|
|
ep.locator = n.getController().clusterHostID()
|
|
ep.network, err = ep.getNetworkFromStore()
|
|
ep.network, err = ep.getNetworkFromStore()
|
|
@@ -1237,3 +1249,10 @@ func (n *network) Internal() bool {
|
|
|
|
|
|
return n.internal
|
|
return n.internal
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func (n *network) IPv6Enabled() bool {
|
|
|
|
+ n.Lock()
|
|
|
|
+ defer n.Unlock()
|
|
|
|
+
|
|
|
|
+ return n.enableIPv6
|
|
|
|
+}
|