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 @@ byte[] generateReply(Message query, Socket s)
LOG.debug("calling addAnswer");
byte rcode = addAnswer(response, name, type, dclass, 0, flags);
if (rcode != Rcode.NOERROR) {
rcode = remoteLookup(response, name, 0);
rcode = remoteLookup(response, name, type, 0);
response.getHeader().setRcode(rcode);
}
addAdditional(response, flags);
@ -1124,9 +1124,10 @@ byte[] generateReply(Message query, Socket s)
/**
* 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
Record[] answers = getRecords(name, Type.ANY);
Record[] answers = getRecords(name, type);
try {
for (Record r : answers) {
if (r.getType() == Type.SOA) {
@ -1137,7 +1138,7 @@ private byte remoteLookup(Message response, Name name, int iterations) {
if (r.getType() == Type.CNAME) {
Name cname = ((CNAMERecord) r).getAlias();
if (iterations < 6) {
remoteLookup(response, cname, iterations + 1);
remoteLookup(response, cname, Type.CNAME, iterations + 1);
}
}
}

View File

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