124 query_error(
query_type* q, ldns_pkt_rcode rcode)
149 ldns_pkt_opcode opcode = LDNS_PACKET_QUERY;
159 return query_error(q, LDNS_RCODE_FORMERR);
177 return query_error(q, LDNS_RCODE_SERVFAIL);
192 return query_error(q, LDNS_RCODE_NOTIMPL);
207 return query_error(q, LDNS_RCODE_REFUSED);
222 return query_error(q, LDNS_RCODE_NOTAUTH);
232 query_parse_soa(
buffer_type* buffer, uint32_t* serial)
234 ldns_rr_type type = 0;
241 if (type != LDNS_RR_TYPE_SOA) {
274 query_process_notify(
query_type* q, ldns_rr_type qtype,
void* engine)
279 uint16_t rrcount = 0;
283 if (!e || !q || !q->
zone) {
300 qtype != LDNS_RR_TYPE_SOA) {
301 return query_formerr(q);
304 ods_log_error(
"[%s] zone %s is not configured to have input dns "
306 return query_notauth(q);
312 ods_log_info(
"[%s] unauthorized notify for zone %s from client %s: "
315 ods_log_info(
"[%s] unauthorized notify for zone %s from unknown "
318 return query_notauth(q);
324 for (rrcount = 0; rrcount < count; rrcount++) {
326 ods_log_error(
"[%s] dropped packet: zone %s received bad notify "
337 !query_parse_soa(q->
buffer, &serial)) {
338 ods_log_error(
"[%s] dropped packet: zone %s received bad notify "
346 ods_log_debug(
"[%s] ignore notify: already got zone %s serial "
351 ods_log_debug(
"[%s] ignore notify: zone %s transfer in process",
398 ods_log_error(
"[%s] dropped packet: zone %s received bad ixfr "
410 ods_log_error(
"[%s] dropped packet: zone %s received bad ixfr "
431 ldns_pkt_section section)
433 if (!r || !rrset || !section) {
449 response_encode_rr(
query_type* q, ldns_rr* rr, ldns_pkt_section section)
451 uint8_t *data = NULL;
453 ldns_status status = LDNS_STATUS_OK;
457 status = ldns_rr2wire(&data, rr, section, &size);
458 if (status != LDNS_STATUS_OK) {
459 ods_log_error(
"[%s] unable to send good response: ldns_rr2wire() "
460 "failed (%s)",
query_str, ldns_get_errorstr_by_id(status));
482 for (i = 0; i < rrset->
rr_count; i++) {
483 added += response_encode_rr(q, rrset->
rrs[i].
rr, section);
487 added += response_encode_rr(q, rrset->
rrsigs[i].
rr, section);
502 uint16_t counts[LDNS_SECTION_ANY];
503 ldns_pkt_section s = LDNS_SECTION_QUESTION;
507 for (s = LDNS_SECTION_ANSWER; s < LDNS_SECTION_ANY; s++) {
510 for (s = LDNS_SECTION_ANSWER; s < LDNS_SECTION_ANY; s++) {
513 counts[s] += response_encode_rrset(q, r->
rrsets[i], s);
531 query_response(
query_type* q, ldns_rr_type qtype)
535 if (!q || !q->
zone) {
542 if (!response_add_rrset(&r, rrset, LDNS_SECTION_ANSWER)) {
544 return query_servfail(q);
549 if (!response_add_rrset(&r, rrset, LDNS_SECTION_AUTHORITY)) {
551 return query_servfail(q);
554 }
else if (qtype != LDNS_RR_TYPE_SOA) {
557 if (!response_add_rrset(&r, rrset, LDNS_SECTION_AUTHORITY)) {
559 return query_servfail(q);
564 return query_servfail(q);
568 response_encode(q, &r);
607 if (!q || !q->
zone) {
616 return query_formerr(q);
621 return query_formerr(q);
625 ods_log_error(
"[%s] zone %s is not configured to have output dns "
627 return query_refused(q);
635 return query_refused(q);
640 if (qtype == LDNS_RR_TYPE_IXFR) {
642 ods_log_debug(
"[%s] incoming ixfr request serial=%u for zone %s",
644 return ixfr(q, engine);
647 if (qtype == LDNS_RR_TYPE_AXFR) {
651 return axfr(q, engine, 0);
654 if (qtype == LDNS_RR_TYPE_SOA) {
661 return query_response(q, qtype);
672 if (!q || !q->
zone) {
676 return query_notimpl(q);
684 static ldns_pkt_rcode
688 return LDNS_RCODE_SERVFAIL;
691 return LDNS_RCODE_FORMERR;
696 return LDNS_RCODE_REFUSED;
704 return LDNS_RCODE_NOTAUTH;
707 return LDNS_RCODE_NOERROR;
715 static ldns_pkt_rcode
719 return LDNS_RCODE_SERVFAIL;
723 return LDNS_RCODE_FORMERR;
739 return LDNS_RCODE_NOERROR;
750 size_t saved_pos = 0;
765 for (i=0; i < rrcount; i++) {
812 ldns_status status = LDNS_STATUS_OK;
813 ldns_pkt* pkt = NULL;
815 ldns_pkt_rcode rcode = LDNS_RCODE_NOERROR;
816 ldns_pkt_opcode opcode = LDNS_PACKET_QUERY;
817 ldns_rr_type qtype = LDNS_RR_TYPE_SOA;
822 if (!e || !q || !q->
buffer) {
837 if (status != LDNS_STATUS_OK) {
839 ldns_get_errorstr_by_id(status));
840 return query_formerr(q);
842 rr = ldns_rr_list_rr(ldns_pkt_question(pkt), 0);
847 ldns_rr_get_class(rr));
858 return query_servfail(q);
861 if (!query_find_tsig(q)) {
862 return query_formerr(q);
867 opcode = ldns_pkt_get_opcode(pkt);
868 qtype = ldns_rr_get_type(rr);
869 if (qtype == LDNS_RR_TYPE_IXFR) {
874 return query_formerr(q);
878 rcode = query_process_tsig(q);
879 if (rcode != LDNS_RCODE_NOERROR) {
880 return query_error(q, rcode);
883 rcode = query_process_edns(q);
884 if (rcode != LDNS_RCODE_NOERROR) {
889 return query_error(q, LDNS_RCODE_NOERROR);
894 case LDNS_PACKET_NOTIFY:
895 return query_process_notify(q, qtype, engine);
896 case LDNS_PACKET_QUERY:
897 return query_process_query(q, qtype, engine);
898 case LDNS_PACKET_UPDATE:
899 return query_process_update(q);
903 return query_notimpl(q);
1010 size_t rdlength_pos = 0;
1011 uint16_t rdlength = 0;
1021 goto query_add_rr_tc;
1025 sizeof(uint32_t) +
sizeof(rdlength))) {
1026 goto query_add_rr_tc;
1035 for (i=0; i < ldns_rr_rd_count(rr); i++) {
1037 goto query_add_rr_tc;
1042 if (!query_overflow(q)) {