[
https://issues.apache.org/jira/browse/HADOOP-19960?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18125679#comment-18125679
]
ASF GitHub Bot commented on HADOOP-19960:
-----------------------------------------
joseluisll commented on code in PR #8807:
URL: https://github.com/apache/hadoop/pull/8807#discussion_r4234113131
##########
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestDNS.java:
##########
@@ -185,6 +186,29 @@ public void testRDNS() throws Exception {
}
}
+ /**
+ * Test the reverse lookup names built for IPv4 and IPv6 addresses.
+ */
+ @Test
+ public void testReverseDnsName() throws Exception {
+ assertThat(DNS.getReverseDnsName(InetAddress.getByName("192.0.2.129")))
+ .isEqualTo("129.2.0.192.in-addr.arpa");
+ // The example from RFC 3596 section 2.5
+
assertThat(DNS.getReverseDnsName(InetAddress.getByName("4321:0:1:2:3:4:567:89ab")))
+
.isEqualTo("b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.ip6.arpa");
+ assertThat(DNS.getReverseDnsName(InetAddress.getByName("2001:db8::1")))
+
.isEqualTo("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa");
+ assertThat(DNS.getReverseDnsName(InetAddress.getByName("::1")))
+
.isEqualTo("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa");
+ // The JDK resolves an IPv4-mapped address to an Inet4Address
+
assertThat(DNS.getReverseDnsName(InetAddress.getByName("::ffff:192.0.2.129")))
+ .isEqualTo("129.2.0.192.in-addr.arpa");
+ // The scope id is not part of the name
+ byte[] linkLocal = InetAddress.getByName("fe80::1").getAddress();
+ assertThat(DNS.getReverseDnsName(Inet6Address.getByAddress(null,
linkLocal, 5)))
+
.isEqualTo("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa");
+ }
Review Comment:
Optional suggestion: `testReverseDnsName` covers how the name is built, but
nothing tests the bug the PR fixes: `reverseDns` throwing a `RuntimeException`
that `getHosts` doesn't catch (it only catches `NamingException`). A test
through the public method would guard that, and it reuses `INVALID_DNS_SERVER`,
so it doesn't need a real DNS server:
```java
/**
* Test that the reverse lookup of an IPv6 address fails with a
* NamingException, which DNS#getHosts handles, when no DNS server answers.
*/
@Test
public void testReverseDnsIPv6WithInvalidServer() throws Exception {
assertThrows(NamingException.class,
() -> DNS.reverseDns(InetAddress.getByName("2001:db8::1"),
INVALID_DNS_SERVER));
}
```
It needs `import javax.naming.NamingException;` and `import static
org.junit.jupiter.api.Assertions.assertThrows;`.
I ran it locally: it passes on this branch (all 14 `TestDNS` tests green)
and fails on trunk with `expected NamingException but was
ArrayIndexOutOfBoundsException`.
> Support IPv6 reverse DNS names in DNS.reverseDns
> ------------------------------------------------
>
> Key: HADOOP-19960
> URL: https://issues.apache.org/jira/browse/HADOOP-19960
> Project: Hadoop Common
> Issue Type: Sub-task
> Reporter: Siyao Meng
> Assignee: Siyao Meng
> Priority: Major
> Labels: pull-request-available
>
> DNS.reverseDns creates only IPv4 in-addr.arpa names. Create standards-based
> ip6.arpa names for IPv6 addresses. Preserve IPv4 behavior. Test the generated
> names without an external DNS dependency.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]