Skip to content

Commit 48e0b24

Browse files
committed
libnetwork/d/overlay: elide vtep for local peers
The VTEP value for a peer in peerDB is only accurate for a remote peer. The VTEP for a local peer would be the driver's advertise address, which is not necessarily constant for the lifetime of the driver instance. The VTEP values persisted in the peerDB entries for local peers could be stale or missing if not kept in sync with the advertise address. And the peerDB could get polluted with duplicate entries for local peers if the advertise address was to change, as entries which differ only by VTEP are considered distinct by SetMatrix. Persisting the advertise address as the VTEP for local peers creates lots of problems that are not easy to solve. Stop persisting the VTEP for local peers in peerDB. Any code that needs to know the VTEP for local peers can look that up from the source of truth: the driver's advertise address. Use the lack of a VTEP in peerDB entries to signify local peers, making the isLocal flag redundant. Signed-off-by: Cory Snider <[email protected]>
1 parent a9e2d6d commit 48e0b24

2 files changed

Lines changed: 16 additions & 9 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 !pEntry.isLocal {
135+
if !pEntry.isLocal() {
136136
nodes[pEntry.vtep] = struct{}{}
137137
}
138138
return false

libnetwork/drivers/overlay/peerdb.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ const ovPeerTable = "overlay_peer_table"
2020

2121
type peerEntry struct {
2222
eid string
23-
vtep netip.Addr
24-
prefixBits int // number of 1-bits in network mask of peerIP
25-
isLocal bool
23+
vtep netip.Addr // Virtual Tunnel End Point for non-local peers
24+
prefixBits int // number of 1-bits in network mask of peerIP
25+
}
26+
27+
func (p *peerEntry) isLocal() bool {
28+
return !p.vtep.IsValid()
2629
}
2730

2831
type peerMap struct {
@@ -105,7 +108,9 @@ func (d *driver) peerDbAdd(nid, eid string, peerIP netip.Prefix, peerMac net.Har
105108
eid: eid,
106109
vtep: vtep,
107110
prefixBits: peerIP.Bits(),
108-
isLocal: isLocal,
111+
}
112+
if isLocal {
113+
pEntry.vtep = netip.Addr{}
109114
}
110115

111116
pMap.Lock()
@@ -134,7 +139,9 @@ func (d *driver) peerDbDelete(nid, eid string, peerIP netip.Prefix, peerMac net.
134139
eid: eid,
135140
vtep: vtep,
136141
prefixBits: peerIP.Bits(),
137-
isLocal: isLocal,
142+
}
143+
if isLocal {
144+
pEntry.vtep = netip.Addr{}
138145
}
139146

140147
pMap.Lock()
@@ -170,11 +177,11 @@ func (d *driver) initSandboxPeerDB(nid string) {
170177
func (d *driver) peerInitOp(nid string) error {
171178
return d.peerDbNetworkWalk(nid, func(peerIP netip.Addr, peerMac net.HardwareAddr, pEntry *peerEntry) bool {
172179
// Local entries do not need to be added
173-
if pEntry.isLocal {
180+
if pEntry.isLocal() {
174181
return false
175182
}
176183

177-
d.peerAddOp(nid, pEntry.eid, netip.PrefixFrom(peerIP, pEntry.prefixBits), peerMac, pEntry.vtep, false, pEntry.isLocal)
184+
d.peerAddOp(nid, pEntry.eid, netip.PrefixFrom(peerIP, pEntry.prefixBits), peerMac, pEntry.vtep, false, pEntry.isLocal())
178185
// return false to loop on all entries
179186
return false
180187
})
@@ -322,7 +329,7 @@ func (d *driver) peerDeleteOp(nid, eid string, peerIP netip.Prefix, peerMac net.
322329
log.G(context.TODO()).Errorf("peerDeleteOp unable to restore a configuration for nid:%s ip:%v mac:%v err:%s", nid, peerIP, peerMac, err)
323330
return err
324331
}
325-
return d.peerAddOp(nid, peerEntry.eid, netip.PrefixFrom(peerIPAddr, peerEntry.prefixBits), peerMac, peerEntry.vtep, false, peerEntry.isLocal)
332+
return d.peerAddOp(nid, peerEntry.eid, netip.PrefixFrom(peerIPAddr, peerEntry.prefixBits), peerMac, peerEntry.vtep, false, peerEntry.isLocal())
326333
}
327334

328335
func (d *driver) peerFlush(nid string) {

0 commit comments

Comments
 (0)