@@ -113,12 +113,9 @@ func (e *encrMap) String() string {
113113 return b .String ()
114114}
115115
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 )
116+ // initEncryption sets up IPsec encryption parameters for all known peers on a network.
117+ func (d * driver ) initEncryption (nid string ) error {
118+ log .G (context .TODO ()).Debugf ("initEncryption(%.7s)" , nid )
122119
123120 n := d .network (nid )
124121 if n == nil || ! n .secure {
@@ -131,35 +128,20 @@ func (d *driver) checkEncryption(nid string, rIP netip.Addr, add bool) error {
131128
132129 nodes := map [netip.Addr ]struct {}{}
133130
134- switch {
135- case ! rIP .IsValid ():
136- if err := d .peerDbNetworkWalk (nid , func (_ netip.Addr , _ net.HardwareAddr , pEntry * peerEntry ) bool {
137- if ! pEntry .isLocal () {
138- nodes [pEntry .vtep ] = struct {}{}
139- }
140- return false
141- }); err != nil {
142- log .G (context .TODO ()).Warnf ("Failed to retrieve list of participating nodes in overlay network %.5s: %v" , nid , err )
143- }
144- default :
145- if len (d .network (nid ).endpoints ) > 0 {
146- nodes [rIP ] = struct {}{}
131+ if err := d .peerDbNetworkWalk (nid , func (_ netip.Addr , _ net.HardwareAddr , pEntry * peerEntry ) bool {
132+ if ! pEntry .isLocal () {
133+ nodes [pEntry .vtep ] = struct {}{}
147134 }
135+ return false
136+ }); err != nil {
137+ log .G (context .TODO ()).Warnf ("Failed to retrieve list of participating nodes in overlay network %.5s: %v" , nid , err )
148138 }
149139
150140 log .G (context .TODO ()).Debugf ("List of nodes: %s" , nodes )
151141
152- if add {
153- for rIP := range nodes {
154- if err := d .setupEncryption (rIP ); err != nil {
155- log .G (context .TODO ()).Warnf ("Failed to program network encryption to remote peer %s: %v" , rIP , err )
156- }
157- }
158- } else {
159- if rIP .IsValid () && len (nodes ) == 0 {
160- if err := d .removeEncryption (rIP ); err != nil {
161- log .G (context .TODO ()).Warnf ("Failed to remove network encryption to remote peer %s: %v" , rIP , err )
162- }
142+ for rIP := range nodes {
143+ if err := d .setupEncryption (rIP ); err != nil {
144+ log .G (context .TODO ()).Warnf ("Failed to program network encryption to remote peer %s: %v" , rIP , err )
163145 }
164146 }
165147
@@ -169,8 +151,13 @@ func (d *driver) checkEncryption(nid string, rIP netip.Addr, add bool) error {
169151// setupEncryption programs the encryption parameters for secure communication
170152// between the local node and a remote node.
171153func (d * driver ) setupEncryption (remoteIP netip.Addr ) error {
154+ log .G (context .TODO ()).Debugf ("setupEncryption(%s)" , remoteIP )
155+
172156 localIP , advIP := d .bindAddress , d .advertiseAddress
173157 keys := d .keys // FIXME: data race
158+ if len (keys ) == 0 {
159+ return types .ForbiddenErrorf ("encryption key is not present" )
160+ }
174161 log .G (context .TODO ()).Debugf ("Programming encryption between %s and %s" , localIP , remoteIP )
175162
176163 indices := make ([]* spi , 0 , len (keys ))
@@ -203,6 +190,8 @@ func (d *driver) setupEncryption(remoteIP netip.Addr) error {
203190}
204191
205192func (d * driver ) removeEncryption (remoteIP netip.Addr ) error {
193+ log .G (context .TODO ()).Debugf ("removeEncryption(%s)" , remoteIP )
194+
206195 d .secMap .Lock ()
207196 indices , ok := d .secMap .nodes [remoteIP ]
208197 d .secMap .Unlock ()
0 commit comments