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


##########
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:
   Good catch. Scoped IPv6 literals now skip the reverse lookup and keep the 
literal (d2ec49ab533). testAdvertisedAddress now serializes a scoped address 
through getNNUri, resolves it again with getNNAddress, and checks the scope id. 
I also checked this with a fake PTR record for fe80::1: before the fix it 
advertised hdfs://nn1.example.com and lost the scope, now it advertises 
hdfs://[fe80:0:0:0:0:0:0:1%1].
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



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