Skip to content

Commit a9e2d6d

Browse files
committed
libnetwork/d/overlay: filter local peers explicitly
The overlay driver's checkEncryption function configures the IPSec parameters for the VXLAN tunnels to peer nodes. When called with isLocal=true, it configures encryption for all peer nodes with at least one peerDB entry. Since the local peers are also included in the peerDB, it needs to filter those entries out. It does so by filtering out any peer entries whose VTEP address is equal to the current local advertise address. Trouble is, the local advertise address is not necessarily constant. The driver tries to handle this case by calling peerDBUpdateSelf() when the advertise address changes. This function iterates through the peerDB and tries to update the VTEP address for all local peer entries, but it does not actually do anything: it mutates a temporary copy of the entry which is not persisted back into the peerDB. (It used to be functional, but was broken when the peerDB was extended to use SetMatrix.) So there may be cases where local peer entries are not filtered out properly, resulting in spurious encryption parameters being programmed into the kernel. Filter out local peers when walking the peerDB by filtering on whether the entry has the isLocal flag set. Remove the no-op code which attempts to update local entries in the peerDB. No other code takes any interest in the VTEP value for isLocal peer entries. Signed-off-by: Cory Snider <[email protected]>
1 parent f144264 commit a9e2d6d

3 files changed

Lines changed: 8 additions & 40 deletions

File tree

libnetwork/drivers/overlay/encryption.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (d *driver) checkEncryption(nid string, rIP netip.Addr, isLocal, add bool)
132132
switch {
133133
case isLocal:
134134
if err := d.peerDbNetworkWalk(nid, func(_ netip.Addr, _ net.HardwareAddr, pEntry *peerEntry) bool {
135-
if aIP != pEntry.vtep {
135+
if !pEntry.isLocal {
136136
nodes[pEntry.vtep] = struct{}{}
137137
}
138138
return false

libnetwork/drivers/overlay/overlay.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ var _ discoverapi.Discover = (*driver)(nil)
3030
type driver struct {
3131
bindAddress, advertiseAddress netip.Addr
3232

33-
config map[string]interface{}
34-
peerDb peerNetworkMap
35-
secMap *encrMap
36-
networks networkTable
37-
initOS sync.Once
38-
localJoinOnce sync.Once
39-
keys []*key
40-
peerOpMu sync.Mutex
33+
config map[string]interface{}
34+
peerDb peerNetworkMap
35+
secMap *encrMap
36+
networks networkTable
37+
initOS sync.Once
38+
keys []*key
39+
peerOpMu sync.Mutex
4140
sync.Mutex
4241
}
4342

@@ -95,12 +94,6 @@ func (d *driver) nodeJoin(data discoverapi.NodeDiscoveryData) error {
9594
d.advertiseAddress = advAddr
9695
d.bindAddress = bindAddr
9796
d.Unlock()
98-
99-
// If containers are already running on this network update the
100-
// advertise address in the peerDB
101-
d.localJoinOnce.Do(func() {
102-
d.peerDBUpdateSelf()
103-
})
10497
}
10598
return nil
10699
}

libnetwork/drivers/overlay/peerdb.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,6 @@ type peerNetworkMap struct {
3737
sync.Mutex
3838
}
3939

40-
func (d *driver) peerDbWalk(f func(string, netip.Addr, net.HardwareAddr, *peerEntry) bool) error {
41-
d.peerDb.Lock()
42-
nids := []string{}
43-
for nid := range d.peerDb.mp {
44-
nids = append(nids, nid)
45-
}
46-
d.peerDb.Unlock()
47-
48-
for _, nid := range nids {
49-
d.peerDbNetworkWalk(nid, func(peerIP netip.Addr, peerMac net.HardwareAddr, pEntry *peerEntry) bool {
50-
return f(nid, peerIP, peerMac, pEntry)
51-
})
52-
}
53-
return nil
54-
}
55-
5640
func (d *driver) peerDbNetworkWalk(nid string, f func(netip.Addr, net.HardwareAddr, *peerEntry) bool) error {
5741
d.peerDb.Lock()
5842
pMap, ok := d.peerDb.mp[nid]
@@ -359,12 +343,3 @@ func (d *driver) peerFlushOp(nid string) error {
359343
delete(d.peerDb.mp, nid)
360344
return nil
361345
}
362-
363-
func (d *driver) peerDBUpdateSelf() {
364-
d.peerDbWalk(func(nid string, _ netip.Addr, _ net.HardwareAddr, pEntry *peerEntry) bool {
365-
if pEntry.isLocal {
366-
pEntry.vtep = d.advertiseAddress
367-
}
368-
return false
369-
})
370-
}

0 commit comments

Comments
 (0)