@@ -1205,21 +1205,17 @@ func (s *Server) handleWireguardEndpointRemove(msg *proto.WireguardEndpointRemov
1205
1205
}
1206
1206
1207
1207
func (s * Server ) onNodeUpdated (old * common.LocalNodeSpec , node * common.LocalNodeSpec ) (err error ) {
1208
- // This is used by the routing server to process Wireguard key updates
1209
- // As a result we only send an event when a node is updated, not when it is added or deleted
1210
- common .SendEvent (common.CalicoVppEvent {
1211
- Type : common .PeerNodeStateChanged ,
1212
- Old : old ,
1213
- New : node ,
1214
- })
1215
1208
change := common .GetIpNetChangeType (old .IPv4Address , node .IPv4Address ) | common .GetIpNetChangeType (old .IPv6Address , node .IPv6Address )
1216
1209
if change & (common .ChangeDeleted | common .ChangeUpdated ) != 0 && node .Name == * config .NodeName {
1217
1210
// restart if our BGP config changed
1218
1211
return NodeWatcherRestartError {}
1219
1212
}
1220
1213
if change != common .ChangeSame {
1221
- s .configureRemoteNodeSnat (old , false /* isAdd */ )
1222
- s .configureRemoteNodeSnat (node , true /* isAdd */ )
1214
+ common .SendEvent (common.CalicoVppEvent {
1215
+ Type : common .PeerNodeStateChanged ,
1216
+ Old : old ,
1217
+ New : node ,
1218
+ })
1223
1219
}
1224
1220
1225
1221
return nil
@@ -1232,12 +1228,21 @@ func (s *Server) onNodeAdded(node *common.LocalNodeSpec) (err error) {
1232
1228
/* We found a BGP Spec that seems valid enough */
1233
1229
s .GotOurNodeBGPchan <- node
1234
1230
}
1231
+ ip4 := net.IP {}
1232
+ ip6 := net.IP {}
1235
1233
if node .IPv4Address != nil {
1236
1234
s .ip4 = & node .IPv4Address .IP
1235
+ ip4 = node .IPv4Address .IP
1237
1236
}
1238
1237
if node .IPv6Address != nil {
1239
1238
s .ip6 = & node .IPv6Address .IP
1239
+ ip6 = node .IPv6Address .IP
1240
+ }
1241
+ err = s .vpp .CnatSetSnatAddresses (ip4 , ip6 )
1242
+ if err != nil {
1243
+ s .log .Errorf ("Failed to configure SNAT addresses %v" , err )
1240
1244
}
1245
+
1241
1246
err = s .createAllowFromHostPolicy ()
1242
1247
if err != nil {
1243
1248
return errors .Wrap (err , "Error in creating AllowFromHostPolicy" )
@@ -1252,26 +1257,10 @@ func (s *Server) onNodeAdded(node *common.LocalNodeSpec) (err error) {
1252
1257
Type : common .PeerNodeStateChanged ,
1253
1258
New : node ,
1254
1259
})
1255
- s .configureRemoteNodeSnat (node , true /* isAdd */ )
1256
1260
1257
1261
return nil
1258
1262
}
1259
1263
1260
- func (s * Server ) configureRemoteNodeSnat (node * common.LocalNodeSpec , isAdd bool ) {
1261
- if node .IPv4Address != nil {
1262
- err := s .vpp .CnatAddDelSnatPrefix (common .ToMaxLenCIDR (node .IPv4Address .IP ), isAdd )
1263
- if err != nil {
1264
- s .log .Errorf ("error configuring snat prefix for current node (%v): %v" , node .IPv4Address .IP , err )
1265
- }
1266
- }
1267
- if node .IPv6Address != nil {
1268
- err := s .vpp .CnatAddDelSnatPrefix (common .ToMaxLenCIDR (node .IPv6Address .IP ), isAdd )
1269
- if err != nil {
1270
- s .log .Errorf ("error configuring snat prefix for current node (%v): %v" , node .IPv6Address .IP , err )
1271
- }
1272
- }
1273
- }
1274
-
1275
1264
func (s * Server ) onNodeDeleted (old * common.LocalNodeSpec , node * common.LocalNodeSpec ) error {
1276
1265
common .SendEvent (common.CalicoVppEvent {
1277
1266
Type : common .PeerNodeStateChanged ,
@@ -1282,7 +1271,6 @@ func (s *Server) onNodeDeleted(old *common.LocalNodeSpec, node *common.LocalNode
1282
1271
return NodeWatcherRestartError {}
1283
1272
}
1284
1273
1285
- s .configureRemoteNodeSnat (old , false /* isAdd */ )
1286
1274
return nil
1287
1275
}
1288
1276
@@ -1305,8 +1293,8 @@ func (s *Server) handleIpamPoolUpdate(msg *proto.IPAMPoolUpdate, pending bool) (
1305
1293
if msg .Pool .Cidr != existing .Pool .Cidr ||
1306
1294
msg .Pool .Masquerade != existing .Pool .Masquerade {
1307
1295
var err , err2 error
1308
- err = s .addDelSnatPrefix (& existing , false /* isAdd */ )
1309
- err2 = s .addDelSnatPrefix (msg , true /* isAdd */ )
1296
+ err = s .addDelSnatPrefixForIPPool (& existing , false /* isAdd */ )
1297
+ err2 = s .addDelSnatPrefixForIPPool (msg , true /* isAdd */ )
1310
1298
if err != nil || err2 != nil {
1311
1299
return errors .Errorf ("error updating snat prefix del:%s, add:%s" , err , err2 )
1312
1300
}
@@ -1320,7 +1308,7 @@ func (s *Server) handleIpamPoolUpdate(msg *proto.IPAMPoolUpdate, pending bool) (
1320
1308
s .log .Infof ("Adding pool: %s, nat:%t" , key , msg .Pool .Masquerade )
1321
1309
s .ippoolmap [key ] = * msg
1322
1310
s .log .Debugf ("Pool %v Added, handler called" , msg )
1323
- err = s .addDelSnatPrefix (msg , true /* isAdd */ )
1311
+ err = s .addDelSnatPrefixForIPPool (msg , true /* isAdd */ )
1324
1312
if err != nil {
1325
1313
return errors .Wrap (err , "error handling ipam add" )
1326
1314
}
@@ -1348,7 +1336,7 @@ func (s *Server) handleIpamPoolRemove(msg *proto.IPAMPoolRemove, pending bool) (
1348
1336
delete (s .ippoolmap , key )
1349
1337
s .log .Infof ("Deleting pool: %s" , key )
1350
1338
s .log .Debugf ("Pool %s deleted, handler called" , existing .Pool .Cidr )
1351
- err = s .addDelSnatPrefix (& existing , false /* isAdd */ )
1339
+ err = s .addDelSnatPrefixForIPPool (& existing , false /* isAdd */ )
1352
1340
if err != nil {
1353
1341
return errors .Wrap (err , "error handling ipam deletion" )
1354
1342
}
@@ -1386,12 +1374,12 @@ func equalPools(a *proto.IPAMPoolUpdate, b *proto.IPAMPoolUpdate) bool {
1386
1374
return true
1387
1375
}
1388
1376
1389
- // addDelSnatPrefix configures IP Pool prefixes so that we don't source-NAT the packets going
1377
+ // addDelSnatPrefixForIPPool configures IP Pool prefixes so that we don't source-NAT the packets going
1390
1378
// to these addresses. All the IP Pools prefixes are configured that way so that pod <-> pod
1391
1379
// communications are never source-nated in the cluster
1392
1380
// Note(aloaugus) - I think the iptables dataplane behaves differently and uses the k8s level
1393
1381
// pod CIDR for this rather than the individual pool prefixes
1394
- func (s * Server ) addDelSnatPrefix (pool * proto.IPAMPoolUpdate , isAdd bool ) (err error ) {
1382
+ func (s * Server ) addDelSnatPrefixForIPPool (pool * proto.IPAMPoolUpdate , isAdd bool ) (err error ) {
1395
1383
_ , ipNet , err := net .ParseCIDR (pool .Pool .Cidr )
1396
1384
if err != nil {
1397
1385
return errors .Wrapf (err , "Couldn't parse pool CIDR %s" , pool .Pool .Cidr )
0 commit comments