anchor.diff:  
   %% There were no exact type matches, but there were other name matches and there are NS records.
   %% Since the Qtype is ANY we indicate we are authoritative and include the NS records.
  -resolve_no_exact_type_match(Message, ?DNS_TYPE_ANY, _ClientIP, _CnameChain, _ExactTypeMatches, _Zone, [], [], AuthorityRecords) ->
  +resolve_no_exact_type_match(Message, ?DNS_TYPE_ANY, {_ClientIP, _ServerIP}, _CnameChain, _ExactTypeMatches, _Zone, [], [], AuthorityRecords) ->
     Message#dns_message{aa = true, authority = AuthorityRecords};
  -resolve_no_exact_type_match(Message, _Qtype, _ClientIP, _CnameChain, [], Zone, _MatchedRecords, [], _AuthorityRecords) ->
  +resolve_no_exact_type_match(Message, _Qtype, {_ClientIP, _ServerIP}, _CnameChain, [], Zone, _MatchedRecords, [], _AuthorityRecords) ->
     Message#dns_message{aa = true, authority = Zone#zone.authority};
  -resolve_no_exact_type_match(Message, _Qtype, _ClientIP, _CnameChain, ExactTypeMatches, _Zone, _MatchedRecords, [], _AuthorityRecords) ->
  +resolve_no_exact_type_match(Message, _Qtype, {_ClientIP, _ServerIP}, _CnameChain, ExactTypeMatches, _Zone, _MatchedRecords, [], _AuthorityRecords) ->
     Message#dns_message{aa = true, answers = Message#dns_message.answers ++ ExactTypeMatches};
  -resolve_no_exact_type_match(Message, Qtype, _ClientIP, _CnameChain, _ExactTypeMatches, _Zone, MatchedRecords, ReferralRecords, AuthorityRecords) ->
  +resolve_no_exact_type_match(Message, Qtype, {_ClientIP, _ServerIP}, _CnameChain, _ExactTypeMatches, _Zone, MatchedRecords, ReferralRecords, AuthorityRecords) ->
     resolve_exact_match_referral(Message, Qtype, MatchedRecords, ReferralRecords, AuthorityRecords).
   
   
  
