+// The caller already checks that this is a dotlocal question.
+mDNSlocal mDNSBool ShouldDeliverNegativeResponse(mDNS *const m, DNSQuestion *question)
+{
+ mDNSu16 qtype;
+
+ // If the question matches the search domain exactly or the search domain is a
+ // subdomain of the question, it is most likely a valid unicast domain and hence
+ // don't suppress negative responses.
+ //
+ // If the user has configured ".local" as a search domain, we don't want
+ // to deliver a negative response for names ending in ".local" as that would
+ // prevent bonjour discovery. Passing mDNStrue for the last argument excludes
+ // ".local" search domains.
+ if (DomainInSearchList(&question->qname, mDNStrue))
+ {
+ LogOperation("ShouldDeliverNegativeResponse: Question %##s (%s) in SearchList", question->qname.c, DNSTypeName(question->qtype));
+ return mDNStrue;
+ }
+
+ // Deliver negative response for A/AAAA if there was a positive response for AAAA/A respectively.
+ if (question->qtype != kDNSType_A && question->qtype != kDNSType_AAAA)
+ {
+ LogOperation("ShouldDeliverNegativeResponse: Question %##s (%s) not answering local question with negative unicast response",
+ question->qname.c, DNSTypeName(question->qtype));
+ return mDNSfalse;
+ }
+ qtype = (question->qtype == kDNSType_A ? kDNSType_AAAA : kDNSType_A);
+ if (!mDNS_CheckForCacheRecord(m, question, qtype))
+ {
+ LogOperation("ShouldDeliverNegativeResponse:Question %##s (%s) not answering local question with negative unicast response"
+ " (can't find positive record)", question->qname.c, DNSTypeName(question->qtype));
+ return mDNSfalse;
+ }
+ LogOperation("ShouldDeliverNegativeResponse:Question %##s (%s) answering local with negative unicast response (found positive record)",
+ question->qname.c, DNSTypeName(question->qtype));
+ return mDNStrue;
+}
+