@@ -446,6 +446,7 @@ public void createApplyStaticNatRulesCommands(final List<? extends StaticNatRule
446446 for (final StaticNatRule rule : rules ) {
447447 final IpAddress sourceIp = _networkModel .getIp (rule .getSourceIpAddressId ());
448448 final StaticNatRuleTO ruleTO = new StaticNatRuleTO (rule , null , sourceIp .getAddress ().addr (), rule .getDestIpAddress ());
449+ ruleTO .setDestinationIpOnDefaultNic (isDestinationIpOnDefaultNic (guestNetworkId , rule .getDestIpAddress ()));
449450 rulesTO .add (ruleTO );
450451 }
451452 }
@@ -459,6 +460,15 @@ public void createApplyStaticNatRulesCommands(final List<? extends StaticNatRule
459460 cmds .addCommand (cmd );
460461 }
461462
463+ private boolean isDestinationIpOnDefaultNic (final long networkId , final String destinationIp ) {
464+ final NicVO destinationNic = _nicDao .findByIp4AddressAndNetworkId (destinationIp , networkId );
465+ if (destinationNic == null ) {
466+ logger .debug ("Unable to find destination NIC for ip [{}] in network [{}], assuming default NIC." , destinationIp , networkId );
467+ return true ;
468+ }
469+ return destinationNic .isDefaultNic ();
470+ }
471+
462472 public void createApplyFirewallRulesCommands (final List <? extends FirewallRule > rules , final VirtualRouter router , final Commands cmds , final long guestNetworkId ) {
463473 final List <FirewallRuleTO > rulesTO = new ArrayList <>();
464474 String systemRule = null ;
@@ -697,6 +707,7 @@ public void createApplyStaticNatCommands(final List<? extends StaticNat> rules,
697707 final IpAddress sourceIp = _networkModel .getIp (rule .getSourceIpAddressId ());
698708 final StaticNatRuleTO ruleTO = new StaticNatRuleTO (0 , sourceIp .getAddress ().addr (), null , null , rule .getDestIpAddress (), null , null , null , rule .isForRevoke (),
699709 false );
710+ ruleTO .setDestinationIpOnDefaultNic (isDestinationIpOnDefaultNic (guestNetworkId , rule .getDestIpAddress ()));
700711 rulesTO .add (ruleTO );
701712 }
702713 }
0 commit comments