Skip to content

Commit 0d89325

Browse files
committed
libnetwork/d/overlay: checkEncryption: drop isLocal param
Since it is not meaningful to add or remove encryption between the local node and itself, the isLocal parameter is redundant. Setting up encryption for all network peers is now invoked by calling checkEncryption(nid, netip.Addr{}, true) Calling checkEncryption with isLocal=true, add=false is now more explicitly a no-op. It always was effectively a no-op, but that was not easy to spot by inspection. In the world with the isLocal flag, calls to checkEncryption where isLocal=true and add=false would have rIP set to d.advertiseAddr. In other words, it was a request to remove encryption parameters between the local peer and itself if peerDB had no remote-peer entries for the network. So either the call would do nothing, or it would remove encryption parameters that aren't used for anything. Now the equivalent call always does nothing. Signed-off-by: Cory Snider <[email protected]>
1 parent 4b1c123 commit 0d89325

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

libnetwork/drivers/overlay/encryption.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,12 @@ func (e *encrMap) String() string {
113113
return b.String()
114114
}
115115

116-
func (d *driver) checkEncryption(nid string, rIP netip.Addr, isLocal, add bool) error {
117-
log.G(context.TODO()).Debugf("checkEncryption(%.7s, %v, %t)", nid, rIP, isLocal)
116+
// checkEncryption sets up or removes IPsec encryption parameters for peers on a network.
117+
//
118+
// When given an rIP, encryption paremeters will be set up for the VXLAN tunnel to that peer.
119+
// When !rIP.IsValid(), encryption parameters will be set up for all network peers.
120+
func (d *driver) checkEncryption(nid string, rIP netip.Addr, add bool) error {
121+
log.G(context.TODO()).Debugf("checkEncryption(%.7s, %v)", nid, rIP)
118122

119123
n := d.network(nid)
120124
if n == nil || !n.secure {
@@ -130,7 +134,7 @@ func (d *driver) checkEncryption(nid string, rIP netip.Addr, isLocal, add bool)
130134
nodes := map[netip.Addr]struct{}{}
131135

132136
switch {
133-
case isLocal:
137+
case !rIP.IsValid():
134138
if err := d.peerDbNetworkWalk(nid, func(_ netip.Addr, _ net.HardwareAddr, pEntry *peerEntry) bool {
135139
if !pEntry.isLocal() {
136140
nodes[pEntry.vtep] = struct{}{}
@@ -154,7 +158,7 @@ func (d *driver) checkEncryption(nid string, rIP netip.Addr, isLocal, add bool)
154158
}
155159
}
156160
} else {
157-
if len(nodes) == 0 {
161+
if rIP.IsValid() && len(nodes) == 0 {
158162
if err := removeEncryption(lIP, rIP, d.secMap); err != nil {
159163
log.G(context.TODO()).Warnf("Failed to remove network encryption between %s and %s: %v", lIP, rIP, err)
160164
}

libnetwork/drivers/overlay/joinleave.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinf
121121

122122
d.peerAdd(nid, eid, ep.addr, ep.mac, netip.Addr{})
123123

124-
if err = d.checkEncryption(nid, netip.Addr{}, true, true); err != nil {
124+
if err = d.checkEncryption(nid, netip.Addr{}, true); err != nil {
125125
log.G(ctx).Warn(err)
126126
}
127127

libnetwork/drivers/overlay/peerdb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func (d *driver) peerAddOp(nid, eid string, peerIP netip.Prefix, peerMac net.Har
235235
return fmt.Errorf("subnet sandbox join failed for %q: %v", s.subnetIP.String(), err)
236236
}
237237

238-
if err := d.checkEncryption(nid, vtep, false, true); err != nil {
238+
if err := d.checkEncryption(nid, vtep, true); err != nil {
239239
log.G(context.TODO()).Warn(err)
240240
}
241241

@@ -291,7 +291,7 @@ func (d *driver) peerDeleteOp(nid, eid string, peerIP netip.Prefix, peerMac net.
291291
return nil
292292
}
293293

294-
if err := d.checkEncryption(nid, vtep, !vtep.IsValid(), false); err != nil {
294+
if err := d.checkEncryption(nid, vtep, false); err != nil {
295295
log.G(context.TODO()).Warn(err)
296296
}
297297

0 commit comments

Comments
 (0)