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


##########
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:
   I recall there was a pull request recently to fetch the IPs even when they 
are fetched, but I could not find it



-- 
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