+ // When processing CNAME responses, if we have wildcard-generated CNAMEs we
+ // have to keep track of several bits of information per-cname. This small
+ // inner class is for that.
+ class CNAMEWildcardEntry {
+ public Name owner;
+ public Name wildcard;
+ public Name signer;
+
+ public CNAMEWildcardEntry(Name owner, Name wildcard, Name signer) {
+ this.owner = owner;
+ this.wildcard = wildcard;
+ this.signer = signer;
+ }
+ }
+
+ // When processing CNAME responses, our final step is check the end of the
+ // chain if we ended up in zone. To that end, we generate a temporary
+ // message that removes the CNAME/DNAME chain.
+ private SMessage messageFromCNAME(SMessage source, Name sname, Name zone) {
+
+ SMessage m = new SMessage();
+ m.setHeader(source.getHeader());
+ Record oldQuestion = source.getQuestion();
+ Record newQuestion = Record.newRecord(sname, oldQuestion.getType(), oldQuestion.getDClass());
+ m.setQuestion(newQuestion);
+ m.setOPT(source.getOPT());
+
+ // Add the rrsets from the source message, stripping answers that don't
+ // belong to the end of the chain
+ RRset[] rrsets = source.getSectionRRsets(Section.ANSWER);
+ for (int i = 0; i < rrsets.length; i++) {
+ Name rname = rrsets[i].getName();
+
+ if (rname.equals(sname)) {
+ m.addRRset(rrsets[i], Section.ANSWER);
+ }
+ }
+
+ // The authority and additional sections should be about the end of the
+ // chain, plus some additional NSEC or NSEC3 records.
+ for (int i = Section.AUTHORITY; i <= Section.ADDITIONAL; i++) {
+ rrsets = source.getSectionRRsets(i);
+
+ for (int j = 0; j < rrsets.length; j++) {
+ m.addRRset(rrsets[j], i);
+ }
+ }
+ return m;
+ }
+