positive.code:       %erldns_log:debug("No type matches found, using custom handlers"),
        NewRecords = lists:map(erldns_records:replace_name(Qname), lists:flatten(lists:map(custom_lookup(Qname, Qtype, MatchedRecords), erldns_handler:get_handlers()))),
        %erldns_log:debug("Records from custom handlers: ~p", [NewRecords]),
        resolve_best_match_with_wildcard(Message, Qname, Qtype, ClientIP, CnameChain, MatchedRecords, Zone, [], NewRecords);
      _ ->
        resolve_best_match_with_wildcard(Message, Qname, Qtype, ClientIP, CnameChain, MatchedRecords, Zone, [], TypeMatches)
    end;
  
  % It is a wildcard CNAME
  resolve_best_match_with_wildcard(Message, Qname, Qtype, ClientIP, CnameChain, BestMatchRecords, Zone, CnameRecords) ->
    resolve_best_match_with_wildcard_cname(Message, Qname, Qtype, ClientIP, CnameChain, BestMatchRecords, Zone, CnameRecords).
  
  % It is not a CNAME and there were no exact type matches
  resolve_best_match_with_wildcard(Message, _Qname, _Qtype, _ClientIP, _CnameChain, _BestMatchRecords, Zone, [], []) ->
    Message#dns_message{aa = true, authority=Zone#zone.authority};
  
  % It is not a CNAME and there were exact type matches
  resolve_best_match_with_wildcard(Message, _Qname, _Qtype, _ClientIP, _CnameChain, _BestMatchRecords, _Zone, [], TypeMatches) ->
    Message#dns_message{aa = true, answers = Message#dns_message.answers ++ TypeMatches}.
  
  
  
  
  % It is a CNAME and the Qtype was CNAME
  resolve_best_match_with_wildcard_cname(Message, _Qname, ?DNS_TYPE_CNAME, _ClientIP, _CnameChain, _BestMatchRecords, _Zone, CnameRecords) ->
    Message#dns_message{aa = true, answers = Message#dns_message.answers ++ CnameRecords};
  
  % It is a CNAME and the Qtype was not CNAME
  resolve_best_match_with_wildcard_cname(Message, Qname, Qtype, ClientIP, CnameChain, BestMatchRecords, Zone, CnameRecords) ->
    CnameRecord = lists:last(CnameRecords), % There should only be one CNAME. Multiple CNAMEs kill unicorns.
    resolve_best_match_with_wildcard_cname(Message, Qname, Qtype, ClientIP, CnameChain, BestMatchRecords, Zone, CnameRecords, lists:member(CnameRecord, CnameChain)).
  
  % Indicates CNAME loop
  resolve_best_match_with_wildcard_cname(Message, _Qname, _Qtype, _ClientIP, _CnameChain, _BestMatchRecords, _Zone, _CnameRecords, true) ->
    %erldns_log:debug("CNAME loop detected (best match)"),
    Message#dns_message{aa = true, rc = ?DNS_RCODE_SERVFAIL};
  
  % We should follow the CNAME
  resolve_best_match_with_wildcard_cname(Message, _Qname, Qtype, ClientIP, CnameChain, _BestMatchRecords, Zone, CnameRecords, false) ->
    %erldns_log:debug("Follow CNAME (best match)"),
    CnameRecord = lists:last(CnameRecords),
    Name = CnameRecord#dns_rr.data#dns_rrdata_cname.dname,
    restart_query(Message#dns_message{aa = true, answers = Message#dns_message.answers ++ CnameRecords}, Name, Qtype, ClientIP, CnameChain ++ CnameRecords, Zone, erldns_zone_cache:in_zone(Name)).
  
  
  
  
  % There are referral records
  resolve_best_match_referral(Message, Qname, Qtype, ClientIP, CnameChain, BestMatchRecords, Zone, ReferralRecords) ->
    resolve_best_match_referral(Message, Qname, Qtype, ClientIP, CnameChain, BestMatchRecords, Zone, ReferralRecords, lists:filter(erldns_records:match_type(?DNS_TYPE_SOA), BestMatchRecords)). % Lookup SOA in best match records
  
  % Indicate that we are not authoritative for the name as there were no
  % SOA records in the best-match results. The name has thus been delegated
  % to another authority.
  resolve_best_match_referral(Message, _Qname, _Qtype, _ClientIP, _CnameChain, _BestMatchRecords, _Zone, ReferralRecords, []) ->
    Message#dns_message{aa = false, authority = Message#dns_message.authority ++ ReferralRecords};
  
  % We are authoritative for the name since there was an SOA record in
  % the best match results.
  resolve_best_match_referral(Message, _Qname, _Qtype, _ClientIP, [], _BestMatchRecords, _Zone, _ReferralRecords, Authority) ->
    Message#dns_message{aa = true, rc = ?DNS_RCODE_NXDOMAIN, authority = Authority};
  
  % We are authoritative and the Qtype is ANY so we just return the 
  % original message.
  resolve_best_match_referral(Message, _Qname, ?DNS_TYPE_ANY, _ClientIP, _CnameChain, _BestMatchRecords, _Zone, _ReferralRecords, _Authority) ->
    Message;
  resolve_best_match_referral(Message, _Qname, _Qtype, _ClientIP, _CnameChain, _BestMatchRecords, _Zone, _ReferralRecords, Authority) ->
    Message#dns_message{authority = Authority}.
  
  
  
negative.code:       % if it is a sibling then we should not restart
        case check_if_parent(Name, Answer#dns_rr.name) of
          true ->
            restart_delegated_query(Message, Name, Qtype, {ClientIP, _ServerIP}, CnameChain, Zone, erldns_zone_cache:in_zone(Name));
          false ->
            Message#dns_message{aa = true, rc = ?DNS_RCODE_NOERROR, answers = Message#dns_message.answers ++ MatchedRecords}
        end
  