|
@@ -7,6 +7,7 @@ package overlay
|
|
|
import (
|
|
|
"context"
|
|
|
"fmt"
|
|
|
+ "net"
|
|
|
"sync"
|
|
|
|
|
|
"github.com/containerd/log"
|
|
@@ -27,16 +28,16 @@ const (
|
|
|
var _ discoverapi.Discover = (*driver)(nil)
|
|
|
|
|
|
type driver struct {
|
|
|
- bindAddress string
|
|
|
- advertiseAddress string
|
|
|
- config map[string]interface{}
|
|
|
- peerDb peerNetworkMap
|
|
|
- secMap *encrMap
|
|
|
- networks networkTable
|
|
|
- initOS sync.Once
|
|
|
- localJoinOnce sync.Once
|
|
|
- keys []*key
|
|
|
- peerOpMu sync.Mutex
|
|
|
+ bindAddress, advertiseAddress net.IP
|
|
|
+
|
|
|
+ config map[string]interface{}
|
|
|
+ peerDb peerNetworkMap
|
|
|
+ secMap *encrMap
|
|
|
+ networks networkTable
|
|
|
+ initOS sync.Once
|
|
|
+ localJoinOnce sync.Once
|
|
|
+ keys []*key
|
|
|
+ peerOpMu sync.Mutex
|
|
|
sync.Mutex
|
|
|
}
|
|
|
|
|
@@ -71,11 +72,27 @@ func (d *driver) IsBuiltIn() bool {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
-func (d *driver) nodeJoin(advertiseAddress, bindAddress string, self bool) {
|
|
|
- if self {
|
|
|
+// isIPv6Transport reports whether the outer Layer-3 transport for VXLAN datagrams is IPv6.
|
|
|
+func (d *driver) isIPv6Transport() (bool, error) {
|
|
|
+ // Infer whether remote peers' virtual tunnel endpoints will be IPv4 or IPv6
|
|
|
+ // from the address family of our own advertise address. This is a
|
|
|
+ // reasonable inference to make as Linux VXLAN links do not support
|
|
|
+ // mixed-address-family remote peers.
|
|
|
+ if d.advertiseAddress == nil {
|
|
|
+ return false, fmt.Errorf("overlay: cannot determine address family of transport: the local data-plane address is not currently known")
|
|
|
+ }
|
|
|
+ return d.advertiseAddress.To4() == nil, nil
|
|
|
+}
|
|
|
+
|
|
|
+func (d *driver) nodeJoin(data discoverapi.NodeDiscoveryData) error {
|
|
|
+ if data.Self {
|
|
|
+ advAddr, bindAddr := net.ParseIP(data.Address), net.ParseIP(data.BindAddress)
|
|
|
+ if advAddr == nil {
|
|
|
+ return fmt.Errorf("invalid discovery data")
|
|
|
+ }
|
|
|
d.Lock()
|
|
|
- d.advertiseAddress = advertiseAddress
|
|
|
- d.bindAddress = bindAddress
|
|
|
+ d.advertiseAddress = advAddr
|
|
|
+ d.bindAddress = bindAddr
|
|
|
d.Unlock()
|
|
|
|
|
|
// If containers are already running on this network update the
|
|
@@ -84,6 +101,7 @@ func (d *driver) nodeJoin(advertiseAddress, bindAddress string, self bool) {
|
|
|
d.peerDBUpdateSelf()
|
|
|
})
|
|
|
}
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster
|
|
@@ -91,10 +109,10 @@ func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{})
|
|
|
switch dType {
|
|
|
case discoverapi.NodeDiscovery:
|
|
|
nodeData, ok := data.(discoverapi.NodeDiscoveryData)
|
|
|
- if !ok || nodeData.Address == "" {
|
|
|
- return fmt.Errorf("invalid discovery data")
|
|
|
+ if !ok {
|
|
|
+ return fmt.Errorf("invalid discovery data type: %T", data)
|
|
|
}
|
|
|
- d.nodeJoin(nodeData.Address, nodeData.BindAddress, nodeData.Self)
|
|
|
+ return d.nodeJoin(nodeData)
|
|
|
case discoverapi.EncryptionKeysConfig:
|
|
|
encrData, ok := data.(discoverapi.DriverEncryptionConfig)
|
|
|
if !ok {
|