qingzhongli commented on issue #17433:
URL: 
https://github.com/apache/dolphinscheduler/issues/17433#issuecomment-3222550339

   > Seems we have incorrect filter logic in `NetUtils`.
   
   Yes. Perhaps there are three points that need adjustment, as follows:
   
   1. The `isValidV6Address` method in the `NetUtils` class should support IPv6 
addresses with scope identifiers (e.g., 
`fd15:4ba5:5a2b:1008:71bc:dd01:e661:e831%ens33`) and exclude link-local 
addresses. Maybe like this:
   ```
       protected static boolean isValidV6Address(InetAddress address) {
           if (!(address instanceof Inet6Address)) {
               return false;
           }
           String name = address.getHostAddress();
           // remove scope
           int i = name.indexOf('%');
           if (i > 0) {
               name = name.substring(0, i);
           }
           return (name != null
                   && InetAddressUtils.isIPv6Address(name)
                   && !address.isAnyLocalAddress()
                   && !address.isLoopbackAddress()
                   && !address.isLinkLocalAddress());
       }
   ```
   2. The `getIpv6Addresses` method in the `NetUtils` class should remove scope 
identifiers from IPv6 addresses when they contain scope identifiers. Maybe like 
this:
   ```
       private static List<InetAddress> getIpv6Addresses(List<InetAddress> 
allInetAddresses) {
           if (CollectionUtils.isEmpty(allInetAddresses)) {
               return Collections.emptyList();
           }
           List<InetAddress> validIpv6Addresses = new ArrayList<>();
           for (InetAddress inetAddress : allInetAddresses) {
               if (!isValidV6Address(inetAddress)) {
                   continue;
               }
               Inet6Address v6Address = (Inet6Address) inetAddress;
               InetAddress removedScopeV6Address = 
removeV6AddressScope(v6Address);
               validIpv6Addresses.add(removedScopeV6Address);
           }
           return validIpv6Addresses;
       }
   
       private static InetAddress removeV6AddressScope(Inet6Address address) {
           String addr = address.getHostAddress();
           int i = addr.lastIndexOf('%');
           if (i > 0) {
               try {
                   return InetAddress.getByName(addr.substring(0, i));
               } catch (UnknownHostException e) {
                   log.debug("Unknown IPV6 address: ", e);
               }
           }
           return address;
       }
   ```
   3. The `getAddr`  method in the `NetUtils` class should add brackets for 
IPv6 address. Maybe like this:
   ```
       public static String getAddr(String host, int port) {
           if(InetAddressUtils.isIPv6Address(host)) {
               return String.format("[%s]:%d", host, port);
           }
           return String.format("%s:%d", host, port);
       }
   ```


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