@@ -1218,21 +1218,17 @@ func (s *Server) handleWireguardEndpointRemove(msg *proto.WireguardEndpointRemov
12181218}
12191219
12201220func (s * Server ) onNodeUpdated (old * common.LocalNodeSpec , node * common.LocalNodeSpec ) (err error ) {
1221- // This is used by the routing server to process Wireguard key updates
1222- // As a result we only send an event when a node is updated, not when it is added or deleted
1223- common .SendEvent (common.CalicoVppEvent {
1224- Type : common .PeerNodeStateChanged ,
1225- Old : old ,
1226- New : node ,
1227- })
12281221 change := common .GetIPNetChangeType (old .IPv4Address , node .IPv4Address ) | common .GetIPNetChangeType (old .IPv6Address , node .IPv6Address )
12291222 if change & (common .ChangeDeleted | common .ChangeUpdated ) != 0 && node .Name == * config .NodeName {
12301223 // restart if our BGP config changed
12311224 return NodeWatcherRestartError {}
12321225 }
12331226 if change != common .ChangeSame {
1234- s .configureRemoteNodeSnat (old , false /* isAdd */ )
1235- s .configureRemoteNodeSnat (node , true /* isAdd */ )
1227+ common .SendEvent (common.CalicoVppEvent {
1228+ Type : common .PeerNodeStateChanged ,
1229+ Old : old ,
1230+ New : node ,
1231+ })
12361232 }
12371233
12381234 return nil
@@ -1245,12 +1241,21 @@ func (s *Server) onNodeAdded(node *common.LocalNodeSpec) (err error) {
12451241 /* We found a BGP Spec that seems valid enough */
12461242 s .GotOurNodeBGPchan <- node
12471243 }
1244+ ip4 := net.IP {}
1245+ ip6 := net.IP {}
12481246 if node .IPv4Address != nil {
12491247 s .ip4 = & node .IPv4Address .IP
1248+ ip4 = node .IPv4Address .IP
12501249 }
12511250 if node .IPv6Address != nil {
12521251 s .ip6 = & node .IPv6Address .IP
1252+ ip6 = node .IPv6Address .IP
1253+ }
1254+ err = s .vpp .CnatSetSnatAddresses (ip4 , ip6 )
1255+ if err != nil {
1256+ s .log .Errorf ("Failed to configure SNAT addresses %v" , err )
12531257 }
1258+
12541259 err = s .createAllowFromHostPolicy ()
12551260 if err != nil {
12561261 return errors .Wrap (err , "Error in creating AllowFromHostPolicy" )
@@ -1265,26 +1270,10 @@ func (s *Server) onNodeAdded(node *common.LocalNodeSpec) (err error) {
12651270 Type : common .PeerNodeStateChanged ,
12661271 New : node ,
12671272 })
1268- s .configureRemoteNodeSnat (node , true /* isAdd */ )
12691273
12701274 return nil
12711275}
12721276
1273- func (s * Server ) configureRemoteNodeSnat (node * common.LocalNodeSpec , isAdd bool ) {
1274- if node .IPv4Address != nil {
1275- err := s .vpp .CnatAddDelSnatPrefix (common .ToMaxLenCIDR (node .IPv4Address .IP ), isAdd )
1276- if err != nil {
1277- s .log .Errorf ("error configuring snat prefix for current node (%v): %v" , node .IPv4Address .IP , err )
1278- }
1279- }
1280- if node .IPv6Address != nil {
1281- err := s .vpp .CnatAddDelSnatPrefix (common .ToMaxLenCIDR (node .IPv6Address .IP ), isAdd )
1282- if err != nil {
1283- s .log .Errorf ("error configuring snat prefix for current node (%v): %v" , node .IPv6Address .IP , err )
1284- }
1285- }
1286- }
1287-
12881277func (s * Server ) onNodeDeleted (old * common.LocalNodeSpec , node * common.LocalNodeSpec ) error {
12891278 common .SendEvent (common.CalicoVppEvent {
12901279 Type : common .PeerNodeStateChanged ,
@@ -1295,7 +1284,6 @@ func (s *Server) onNodeDeleted(old *common.LocalNodeSpec, node *common.LocalNode
12951284 return NodeWatcherRestartError {}
12961285 }
12971286
1298- s .configureRemoteNodeSnat (old , false /* isAdd */ )
12991287 return nil
13001288}
13011289
@@ -1318,8 +1306,8 @@ func (s *Server) handleIpamPoolUpdate(msg *proto.IPAMPoolUpdate, pending bool) (
13181306 if newIpamPool .GetCidr () != oldIpamPool .GetCidr () ||
13191307 newIpamPool .GetMasquerade () != oldIpamPool .GetMasquerade () {
13201308 var err , err2 error
1321- err = s .addDelSnatPrefix (oldIpamPool , false /* isAdd */ )
1322- err2 = s .addDelSnatPrefix (newIpamPool , true /* isAdd */ )
1309+ err = s .addDelSnatPrefixForIPPool (oldIpamPool , false /* isAdd */ )
1310+ err2 = s .addDelSnatPrefixForIPPool (newIpamPool , true /* isAdd */ )
13231311 if err != nil || err2 != nil {
13241312 return errors .Errorf ("error updating snat prefix del:%s, add:%s" , err , err2 )
13251313 }
@@ -1333,7 +1321,7 @@ func (s *Server) handleIpamPoolUpdate(msg *proto.IPAMPoolUpdate, pending bool) (
13331321 s .log .Infof ("Adding pool: %s, nat:%t" , msg .GetId (), newIpamPool .GetMasquerade ())
13341322 s .ippoolmap [msg .GetId ()] = newIpamPool
13351323 s .log .Debugf ("Pool %v Added, handler called" , msg )
1336- err = s .addDelSnatPrefix (newIpamPool , true /* isAdd */ )
1324+ err = s .addDelSnatPrefixForIPPool (newIpamPool , true /* isAdd */ )
13371325 if err != nil {
13381326 return errors .Wrap (err , "error handling ipam add" )
13391327 }
@@ -1359,7 +1347,7 @@ func (s *Server) handleIpamPoolRemove(msg *proto.IPAMPoolRemove, pending bool) (
13591347 delete (s .ippoolmap , msg .GetId ())
13601348 s .log .Infof ("Deleting pool: %s" , msg .GetId ())
13611349 s .log .Debugf ("Pool %s deleted, handler called" , oldIpamPool .Cidr )
1362- err = s .addDelSnatPrefix (oldIpamPool , false /* isAdd */ )
1350+ err = s .addDelSnatPrefixForIPPool (oldIpamPool , false /* isAdd */ )
13631351 if err != nil {
13641352 return errors .Wrap (err , "error handling ipam deletion" )
13651353 }
@@ -1404,12 +1392,12 @@ func ipamPoolEquals(a *proto.IPAMPool, b *proto.IPAMPool) 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.IPAMPool , isAdd bool ) (err error ) {
1400+ func (s * Server ) addDelSnatPrefixForIPPool (pool * proto.IPAMPool , isAdd bool ) (err error ) {
14131401 _ , ipNet , err := net .ParseCIDR (pool .GetCidr ())
14141402 if err != nil {
14151403 return errors .Wrapf (err , "Couldn't parse pool CIDR %s" , pool .Cidr )
0 commit comments