Damans227 commented on code in PR #14333:
URL: https://github.com/apache/cloudstack/pull/14333#discussion_r4326418985


##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -802,16 +811,38 @@ protected void runInContext() {
                 Answer answer = _agentMgr.send(hostId, cmd);
                 if (answer.getResult()) {
                     String vmIp = answer.getDetails();
+                    String vmIp6 = answer instanceof GetVmIpAddressAnswer ? 
((GetVmIpAddressAnswer) answer).getIp6Address() : null;
                     if (vmIp == null) {
-                        // we got a valid response and the NIC does not have 
an IP assigned, as such we will update the database with null
+                        // we got a valid response and the NIC does not have 
an IPv4 address assigned, as such we will update the database with null
                         if (nic.getIPv4Address() != null) {
                             nic.setIPv4Address(null);
                             _nicDao.update(nicId, nic);
                         }
+                        if (vmIp6 != null && NetUtils.isValidIp6(vmIp6)) {
+                            // IPv6-only guest
+                            updateNicIp6Address(nic, vmIp6);
+                            logger.debug("Instance [ID: {}, UUID: {}, name: 
{}] - IPv6 {} retrieved successfully", vmId, vmUuid, vmName, vmIp6);
+                            vmIdCountMap.remove(nicId);

Review Comment:
   @nvazquez should we keep checking for the ipv4 address here? if the ipv6 
address shows up before the dhcp lease we stop and never pick it up



##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmIpAddressCommandWrapper.java:
##########
@@ -130,12 +139,29 @@ private Pair<String, String> getIpAddresses(String 
output, String macAddress) {
             found = true;
             String ipFamily = parts[parts.length - 2];
             String ipPart = parts[parts.length - 1].split("/")[0];
+            // Skip link-local IPv4 addresses (e.g. Windows APIPA 
169.254.0.0/16 before a DHCP lease is obtained),
+            // they are not routable and must not be reported as the instance 
IP
             if (ipFamily.equals("ipv4")) {
-                ipv4 = ipPart;
+                if (NetUtils.isLinkLocalIp4(ipPart)) {
+                    logger.debug(String.format("Ignoring link-local ipv4 %s 
with mac address %s", ipPart, macAddress));
+                } else {
+                    ipv4 = ipPart;
+                }
             } else if (ipFamily.equals("ipv6")) {
-                ipv6 = ipPart;
+                // keep the first global address, and the first link-local one 
as a fallback
+                if (NetUtils.isLinkLocalIp6(ipPart)) {
+                    if (linkLocalIpv6 == null) {
+                        int zoneIndex = ipPart.indexOf('%');
+                        linkLocalIpv6 = zoneIndex >= 0 ? ipPart.substring(0, 
zoneIndex) : ipPart;
+                    }
+                } else if (ipv6 == null) {
+                    ipv6 = ipPart;
+                }
             }
         }
+        if (ipv6 == null) {
+            ipv6 = linkLocalIpv6;

Review Comment:
   @nvazquez should we save a link-local ipv6 address at all? it cant be 
reached, same reason we now skip the 169.254 one



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to