This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.2 by this push:
     new c06c11c754 update IPv6 annotation and filter invalid IPv6 (#11266)
c06c11c754 is described below

commit c06c11c75497d02c95d0d589ced3dc187edbb5db
Author: HHoflittlefish777 <[email protected]>
AuthorDate: Tue Jan 10 14:44:51 2023 +0800

    update IPv6 annotation and filter invalid IPv6 (#11266)
---
 .../java/org/apache/dubbo/common/utils/NetUtils.java  | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java 
b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java
index 43656f05b0..28c4fb9f4e 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java
@@ -412,9 +412,11 @@ public final class NetUtils {
             while (addresses.hasMoreElements()) {
                 InetAddress address = addresses.nextElement();
                 if (address instanceof Inet6Address) {
-                    if (!address.isLoopbackAddress() //filter 127.x.x.x
-                        && !address.isAnyLocalAddress() // filter 0.0.0.0
-                        && !address.isLinkLocalAddress() //filter 
169.254.0.0/16
+                    if (!address.isLoopbackAddress() //filter ::1
+                        && !address.isAnyLocalAddress() // filter ::/128
+                        && !address.isLinkLocalAddress() //filter fe80::/10
+                        && !address.isSiteLocalAddress()// filter fec0::/10
+                        && !isUniqueLocalAddress(address) //filter fd00::/8
                         && address.getHostAddress().contains(":")) {//filter 
IPv6
                         return (Inet6Address) address;
                     }
@@ -427,6 +429,17 @@ public final class NetUtils {
         return null;
     }
 
+    /**
+     * If the address is Unique Local Address.
+     *
+     * @param address {@link InetAddress}
+     * @return {@code true} if the address is Unique Local Address,otherwise 
{@code false}
+     */
+    private static boolean isUniqueLocalAddress(InetAddress address) {
+        byte[] ip = address.getAddress();
+        return (ip[0] & 0xff) == 0xfd;
+    }
+
     /**
      * Returns {@code true} if the specified {@link NetworkInterface} should 
be ignored with the given conditions.
      *

Reply via email to