@@ -10,6 +10,7 @@ import (
1010 "fmt"
1111 "hash/fnv"
1212 "net"
13+ "net/netip"
1314 "strconv"
1415 "sync"
1516 "syscall"
@@ -90,7 +91,7 @@ func (s *spi) String() string {
9091}
9192
9293type encrMap struct {
93- nodes map [string ][]* spi
94+ nodes map [netip. Addr ][]* spi
9495 sync.Mutex
9596}
9697
@@ -100,7 +101,7 @@ func (e *encrMap) String() string {
100101 b := new (bytes.Buffer )
101102 for k , v := range e .nodes {
102103 b .WriteString ("\n " )
103- b .WriteString (k )
104+ b .WriteString (k . String () )
104105 b .WriteString (":" )
105106 b .WriteString ("[" )
106107 for _ , s := range v {
@@ -112,7 +113,7 @@ func (e *encrMap) String() string {
112113 return b .String ()
113114}
114115
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 {
116117 log .G (context .TODO ()).Debugf ("checkEncryption(%.7s, %v, %t)" , nid , rIP , isLocal )
117118
118119 n := d .network (nid )
@@ -126,28 +127,28 @@ func (d *driver) checkEncryption(nid string, rIP net.IP, isLocal, add bool) erro
126127
127128 lIP := d .bindAddress
128129 aIP := d .advertiseAddress
129- nodes := map [string ]net. IP {}
130+ nodes := map [netip. Addr ] struct {} {}
130131
131132 switch {
132133 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 {}{}
136137 }
137138 return false
138139 }); err != nil {
139140 log .G (context .TODO ()).Warnf ("Failed to retrieve list of participating nodes in overlay network %.5s: %v" , nid , err )
140141 }
141142 default :
142143 if len (d .network (nid ).endpoints ) > 0 {
143- nodes [rIP . String () ] = rIP
144+ nodes [rIP ] = struct {}{}
144145 }
145146 }
146147
147148 log .G (context .TODO ()).Debugf ("List of nodes: %s" , nodes )
148149
149150 if add {
150- for _ , rIP := range nodes {
151+ for rIP := range nodes {
151152 if err := setupEncryption (lIP , aIP , rIP , d .secMap , d .keys ); err != nil {
152153 log .G (context .TODO ()).Warnf ("Failed to program network encryption between %s and %s: %v" , lIP , rIP , err )
153154 }
@@ -165,19 +166,18 @@ func (d *driver) checkEncryption(nid string, rIP net.IP, isLocal, add bool) erro
165166
166167// setupEncryption programs the encryption parameters for secure communication
167168// 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 {
169170 log .G (context .TODO ()).Debugf ("Programming encryption between %s and %s" , localIP , remoteIP )
170- rIPs := remoteIP .String ()
171171
172172 indices := make ([]* spi , 0 , len (keys ))
173173
174174 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 )}
176176 dir := reverse
177177 if i == 0 {
178178 dir = bidir
179179 }
180- fSA , rSA , err := programSA (localIP , remoteIP , spis , k , dir , true )
180+ fSA , rSA , err := programSA (localIP . AsSlice () , remoteIP . AsSlice () , spis , k , dir , true )
181181 if err != nil {
182182 log .G (context .TODO ()).Warn (err )
183183 }
@@ -192,15 +192,15 @@ func setupEncryption(localIP, advIP, remoteIP net.IP, em *encrMap, keys []*key)
192192 }
193193
194194 em .Lock ()
195- em .nodes [rIPs ] = indices
195+ em .nodes [remoteIP ] = indices
196196 em .Unlock ()
197197
198198 return nil
199199}
200200
201- func removeEncryption (localIP , remoteIP net. IP , em * encrMap ) error {
201+ func removeEncryption (localIP , remoteIP netip. Addr , em * encrMap ) error {
202202 em .Lock ()
203- indices , ok := em .nodes [remoteIP . String () ]
203+ indices , ok := em .nodes [remoteIP ]
204204 em .Unlock ()
205205 if ! ok {
206206 return nil
@@ -210,7 +210,7 @@ func removeEncryption(localIP, remoteIP net.IP, em *encrMap) error {
210210 if i == 0 {
211211 dir = bidir
212212 }
213- fSA , rSA , err := programSA (localIP , remoteIP , idxs , nil , dir , false )
213+ fSA , rSA , err := programSA (localIP . AsSlice () , remoteIP . AsSlice () , idxs , nil , dir , false )
214214 if err != nil {
215215 log .G (context .TODO ()).Warn (err )
216216 }
@@ -477,7 +477,7 @@ func buildAeadAlgo(k *key, s int) *netlink.XfrmStateAlgo {
477477 }
478478}
479479
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 {
481481 d .secMap .Lock ()
482482 for node , indices := range d .secMap .nodes {
483483 idxs , stop := f (node , indices )
@@ -498,7 +498,7 @@ func (d *driver) setKeys(keys []*key) error {
498498 // Accept the encryption keys and clear any stale encryption map
499499 d .Lock ()
500500 d .keys = keys
501- d .secMap = & encrMap {nodes : map [string ][]* spi {}}
501+ d .secMap = & encrMap {nodes : map [netip. Addr ][]* spi {}}
502502 d .Unlock ()
503503 log .G (context .TODO ()).Debugf ("Initial encryption keys: %v" , keys )
504504 return nil
@@ -547,9 +547,8 @@ func (d *driver) updateKeys(newKey, primary, pruneKey *key) error {
547547 return types .InvalidParameterErrorf ("attempting to both make a key (index %d) primary and delete it" , priIdx )
548548 }
549549
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
553552 })
554553
555554 // swap primary
0 commit comments