@@ -10,6 +10,7 @@ import (
10
10
"fmt"
11
11
"hash/fnv"
12
12
"net"
13
+ "net/netip"
13
14
"strconv"
14
15
"sync"
15
16
"syscall"
@@ -90,7 +91,7 @@ func (s *spi) String() string {
90
91
}
91
92
92
93
type encrMap struct {
93
- nodes map [string ][]* spi
94
+ nodes map [netip. Addr ][]* spi
94
95
sync.Mutex
95
96
}
96
97
@@ -100,7 +101,7 @@ func (e *encrMap) String() string {
100
101
b := new (bytes.Buffer )
101
102
for k , v := range e .nodes {
102
103
b .WriteString ("\n " )
103
- b .WriteString (k )
104
+ b .WriteString (k . String () )
104
105
b .WriteString (":" )
105
106
b .WriteString ("[" )
106
107
for _ , s := range v {
@@ -112,7 +113,7 @@ func (e *encrMap) String() string {
112
113
return b .String ()
113
114
}
114
115
115
- func (d * driver ) checkEncryption (nid string , rIP net. IP , isLocal , add bool ) error {
116
+ func (d * driver ) checkEncryption (nid string , rIP netip. Addr , isLocal , add bool ) error {
116
117
log .G (context .TODO ()).Debugf ("checkEncryption(%.7s, %v, %t)" , nid , rIP , isLocal )
117
118
118
119
n := d .network (nid )
@@ -126,28 +127,28 @@ func (d *driver) checkEncryption(nid string, rIP net.IP, isLocal, add bool) erro
126
127
127
128
lIP := d .bindAddress
128
129
aIP := d .advertiseAddress
129
- nodes := map [string ]net. IP {}
130
+ nodes := map [netip. Addr ] struct {} {}
130
131
131
132
switch {
132
133
case isLocal :
133
- if err := d .peerDbNetworkWalk (nid , func (pKey * peerKey , pEntry * peerEntry ) bool {
134
- if ! aIP . Equal ( pEntry .vtep ) {
135
- nodes [pEntry .vtep . String () ] = pEntry . vtep
134
+ if err := d .peerDbNetworkWalk (nid , func (_ netip. Addr , _ net. HardwareAddr , pEntry * peerEntry ) bool {
135
+ if aIP != pEntry .vtep {
136
+ nodes [pEntry .vtep ] = struct {}{}
136
137
}
137
138
return false
138
139
}); err != nil {
139
140
log .G (context .TODO ()).Warnf ("Failed to retrieve list of participating nodes in overlay network %.5s: %v" , nid , err )
140
141
}
141
142
default :
142
143
if len (d .network (nid ).endpoints ) > 0 {
143
- nodes [rIP . String () ] = rIP
144
+ nodes [rIP ] = struct {}{}
144
145
}
145
146
}
146
147
147
148
log .G (context .TODO ()).Debugf ("List of nodes: %s" , nodes )
148
149
149
150
if add {
150
- for _ , rIP := range nodes {
151
+ for rIP := range nodes {
151
152
if err := setupEncryption (lIP , aIP , rIP , d .secMap , d .keys ); err != nil {
152
153
log .G (context .TODO ()).Warnf ("Failed to program network encryption between %s and %s: %v" , lIP , rIP , err )
153
154
}
@@ -165,19 +166,18 @@ func (d *driver) checkEncryption(nid string, rIP net.IP, isLocal, add bool) erro
165
166
166
167
// setupEncryption programs the encryption parameters for secure communication
167
168
// between the local node and a remote node.
168
- func setupEncryption (localIP , advIP , remoteIP net. IP , em * encrMap , keys []* key ) error {
169
+ func setupEncryption (localIP , advIP , remoteIP netip. Addr , em * encrMap , keys []* key ) error {
169
170
log .G (context .TODO ()).Debugf ("Programming encryption between %s and %s" , localIP , remoteIP )
170
- rIPs := remoteIP .String ()
171
171
172
172
indices := make ([]* spi , 0 , len (keys ))
173
173
174
174
for i , k := range keys {
175
- spis := & spi {buildSPI (advIP , remoteIP , k .tag ), buildSPI (remoteIP , advIP , k .tag )}
175
+ spis := & spi {buildSPI (advIP . AsSlice () , remoteIP . AsSlice () , k .tag ), buildSPI (remoteIP . AsSlice () , advIP . AsSlice () , k .tag )}
176
176
dir := reverse
177
177
if i == 0 {
178
178
dir = bidir
179
179
}
180
- fSA , rSA , err := programSA (localIP , remoteIP , spis , k , dir , true )
180
+ fSA , rSA , err := programSA (localIP . AsSlice () , remoteIP . AsSlice () , spis , k , dir , true )
181
181
if err != nil {
182
182
log .G (context .TODO ()).Warn (err )
183
183
}
@@ -192,15 +192,15 @@ func setupEncryption(localIP, advIP, remoteIP net.IP, em *encrMap, keys []*key)
192
192
}
193
193
194
194
em .Lock ()
195
- em .nodes [rIPs ] = indices
195
+ em .nodes [remoteIP ] = indices
196
196
em .Unlock ()
197
197
198
198
return nil
199
199
}
200
200
201
- func removeEncryption (localIP , remoteIP net. IP , em * encrMap ) error {
201
+ func removeEncryption (localIP , remoteIP netip. Addr , em * encrMap ) error {
202
202
em .Lock ()
203
- indices , ok := em .nodes [remoteIP . String () ]
203
+ indices , ok := em .nodes [remoteIP ]
204
204
em .Unlock ()
205
205
if ! ok {
206
206
return nil
@@ -210,7 +210,7 @@ func removeEncryption(localIP, remoteIP net.IP, em *encrMap) error {
210
210
if i == 0 {
211
211
dir = bidir
212
212
}
213
- fSA , rSA , err := programSA (localIP , remoteIP , idxs , nil , dir , false )
213
+ fSA , rSA , err := programSA (localIP . AsSlice () , remoteIP . AsSlice () , idxs , nil , dir , false )
214
214
if err != nil {
215
215
log .G (context .TODO ()).Warn (err )
216
216
}
@@ -477,7 +477,7 @@ func buildAeadAlgo(k *key, s int) *netlink.XfrmStateAlgo {
477
477
}
478
478
}
479
479
480
- func (d * driver ) secMapWalk (f func (string , []* spi ) ([]* spi , bool )) error {
480
+ func (d * driver ) secMapWalk (f func (netip. Addr , []* spi ) ([]* spi , bool )) error {
481
481
d .secMap .Lock ()
482
482
for node , indices := range d .secMap .nodes {
483
483
idxs , stop := f (node , indices )
@@ -498,7 +498,7 @@ func (d *driver) setKeys(keys []*key) error {
498
498
// Accept the encryption keys and clear any stale encryption map
499
499
d .Lock ()
500
500
d .keys = keys
501
- d .secMap = & encrMap {nodes : map [string ][]* spi {}}
501
+ d .secMap = & encrMap {nodes : map [netip. Addr ][]* spi {}}
502
502
d .Unlock ()
503
503
log .G (context .TODO ()).Debugf ("Initial encryption keys: %v" , keys )
504
504
return nil
@@ -547,9 +547,8 @@ func (d *driver) updateKeys(newKey, primary, pruneKey *key) error {
547
547
return types .InvalidParameterErrorf ("attempting to both make a key (index %d) primary and delete it" , priIdx )
548
548
}
549
549
550
- d .secMapWalk (func (rIPs string , spis []* spi ) ([]* spi , bool ) {
551
- rIP := net .ParseIP (rIPs )
552
- return updateNodeKey (lIP , aIP , rIP , spis , d .keys , newIdx , priIdx , delIdx ), false
550
+ d .secMapWalk (func (rIP netip.Addr , spis []* spi ) ([]* spi , bool ) {
551
+ return updateNodeKey (lIP .AsSlice (), aIP .AsSlice (), rIP .AsSlice (), spis , d .keys , newIdx , priIdx , delIdx ), false
553
552
})
554
553
555
554
// swap primary
0 commit comments