smengcl commented on code in PR #8812:
URL: https://github.com/apache/hadoop/pull/8812#discussion_r4243611237


##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/MachineList.java:
##########
@@ -60,10 +63,48 @@ public InetAddress getByName (String host) throws 
UnknownHostException {
     }
   }
 
+  /**
+   * An IPv6 address range in CIDR format, which SubnetUtils does not support.
+   */
+  private static final class Inet6Subnet {
+    private static final int MAX_PREFIX_LENGTH = 128;
+
+    private final byte[] network;
+    private final int prefixLength;
+
+    Inet6Subnet(String cidr) {
+      int slash = cidr.indexOf('/');
+      String prefix = cidr.substring(slash + 1);
+      // Any other character is rejected, in particular a scope id because the 
prefix match
+      // would silently ignore it.
+      InetAddress address = cidr.matches("[0-9A-Fa-f:.]+/\\d{1,3}")
+          ? InetAddresses.forString(cidr.substring(0, slash)) : null;
+      // An IPv4-mapped address is parsed as an Inet4Address and belongs in an 
IPv4 CIDR.
+      if (!(address instanceof Inet6Address) || Integer.parseInt(prefix) > 
MAX_PREFIX_LENGTH) {

Review Comment:
   No change needed. `InetAddresses.forString("::ffff:10.222.0.0")` returns an 
`Inet4Address`, because the JDK converts IPv4 mapped addresses when the address 
is built from bytes. The `instanceof Inet6Address` check therefore rejects 
`::ffff:10.222.0.0/112`. `testInvalidIPv6CIDR` covers this value and passes.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to