From ff7527fc87656f734ddbe804a451c67423fecdea Mon Sep 17 00:00:00 2001 From: Jayapal Date: Tue, 6 Aug 2013 15:59:01 +0530 Subject: [PATCH] CLOUDSTACK-4084 Fixed the static nat vm ip address in public ip address table in external network gc In external network after network GC the network n/w cidr changes. In this case the static nat enable vm ip also chagnes. So updated the new vm ip address in user_ip_address table. --- .../network/guru/ExternalGuestNetworkGuru.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java index 87098f5049b..c799cfe1f25 100644 --- a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java @@ -22,6 +22,8 @@ import javax.ejb.Local; import javax.inject.Inject; import com.cloud.event.ActionEventUtils; +import com.cloud.network.dao.IPAddressDao; +import com.cloud.network.dao.IPAddressVO; import org.apache.log4j.Logger; import com.cloud.configuration.Config; @@ -70,6 +72,9 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { DataCenterDao _zoneDao; @Inject PortForwardingRulesDao _pfRulesDao; + @Inject + IPAddressDao _ipAddressDao; + public ExternalGuestNetworkGuru() { super(); @@ -191,6 +196,17 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { _pfRulesDao.update(pfRule.getId(), pfRule); } } + // Mask the destination address of all static nat rules in this network with the new guest VLAN offset + // Here the private ip of the nic get updated. When secondary ip are present the gc will not triggered + List ipAddrsOfNw = _ipAddressDao.listStaticNatPublicIps(config.getId()); + for (IPAddressVO ip: ipAddrsOfNw) { + if (ip.getVmIp() != null) { + long ipMask = getIpMask(ip.getVmIp(), cidrSize); + String maskedVmIp = NetUtils.long2Ip(newCidrAddress | ipMask); + ip.setVmIp(maskedVmIp); + _ipAddressDao.update(ip.getId(), ip); + } + } return implemented; }