@@ -1223,21 +1223,17 @@ func (s *Server) handleWireguardEndpointRemove(msg *proto.WireguardEndpointRemov
12231223}
12241224
12251225func  (s  * Server ) onNodeUpdated (old  * common.LocalNodeSpec , node  * common.LocalNodeSpec ) (err  error ) {
1226- 	// This is used by the routing server to process Wireguard key updates 
1227- 	// As a result we only send an event when a node is updated, not when it is added or deleted 
1228- 	common .SendEvent (common.CalicoVppEvent {
1229- 		Type : common .PeerNodeStateChanged ,
1230- 		Old :  old ,
1231- 		New :  node ,
1232- 	})
12331226	change  :=  common .GetIPNetChangeType (old .IPv4Address , node .IPv4Address ) |  common .GetIPNetChangeType (old .IPv6Address , node .IPv6Address )
12341227	if  change & (common .ChangeDeleted | common .ChangeUpdated ) !=  0  &&  node .Name  ==  * config .NodeName  {
12351228		// restart if our BGP config changed 
12361229		return  NodeWatcherRestartError {}
12371230	}
12381231	if  change  !=  common .ChangeSame  {
1239- 		s .configureRemoteNodeSnat (old , false  /* isAdd */ )
1240- 		s .configureRemoteNodeSnat (node , true  /* isAdd */ )
1232+ 		common .SendEvent (common.CalicoVppEvent {
1233+ 			Type : common .PeerNodeStateChanged ,
1234+ 			Old :  old ,
1235+ 			New :  node ,
1236+ 		})
12411237	}
12421238
12431239	return  nil 
@@ -1250,12 +1246,21 @@ func (s *Server) onNodeAdded(node *common.LocalNodeSpec) (err error) {
12501246			/* We found a BGP Spec that seems valid enough */ 
12511247			s .GotOurNodeBGPchan  <-  node 
12521248		}
1249+ 		ip4  :=  net.IP {}
1250+ 		ip6  :=  net.IP {}
12531251		if  node .IPv4Address  !=  nil  {
12541252			s .ip4  =  & node .IPv4Address .IP 
1253+ 			ip4  =  node .IPv4Address .IP 
12551254		}
12561255		if  node .IPv6Address  !=  nil  {
12571256			s .ip6  =  & node .IPv6Address .IP 
1257+ 			ip6  =  node .IPv6Address .IP 
1258+ 		}
1259+ 		err  =  s .vpp .CnatSetSnatAddresses (ip4 , ip6 )
1260+ 		if  err  !=  nil  {
1261+ 			s .log .Errorf ("Failed to configure SNAT addresses %v" , err )
12581262		}
1263+ 
12591264		err  =  s .createAllowFromHostPolicy ()
12601265		if  err  !=  nil  {
12611266			return  errors .Wrap (err , "Error in creating AllowFromHostPolicy" )
@@ -1270,26 +1275,10 @@ func (s *Server) onNodeAdded(node *common.LocalNodeSpec) (err error) {
12701275		Type : common .PeerNodeStateChanged ,
12711276		New :  node ,
12721277	})
1273- 	s .configureRemoteNodeSnat (node , true  /* isAdd */ )
12741278
12751279	return  nil 
12761280}
12771281
1278- func  (s  * Server ) configureRemoteNodeSnat (node  * common.LocalNodeSpec , isAdd  bool ) {
1279- 	if  node .IPv4Address  !=  nil  {
1280- 		err  :=  s .vpp .CnatAddDelSnatPrefix (common .ToMaxLenCIDR (node .IPv4Address .IP ), isAdd )
1281- 		if  err  !=  nil  {
1282- 			s .log .Errorf ("error configuring snat prefix for current node (%v): %v" , node .IPv4Address .IP , err )
1283- 		}
1284- 	}
1285- 	if  node .IPv6Address  !=  nil  {
1286- 		err  :=  s .vpp .CnatAddDelSnatPrefix (common .ToMaxLenCIDR (node .IPv6Address .IP ), isAdd )
1287- 		if  err  !=  nil  {
1288- 			s .log .Errorf ("error configuring snat prefix for current node (%v): %v" , node .IPv6Address .IP , err )
1289- 		}
1290- 	}
1291- }
1292- 
12931282func  (s  * Server ) onNodeDeleted (old  * common.LocalNodeSpec , node  * common.LocalNodeSpec ) error  {
12941283	common .SendEvent (common.CalicoVppEvent {
12951284		Type : common .PeerNodeStateChanged ,
@@ -1300,7 +1289,6 @@ func (s *Server) onNodeDeleted(old *common.LocalNodeSpec, node *common.LocalNode
13001289		return  NodeWatcherRestartError {}
13011290	}
13021291
1303- 	s .configureRemoteNodeSnat (old , false  /* isAdd */ )
13041292	return  nil 
13051293}
13061294
@@ -1323,8 +1311,8 @@ func (s *Server) handleIpamPoolUpdate(msg *proto.IPAMPoolUpdate, pending bool) (
13231311			if  msg .Pool .Cidr  !=  existing .Pool .Cidr  || 
13241312				msg .Pool .Masquerade  !=  existing .Pool .Masquerade  {
13251313				var  err , err2  error 
1326- 				err  =  s .addDelSnatPrefix (& existing , false  /* isAdd */ )
1327- 				err2  =  s .addDelSnatPrefix (msg , true  /* isAdd */ )
1314+ 				err  =  s .addDelSnatPrefixForIPPool (& existing , false  /* isAdd */ )
1315+ 				err2  =  s .addDelSnatPrefixForIPPool (msg , true  /* isAdd */ )
13281316				if  err  !=  nil  ||  err2  !=  nil  {
13291317					return  errors .Errorf ("error updating snat prefix del:%s, add:%s" , err , err2 )
13301318				}
@@ -1338,7 +1326,7 @@ func (s *Server) handleIpamPoolUpdate(msg *proto.IPAMPoolUpdate, pending bool) (
13381326			s .log .Infof ("Adding pool: %s, nat:%t" , key , msg .Pool .Masquerade )
13391327			s .ippoolmap [key ] =  * msg 
13401328			s .log .Debugf ("Pool %v Added, handler called" , msg )
1341- 			err  =  s .addDelSnatPrefix (msg , true  /* isAdd */ )
1329+ 			err  =  s .addDelSnatPrefixForIPPool (msg , true  /* isAdd */ )
13421330			if  err  !=  nil  {
13431331				return  errors .Wrap (err , "error handling ipam add" )
13441332			}
@@ -1366,7 +1354,7 @@ func (s *Server) handleIpamPoolRemove(msg *proto.IPAMPoolRemove, pending bool) (
13661354			delete (s .ippoolmap , key )
13671355			s .log .Infof ("Deleting pool: %s" , key )
13681356			s .log .Debugf ("Pool %s deleted, handler called" , existing .Pool .Cidr )
1369- 			err  =  s .addDelSnatPrefix (& existing , false  /* isAdd */ )
1357+ 			err  =  s .addDelSnatPrefixForIPPool (& existing , false  /* isAdd */ )
13701358			if  err  !=  nil  {
13711359				return  errors .Wrap (err , "error handling ipam deletion" )
13721360			}
@@ -1404,12 +1392,12 @@ func equalPools(a *proto.IPAMPoolUpdate, b *proto.IPAMPoolUpdate) bool {
14041392	return  true 
14051393}
14061394
1407- // addDelSnatPrefix  configures IP Pool prefixes so that we don't source-NAT the packets going 
1395+ // addDelSnatPrefixForIPPool  configures IP Pool prefixes so that we don't source-NAT the packets going 
14081396// to these addresses. All the IP Pools prefixes are configured that way so that pod <-> pod 
14091397// communications are never source-nated in the cluster 
14101398// Note(aloaugus) - I think the iptables dataplane behaves differently and uses the k8s level 
14111399// pod CIDR for this rather than the individual pool prefixes 
1412- func  (s  * Server ) addDelSnatPrefix (pool  * proto.IPAMPoolUpdate , isAdd  bool ) (err  error ) {
1400+ func  (s  * Server ) addDelSnatPrefixForIPPool (pool  * proto.IPAMPoolUpdate , isAdd  bool ) (err  error ) {
14131401	_ , ipNet , err  :=  net .ParseCIDR (pool .Pool .Cidr )
14141402	if  err  !=  nil  {
14151403		return  errors .Wrapf (err , "Couldn't parse pool CIDR %s" , pool .Pool .Cidr )
0 commit comments