@@ -1215,21 +1215,17 @@ func (s *Server) handleWireguardEndpointRemove(msg *proto.WireguardEndpointRemov
1215
1215
}
1216
1216
1217
1217
func (s * Server ) onNodeUpdated (old * common.LocalNodeSpec , node * common.LocalNodeSpec ) (err error ) {
1218
- // This is used by the routing server to process Wireguard key updates
1219
- // As a result we only send an event when a node is updated, not when it is added or deleted
1220
- common .SendEvent (common.CalicoVppEvent {
1221
- Type : common .PeerNodeStateChanged ,
1222
- Old : old ,
1223
- New : node ,
1224
- })
1225
1218
change := common .GetIPNetChangeType (old .IPv4Address , node .IPv4Address ) | common .GetIPNetChangeType (old .IPv6Address , node .IPv6Address )
1226
1219
if change & (common .ChangeDeleted | common .ChangeUpdated ) != 0 && node .Name == * config .NodeName {
1227
1220
// restart if our BGP config changed
1228
1221
return NodeWatcherRestartError {}
1229
1222
}
1230
1223
if change != common .ChangeSame {
1231
- s .configureRemoteNodeSnat (old , false /* isAdd */ )
1232
- s .configureRemoteNodeSnat (node , true /* isAdd */ )
1224
+ common .SendEvent (common.CalicoVppEvent {
1225
+ Type : common .PeerNodeStateChanged ,
1226
+ Old : old ,
1227
+ New : node ,
1228
+ })
1233
1229
}
1234
1230
1235
1231
return nil
@@ -1242,12 +1238,21 @@ func (s *Server) onNodeAdded(node *common.LocalNodeSpec) (err error) {
1242
1238
/* We found a BGP Spec that seems valid enough */
1243
1239
s .GotOurNodeBGPchan <- node
1244
1240
}
1241
+ ip4 := net.IP {}
1242
+ ip6 := net.IP {}
1245
1243
if node .IPv4Address != nil {
1246
1244
s .ip4 = & node .IPv4Address .IP
1245
+ ip4 = node .IPv4Address .IP
1247
1246
}
1248
1247
if node .IPv6Address != nil {
1249
1248
s .ip6 = & node .IPv6Address .IP
1249
+ ip6 = node .IPv6Address .IP
1250
+ }
1251
+ err = s .vpp .CnatSetSnatAddresses (ip4 , ip6 )
1252
+ if err != nil {
1253
+ s .log .Errorf ("Failed to configure SNAT addresses %v" , err )
1250
1254
}
1255
+
1251
1256
err = s .createAllowFromHostPolicy ()
1252
1257
if err != nil {
1253
1258
return errors .Wrap (err , "Error in creating AllowFromHostPolicy" )
@@ -1262,26 +1267,10 @@ func (s *Server) onNodeAdded(node *common.LocalNodeSpec) (err error) {
1262
1267
Type : common .PeerNodeStateChanged ,
1263
1268
New : node ,
1264
1269
})
1265
- s .configureRemoteNodeSnat (node , true /* isAdd */ )
1266
1270
1267
1271
return nil
1268
1272
}
1269
1273
1270
- func (s * Server ) configureRemoteNodeSnat (node * common.LocalNodeSpec , isAdd bool ) {
1271
- if node .IPv4Address != nil {
1272
- err := s .vpp .CnatAddDelSnatPrefix (common .ToMaxLenCIDR (node .IPv4Address .IP ), isAdd )
1273
- if err != nil {
1274
- s .log .Errorf ("error configuring snat prefix for current node (%v): %v" , node .IPv4Address .IP , err )
1275
- }
1276
- }
1277
- if node .IPv6Address != nil {
1278
- err := s .vpp .CnatAddDelSnatPrefix (common .ToMaxLenCIDR (node .IPv6Address .IP ), isAdd )
1279
- if err != nil {
1280
- s .log .Errorf ("error configuring snat prefix for current node (%v): %v" , node .IPv6Address .IP , err )
1281
- }
1282
- }
1283
- }
1284
-
1285
1274
func (s * Server ) onNodeDeleted (old * common.LocalNodeSpec , node * common.LocalNodeSpec ) error {
1286
1275
common .SendEvent (common.CalicoVppEvent {
1287
1276
Type : common .PeerNodeStateChanged ,
@@ -1292,7 +1281,6 @@ func (s *Server) onNodeDeleted(old *common.LocalNodeSpec, node *common.LocalNode
1292
1281
return NodeWatcherRestartError {}
1293
1282
}
1294
1283
1295
- s .configureRemoteNodeSnat (old , false /* isAdd */ )
1296
1284
return nil
1297
1285
}
1298
1286
@@ -1315,8 +1303,8 @@ func (s *Server) handleIpamPoolUpdate(msg *proto.IPAMPoolUpdate, pending bool) (
1315
1303
if newIpamPool .GetCidr () != oldIpamPool .GetCidr () ||
1316
1304
newIpamPool .GetMasquerade () != oldIpamPool .GetMasquerade () {
1317
1305
var err , err2 error
1318
- err = s .addDelSnatPrefix (oldIpamPool , false /* isAdd */ )
1319
- err2 = s .addDelSnatPrefix (newIpamPool , true /* isAdd */ )
1306
+ err = s .addDelSnatPrefixForIPPool (oldIpamPool , false /* isAdd */ )
1307
+ err2 = s .addDelSnatPrefixForIPPool (newIpamPool , true /* isAdd */ )
1320
1308
if err != nil || err2 != nil {
1321
1309
return errors .Errorf ("error updating snat prefix del:%s, add:%s" , err , err2 )
1322
1310
}
@@ -1330,7 +1318,7 @@ func (s *Server) handleIpamPoolUpdate(msg *proto.IPAMPoolUpdate, pending bool) (
1330
1318
s .log .Infof ("Adding pool: %s, nat:%t" , msg .GetId (), newIpamPool .GetMasquerade ())
1331
1319
s .ippoolmap [msg .GetId ()] = newIpamPool
1332
1320
s .log .Debugf ("Pool %v Added, handler called" , msg )
1333
- err = s .addDelSnatPrefix (newIpamPool , true /* isAdd */ )
1321
+ err = s .addDelSnatPrefixForIPPool (newIpamPool , true /* isAdd */ )
1334
1322
if err != nil {
1335
1323
return errors .Wrap (err , "error handling ipam add" )
1336
1324
}
@@ -1356,7 +1344,7 @@ func (s *Server) handleIpamPoolRemove(msg *proto.IPAMPoolRemove, pending bool) (
1356
1344
delete (s .ippoolmap , msg .GetId ())
1357
1345
s .log .Infof ("Deleting pool: %s" , msg .GetId ())
1358
1346
s .log .Debugf ("Pool %s deleted, handler called" , oldIpamPool .Cidr )
1359
- err = s .addDelSnatPrefix (oldIpamPool , false /* isAdd */ )
1347
+ err = s .addDelSnatPrefixForIPPool (oldIpamPool , false /* isAdd */ )
1360
1348
if err != nil {
1361
1349
return errors .Wrap (err , "error handling ipam deletion" )
1362
1350
}
@@ -1401,12 +1389,12 @@ func ipamPoolEquals(a *proto.IPAMPool, b *proto.IPAMPool) bool {
1401
1389
return true
1402
1390
}
1403
1391
1404
- // addDelSnatPrefix configures IP Pool prefixes so that we don't source-NAT the packets going
1392
+ // addDelSnatPrefixForIPPool configures IP Pool prefixes so that we don't source-NAT the packets going
1405
1393
// to these addresses. All the IP Pools prefixes are configured that way so that pod <-> pod
1406
1394
// communications are never source-nated in the cluster
1407
1395
// Note(aloaugus) - I think the iptables dataplane behaves differently and uses the k8s level
1408
1396
// pod CIDR for this rather than the individual pool prefixes
1409
- func (s * Server ) addDelSnatPrefix (pool * proto.IPAMPool , isAdd bool ) (err error ) {
1397
+ func (s * Server ) addDelSnatPrefixForIPPool (pool * proto.IPAMPool , isAdd bool ) (err error ) {
1410
1398
_ , ipNet , err := net .ParseCIDR (pool .GetCidr ())
1411
1399
if err != nil {
1412
1400
return errors .Wrapf (err , "Couldn't parse pool CIDR %s" , pool .Cidr )
0 commit comments