YARN-8365. Set DNS query type according to client request.

Contributed by Shane Kumpf
This commit is contained in:
Eric Yang 2018-06-04 19:01:17 -04:00
parent 0cd145a443
commit 5cf37418bd
2 changed files with 7 additions and 11 deletions

View File

@ -1106,7 +1106,7 @@ public class RegistryDNS extends AbstractService implements DNSOperations,
LOG.debug("calling addAnswer"); LOG.debug("calling addAnswer");
byte rcode = addAnswer(response, name, type, dclass, 0, flags); byte rcode = addAnswer(response, name, type, dclass, 0, flags);
if (rcode != Rcode.NOERROR) { if (rcode != Rcode.NOERROR) {
rcode = remoteLookup(response, name, 0); rcode = remoteLookup(response, name, type, 0);
response.getHeader().setRcode(rcode); response.getHeader().setRcode(rcode);
} }
addAdditional(response, flags); addAdditional(response, flags);
@ -1124,9 +1124,10 @@ public class RegistryDNS extends AbstractService implements DNSOperations,
/** /**
* Lookup record from upstream DNS servers. * Lookup record from upstream DNS servers.
*/ */
private byte remoteLookup(Message response, Name name, int iterations) { private byte remoteLookup(Message response, Name name, int type,
int iterations) {
// Forward lookup to primary DNS servers // Forward lookup to primary DNS servers
Record[] answers = getRecords(name, Type.ANY); Record[] answers = getRecords(name, type);
try { try {
for (Record r : answers) { for (Record r : answers) {
if (r.getType() == Type.SOA) { if (r.getType() == Type.SOA) {
@ -1137,7 +1138,7 @@ public class RegistryDNS extends AbstractService implements DNSOperations,
if (r.getType() == Type.CNAME) { if (r.getType() == Type.CNAME) {
Name cname = ((CNAMERecord) r).getAlias(); Name cname = ((CNAMERecord) r).getAlias();
if (iterations < 6) { if (iterations < 6) {
remoteLookup(response, cname, iterations + 1); remoteLookup(response, cname, Type.CNAME, iterations + 1);
} }
} }
} }

View File

@ -424,13 +424,8 @@ public class TestRegistryDNS extends Assert {
assertEquals("Questions do not match", query.getQuestion(), assertEquals("Questions do not match", query.getQuestion(),
response.getQuestion()); response.getQuestion());
Record[] recs = response.getSectionArray(Section.ANSWER); Record[] recs = response.getSectionArray(Section.ANSWER);
boolean found = false; assertEquals(1, recs.length);
for (Record r : recs) { assertEquals(recs[0].getType(), type);
if (r.getType()==Type.A) {
found = true;
}
}
assertTrue("No A records in answer", found);
return recs; return recs;
} }