2015-06-10 17:24:19 -04:00
|
|
|
package overlay
|
|
|
|
|
|
|
|
import (
|
2017-07-27 14:43:13 -04:00
|
|
|
"context"
|
2015-06-10 17:24:19 -04:00
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
"sync"
|
|
|
|
"syscall"
|
2016-06-06 21:17:10 -04:00
|
|
|
|
2021-04-05 20:24:47 -04:00
|
|
|
"github.com/docker/docker/libnetwork/internal/caller"
|
|
|
|
"github.com/docker/docker/libnetwork/internal/setmatrix"
|
|
|
|
"github.com/docker/docker/libnetwork/osl"
|
2017-07-26 17:18:31 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2015-06-10 17:24:19 -04:00
|
|
|
)
|
|
|
|
|
2016-04-28 19:54:47 -04:00
|
|
|
const ovPeerTable = "overlay_peer_table"
|
|
|
|
|
2015-06-10 17:24:19 -04:00
|
|
|
type peerKey struct {
|
|
|
|
peerIP net.IP
|
|
|
|
peerMac net.HardwareAddr
|
|
|
|
}
|
|
|
|
|
|
|
|
type peerEntry struct {
|
2015-09-29 02:06:57 -04:00
|
|
|
eid string
|
|
|
|
vtep net.IP
|
|
|
|
peerIPMask net.IPMask
|
|
|
|
isLocal bool
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
|
|
|
|
2017-09-05 13:43:20 -04:00
|
|
|
func (p *peerEntry) MarshalDB() peerEntryDB {
|
2017-10-03 20:12:57 -04:00
|
|
|
ones, bits := p.peerIPMask.Size()
|
2017-09-05 13:43:20 -04:00
|
|
|
return peerEntryDB{
|
2017-10-03 20:12:57 -04:00
|
|
|
eid: p.eid,
|
|
|
|
vtep: p.vtep.String(),
|
|
|
|
peerIPMaskOnes: ones,
|
|
|
|
peerIPMaskBits: bits,
|
|
|
|
isLocal: p.isLocal,
|
2017-09-05 13:43:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This the structure saved into the set (SetMatrix), due to the implementation of it
|
|
|
|
// the value inserted in the set has to be Hashable so the []byte had to be converted into
|
|
|
|
// strings
|
|
|
|
type peerEntryDB struct {
|
2017-10-03 20:12:57 -04:00
|
|
|
eid string
|
|
|
|
vtep string
|
|
|
|
peerIPMaskOnes int
|
|
|
|
peerIPMaskBits int
|
|
|
|
isLocal bool
|
2017-09-05 13:43:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *peerEntryDB) UnMarshalDB() peerEntry {
|
|
|
|
return peerEntry{
|
|
|
|
eid: p.eid,
|
|
|
|
vtep: net.ParseIP(p.vtep),
|
2017-10-03 20:12:57 -04:00
|
|
|
peerIPMask: net.CIDRMask(p.peerIPMaskOnes, p.peerIPMaskBits),
|
2017-09-05 13:43:20 -04:00
|
|
|
isLocal: p.isLocal,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-10 17:24:19 -04:00
|
|
|
type peerMap struct {
|
2017-09-07 14:25:06 -04:00
|
|
|
// set of peerEntry, note they have to be objects and not pointers to maintain the proper equality checks
|
2018-07-16 20:34:20 -04:00
|
|
|
mp setmatrix.SetMatrix
|
2015-06-10 17:24:19 -04:00
|
|
|
sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
type peerNetworkMap struct {
|
2017-09-07 14:25:06 -04:00
|
|
|
// map with key peerKey
|
2015-12-07 17:20:13 -05:00
|
|
|
mp map[string]*peerMap
|
2015-06-10 17:24:19 -04:00
|
|
|
sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pKey peerKey) String() string {
|
|
|
|
return fmt.Sprintf("%s %s", pKey.peerIP, pKey.peerMac)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pKey *peerKey) Scan(state fmt.ScanState, verb rune) error {
|
|
|
|
ipB, err := state.Token(true, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
pKey.peerIP = net.ParseIP(string(ipB))
|
|
|
|
|
|
|
|
macB, err := state.Token(true, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
pKey.peerMac, err = net.ParseMAC(string(macB))
|
2017-09-05 13:43:20 -04:00
|
|
|
return err
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
|
|
|
|
2015-10-02 15:20:29 -04:00
|
|
|
func (d *driver) peerDbWalk(f func(string, *peerKey, *peerEntry) bool) error {
|
|
|
|
d.peerDb.Lock()
|
|
|
|
nids := []string{}
|
|
|
|
for nid := range d.peerDb.mp {
|
|
|
|
nids = append(nids, nid)
|
|
|
|
}
|
|
|
|
d.peerDb.Unlock()
|
|
|
|
|
|
|
|
for _, nid := range nids {
|
|
|
|
d.peerDbNetworkWalk(nid, func(pKey *peerKey, pEntry *peerEntry) bool {
|
|
|
|
return f(nid, pKey, pEntry)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) peerDbNetworkWalk(nid string, f func(*peerKey, *peerEntry) bool) error {
|
2015-06-10 17:24:19 -04:00
|
|
|
d.peerDb.Lock()
|
|
|
|
pMap, ok := d.peerDb.mp[nid]
|
2017-02-07 13:04:38 -05:00
|
|
|
d.peerDb.Unlock()
|
|
|
|
|
2015-06-10 17:24:19 -04:00
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
2017-02-07 13:04:38 -05:00
|
|
|
|
|
|
|
mp := map[string]peerEntry{}
|
2015-06-10 17:24:19 -04:00
|
|
|
pMap.Lock()
|
2017-09-05 13:43:20 -04:00
|
|
|
for _, pKeyStr := range pMap.mp.Keys() {
|
|
|
|
entryDBList, ok := pMap.mp.Get(pKeyStr)
|
|
|
|
if ok {
|
|
|
|
peerEntryDB := entryDBList[0].(peerEntryDB)
|
|
|
|
mp[pKeyStr] = peerEntryDB.UnMarshalDB()
|
|
|
|
}
|
2017-02-07 13:04:38 -05:00
|
|
|
}
|
|
|
|
pMap.Unlock()
|
|
|
|
|
|
|
|
for pKeyStr, pEntry := range mp {
|
2015-06-10 17:24:19 -04:00
|
|
|
var pKey peerKey
|
|
|
|
if _, err := fmt.Sscan(pKeyStr, &pKey); err != nil {
|
2016-11-01 00:26:14 -04:00
|
|
|
logrus.Warnf("Peer key scan on network %s failed: %v", nid, err)
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
|
|
|
if f(&pKey, &pEntry) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-09-05 13:43:20 -04:00
|
|
|
func (d *driver) peerDbSearch(nid string, peerIP net.IP) (*peerKey, *peerEntry, error) {
|
|
|
|
var pKeyMatched *peerKey
|
|
|
|
var pEntryMatched *peerEntry
|
2015-10-02 15:20:29 -04:00
|
|
|
err := d.peerDbNetworkWalk(nid, func(pKey *peerKey, pEntry *peerEntry) bool {
|
2015-06-10 17:24:19 -04:00
|
|
|
if pKey.peerIP.Equal(peerIP) {
|
2017-09-05 13:43:20 -04:00
|
|
|
pKeyMatched = pKey
|
|
|
|
pEntryMatched = pEntry
|
|
|
|
return true
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
|
|
|
|
2017-09-05 13:43:20 -04:00
|
|
|
return false
|
2015-06-10 17:24:19 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
2017-09-05 13:43:20 -04:00
|
|
|
return nil, nil, fmt.Errorf("peerdb search for peer ip %q failed: %v", peerIP, err)
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
|
|
|
|
2017-09-05 13:43:20 -04:00
|
|
|
if pKeyMatched == nil || pEntryMatched == nil {
|
|
|
|
return nil, nil, fmt.Errorf("peer ip %q not found in peerdb", peerIP)
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
|
|
|
|
2017-09-05 13:43:20 -04:00
|
|
|
return pKeyMatched, pEntryMatched, nil
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
|
|
|
|
2015-09-29 02:06:57 -04:00
|
|
|
func (d *driver) peerDbAdd(nid, eid string, peerIP net.IP, peerIPMask net.IPMask,
|
2017-09-05 13:43:20 -04:00
|
|
|
peerMac net.HardwareAddr, vtep net.IP, isLocal bool) (bool, int) {
|
2015-06-10 17:24:19 -04:00
|
|
|
|
|
|
|
d.peerDb.Lock()
|
|
|
|
pMap, ok := d.peerDb.mp[nid]
|
|
|
|
if !ok {
|
2015-12-07 17:20:13 -05:00
|
|
|
d.peerDb.mp[nid] = &peerMap{
|
2018-07-16 20:34:20 -04:00
|
|
|
mp: setmatrix.NewSetMatrix(),
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pMap = d.peerDb.mp[nid]
|
|
|
|
}
|
|
|
|
d.peerDb.Unlock()
|
|
|
|
|
|
|
|
pKey := peerKey{
|
|
|
|
peerIP: peerIP,
|
|
|
|
peerMac: peerMac,
|
|
|
|
}
|
|
|
|
|
|
|
|
pEntry := peerEntry{
|
2015-09-29 02:06:57 -04:00
|
|
|
eid: eid,
|
|
|
|
vtep: vtep,
|
|
|
|
peerIPMask: peerIPMask,
|
|
|
|
isLocal: isLocal,
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pMap.Lock()
|
2017-09-05 13:43:20 -04:00
|
|
|
defer pMap.Unlock()
|
|
|
|
b, i := pMap.mp.Insert(pKey.String(), pEntry.MarshalDB())
|
|
|
|
if i != 1 {
|
|
|
|
// Transient case, there is more than one endpoint that is using the same IP,MAC pair
|
|
|
|
s, _ := pMap.mp.String(pKey.String())
|
|
|
|
logrus.Warnf("peerDbAdd transient condition - Key:%s cardinality:%d db state:%s", pKey.String(), i, s)
|
|
|
|
}
|
|
|
|
return b, i
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
|
|
|
|
2015-09-29 02:06:57 -04:00
|
|
|
func (d *driver) peerDbDelete(nid, eid string, peerIP net.IP, peerIPMask net.IPMask,
|
2017-09-05 13:43:20 -04:00
|
|
|
peerMac net.HardwareAddr, vtep net.IP, isLocal bool) (bool, int) {
|
2015-06-10 17:24:19 -04:00
|
|
|
|
|
|
|
d.peerDb.Lock()
|
|
|
|
pMap, ok := d.peerDb.mp[nid]
|
|
|
|
if !ok {
|
|
|
|
d.peerDb.Unlock()
|
2017-09-05 13:43:20 -04:00
|
|
|
return false, 0
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
|
|
|
d.peerDb.Unlock()
|
|
|
|
|
|
|
|
pKey := peerKey{
|
|
|
|
peerIP: peerIP,
|
|
|
|
peerMac: peerMac,
|
|
|
|
}
|
|
|
|
|
2017-09-05 13:43:20 -04:00
|
|
|
pEntry := peerEntry{
|
|
|
|
eid: eid,
|
|
|
|
vtep: vtep,
|
|
|
|
peerIPMask: peerIPMask,
|
|
|
|
isLocal: isLocal,
|
2016-08-08 14:55:06 -04:00
|
|
|
}
|
|
|
|
|
2017-09-05 13:43:20 -04:00
|
|
|
pMap.Lock()
|
|
|
|
defer pMap.Unlock()
|
|
|
|
b, i := pMap.mp.Remove(pKey.String(), pEntry.MarshalDB())
|
|
|
|
if i != 0 {
|
|
|
|
// Transient case, there is more than one endpoint that is using the same IP,MAC pair
|
|
|
|
s, _ := pMap.mp.String(pKey.String())
|
|
|
|
logrus.Warnf("peerDbDelete transient condition - Key:%s cardinality:%d db state:%s", pKey.String(), i, s)
|
|
|
|
}
|
|
|
|
return b, i
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
|
|
|
|
2017-08-05 11:42:20 -04:00
|
|
|
// The overlay uses a lazy initialization approach, this means that when a network is created
|
|
|
|
// and the driver registered the overlay does not allocate resources till the moment that a
|
|
|
|
// sandbox is actually created.
|
|
|
|
// At the moment of this call, that happens when a sandbox is initialized, is possible that
|
|
|
|
// networkDB has already delivered some events of peers already available on remote nodes,
|
|
|
|
// these peers are saved into the peerDB and this function is used to properly configure
|
|
|
|
// the network sandbox with all those peers that got previously notified.
|
|
|
|
// Note also that this method sends a single message on the channel and the go routine on the
|
|
|
|
// other side, will atomically loop on the whole table of peers and will program their state
|
|
|
|
// in one single atomic operation. This is fundamental to guarantee consistency, and avoid that
|
|
|
|
// new peerAdd or peerDelete gets reordered during the sandbox init.
|
|
|
|
func (d *driver) initSandboxPeerDB(nid string) {
|
|
|
|
d.peerInit(nid)
|
|
|
|
}
|
2015-06-10 17:24:19 -04:00
|
|
|
|
2017-08-05 11:42:20 -04:00
|
|
|
type peerOperationType int32
|
2015-06-10 17:24:19 -04:00
|
|
|
|
2017-08-05 11:42:20 -04:00
|
|
|
const (
|
|
|
|
peerOperationINIT peerOperationType = iota
|
|
|
|
peerOperationADD
|
|
|
|
peerOperationDELETE
|
2017-09-07 14:25:06 -04:00
|
|
|
peerOperationFLUSH
|
2017-08-05 11:42:20 -04:00
|
|
|
)
|
2015-06-10 17:24:19 -04:00
|
|
|
|
2017-07-27 14:43:13 -04:00
|
|
|
type peerOperation struct {
|
2017-08-05 11:42:20 -04:00
|
|
|
opType peerOperationType
|
2017-07-27 14:43:13 -04:00
|
|
|
networkID string
|
|
|
|
endpointID string
|
|
|
|
peerIP net.IP
|
|
|
|
peerIPMask net.IPMask
|
|
|
|
peerMac net.HardwareAddr
|
|
|
|
vtepIP net.IP
|
|
|
|
l2Miss bool
|
|
|
|
l3Miss bool
|
|
|
|
localPeer bool
|
|
|
|
callerName string
|
|
|
|
}
|
2015-06-10 17:24:19 -04:00
|
|
|
|
2017-07-27 14:43:13 -04:00
|
|
|
func (d *driver) peerOpRoutine(ctx context.Context, ch chan *peerOperation) {
|
|
|
|
var err error
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
case op := <-ch:
|
2017-08-05 11:42:20 -04:00
|
|
|
switch op.opType {
|
|
|
|
case peerOperationINIT:
|
|
|
|
err = d.peerInitOp(op.networkID)
|
|
|
|
case peerOperationADD:
|
2017-08-14 12:20:55 -04:00
|
|
|
err = d.peerAddOp(op.networkID, op.endpointID, op.peerIP, op.peerIPMask, op.peerMac, op.vtepIP, op.l2Miss, op.l3Miss, true, op.localPeer)
|
2017-08-05 11:42:20 -04:00
|
|
|
case peerOperationDELETE:
|
2017-09-05 13:43:20 -04:00
|
|
|
err = d.peerDeleteOp(op.networkID, op.endpointID, op.peerIP, op.peerIPMask, op.peerMac, op.vtepIP, op.localPeer)
|
2017-09-07 14:25:06 -04:00
|
|
|
case peerOperationFLUSH:
|
|
|
|
err = d.peerFlushOp(op.networkID)
|
2017-07-27 14:43:13 -04:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
logrus.Warnf("Peer operation failed:%s op:%v", err, op)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-27 14:43:13 -04:00
|
|
|
}
|
|
|
|
|
2017-08-05 11:42:20 -04:00
|
|
|
func (d *driver) peerInit(nid string) {
|
2018-07-16 20:34:20 -04:00
|
|
|
callerName := caller.Name(1)
|
2017-08-05 11:42:20 -04:00
|
|
|
d.peerOpCh <- &peerOperation{
|
|
|
|
opType: peerOperationINIT,
|
|
|
|
networkID: nid,
|
|
|
|
callerName: callerName,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) peerInitOp(nid string) error {
|
|
|
|
return d.peerDbNetworkWalk(nid, func(pKey *peerKey, pEntry *peerEntry) bool {
|
|
|
|
// Local entries do not need to be added
|
|
|
|
if pEntry.isLocal {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-08-14 12:20:55 -04:00
|
|
|
d.peerAddOp(nid, pEntry.eid, pKey.peerIP, pEntry.peerIPMask, pKey.peerMac, pEntry.vtep, false, false, false, pEntry.isLocal)
|
2017-08-05 11:42:20 -04:00
|
|
|
// return false to loop on all entries
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-02 17:48:20 -04:00
|
|
|
func (d *driver) peerAdd(nid, eid string, peerIP net.IP, peerIPMask net.IPMask,
|
2017-08-14 12:20:55 -04:00
|
|
|
peerMac net.HardwareAddr, vtep net.IP, l2Miss, l3Miss, localPeer bool) {
|
2017-07-27 14:43:13 -04:00
|
|
|
d.peerOpCh <- &peerOperation{
|
2017-08-05 11:42:20 -04:00
|
|
|
opType: peerOperationADD,
|
2017-07-27 14:43:13 -04:00
|
|
|
networkID: nid,
|
|
|
|
endpointID: eid,
|
|
|
|
peerIP: peerIP,
|
|
|
|
peerIPMask: peerIPMask,
|
|
|
|
peerMac: peerMac,
|
|
|
|
vtepIP: vtep,
|
|
|
|
l2Miss: l2Miss,
|
|
|
|
l3Miss: l3Miss,
|
|
|
|
localPeer: localPeer,
|
2018-07-16 20:34:20 -04:00
|
|
|
callerName: caller.Name(1),
|
2017-07-27 14:43:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) peerAddOp(nid, eid string, peerIP net.IP, peerIPMask net.IPMask,
|
2017-09-05 13:43:20 -04:00
|
|
|
peerMac net.HardwareAddr, vtep net.IP, l2Miss, l3Miss, updateDB, localPeer bool) error {
|
2015-06-10 17:24:19 -04:00
|
|
|
|
|
|
|
if err := validateID(nid, eid); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-09-05 13:43:20 -04:00
|
|
|
var dbEntries int
|
|
|
|
var inserted bool
|
2017-08-14 12:20:55 -04:00
|
|
|
if updateDB {
|
2017-09-05 13:43:20 -04:00
|
|
|
inserted, dbEntries = d.peerDbAdd(nid, eid, peerIP, peerIPMask, peerMac, vtep, localPeer)
|
|
|
|
if !inserted {
|
|
|
|
logrus.Warnf("Entry already present in db: nid:%s eid:%s peerIP:%v peerMac:%v isLocal:%t vtep:%v",
|
|
|
|
nid, eid, peerIP, peerMac, localPeer, vtep)
|
2017-07-27 14:43:13 -04:00
|
|
|
}
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
|
|
|
|
2017-09-05 13:43:20 -04:00
|
|
|
// Local peers do not need any further configuration
|
|
|
|
if localPeer {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-06-10 17:24:19 -04:00
|
|
|
n := d.network(nid)
|
|
|
|
if n == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
sbox := n.sandbox()
|
|
|
|
if sbox == nil {
|
2017-08-05 11:42:20 -04:00
|
|
|
// We are hitting this case for all the events that are arriving before that the sandbox
|
|
|
|
// is being created. The peer got already added into the database and the sanbox init will
|
|
|
|
// call the peerDbUpdateSandbox that will configure all these peers from the database
|
2015-06-10 17:24:19 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-09-29 02:06:57 -04:00
|
|
|
IP := &net.IPNet{
|
|
|
|
IP: peerIP,
|
|
|
|
Mask: peerIPMask,
|
|
|
|
}
|
|
|
|
|
|
|
|
s := n.getSubnetforIP(IP)
|
|
|
|
if s == nil {
|
2016-11-14 19:41:54 -05:00
|
|
|
return fmt.Errorf("couldn't find the subnet %q in network %q", IP.String(), n.id)
|
2015-09-29 02:06:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := n.obtainVxlanID(s); err != nil {
|
|
|
|
return fmt.Errorf("couldn't get vxlan id for %q: %v", s.subnetIP.String(), err)
|
|
|
|
}
|
|
|
|
|
2018-05-04 14:33:00 -04:00
|
|
|
if err := n.joinSandbox(s, false, false); err != nil {
|
2015-09-29 02:06:57 -04:00
|
|
|
return fmt.Errorf("subnet sandbox join failed for %q: %v", s.subnetIP.String(), err)
|
|
|
|
}
|
|
|
|
|
2016-06-06 21:17:10 -04:00
|
|
|
if err := d.checkEncryption(nid, vtep, n.vxlanID(s), false, true); err != nil {
|
2016-11-01 00:26:14 -04:00
|
|
|
logrus.Warn(err)
|
2016-06-06 21:17:10 -04:00
|
|
|
}
|
|
|
|
|
2015-06-10 17:24:19 -04:00
|
|
|
// Add neighbor entry for the peer IP
|
2017-03-16 21:12:52 -04:00
|
|
|
if err := sbox.AddNeighbor(peerIP, peerMac, l3Miss, sbox.NeighborOptions().LinkName(s.vxlanName)); err != nil {
|
2017-09-05 13:43:20 -04:00
|
|
|
if _, ok := err.(osl.NeighborSearchError); ok && dbEntries > 1 {
|
|
|
|
// We are in the transient case so only the first configuration is programmed into the kernel
|
|
|
|
// Upon deletion if the active configuration is deleted the next one from the database will be restored
|
|
|
|
// Note we are skipping also the next configuration
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return fmt.Errorf("could not add neighbor entry for nid:%s eid:%s into the sandbox:%v", nid, eid, err)
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add fdb entry to the bridge for the peer mac
|
2017-03-16 21:12:52 -04:00
|
|
|
if err := sbox.AddNeighbor(vtep, peerMac, l2Miss, sbox.NeighborOptions().LinkName(s.vxlanName),
|
2015-06-10 17:24:19 -04:00
|
|
|
sbox.NeighborOptions().Family(syscall.AF_BRIDGE)); err != nil {
|
2017-09-05 13:43:20 -04:00
|
|
|
return fmt.Errorf("could not add fdb entry for nid:%s eid:%s into the sandbox:%v", nid, eid, err)
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-09-29 02:06:57 -04:00
|
|
|
func (d *driver) peerDelete(nid, eid string, peerIP net.IP, peerIPMask net.IPMask,
|
2017-09-05 13:43:20 -04:00
|
|
|
peerMac net.HardwareAddr, vtep net.IP, localPeer bool) {
|
2017-07-27 14:43:13 -04:00
|
|
|
d.peerOpCh <- &peerOperation{
|
2017-08-05 11:42:20 -04:00
|
|
|
opType: peerOperationDELETE,
|
2017-07-27 14:43:13 -04:00
|
|
|
networkID: nid,
|
|
|
|
endpointID: eid,
|
|
|
|
peerIP: peerIP,
|
|
|
|
peerIPMask: peerIPMask,
|
|
|
|
peerMac: peerMac,
|
|
|
|
vtepIP: vtep,
|
2018-07-16 20:34:20 -04:00
|
|
|
callerName: caller.Name(1),
|
2017-09-05 13:43:20 -04:00
|
|
|
localPeer: localPeer,
|
2017-07-27 14:43:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) peerDeleteOp(nid, eid string, peerIP net.IP, peerIPMask net.IPMask,
|
2017-09-05 13:43:20 -04:00
|
|
|
peerMac net.HardwareAddr, vtep net.IP, localPeer bool) error {
|
2015-06-10 17:24:19 -04:00
|
|
|
|
|
|
|
if err := validateID(nid, eid); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-09-05 13:43:20 -04:00
|
|
|
deleted, dbEntries := d.peerDbDelete(nid, eid, peerIP, peerIPMask, peerMac, vtep, localPeer)
|
|
|
|
if !deleted {
|
|
|
|
logrus.Warnf("Entry was not in db: nid:%s eid:%s peerIP:%v peerMac:%v isLocal:%t vtep:%v",
|
|
|
|
nid, eid, peerIP, peerMac, localPeer, vtep)
|
|
|
|
}
|
2015-06-10 17:24:19 -04:00
|
|
|
|
|
|
|
n := d.network(nid)
|
|
|
|
if n == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
sbox := n.sandbox()
|
|
|
|
if sbox == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-09-07 14:25:06 -04:00
|
|
|
if err := d.checkEncryption(nid, vtep, 0, localPeer, false); err != nil {
|
2017-09-05 13:43:20 -04:00
|
|
|
logrus.Warn(err)
|
|
|
|
}
|
|
|
|
|
2017-10-02 20:05:12 -04:00
|
|
|
// Local peers do not have any local configuration to delete
|
|
|
|
if !localPeer {
|
|
|
|
// Remove fdb entry to the bridge for the peer mac
|
|
|
|
if err := sbox.DeleteNeighbor(vtep, peerMac, true); err != nil {
|
|
|
|
if _, ok := err.(osl.NeighborSearchError); ok && dbEntries > 0 {
|
|
|
|
// We fall in here if there is a transient state and if the neighbor that is being deleted
|
|
|
|
// was never been configured into the kernel (we allow only 1 configuration at the time per <ip,mac> mapping)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return fmt.Errorf("could not delete fdb entry for nid:%s eid:%s into the sandbox:%v", nid, eid, err)
|
2016-09-07 13:45:40 -04:00
|
|
|
}
|
2015-06-10 17:24:19 -04:00
|
|
|
|
2017-10-02 20:05:12 -04:00
|
|
|
// Delete neighbor entry for the peer IP
|
|
|
|
if err := sbox.DeleteNeighbor(peerIP, peerMac, true); err != nil {
|
|
|
|
return fmt.Errorf("could not delete neighbor entry for nid:%s eid:%s into the sandbox:%v", nid, eid, err)
|
|
|
|
}
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
|
|
|
|
2017-09-05 13:43:20 -04:00
|
|
|
if dbEntries == 0 {
|
|
|
|
return nil
|
2016-06-06 21:17:10 -04:00
|
|
|
}
|
|
|
|
|
2017-09-05 13:43:20 -04:00
|
|
|
// If there is still an entry into the database and the deletion went through without errors means that there is now no
|
|
|
|
// configuration active in the kernel.
|
|
|
|
// Restore one configuration for the <ip,mac> directly from the database, note that is guaranteed that there is one
|
|
|
|
peerKey, peerEntry, err := d.peerDbSearch(nid, peerIP)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Errorf("peerDeleteOp unable to restore a configuration for nid:%s ip:%v mac:%v err:%s", nid, peerIP, peerMac, err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return d.peerAddOp(nid, peerEntry.eid, peerIP, peerEntry.peerIPMask, peerKey.peerMac, peerEntry.vtep, false, false, false, peerEntry.isLocal)
|
2015-06-10 17:24:19 -04:00
|
|
|
}
|
2015-10-02 15:20:29 -04:00
|
|
|
|
2017-09-07 14:25:06 -04:00
|
|
|
func (d *driver) peerFlush(nid string) {
|
|
|
|
d.peerOpCh <- &peerOperation{
|
|
|
|
opType: peerOperationFLUSH,
|
|
|
|
networkID: nid,
|
2018-07-16 20:34:20 -04:00
|
|
|
callerName: caller.Name(1),
|
2017-09-07 14:25:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) peerFlushOp(nid string) error {
|
|
|
|
d.peerDb.Lock()
|
|
|
|
defer d.peerDb.Unlock()
|
|
|
|
_, ok := d.peerDb.mp[nid]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Unable to find the peerDB for nid:%s", nid)
|
|
|
|
}
|
|
|
|
delete(d.peerDb.mp, nid)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-10-02 15:20:29 -04:00
|
|
|
func (d *driver) pushLocalDb() {
|
|
|
|
d.peerDbWalk(func(nid string, pKey *peerKey, pEntry *peerEntry) bool {
|
|
|
|
if pEntry.isLocal {
|
|
|
|
d.pushLocalEndpointEvent("join", nid, pEntry.eid)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
}
|
2017-02-10 17:24:24 -05:00
|
|
|
|
|
|
|
func (d *driver) peerDBUpdateSelf() {
|
|
|
|
d.peerDbWalk(func(nid string, pkey *peerKey, pEntry *peerEntry) bool {
|
|
|
|
if pEntry.isLocal {
|
|
|
|
pEntry.vtep = net.ParseIP(d.advertiseAddress)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
}
|