2015-04-13 14:40:42 -04:00
|
|
|
package libnetwork
|
2015-02-27 12:34:30 -05:00
|
|
|
|
2015-04-13 14:40:42 -04:00
|
|
|
import (
|
2015-05-08 09:26:35 -04:00
|
|
|
"encoding/json"
|
2015-10-05 07:21:15 -04:00
|
|
|
"fmt"
|
2015-06-19 02:40:17 -04:00
|
|
|
"net"
|
2015-10-23 13:09:00 -04:00
|
|
|
"strings"
|
2015-04-13 14:40:42 -04:00
|
|
|
"sync"
|
2015-02-27 12:34:30 -05:00
|
|
|
|
2015-06-10 16:27:23 -04:00
|
|
|
log "github.com/Sirupsen/logrus"
|
2015-04-18 00:37:54 -04:00
|
|
|
"github.com/docker/docker/pkg/stringid"
|
2015-06-14 12:00:27 -04:00
|
|
|
"github.com/docker/libnetwork/config"
|
2015-05-15 18:23:59 -04:00
|
|
|
"github.com/docker/libnetwork/datastore"
|
2015-04-13 14:40:42 -04:00
|
|
|
"github.com/docker/libnetwork/driverapi"
|
2015-06-19 02:40:17 -04:00
|
|
|
"github.com/docker/libnetwork/etchosts"
|
2015-10-06 23:29:30 -04:00
|
|
|
"github.com/docker/libnetwork/ipamapi"
|
2015-05-16 19:02:51 -04:00
|
|
|
"github.com/docker/libnetwork/netlabel"
|
2015-12-09 21:09:58 -05:00
|
|
|
"github.com/docker/libnetwork/netutils"
|
2015-05-16 19:02:51 -04:00
|
|
|
"github.com/docker/libnetwork/options"
|
2015-04-20 11:44:06 -04:00
|
|
|
"github.com/docker/libnetwork/types"
|
2015-04-13 14:40:42 -04:00
|
|
|
)
|
2015-02-27 12:34:30 -05:00
|
|
|
|
2015-03-02 13:17:12 -05:00
|
|
|
// A Network represents a logical connectivity zone that containers may
|
2015-04-15 08:42:25 -04:00
|
|
|
// join using the Link method. A Network is managed by a specific driver.
|
2015-03-02 13:17:12 -05:00
|
|
|
type Network interface {
|
|
|
|
// A user chosen name for this network.
|
|
|
|
Name() string
|
|
|
|
|
2015-04-13 14:40:42 -04:00
|
|
|
// A system generated id for this network.
|
|
|
|
ID() string
|
|
|
|
|
2015-03-02 13:17:12 -05:00
|
|
|
// The type of network, which corresponds to its managing driver.
|
|
|
|
Type() string
|
|
|
|
|
2015-04-13 14:40:42 -04:00
|
|
|
// Create a new endpoint to this network symbolically identified by the
|
|
|
|
// specified unique name. The options parameter carry driver specific options.
|
2015-04-30 20:57:06 -04:00
|
|
|
CreateEndpoint(name string, options ...EndpointOption) (Endpoint, error)
|
2015-03-20 16:54:49 -04:00
|
|
|
|
2015-04-24 15:05:33 -04:00
|
|
|
// Delete the network.
|
|
|
|
Delete() error
|
|
|
|
|
2015-04-20 12:46:11 -04:00
|
|
|
// Endpoints returns the list of Endpoint(s) in this network.
|
2015-04-18 02:13:29 -04:00
|
|
|
Endpoints() []Endpoint
|
|
|
|
|
2015-04-20 12:46:11 -04:00
|
|
|
// WalkEndpoints uses the provided function to walk the Endpoints
|
|
|
|
WalkEndpoints(walker EndpointWalker)
|
|
|
|
|
2015-05-15 19:04:09 -04:00
|
|
|
// EndpointByName returns the Endpoint which has the passed name. If not found, the error ErrNoSuchEndpoint is returned.
|
2015-05-11 19:13:27 -04:00
|
|
|
EndpointByName(name string) (Endpoint, error)
|
2015-04-24 15:05:33 -04:00
|
|
|
|
2015-05-15 19:04:09 -04:00
|
|
|
// EndpointByID returns the Endpoint which has the passed id. If not found, the error ErrNoSuchEndpoint is returned.
|
2015-05-11 19:13:27 -04:00
|
|
|
EndpointByID(id string) (Endpoint, error)
|
2015-10-06 15:08:54 -04:00
|
|
|
|
|
|
|
// Return certain operational data belonging to this network
|
|
|
|
Info() NetworkInfo
|
|
|
|
}
|
|
|
|
|
2015-10-09 16:46:33 -04:00
|
|
|
// NetworkInfo returns some configuration and operational information about the network
|
2015-10-06 15:08:54 -04:00
|
|
|
type NetworkInfo interface {
|
2016-01-07 15:57:22 -05:00
|
|
|
IpamConfig() (string, map[string]string, []*IpamConf, []*IpamConf)
|
2015-12-16 04:30:21 -05:00
|
|
|
IpamInfo() ([]*IpamInfo, []*IpamInfo)
|
2015-10-14 19:38:46 -04:00
|
|
|
DriverOptions() map[string]string
|
2015-10-06 15:08:54 -04:00
|
|
|
Scope() string
|
2016-01-29 13:10:06 -05:00
|
|
|
IPv6Enabled() bool
|
2015-12-27 21:30:38 -05:00
|
|
|
Internal() bool
|
2015-03-02 13:17:12 -05:00
|
|
|
}
|
|
|
|
|
2015-04-20 12:46:11 -04:00
|
|
|
// EndpointWalker is a client provided function which will be used to walk the Endpoints.
|
|
|
|
// When the function returns true, the walk will stop.
|
|
|
|
type EndpointWalker func(ep Endpoint) bool
|
2015-02-27 12:34:30 -05:00
|
|
|
|
2015-12-24 04:51:32 -05:00
|
|
|
type svcInfo struct {
|
2016-01-07 22:19:31 -05:00
|
|
|
svcMap map[string][]net.IP
|
2015-12-24 04:51:32 -05:00
|
|
|
ipMap map[string]string
|
|
|
|
}
|
2015-06-19 02:40:17 -04:00
|
|
|
|
2015-10-03 19:11:50 -04:00
|
|
|
// IpamConf contains all the ipam related configurations for a network
|
|
|
|
type IpamConf struct {
|
2015-10-12 16:39:38 -04:00
|
|
|
// The master address pool for containers and network interfaces
|
2015-10-03 19:11:50 -04:00
|
|
|
PreferredPool string
|
2015-10-06 23:29:30 -04:00
|
|
|
// A subset of the master pool. If specified,
|
|
|
|
// this becomes the container pool
|
|
|
|
SubPool string
|
|
|
|
// Preferred Network Gateway address (optional)
|
|
|
|
Gateway string
|
|
|
|
// Auxiliary addresses for network driver. Must be within the master pool.
|
|
|
|
// libnetwork will reserve them if they fall into the container pool
|
|
|
|
AuxAddresses map[string]string
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate checks whether the configuration is valid
|
|
|
|
func (c *IpamConf) Validate() error {
|
|
|
|
if c.Gateway != "" && nil == net.ParseIP(c.Gateway) {
|
2015-10-10 06:49:09 -04:00
|
|
|
return types.BadRequestErrorf("invalid gateway address %s in Ipam configuration", c.Gateway)
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// IpamInfo contains all the ipam related operational info for a network
|
|
|
|
type IpamInfo struct {
|
|
|
|
PoolID string
|
|
|
|
Meta map[string]string
|
|
|
|
driverapi.IPAMData
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalJSON encodes IpamInfo into json message
|
|
|
|
func (i *IpamInfo) MarshalJSON() ([]byte, error) {
|
|
|
|
m := map[string]interface{}{
|
|
|
|
"PoolID": i.PoolID,
|
|
|
|
}
|
|
|
|
v, err := json.Marshal(&i.IPAMData)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
m["IPAMData"] = string(v)
|
|
|
|
|
|
|
|
if i.Meta != nil {
|
|
|
|
m["Meta"] = i.Meta
|
|
|
|
}
|
|
|
|
return json.Marshal(m)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON decodes json message into PoolData
|
|
|
|
func (i *IpamInfo) UnmarshalJSON(data []byte) error {
|
|
|
|
var (
|
|
|
|
m map[string]interface{}
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if err = json.Unmarshal(data, &m); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
i.PoolID = m["PoolID"].(string)
|
|
|
|
if v, ok := m["Meta"]; ok {
|
|
|
|
b, _ := json.Marshal(v)
|
|
|
|
if err = json.Unmarshal(b, &i.Meta); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if v, ok := m["IPAMData"]; ok {
|
|
|
|
if err = json.Unmarshal([]byte(v.(string)), &i.IPAMData); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-04-13 14:40:42 -04:00
|
|
|
type network struct {
|
2015-10-03 19:11:50 -04:00
|
|
|
ctrlr *controller
|
|
|
|
name string
|
|
|
|
networkType string
|
|
|
|
id string
|
2016-01-17 15:43:41 -05:00
|
|
|
scope string
|
2015-10-03 19:11:50 -04:00
|
|
|
ipamType string
|
2016-01-07 15:57:22 -05:00
|
|
|
ipamOptions map[string]string
|
2015-10-03 19:11:50 -04:00
|
|
|
addrSpace string
|
|
|
|
ipamV4Config []*IpamConf
|
|
|
|
ipamV6Config []*IpamConf
|
|
|
|
ipamV4Info []*IpamInfo
|
|
|
|
ipamV6Info []*IpamInfo
|
|
|
|
enableIPv6 bool
|
2015-11-06 02:50:10 -05:00
|
|
|
postIPv6 bool
|
2015-10-12 01:28:26 -04:00
|
|
|
epCnt *endpointCnt
|
2015-10-03 19:11:50 -04:00
|
|
|
generic options.Generic
|
|
|
|
dbIndex uint64
|
|
|
|
dbExists bool
|
|
|
|
persist bool
|
|
|
|
stopWatchCh chan struct{}
|
2015-10-05 07:21:15 -04:00
|
|
|
drvOnce *sync.Once
|
2015-12-21 20:29:39 -05:00
|
|
|
internal bool
|
2015-04-13 14:40:42 -04:00
|
|
|
sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *network) Name() string {
|
2015-05-28 19:29:21 -04:00
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
|
|
|
|
2015-04-13 14:40:42 -04:00
|
|
|
return n.name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *network) ID() string {
|
2015-05-28 19:29:21 -04:00
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
|
|
|
|
2015-07-02 01:00:48 -04:00
|
|
|
return n.id
|
2015-04-13 14:40:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *network) Type() string {
|
2015-05-28 19:29:21 -04:00
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
|
|
|
|
2015-10-05 07:21:15 -04:00
|
|
|
return n.networkType
|
2015-04-13 14:40:42 -04:00
|
|
|
}
|
|
|
|
|
2015-05-08 09:26:35 -04:00
|
|
|
func (n *network) Key() []string {
|
2015-06-05 16:31:12 -04:00
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
2015-07-02 01:00:48 -04:00
|
|
|
return []string{datastore.NetworkKeyPrefix, n.id}
|
2015-05-08 09:26:35 -04:00
|
|
|
}
|
|
|
|
|
2015-06-01 12:43:24 -04:00
|
|
|
func (n *network) KeyPrefix() []string {
|
|
|
|
return []string{datastore.NetworkKeyPrefix}
|
|
|
|
}
|
|
|
|
|
2015-05-08 09:26:35 -04:00
|
|
|
func (n *network) Value() []byte {
|
2015-06-05 16:31:12 -04:00
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
2015-05-08 09:26:35 -04:00
|
|
|
b, err := json.Marshal(n)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2015-06-18 18:13:38 -04:00
|
|
|
func (n *network) SetValue(value []byte) error {
|
|
|
|
return json.Unmarshal(value, n)
|
|
|
|
}
|
|
|
|
|
2015-05-08 09:26:35 -04:00
|
|
|
func (n *network) Index() uint64 {
|
2015-06-05 16:31:12 -04:00
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
2015-05-08 09:26:35 -04:00
|
|
|
return n.dbIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *network) SetIndex(index uint64) {
|
2015-06-05 16:31:12 -04:00
|
|
|
n.Lock()
|
2015-05-08 09:26:35 -04:00
|
|
|
n.dbIndex = index
|
2015-06-18 18:13:38 -04:00
|
|
|
n.dbExists = true
|
2015-06-05 16:31:12 -04:00
|
|
|
n.Unlock()
|
|
|
|
}
|
|
|
|
|
2015-06-18 18:13:38 -04:00
|
|
|
func (n *network) Exists() bool {
|
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
|
|
|
return n.dbExists
|
|
|
|
}
|
|
|
|
|
2015-09-22 10:09:39 -04:00
|
|
|
func (n *network) Skip() bool {
|
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
|
|
|
return !n.persist
|
|
|
|
}
|
|
|
|
|
2015-10-05 07:21:15 -04:00
|
|
|
func (n *network) New() datastore.KVObject {
|
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
|
|
|
|
|
|
|
return &network{
|
|
|
|
ctrlr: n.ctrlr,
|
|
|
|
drvOnce: &sync.Once{},
|
2016-01-17 15:43:41 -05:00
|
|
|
scope: n.scope,
|
2015-10-05 07:21:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-09 16:46:33 -04:00
|
|
|
// CopyTo deep copies to the destination IpamConfig
|
|
|
|
func (c *IpamConf) CopyTo(dstC *IpamConf) error {
|
|
|
|
dstC.PreferredPool = c.PreferredPool
|
|
|
|
dstC.SubPool = c.SubPool
|
|
|
|
dstC.Gateway = c.Gateway
|
|
|
|
if c.AuxAddresses != nil {
|
|
|
|
dstC.AuxAddresses = make(map[string]string, len(c.AuxAddresses))
|
|
|
|
for k, v := range c.AuxAddresses {
|
|
|
|
dstC.AuxAddresses[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-10-05 07:21:15 -04:00
|
|
|
// CopyTo deep copies to the destination IpamInfo
|
|
|
|
func (i *IpamInfo) CopyTo(dstI *IpamInfo) error {
|
|
|
|
dstI.PoolID = i.PoolID
|
|
|
|
if i.Meta != nil {
|
|
|
|
dstI.Meta = make(map[string]string)
|
|
|
|
for k, v := range i.Meta {
|
|
|
|
dstI.Meta[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dstI.AddressSpace = i.AddressSpace
|
|
|
|
dstI.Pool = types.GetIPNetCopy(i.Pool)
|
|
|
|
dstI.Gateway = types.GetIPNetCopy(i.Gateway)
|
|
|
|
|
|
|
|
if i.AuxAddresses != nil {
|
|
|
|
dstI.AuxAddresses = make(map[string]*net.IPNet)
|
|
|
|
for k, v := range i.AuxAddresses {
|
|
|
|
dstI.AuxAddresses[k] = types.GetIPNetCopy(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *network) CopyTo(o datastore.KVObject) error {
|
2015-09-16 07:39:46 -04:00
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
2015-10-05 07:21:15 -04:00
|
|
|
|
|
|
|
dstN := o.(*network)
|
|
|
|
dstN.name = n.name
|
|
|
|
dstN.id = n.id
|
|
|
|
dstN.networkType = n.networkType
|
2016-01-17 15:43:41 -05:00
|
|
|
dstN.scope = n.scope
|
2015-10-05 07:21:15 -04:00
|
|
|
dstN.ipamType = n.ipamType
|
|
|
|
dstN.enableIPv6 = n.enableIPv6
|
|
|
|
dstN.persist = n.persist
|
2015-11-06 02:50:10 -05:00
|
|
|
dstN.postIPv6 = n.postIPv6
|
2015-10-05 07:21:15 -04:00
|
|
|
dstN.dbIndex = n.dbIndex
|
|
|
|
dstN.dbExists = n.dbExists
|
|
|
|
dstN.drvOnce = n.drvOnce
|
2015-12-21 20:29:39 -05:00
|
|
|
dstN.internal = n.internal
|
2015-10-05 07:21:15 -04:00
|
|
|
|
2015-10-09 16:46:33 -04:00
|
|
|
for _, v4conf := range n.ipamV4Config {
|
|
|
|
dstV4Conf := &IpamConf{}
|
|
|
|
v4conf.CopyTo(dstV4Conf)
|
|
|
|
dstN.ipamV4Config = append(dstN.ipamV4Config, dstV4Conf)
|
|
|
|
}
|
|
|
|
|
2015-10-05 07:21:15 -04:00
|
|
|
for _, v4info := range n.ipamV4Info {
|
|
|
|
dstV4Info := &IpamInfo{}
|
|
|
|
v4info.CopyTo(dstV4Info)
|
|
|
|
dstN.ipamV4Info = append(dstN.ipamV4Info, dstV4Info)
|
|
|
|
}
|
|
|
|
|
2015-10-09 16:46:33 -04:00
|
|
|
for _, v6conf := range n.ipamV6Config {
|
|
|
|
dstV6Conf := &IpamConf{}
|
|
|
|
v6conf.CopyTo(dstV6Conf)
|
|
|
|
dstN.ipamV6Config = append(dstN.ipamV6Config, dstV6Conf)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v6info := range n.ipamV6Info {
|
|
|
|
dstV6Info := &IpamInfo{}
|
|
|
|
v6info.CopyTo(dstV6Info)
|
|
|
|
dstN.ipamV6Info = append(dstN.ipamV6Info, dstV6Info)
|
2015-10-04 00:25:57 -04:00
|
|
|
}
|
|
|
|
|
2015-10-05 07:21:15 -04:00
|
|
|
dstN.generic = options.Generic{}
|
|
|
|
for k, v := range n.generic {
|
|
|
|
dstN.generic[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *network) DataScope() string {
|
2016-01-17 15:43:41 -05:00
|
|
|
return n.Scope()
|
2015-09-16 07:39:46 -04:00
|
|
|
}
|
|
|
|
|
2015-10-12 01:28:26 -04:00
|
|
|
func (n *network) getEpCnt() *endpointCnt {
|
2015-06-05 16:31:12 -04:00
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
2015-10-09 22:31:44 -04:00
|
|
|
|
2015-10-12 01:28:26 -04:00
|
|
|
return n.epCnt
|
2015-05-08 09:26:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO : Can be made much more generic with the help of reflection (but has some golang limitations)
|
|
|
|
func (n *network) MarshalJSON() ([]byte, error) {
|
|
|
|
netMap := make(map[string]interface{})
|
|
|
|
netMap["name"] = n.name
|
2015-07-02 01:00:48 -04:00
|
|
|
netMap["id"] = n.id
|
2015-05-08 09:26:35 -04:00
|
|
|
netMap["networkType"] = n.networkType
|
2016-01-17 15:43:41 -05:00
|
|
|
netMap["scope"] = n.scope
|
2015-09-22 16:20:55 -04:00
|
|
|
netMap["ipamType"] = n.ipamType
|
2015-10-03 19:11:50 -04:00
|
|
|
netMap["addrSpace"] = n.addrSpace
|
2015-05-08 09:26:35 -04:00
|
|
|
netMap["enableIPv6"] = n.enableIPv6
|
2015-10-03 19:11:50 -04:00
|
|
|
if n.generic != nil {
|
|
|
|
netMap["generic"] = n.generic
|
|
|
|
}
|
2015-09-22 10:09:39 -04:00
|
|
|
netMap["persist"] = n.persist
|
2015-11-06 02:50:10 -05:00
|
|
|
netMap["postIPv6"] = n.postIPv6
|
2015-10-03 19:11:50 -04:00
|
|
|
if len(n.ipamV4Config) > 0 {
|
|
|
|
ics, err := json.Marshal(n.ipamV4Config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
netMap["ipamV4Config"] = string(ics)
|
|
|
|
}
|
|
|
|
if len(n.ipamV4Info) > 0 {
|
|
|
|
iis, err := json.Marshal(n.ipamV4Info)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
netMap["ipamV4Info"] = string(iis)
|
|
|
|
}
|
|
|
|
if len(n.ipamV6Config) > 0 {
|
|
|
|
ics, err := json.Marshal(n.ipamV6Config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
netMap["ipamV6Config"] = string(ics)
|
|
|
|
}
|
|
|
|
if len(n.ipamV6Info) > 0 {
|
|
|
|
iis, err := json.Marshal(n.ipamV6Info)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
netMap["ipamV6Info"] = string(iis)
|
|
|
|
}
|
2015-12-21 20:29:39 -05:00
|
|
|
netMap["internal"] = n.internal
|
2015-05-08 09:26:35 -04:00
|
|
|
return json.Marshal(netMap)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO : Can be made much more generic with the help of reflection (but has some golang limitations)
|
|
|
|
func (n *network) UnmarshalJSON(b []byte) (err error) {
|
|
|
|
var netMap map[string]interface{}
|
|
|
|
if err := json.Unmarshal(b, &netMap); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
n.name = netMap["name"].(string)
|
2015-07-02 01:00:48 -04:00
|
|
|
n.id = netMap["id"].(string)
|
2015-05-08 09:26:35 -04:00
|
|
|
n.networkType = netMap["networkType"].(string)
|
|
|
|
n.enableIPv6 = netMap["enableIPv6"].(bool)
|
2015-10-07 16:04:21 -04:00
|
|
|
|
2015-10-03 19:11:50 -04:00
|
|
|
if v, ok := netMap["generic"]; ok {
|
|
|
|
n.generic = v.(map[string]interface{})
|
2015-10-14 19:38:46 -04:00
|
|
|
// Restore opts in their map[string]string form
|
2015-10-06 15:08:54 -04:00
|
|
|
if v, ok := n.generic[netlabel.GenericData]; ok {
|
|
|
|
var lmap map[string]string
|
|
|
|
ba, err := json.Marshal(v)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := json.Unmarshal(ba, &lmap); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
n.generic[netlabel.GenericData] = lmap
|
|
|
|
}
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
|
|
|
if v, ok := netMap["persist"]; ok {
|
|
|
|
n.persist = v.(bool)
|
|
|
|
}
|
2015-11-06 02:50:10 -05:00
|
|
|
if v, ok := netMap["postIPv6"]; ok {
|
|
|
|
n.postIPv6 = v.(bool)
|
|
|
|
}
|
2015-10-07 16:04:21 -04:00
|
|
|
if v, ok := netMap["ipamType"]; ok {
|
|
|
|
n.ipamType = v.(string)
|
|
|
|
} else {
|
|
|
|
n.ipamType = ipamapi.DefaultIPAM
|
|
|
|
}
|
|
|
|
if v, ok := netMap["addrSpace"]; ok {
|
|
|
|
n.addrSpace = v.(string)
|
|
|
|
}
|
2015-10-03 19:11:50 -04:00
|
|
|
if v, ok := netMap["ipamV4Config"]; ok {
|
|
|
|
if err := json.Unmarshal([]byte(v.(string)), &n.ipamV4Config); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if v, ok := netMap["ipamV4Info"]; ok {
|
|
|
|
if err := json.Unmarshal([]byte(v.(string)), &n.ipamV4Info); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if v, ok := netMap["ipamV6Config"]; ok {
|
|
|
|
if err := json.Unmarshal([]byte(v.(string)), &n.ipamV6Config); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-05-13 11:41:45 -04:00
|
|
|
}
|
2015-10-03 19:11:50 -04:00
|
|
|
if v, ok := netMap["ipamV6Info"]; ok {
|
|
|
|
if err := json.Unmarshal([]byte(v.(string)), &n.ipamV6Info); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-09-22 10:09:39 -04:00
|
|
|
}
|
2015-12-21 20:29:39 -05:00
|
|
|
if v, ok := netMap["internal"]; ok {
|
|
|
|
n.internal = v.(bool)
|
|
|
|
}
|
2016-01-17 15:43:41 -05:00
|
|
|
if s, ok := netMap["scope"]; ok {
|
|
|
|
n.scope = s.(string)
|
|
|
|
}
|
2015-05-08 09:26:35 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-11 05:15:20 -05:00
|
|
|
// NetworkOption is an option setter function type used to pass various options to
|
2015-04-30 20:57:06 -04:00
|
|
|
// NewNetwork method. The various setter functions of type NetworkOption are
|
|
|
|
// provided by libnetwork, they look like NetworkOptionXXXX(...)
|
|
|
|
type NetworkOption func(n *network)
|
|
|
|
|
|
|
|
// NetworkOptionGeneric function returns an option setter for a Generic option defined
|
|
|
|
// in a Dictionary of Key-Value pair
|
|
|
|
func NetworkOptionGeneric(generic map[string]interface{}) NetworkOption {
|
|
|
|
return func(n *network) {
|
2016-01-29 19:54:57 -05:00
|
|
|
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
|
2015-05-06 02:41:20 -04:00
|
|
|
}
|
2015-04-30 20:57:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-22 10:09:39 -04:00
|
|
|
// NetworkOptionPersist returns an option setter to set persistence policy for a network
|
|
|
|
func NetworkOptionPersist(persist bool) NetworkOption {
|
|
|
|
return func(n *network) {
|
|
|
|
n.persist = persist
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-29 19:54:57 -05:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-21 20:29:39 -05:00
|
|
|
// NetworkOptionInternalNetwork returns an option setter to config the network
|
|
|
|
// to be internal which disables default gateway service
|
|
|
|
func NetworkOptionInternalNetwork() NetworkOption {
|
|
|
|
return func(n *network) {
|
|
|
|
if n.generic == nil {
|
|
|
|
n.generic = make(map[string]interface{})
|
|
|
|
}
|
2016-01-29 19:54:57 -05:00
|
|
|
n.internal = true
|
2015-12-21 20:29:39 -05:00
|
|
|
n.generic[netlabel.Internal] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-03 19:11:50 -04:00
|
|
|
// NetworkOptionIpam function returns an option setter for the ipam configuration for this network
|
2016-01-07 15:57:22 -05:00
|
|
|
func NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ipV6 []*IpamConf, opts map[string]string) NetworkOption {
|
2015-10-03 19:11:50 -04:00
|
|
|
return func(n *network) {
|
2015-10-09 16:57:49 -04:00
|
|
|
if ipamDriver != "" {
|
|
|
|
n.ipamType = ipamDriver
|
|
|
|
}
|
2016-01-07 15:57:22 -05:00
|
|
|
n.ipamOptions = opts
|
2015-10-03 19:11:50 -04:00
|
|
|
n.addrSpace = addrSpace
|
|
|
|
n.ipamV4Config = ipV4
|
|
|
|
n.ipamV6Config = ipV6
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-14 19:38:46 -04:00
|
|
|
// NetworkOptionDriverOpts function returns an option setter for any parameter described by a map
|
|
|
|
func NetworkOptionDriverOpts(opts map[string]string) NetworkOption {
|
2015-10-06 15:08:54 -04:00
|
|
|
return func(n *network) {
|
|
|
|
if n.generic == nil {
|
|
|
|
n.generic = make(map[string]interface{})
|
|
|
|
}
|
2015-10-14 19:38:46 -04:00
|
|
|
if opts == nil {
|
|
|
|
opts = make(map[string]string)
|
2015-10-10 06:49:09 -04:00
|
|
|
}
|
2015-10-06 15:08:54 -04:00
|
|
|
// Store the options
|
2015-10-14 19:38:46 -04:00
|
|
|
n.generic[netlabel.GenericData] = opts
|
2015-10-06 15:08:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-06 02:50:10 -05:00
|
|
|
// NetworkOptionDeferIPv6Alloc instructs the network to defer the IPV6 address allocation until after the endpoint has been created
|
|
|
|
// It is being provided to support the specific docker daemon flags where user can deterministically assign an IPv6 address
|
|
|
|
// to a container as combination of fixed-cidr-v6 + mac-address
|
|
|
|
// TODO: Remove this option setter once we support endpoint ipam options
|
|
|
|
func NetworkOptionDeferIPv6Alloc(enable bool) NetworkOption {
|
|
|
|
return func(n *network) {
|
|
|
|
n.postIPv6 = enable
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 20:57:06 -04:00
|
|
|
func (n *network) processOptions(options ...NetworkOption) {
|
|
|
|
for _, opt := range options {
|
|
|
|
if opt != nil {
|
|
|
|
opt(n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-05 07:21:15 -04:00
|
|
|
func (n *network) driverScope() string {
|
|
|
|
c := n.getController()
|
|
|
|
|
|
|
|
c.Lock()
|
|
|
|
// Check if a driver for the specified network type is available
|
|
|
|
dd, ok := c.drivers[n.networkType]
|
|
|
|
c.Unlock()
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
var err error
|
|
|
|
dd, err = c.loadDriver(n.networkType)
|
|
|
|
if err != nil {
|
|
|
|
// If driver could not be resolved simply return an empty string
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dd.capability.DataScope
|
|
|
|
}
|
2015-06-05 16:31:12 -04:00
|
|
|
|
2016-01-16 17:24:44 -05:00
|
|
|
func (n *network) driver(load bool) (driverapi.Driver, error) {
|
2015-10-05 07:21:15 -04:00
|
|
|
c := n.getController()
|
2015-06-05 16:31:12 -04:00
|
|
|
|
2015-10-05 07:21:15 -04:00
|
|
|
c.Lock()
|
|
|
|
// Check if a driver for the specified network type is available
|
|
|
|
dd, ok := c.drivers[n.networkType]
|
|
|
|
c.Unlock()
|
2015-06-05 16:31:12 -04:00
|
|
|
|
2016-01-16 17:24:44 -05:00
|
|
|
if !ok && load {
|
2015-10-05 07:21:15 -04:00
|
|
|
var err error
|
|
|
|
dd, err = c.loadDriver(n.networkType)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-01-16 17:24:44 -05:00
|
|
|
} else if !ok {
|
2016-02-23 16:44:38 -05:00
|
|
|
// don't fail if driver loading is not required
|
2016-01-16 17:24:44 -05:00
|
|
|
return nil, nil
|
2015-10-05 07:21:15 -04:00
|
|
|
}
|
|
|
|
|
2016-01-17 15:43:41 -05:00
|
|
|
n.Lock()
|
|
|
|
n.scope = dd.capability.DataScope
|
|
|
|
n.Unlock()
|
2015-10-05 07:21:15 -04:00
|
|
|
return dd.driver, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *network) Delete() error {
|
|
|
|
n.Lock()
|
|
|
|
c := n.ctrlr
|
|
|
|
name := n.name
|
|
|
|
id := n.id
|
|
|
|
n.Unlock()
|
|
|
|
|
|
|
|
n, err := c.getNetworkFromStore(id)
|
|
|
|
if err != nil {
|
|
|
|
return &UnknownNetworkError{name: name, id: id}
|
2015-04-13 14:40:42 -04:00
|
|
|
}
|
|
|
|
|
2015-10-12 01:28:26 -04:00
|
|
|
numEps := n.getEpCnt().EndpointCnt()
|
2015-04-13 14:40:42 -04:00
|
|
|
if numEps != 0 {
|
2015-07-02 01:00:48 -04:00
|
|
|
return &ActiveEndpointsError{name: n.name, id: n.id}
|
2015-04-13 14:40:42 -04:00
|
|
|
}
|
2015-06-01 12:43:24 -04:00
|
|
|
|
2015-10-05 07:21:15 -04:00
|
|
|
if err = n.deleteNetwork(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if e := c.addNetwork(n); e != nil {
|
|
|
|
log.Warnf("failed to rollback deleteNetwork for network %s: %v",
|
|
|
|
n.Name(), err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
// deleteFromStore performs an atomic delete operation and the
|
2015-10-12 01:28:26 -04:00
|
|
|
// network.epCnt will help prevent any possible
|
2015-10-05 07:21:15 -04:00
|
|
|
// race between endpoint join and network delete
|
2015-10-12 01:28:26 -04:00
|
|
|
if err = n.getController().deleteFromStore(n.getEpCnt()); err != nil {
|
|
|
|
return fmt.Errorf("error deleting network endpoint count from store: %v", err)
|
|
|
|
}
|
2015-12-01 20:53:09 -05:00
|
|
|
|
|
|
|
n.ipamRelease()
|
|
|
|
|
2015-10-05 07:21:15 -04:00
|
|
|
if err = n.getController().deleteFromStore(n); err != nil {
|
2015-10-12 01:28:26 -04:00
|
|
|
return fmt.Errorf("error deleting network from store: %v", err)
|
2015-06-01 12:43:24 -04:00
|
|
|
}
|
2015-04-13 14:40:42 -04:00
|
|
|
|
2015-06-01 12:43:24 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *network) deleteNetwork() error {
|
2016-01-16 17:24:44 -05:00
|
|
|
d, err := n.driver(true)
|
2015-10-05 07:21:15 -04:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed deleting network: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := d.DeleteNetwork(n.ID()); err != nil {
|
2015-06-10 16:27:23 -04:00
|
|
|
// Forbidden Errors should be honored
|
|
|
|
if _, ok := err.(types.ForbiddenError); ok {
|
|
|
|
return err
|
2015-04-13 14:40:42 -04:00
|
|
|
}
|
2015-10-10 12:00:35 -04:00
|
|
|
|
|
|
|
if _, ok := err.(types.MaskableError); !ok {
|
|
|
|
log.Warnf("driver error deleting network %s : %v", n.name, err)
|
|
|
|
}
|
2015-06-10 16:27:23 -04:00
|
|
|
}
|
2015-10-05 07:21:15 -04:00
|
|
|
|
2015-06-10 16:27:23 -04:00
|
|
|
return nil
|
2015-04-13 14:40:42 -04:00
|
|
|
}
|
|
|
|
|
2015-05-31 14:49:11 -04:00
|
|
|
func (n *network) addEndpoint(ep *endpoint) error {
|
2016-01-16 17:24:44 -05:00
|
|
|
d, err := n.driver(true)
|
2015-10-05 07:21:15 -04:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to add endpoint: %v", err)
|
|
|
|
}
|
2015-05-31 14:49:11 -04:00
|
|
|
|
2015-10-03 19:11:50 -04:00
|
|
|
err = d.CreateEndpoint(n.id, ep.id, ep.Interface(), ep.generic)
|
2015-05-31 14:49:11 -04:00
|
|
|
if err != nil {
|
2015-10-05 07:21:15 -04:00
|
|
|
return types.InternalErrorf("failed to create endpoint %s on network %s: %v",
|
|
|
|
ep.Name(), n.Name(), err)
|
2015-05-31 14:49:11 -04:00
|
|
|
}
|
2015-06-19 02:40:17 -04:00
|
|
|
|
2015-05-31 14:49:11 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-04-30 20:57:06 -04:00
|
|
|
func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoint, error) {
|
2015-06-05 16:31:12 -04:00
|
|
|
var err error
|
2015-06-14 12:00:27 -04:00
|
|
|
if !config.IsValidName(name) {
|
2015-05-14 17:56:15 -04:00
|
|
|
return nil, ErrInvalidName(name)
|
2015-05-07 22:59:06 -04:00
|
|
|
}
|
2015-06-04 12:41:42 -04:00
|
|
|
|
2015-06-05 16:31:12 -04:00
|
|
|
if _, err = n.EndpointByName(name); err == nil {
|
2015-06-04 12:41:42 -04:00
|
|
|
return nil, types.ForbiddenErrorf("service endpoint with name %s already exists", name)
|
|
|
|
}
|
|
|
|
|
2015-10-03 19:11:50 -04:00
|
|
|
ep := &endpoint{name: name, generic: make(map[string]interface{}), iface: &endpointInterface{}}
|
2015-07-02 01:00:48 -04:00
|
|
|
ep.id = stringid.GenerateRandomID()
|
2015-10-05 07:21:15 -04:00
|
|
|
|
|
|
|
// Initialize ep.network with a possibly stale copy of n. We need this to get network from
|
2016-01-11 05:15:20 -05:00
|
|
|
// store. But once we get it from store we will have the most uptodate copy possibly.
|
2015-04-13 14:40:42 -04:00
|
|
|
ep.network = n
|
2016-01-08 14:24:14 -05:00
|
|
|
ep.locator = n.getController().clusterHostID()
|
2015-10-05 07:21:15 -04:00
|
|
|
ep.network, err = ep.getNetworkFromStore()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to get network during CreateEndpoint: %v", err)
|
|
|
|
}
|
|
|
|
n = ep.network
|
|
|
|
|
2015-04-30 20:57:06 -04:00
|
|
|
ep.processOptions(options...)
|
2015-04-13 14:40:42 -04:00
|
|
|
|
2015-11-14 16:17:43 -05:00
|
|
|
if opt, ok := ep.generic[netlabel.MacAddress]; ok {
|
|
|
|
if mac, ok := opt.(net.HardwareAddr); ok {
|
|
|
|
ep.iface.mac = mac
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-09 21:09:58 -05:00
|
|
|
ipam, err := n.getController().getIPAM(n.ipamType)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if ipam.capability.RequiresMACAddress {
|
|
|
|
if ep.iface.mac == nil {
|
|
|
|
ep.iface.mac = netutils.GenerateRandomMAC()
|
|
|
|
}
|
|
|
|
if ep.ipamOptions == nil {
|
|
|
|
ep.ipamOptions = make(map[string]string)
|
|
|
|
}
|
|
|
|
ep.ipamOptions[netlabel.MacAddress] = ep.iface.mac.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = ep.assignAddress(ipam.driver, true, !n.postIPv6); err != nil {
|
2015-10-03 19:11:50 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
ep.releaseAddress()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2015-10-05 07:21:15 -04:00
|
|
|
if err = n.addEndpoint(ep); err != nil {
|
2015-05-31 14:49:11 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
2015-06-05 16:31:12 -04:00
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
2016-01-16 17:24:44 -05:00
|
|
|
if e := ep.deleteEndpoint(false); e != nil {
|
2015-10-05 07:21:15 -04:00
|
|
|
log.Warnf("cleaning up endpoint failed %s : %v", name, e)
|
2015-06-05 16:31:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
2015-10-05 07:21:15 -04:00
|
|
|
|
2015-12-09 21:09:58 -05:00
|
|
|
if err = ep.assignAddress(ipam.driver, false, n.postIPv6); err != nil {
|
2015-11-06 02:50:10 -05:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-10-05 07:21:15 -04:00
|
|
|
if err = n.getController().updateToStore(ep); err != nil {
|
2015-06-05 16:31:12 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
2015-10-05 07:21:15 -04:00
|
|
|
if e := n.getController().deleteFromStore(ep); e != nil {
|
|
|
|
log.Warnf("error rolling back endpoint %s from store: %v", name, e)
|
2015-06-05 16:31:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
2015-05-31 14:49:11 -04:00
|
|
|
|
2015-10-23 13:09:00 -04:00
|
|
|
// Watch for service records
|
|
|
|
n.getController().watchSvcRecord(ep)
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
n.getController().unWatchSvcRecord(ep)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2015-10-05 07:21:15 -04:00
|
|
|
// Increment endpoint count to indicate completion of endpoint addition
|
2015-10-12 01:28:26 -04:00
|
|
|
if err = n.getEpCnt().IncEndpointCnt(); err != nil {
|
2015-10-05 07:21:15 -04:00
|
|
|
return nil, err
|
2015-04-13 14:40:42 -04:00
|
|
|
}
|
|
|
|
|
2015-04-17 18:42:23 -04:00
|
|
|
return ep, nil
|
2015-04-13 14:40:42 -04:00
|
|
|
}
|
|
|
|
|
2015-04-18 02:13:29 -04:00
|
|
|
func (n *network) Endpoints() []Endpoint {
|
2015-10-05 07:21:15 -04:00
|
|
|
var list []Endpoint
|
|
|
|
|
|
|
|
endpoints, err := n.getEndpointsFromStore()
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, ep := range endpoints {
|
|
|
|
list = append(list, ep)
|
2015-04-18 02:13:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
2015-04-20 12:46:11 -04:00
|
|
|
func (n *network) WalkEndpoints(walker EndpointWalker) {
|
|
|
|
for _, e := range n.Endpoints() {
|
|
|
|
if walker(e) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-11 19:13:27 -04:00
|
|
|
func (n *network) EndpointByName(name string) (Endpoint, error) {
|
|
|
|
if name == "" {
|
2015-05-14 17:56:15 -04:00
|
|
|
return nil, ErrInvalidName(name)
|
2015-05-11 19:13:27 -04:00
|
|
|
}
|
2015-04-24 15:05:33 -04:00
|
|
|
var e Endpoint
|
|
|
|
|
2015-05-11 19:13:27 -04:00
|
|
|
s := func(current Endpoint) bool {
|
|
|
|
if current.Name() == name {
|
|
|
|
e = current
|
|
|
|
return true
|
2015-04-24 15:05:33 -04:00
|
|
|
}
|
2015-05-11 19:13:27 -04:00
|
|
|
return false
|
2015-04-24 15:05:33 -04:00
|
|
|
}
|
|
|
|
|
2015-05-11 19:13:27 -04:00
|
|
|
n.WalkEndpoints(s)
|
|
|
|
|
2015-05-15 19:04:09 -04:00
|
|
|
if e == nil {
|
2015-05-14 17:56:15 -04:00
|
|
|
return nil, ErrNoSuchEndpoint(name)
|
2015-05-15 19:04:09 -04:00
|
|
|
}
|
|
|
|
|
2015-05-11 19:13:27 -04:00
|
|
|
return e, nil
|
2015-04-24 15:05:33 -04:00
|
|
|
}
|
|
|
|
|
2015-05-11 19:13:27 -04:00
|
|
|
func (n *network) EndpointByID(id string) (Endpoint, error) {
|
|
|
|
if id == "" {
|
2015-05-14 17:56:15 -04:00
|
|
|
return nil, ErrInvalidID(id)
|
2015-05-11 19:13:27 -04:00
|
|
|
}
|
2015-10-05 07:21:15 -04:00
|
|
|
|
|
|
|
ep, err := n.getEndpointFromStore(id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, ErrNoSuchEndpoint(id)
|
2015-04-24 15:05:33 -04:00
|
|
|
}
|
2015-05-13 17:12:57 -04:00
|
|
|
|
2015-10-05 07:21:15 -04:00
|
|
|
return ep, nil
|
2015-05-13 17:12:57 -04:00
|
|
|
}
|
2015-06-19 02:40:17 -04:00
|
|
|
|
2015-10-05 07:21:15 -04:00
|
|
|
func (n *network) updateSvcRecord(ep *endpoint, localEps []*endpoint, isAdd bool) {
|
2016-01-07 22:19:31 -05:00
|
|
|
epName := ep.Name()
|
|
|
|
if iface := ep.Iface(); iface.Address() != nil {
|
|
|
|
myAliases := ep.MyAliases()
|
|
|
|
if isAdd {
|
2016-01-13 15:03:12 -05:00
|
|
|
if !ep.isAnonymous() {
|
|
|
|
n.addSvcRecords(epName, iface.Address().IP, true)
|
|
|
|
}
|
2016-01-07 22:19:31 -05:00
|
|
|
for _, alias := range myAliases {
|
|
|
|
n.addSvcRecords(alias, iface.Address().IP, false)
|
|
|
|
}
|
|
|
|
} else {
|
2016-01-13 15:03:12 -05:00
|
|
|
if !ep.isAnonymous() {
|
|
|
|
n.deleteSvcRecords(epName, iface.Address().IP, true)
|
|
|
|
}
|
2016-01-07 22:19:31 -05:00
|
|
|
for _, alias := range myAliases {
|
|
|
|
n.deleteSvcRecords(alias, iface.Address().IP, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *network) addSvcRecords(name string, epIP net.IP, ipMapUpdate bool) {
|
2015-10-05 07:21:15 -04:00
|
|
|
c := n.getController()
|
2016-01-07 22:19:31 -05:00
|
|
|
c.Lock()
|
|
|
|
defer c.Unlock()
|
2015-10-05 07:21:15 -04:00
|
|
|
sr, ok := c.svcDb[n.ID()]
|
|
|
|
if !ok {
|
2016-01-07 22:19:31 -05:00
|
|
|
sr = svcInfo{
|
|
|
|
svcMap: make(map[string][]net.IP),
|
2015-12-24 04:51:32 -05:00
|
|
|
ipMap: make(map[string]string),
|
|
|
|
}
|
2016-01-07 22:19:31 -05:00
|
|
|
c.svcDb[n.ID()] = sr
|
2015-10-05 07:21:15 -04:00
|
|
|
}
|
|
|
|
|
2016-01-07 22:19:31 -05:00
|
|
|
if ipMapUpdate {
|
|
|
|
reverseIP := netutils.ReverseIP(epIP.String())
|
|
|
|
if _, ok := sr.ipMap[reverseIP]; !ok {
|
|
|
|
sr.ipMap[reverseIP] = name
|
|
|
|
}
|
|
|
|
}
|
2015-12-24 04:51:32 -05:00
|
|
|
|
2016-01-07 22:19:31 -05:00
|
|
|
ipList := sr.svcMap[name]
|
|
|
|
for _, ip := range ipList {
|
|
|
|
if ip.Equal(epIP) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sr.svcMap[name] = append(sr.svcMap[name], epIP)
|
|
|
|
}
|
2015-10-23 13:09:00 -04:00
|
|
|
|
2016-01-07 22:19:31 -05:00
|
|
|
func (n *network) deleteSvcRecords(name string, epIP net.IP, ipMapUpdate bool) {
|
|
|
|
c := n.getController()
|
|
|
|
c.Lock()
|
|
|
|
defer c.Unlock()
|
|
|
|
sr, ok := c.svcDb[n.ID()]
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if ipMapUpdate {
|
|
|
|
delete(sr.ipMap, netutils.ReverseIP(epIP.String()))
|
|
|
|
}
|
|
|
|
|
|
|
|
ipList := sr.svcMap[name]
|
|
|
|
for i, ip := range ipList {
|
|
|
|
if ip.Equal(epIP) {
|
|
|
|
ipList = append(ipList[:i], ipList[i+1:]...)
|
|
|
|
break
|
2015-06-19 02:40:17 -04:00
|
|
|
}
|
|
|
|
}
|
2016-01-07 22:19:31 -05:00
|
|
|
sr.svcMap[name] = ipList
|
|
|
|
|
|
|
|
if len(ipList) == 0 {
|
|
|
|
delete(sr.svcMap, name)
|
|
|
|
}
|
2015-06-19 02:40:17 -04:00
|
|
|
}
|
|
|
|
|
2015-10-23 13:09:00 -04:00
|
|
|
func (n *network) getSvcRecords(ep *endpoint) []etchosts.Record {
|
2015-06-19 02:40:17 -04:00
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
|
|
|
|
|
|
|
var recs []etchosts.Record
|
2015-10-05 07:21:15 -04:00
|
|
|
sr, _ := n.ctrlr.svcDb[n.id]
|
|
|
|
|
2015-12-24 04:51:32 -05:00
|
|
|
for h, ip := range sr.svcMap {
|
2015-10-23 13:09:00 -04:00
|
|
|
if ep != nil && strings.Split(h, ".")[0] == ep.Name() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2015-06-19 02:40:17 -04:00
|
|
|
recs = append(recs, etchosts.Record{
|
|
|
|
Hosts: h,
|
2016-01-07 22:19:31 -05:00
|
|
|
IP: ip[0].String(),
|
2015-06-19 02:40:17 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return recs
|
|
|
|
}
|
2015-07-02 01:00:48 -04:00
|
|
|
|
|
|
|
func (n *network) getController() *controller {
|
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
|
|
|
return n.ctrlr
|
|
|
|
}
|
2015-10-03 19:11:50 -04:00
|
|
|
|
2015-10-04 00:25:57 -04:00
|
|
|
func (n *network) ipamAllocate() error {
|
2015-10-03 19:11:50 -04:00
|
|
|
// For now also exclude bridge from using new ipam
|
2015-10-04 22:08:31 -04:00
|
|
|
if n.Type() == "host" || n.Type() == "null" {
|
2015-10-04 00:25:57 -04:00
|
|
|
return nil
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ipam, err := n.getController().getIpamDriver(n.ipamType)
|
|
|
|
if err != nil {
|
2015-10-04 00:25:57 -04:00
|
|
|
return err
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if n.addrSpace == "" {
|
|
|
|
if n.addrSpace, err = n.deriveAddressSpace(); err != nil {
|
2015-10-04 00:25:57 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = n.ipamAllocateVersion(4, ipam)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
n.ipamReleaseVersion(4, ipam)
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
2015-10-04 00:25:57 -04:00
|
|
|
}()
|
|
|
|
|
|
|
|
return n.ipamAllocateVersion(6, ipam)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error {
|
|
|
|
var (
|
|
|
|
cfgList *[]*IpamConf
|
|
|
|
infoList *[]*IpamInfo
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
switch ipVer {
|
|
|
|
case 4:
|
|
|
|
cfgList = &n.ipamV4Config
|
|
|
|
infoList = &n.ipamV4Info
|
|
|
|
case 6:
|
|
|
|
cfgList = &n.ipamV6Config
|
|
|
|
infoList = &n.ipamV6Info
|
|
|
|
default:
|
|
|
|
return types.InternalErrorf("incorrect ip version passed to ipam allocate: %d", ipVer)
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
|
|
|
|
2015-10-09 20:06:52 -04:00
|
|
|
if len(*cfgList) == 0 {
|
2015-10-04 00:25:57 -04:00
|
|
|
if ipVer == 6 {
|
|
|
|
return nil
|
|
|
|
}
|
2016-02-12 08:07:00 -05:00
|
|
|
*cfgList = []*IpamConf{{}}
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
|
|
|
|
2015-10-04 00:25:57 -04:00
|
|
|
*infoList = make([]*IpamInfo, len(*cfgList))
|
|
|
|
|
2015-10-05 17:53:25 -04:00
|
|
|
log.Debugf("Allocating IPv%d pools for network %s (%s)", ipVer, n.Name(), n.ID())
|
2015-10-03 19:11:50 -04:00
|
|
|
|
2015-10-04 00:25:57 -04:00
|
|
|
for i, cfg := range *cfgList {
|
2015-10-03 19:11:50 -04:00
|
|
|
if err = cfg.Validate(); err != nil {
|
2015-10-04 00:25:57 -04:00
|
|
|
return err
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
|
|
|
d := &IpamInfo{}
|
2015-10-04 00:25:57 -04:00
|
|
|
(*infoList)[i] = d
|
2015-10-03 19:11:50 -04:00
|
|
|
|
2016-01-07 15:57:22 -05:00
|
|
|
d.PoolID, d.Pool, d.Meta, err = ipam.RequestPool(n.addrSpace, cfg.PreferredPool, cfg.SubPool, n.ipamOptions, ipVer == 6)
|
2015-10-03 19:11:50 -04:00
|
|
|
if err != nil {
|
2015-10-04 00:25:57 -04:00
|
|
|
return err
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err := ipam.ReleasePool(d.PoolID); err != nil {
|
|
|
|
log.Warnf("Failed to release address pool %s after failure to create network %s (%s)", d.PoolID, n.Name(), n.ID())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if gws, ok := d.Meta[netlabel.Gateway]; ok {
|
|
|
|
if d.Gateway, err = types.ParseCIDR(gws); err != nil {
|
2015-10-04 00:25:57 -04:00
|
|
|
return types.BadRequestErrorf("failed to parse gateway address (%v) returned by ipam driver: %v", gws, err)
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If user requested a specific gateway, libnetwork will allocate it
|
|
|
|
// irrespective of whether ipam driver returned a gateway already.
|
|
|
|
// If none of the above is true, libnetwork will allocate one.
|
|
|
|
if cfg.Gateway != "" || d.Gateway == nil {
|
2015-12-03 22:20:42 -05:00
|
|
|
var gatewayOpts = map[string]string{
|
|
|
|
ipamapi.RequestAddressType: netlabel.Gateway,
|
|
|
|
}
|
|
|
|
if d.Gateway, _, err = ipam.RequestAddress(d.PoolID, net.ParseIP(cfg.Gateway), gatewayOpts); err != nil {
|
2015-10-04 00:25:57 -04:00
|
|
|
return types.InternalErrorf("failed to allocate gateway (%v): %v", cfg.Gateway, err)
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 23:29:30 -04:00
|
|
|
// Auxiliary addresses must be part of the master address pool
|
|
|
|
// If they fall into the container addressable pool, libnetwork will reserve them
|
2015-10-03 19:11:50 -04:00
|
|
|
if cfg.AuxAddresses != nil {
|
|
|
|
var ip net.IP
|
|
|
|
d.IPAMData.AuxAddresses = make(map[string]*net.IPNet, len(cfg.AuxAddresses))
|
|
|
|
for k, v := range cfg.AuxAddresses {
|
|
|
|
if ip = net.ParseIP(v); ip == nil {
|
2015-10-04 00:25:57 -04:00
|
|
|
return types.BadRequestErrorf("non parsable secondary ip address (%s:%s) passed for network %s", k, v, n.Name())
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
2015-10-06 23:29:30 -04:00
|
|
|
if !d.Pool.Contains(ip) {
|
2015-10-04 00:25:57 -04:00
|
|
|
return types.ForbiddenErrorf("auxilairy address: (%s:%s) must belong to the master pool: %s", k, v, d.Pool)
|
2015-10-06 23:29:30 -04:00
|
|
|
}
|
|
|
|
// Attempt reservation in the container addressable pool, silent the error if address does not belong to that pool
|
|
|
|
if d.IPAMData.AuxAddresses[k], _, err = ipam.RequestAddress(d.PoolID, ip, nil); err != nil && err != ipamapi.ErrIPOutOfRange {
|
2015-10-04 00:25:57 -04:00
|
|
|
return types.InternalErrorf("failed to allocate secondary ip address (%s:%s): %v", k, v, err)
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-04 00:25:57 -04:00
|
|
|
return nil
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *network) ipamRelease() {
|
2015-10-04 22:08:31 -04:00
|
|
|
// For now exclude host and null
|
|
|
|
if n.Type() == "host" || n.Type() == "null" {
|
2015-10-03 19:11:50 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
ipam, err := n.getController().getIpamDriver(n.ipamType)
|
|
|
|
if err != nil {
|
|
|
|
log.Warnf("Failed to retrieve ipam driver to release address pool(s) on delete of network %s (%s): %v", n.Name(), n.ID(), err)
|
|
|
|
return
|
|
|
|
}
|
2015-10-04 00:25:57 -04:00
|
|
|
n.ipamReleaseVersion(4, ipam)
|
|
|
|
n.ipamReleaseVersion(6, ipam)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *network) ipamReleaseVersion(ipVer int, ipam ipamapi.Ipam) {
|
|
|
|
var infoList []*IpamInfo
|
|
|
|
|
|
|
|
switch ipVer {
|
|
|
|
case 4:
|
|
|
|
infoList = n.ipamV4Info
|
|
|
|
case 6:
|
|
|
|
infoList = n.ipamV6Info
|
|
|
|
default:
|
|
|
|
log.Warnf("incorrect ip version passed to ipam release: %d", ipVer)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if infoList == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debugf("releasing IPv%d pools from network %s (%s)", ipVer, n.Name(), n.ID())
|
|
|
|
|
|
|
|
for _, d := range infoList {
|
2015-10-03 19:11:50 -04:00
|
|
|
if d.Gateway != nil {
|
|
|
|
if err := ipam.ReleaseAddress(d.PoolID, d.Gateway.IP); err != nil {
|
|
|
|
log.Warnf("Failed to release gateway ip address %s on delete of network %s (%s): %v", d.Gateway.IP, n.Name(), n.ID(), err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if d.IPAMData.AuxAddresses != nil {
|
|
|
|
for k, nw := range d.IPAMData.AuxAddresses {
|
2015-10-06 23:29:30 -04:00
|
|
|
if d.Pool.Contains(nw.IP) {
|
|
|
|
if err := ipam.ReleaseAddress(d.PoolID, nw.IP); err != nil && err != ipamapi.ErrIPOutOfRange {
|
|
|
|
log.Warnf("Failed to release secondary ip address %s (%v) on delete of network %s (%s): %v", k, nw.IP, n.Name(), n.ID(), err)
|
|
|
|
}
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := ipam.ReleasePool(d.PoolID); err != nil {
|
|
|
|
log.Warnf("Failed to release address pool %s on delete of network %s (%s): %v", d.PoolID, n.Name(), n.ID(), err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-04 00:25:57 -04:00
|
|
|
func (n *network) getIPInfo(ipVer int) []*IpamInfo {
|
|
|
|
var info []*IpamInfo
|
|
|
|
switch ipVer {
|
|
|
|
case 4:
|
|
|
|
info = n.ipamV4Info
|
|
|
|
case 6:
|
|
|
|
info = n.ipamV6Info
|
|
|
|
default:
|
|
|
|
return nil
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
2015-10-04 00:25:57 -04:00
|
|
|
l := make([]*IpamInfo, 0, len(info))
|
2015-10-03 19:11:50 -04:00
|
|
|
n.Lock()
|
2015-10-04 00:25:57 -04:00
|
|
|
for _, d := range info {
|
|
|
|
l = append(l, d)
|
2015-10-03 19:11:50 -04:00
|
|
|
}
|
|
|
|
n.Unlock()
|
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
2015-10-04 00:25:57 -04:00
|
|
|
func (n *network) getIPData(ipVer int) []driverapi.IPAMData {
|
|
|
|
var info []*IpamInfo
|
|
|
|
switch ipVer {
|
|
|
|
case 4:
|
|
|
|
info = n.ipamV4Info
|
|
|
|
case 6:
|
|
|
|
info = n.ipamV6Info
|
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
l := make([]driverapi.IPAMData, 0, len(info))
|
2015-10-03 19:11:50 -04:00
|
|
|
n.Lock()
|
2015-10-04 00:25:57 -04:00
|
|
|
for _, d := range info {
|
2015-10-03 19:11:50 -04:00
|
|
|
l = append(l, d.IPAMData)
|
|
|
|
}
|
|
|
|
n.Unlock()
|
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *network) deriveAddressSpace() (string, error) {
|
|
|
|
c := n.getController()
|
|
|
|
c.Lock()
|
|
|
|
ipd, ok := c.ipamDrivers[n.ipamType]
|
|
|
|
c.Unlock()
|
|
|
|
if !ok {
|
|
|
|
return "", types.NotFoundErrorf("could not find ipam driver %s to get default address space", n.ipamType)
|
|
|
|
}
|
2015-10-05 07:21:15 -04:00
|
|
|
if n.DataScope() == datastore.GlobalScope {
|
2015-10-03 19:11:50 -04:00
|
|
|
return ipd.defaultGlobalAddressSpace, nil
|
|
|
|
}
|
|
|
|
return ipd.defaultLocalAddressSpace, nil
|
|
|
|
}
|
2015-10-06 15:08:54 -04:00
|
|
|
|
|
|
|
func (n *network) Info() NetworkInfo {
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
2015-10-14 19:38:46 -04:00
|
|
|
func (n *network) DriverOptions() map[string]string {
|
2015-10-06 15:08:54 -04:00
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
|
|
|
if n.generic != nil {
|
|
|
|
if m, ok := n.generic[netlabel.GenericData]; ok {
|
2015-10-09 11:59:40 -04:00
|
|
|
return m.(map[string]string)
|
2015-10-06 15:08:54 -04:00
|
|
|
}
|
|
|
|
}
|
2015-10-09 11:59:40 -04:00
|
|
|
return map[string]string{}
|
2015-10-06 15:08:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *network) Scope() string {
|
2016-01-17 15:43:41 -05:00
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
|
|
|
return n.scope
|
2015-10-06 15:08:54 -04:00
|
|
|
}
|
2015-10-09 16:46:33 -04:00
|
|
|
|
2016-01-07 15:57:22 -05:00
|
|
|
func (n *network) IpamConfig() (string, map[string]string, []*IpamConf, []*IpamConf) {
|
2015-10-09 16:46:33 -04:00
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
|
|
|
|
|
|
|
v4L := make([]*IpamConf, len(n.ipamV4Config))
|
|
|
|
v6L := make([]*IpamConf, len(n.ipamV6Config))
|
|
|
|
|
|
|
|
for i, c := range n.ipamV4Config {
|
|
|
|
cc := &IpamConf{}
|
|
|
|
c.CopyTo(cc)
|
|
|
|
v4L[i] = cc
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, c := range n.ipamV6Config {
|
|
|
|
cc := &IpamConf{}
|
|
|
|
c.CopyTo(cc)
|
|
|
|
v6L[i] = cc
|
|
|
|
}
|
|
|
|
|
2016-01-07 15:57:22 -05:00
|
|
|
return n.ipamType, n.ipamOptions, v4L, v6L
|
2015-10-09 16:46:33 -04:00
|
|
|
}
|
2015-12-16 04:30:21 -05:00
|
|
|
|
|
|
|
func (n *network) IpamInfo() ([]*IpamInfo, []*IpamInfo) {
|
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
|
|
|
|
|
|
|
v4Info := make([]*IpamInfo, len(n.ipamV4Info))
|
|
|
|
v6Info := make([]*IpamInfo, len(n.ipamV6Info))
|
|
|
|
|
|
|
|
for i, info := range n.ipamV4Info {
|
|
|
|
ic := &IpamInfo{}
|
|
|
|
info.CopyTo(ic)
|
|
|
|
v4Info[i] = ic
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, info := range n.ipamV6Info {
|
|
|
|
ic := &IpamInfo{}
|
|
|
|
info.CopyTo(ic)
|
|
|
|
v6Info[i] = ic
|
|
|
|
}
|
|
|
|
|
|
|
|
return v4Info, v6Info
|
|
|
|
}
|
2015-12-21 20:29:39 -05:00
|
|
|
|
|
|
|
func (n *network) Internal() bool {
|
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
|
|
|
|
|
|
|
return n.internal
|
|
|
|
}
|
2016-01-29 13:10:06 -05:00
|
|
|
|
|
|
|
func (n *network) IPv6Enabled() bool {
|
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
|
|
|
|
|
|
|
return n.enableIPv6
|
|
|
|
}
|