libnetwork/d/overlay: parse discovery data eagerly
Parse the address strings once and use the binary representation internally. Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
parent
7e66d9900c
commit
e1d85da306
4 changed files with 32 additions and 26 deletions
|
@ -124,8 +124,8 @@ func (d *driver) checkEncryption(nid string, rIP net.IP, isLocal, add bool) erro
|
|||
return types.ForbiddenErrorf("encryption key is not present")
|
||||
}
|
||||
|
||||
lIP := net.ParseIP(d.bindAddress)
|
||||
aIP := net.ParseIP(d.advertiseAddress)
|
||||
lIP := d.bindAddress
|
||||
aIP := d.advertiseAddress
|
||||
nodes := map[string]net.IP{}
|
||||
|
||||
switch {
|
||||
|
@ -495,8 +495,8 @@ func (d *driver) updateKeys(newKey, primary, pruneKey *key) error {
|
|||
newIdx = -1
|
||||
priIdx = -1
|
||||
delIdx = -1
|
||||
lIP = net.ParseIP(d.bindAddress)
|
||||
aIP = net.ParseIP(d.advertiseAddress)
|
||||
lIP = d.bindAddress
|
||||
aIP = d.advertiseAddress
|
||||
)
|
||||
|
||||
d.Lock()
|
||||
|
|
|
@ -107,7 +107,7 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
|
|||
}
|
||||
}
|
||||
|
||||
d.peerAdd(nid, eid, ep.addr.IP, ep.addr.Mask, ep.mac, net.ParseIP(d.advertiseAddress), false, false, true)
|
||||
d.peerAdd(nid, eid, ep.addr.IP, ep.addr.Mask, ep.mac, d.advertiseAddress, false, false, true)
|
||||
|
||||
if err = d.checkEncryption(nid, nil, true, true); err != nil {
|
||||
log.G(context.TODO()).Warn(err)
|
||||
|
@ -116,7 +116,7 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
|
|||
buf, err := proto.Marshal(&PeerRecord{
|
||||
EndpointIP: ep.addr.String(),
|
||||
EndpointMAC: ep.mac.String(),
|
||||
TunnelEndpointIP: d.advertiseAddress,
|
||||
TunnelEndpointIP: d.advertiseAddress.String(),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -162,7 +162,7 @@ func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key stri
|
|||
|
||||
// Ignore local peers. We already know about them and they
|
||||
// should not be added to vxlan fdb.
|
||||
if peer.TunnelEndpointIP == d.advertiseAddress {
|
||||
if net.ParseIP(peer.TunnelEndpointIP).Equal(d.advertiseAddress) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ func (d *driver) Leave(nid, eid string) error {
|
|||
return types.InternalMaskableErrorf("could not find endpoint with id %s", eid)
|
||||
}
|
||||
|
||||
d.peerDelete(nid, eid, ep.addr.IP, ep.addr.Mask, ep.mac, net.ParseIP(d.advertiseAddress), true)
|
||||
d.peerDelete(nid, eid, ep.addr.IP, ep.addr.Mask, ep.mac, d.advertiseAddress, true)
|
||||
|
||||
n.leaveSandbox()
|
||||
|
||||
|
|
|
@ -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,15 @@ func (d *driver) IsBuiltIn() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (d *driver) nodeJoin(advertiseAddress, bindAddress string, self bool) {
|
||||
if self {
|
||||
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 +89,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 +97,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 {
|
||||
|
|
|
@ -429,7 +429,7 @@ func (d *driver) peerFlushOp(nid string) error {
|
|||
func (d *driver) peerDBUpdateSelf() {
|
||||
d.peerDbWalk(func(nid string, pkey *peerKey, pEntry *peerEntry) bool {
|
||||
if pEntry.isLocal {
|
||||
pEntry.vtep = net.ParseIP(d.advertiseAddress)
|
||||
pEntry.vtep = d.advertiseAddress
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue