slfan1989 commented on code in PR #8877:
URL: https://github.com/apache/hadoop/pull/8877#discussion_r4395070599


##########
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java:
##########
@@ -564,6 +565,37 @@ public NameNodeRpcServer(Configuration conf, NameNode nn)
     }
   }
 
+  /**
+   * Address to advertise for a configured RPC address. The reverse DNS name of
+   * an IP literal is used only if it resolves back to that address, so that
+   * connections by name reach the address the server listens on. Otherwise the
+   * literal is kept as the host name of the returned address.
+   */
+  @VisibleForTesting
+  static InetSocketAddress getAdvertisedAddress(InetSocketAddress addr, int 
port)
+      throws UnknownHostException {
+    String host = addr.getHostString();
+    InetAddress ip = addr.getAddress();
+    if (ip == null || !InetAddresses.isInetAddress(host)) {
+      return new InetSocketAddress(host, port);
+    }
+    // getCanonicalHostName() does the reverse lookup even if the resolver 
kept the literal
+    // as the host name (hadoop.security.token.service.use_ip=false).
+    String name = ip.getCanonicalHostName();
+    try {
+      if (!SecurityUtil.getByName(name).equals(ip)) {

Review Comment:
   Could we preserve the original literal for scoped IPv6 addresses? 
`InetAddress.equals()` ignores scope, so a PTR name resolving to unscoped 
`fe80::1` passes this check for `fe80::1%2`. 
   
   The returned address retains the scope, but serializing its hostname into 
`fs.defaultFS` loses `%2`. 
   
   A regression test covering serialization and re-resolution would help catch 
this.



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