Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1127,18 +1127,28 @@ private byte remoteLookup(Message response, Name name, int type,

// Always add any CNAMEs to the response first
if (type != Type.CNAME) {
Record[] cnameAnswers = getRecords(name, Type.CNAME);
if (cnameAnswers != null) {
Name targetName = name;
// support for CNAME chaining
for (int i = iterations; i < 6; i++) {
Record[] cnameAnswers = getRecords(targetName, Type.CNAME);
if (cnameAnswers == null) {
break;
}
for (Record cnameR : cnameAnswers) {
if (!response.findRecord(cnameR)) {
response.addRecord(cnameR, Section.ANSWER);
targetName = ((CNAMERecord) cnameR).getTarget();
}
}
}
}

// Forward lookup to primary DNS servers
Record[] answers = getRecords(name, type);
// no answer
if (answers == null) {
return Rcode.NOERROR;
}
try {
for (Record r : answers) {
if (!response.findRecord(r)) {
Expand All @@ -1148,10 +1158,11 @@ private byte remoteLookup(Message response, Name name, int type,
response.addRecord(r, Section.ANSWER);
}
}
if (r.getType() == Type.CNAME) {
Name cname = r.getName();
// when desired type is CNAME, don't follow CNAME chain
if (type != Type.CNAME && r.getType() == Type.CNAME) {
if (iterations < 6) {
remoteLookup(response, cname, type, iterations + 1);
Name cname = ((CNAMERecord) r).getTarget();
return remoteLookup(response, cname, type, iterations + 1);
}
}
}
Expand Down