@@ -1215,21 +1215,17 @@ func (s *Server) handleWireguardEndpointRemove(msg *proto.WireguardEndpointRemov
12151215}
12161216
12171217func (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- })
12251218 change := common .GetIPNetChangeType (old .IPv4Address , node .IPv4Address ) | common .GetIPNetChangeType (old .IPv6Address , node .IPv6Address )
12261219 if change & (common .ChangeDeleted | common .ChangeUpdated ) != 0 && node .Name == * config .NodeName {
12271220 // restart if our BGP config changed
12281221 return NodeWatcherRestartError {}
12291222 }
12301223 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+ })
12331229 }
12341230
12351231 return nil
@@ -1242,12 +1238,21 @@ func (s *Server) onNodeAdded(node *common.LocalNodeSpec) (err error) {
12421238 /* We found a BGP Spec that seems valid enough */
12431239 s .GotOurNodeBGPchan <- node
12441240 }
1241+ ip4 := net.IP {}
1242+ ip6 := net.IP {}
12451243 if node .IPv4Address != nil {
12461244 s .ip4 = & node .IPv4Address .IP
1245+ ip4 = node .IPv4Address .IP
12471246 }
12481247 if node .IPv6Address != nil {
12491248 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 )
12501254 }
1255+
12511256 err = s .createAllowFromHostPolicy ()
12521257 if err != nil {
12531258 return errors .Wrap (err , "Error in creating AllowFromHostPolicy" )
@@ -1262,26 +1267,10 @@ func (s *Server) onNodeAdded(node *common.LocalNodeSpec) (err error) {
12621267 Type : common .PeerNodeStateChanged ,
12631268 New : node ,
12641269 })
1265- s .configureRemoteNodeSnat (node , true /* isAdd */ )
12661270
12671271 return nil
12681272}
12691273
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-
12851274func (s * Server ) onNodeDeleted (old * common.LocalNodeSpec , node * common.LocalNodeSpec ) error {
12861275 common .SendEvent (common.CalicoVppEvent {
12871276 Type : common .PeerNodeStateChanged ,
@@ -1292,7 +1281,6 @@ func (s *Server) onNodeDeleted(old *common.LocalNodeSpec, node *common.LocalNode
12921281 return NodeWatcherRestartError {}
12931282 }
12941283
1295- s .configureRemoteNodeSnat (old , false /* isAdd */ )
12961284 return nil
12971285}
12981286
@@ -1315,8 +1303,8 @@ func (s *Server) handleIpamPoolUpdate(msg *proto.IPAMPoolUpdate, pending bool) (
13151303 if newIpamPool .GetCidr () != oldIpamPool .GetCidr () ||
13161304 newIpamPool .GetMasquerade () != oldIpamPool .GetMasquerade () {
13171305 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 */ )
13201308 if err != nil || err2 != nil {
13211309 return errors .Errorf ("error updating snat prefix del:%s, add:%s" , err , err2 )
13221310 }
@@ -1330,7 +1318,7 @@ func (s *Server) handleIpamPoolUpdate(msg *proto.IPAMPoolUpdate, pending bool) (
13301318 s .log .Infof ("Adding pool: %s, nat:%t" , msg .GetId (), newIpamPool .GetMasquerade ())
13311319 s .ippoolmap [msg .GetId ()] = newIpamPool
13321320 s .log .Debugf ("Pool %v Added, handler called" , msg )
1333- err = s .addDelSnatPrefix (newIpamPool , true /* isAdd */ )
1321+ err = s .addDelSnatPrefixForIPPool (newIpamPool , true /* isAdd */ )
13341322 if err != nil {
13351323 return errors .Wrap (err , "error handling ipam add" )
13361324 }
@@ -1356,7 +1344,7 @@ func (s *Server) handleIpamPoolRemove(msg *proto.IPAMPoolRemove, pending bool) (
13561344 delete (s .ippoolmap , msg .GetId ())
13571345 s .log .Infof ("Deleting pool: %s" , msg .GetId ())
13581346 s .log .Debugf ("Pool %s deleted, handler called" , oldIpamPool .Cidr )
1359- err = s .addDelSnatPrefix (oldIpamPool , false /* isAdd */ )
1347+ err = s .addDelSnatPrefixForIPPool (oldIpamPool , false /* isAdd */ )
13601348 if err != nil {
13611349 return errors .Wrap (err , "error handling ipam deletion" )
13621350 }
@@ -1401,12 +1389,12 @@ func ipamPoolEquals(a *proto.IPAMPool, b *proto.IPAMPool) bool {
14011389 return true
14021390}
14031391
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
14051393// to these addresses. All the IP Pools prefixes are configured that way so that pod <-> pod
14061394// communications are never source-nated in the cluster
14071395// Note(aloaugus) - I think the iptables dataplane behaves differently and uses the k8s level
14081396// 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 ) {
14101398 _ , ipNet , err := net .ParseCIDR (pool .GetCidr ())
14111399 if err != nil {
14121400 return errors .Wrapf (err , "Couldn't parse pool CIDR %s" , pool .Cidr )
0 commit comments