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


##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -2522,7 +2531,8 @@ private void loadVmDetailsInMapForExternalDhcpIp() {
                 List<NicVO> nics = _nicDao.listByNetworkId(network.getId());
 
                 for (NicVO nic : nics) {
-                    if (nic.getIPv4Address() == null) {
+                    // also retry NICs holding a link-local (APIPA) address 
recorded before the guest obtained its DHCP lease
+                    if (nic.getIPv4Address() == null || 
NetUtils.isLinkLocalIp4(nic.getIPv4Address())) {

Review Comment:
   An existing APIPA value is only queued here, not cleared. The new KVM 
APIPA-only path returns `Answer(result=false, details=null)`, and 
`VmIpAddrFetchThread` deliberately leaves the NIC unchanged for failed answers, 
so `listVirtualMachines` keeps exposing the stale APIPA value until a DHCP 
lease eventually appears. Clear the known-invalid value when loading it for 
retry (or preserve an APIPA signal from KVM so the server-side clearing branch 
can run).



##########
utils/src/main/java/com/cloud/utils/net/NetUtils.java:
##########
@@ -1039,6 +1039,33 @@ public static String getLinkLocalCIDR() {
         return "169.254.0.0/16";
     }
 
+    /**
+     * Returns true if the given address is a valid IPv4 link-local (APIPA, 
RFC 3927) address, i.e. within 169.254.0.0/16.
+     * Such an address is self-assigned by a guest when no DHCP lease has been 
obtained.
+     */
+    public static boolean isLinkLocalIp4(final String ip) {
+        return isValidIp4(ip) && isIpWithInCidrRange(ip, getLinkLocalCIDR());
+    }
+
+    /**
+     * Returns true if the given address is a valid IPv6 link-local address, 
i.e. within fe80::/10.
+     * A zone index suffix (e.g. "fe80::1%6") is accepted and ignored.
+     */
+    public static boolean isLinkLocalIp6(final String ip) {
+        if (ip == null) {
+            return false;
+        }
+        final String address = ip.split("%")[0];

Review Comment:
   A malformed input consisting only of the zone delimiter (`"%"`) makes 
`String.split` return an empty array, so this boolean validation helper throws 
`ArrayIndexOutOfBoundsException` instead of returning `false`. Extracting the 
prefix with `indexOf`/`substring` keeps malformed input on the existing 
validation path; please also cover this case in the unit test.



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