121 query_error(
query_type* q, ldns_pkt_rcode rcode)
146 ldns_pkt_opcode opcode = LDNS_PACKET_QUERY;
156 return query_error(q, LDNS_RCODE_FORMERR);
174 return query_error(q, LDNS_RCODE_SERVFAIL);
189 return query_error(q, LDNS_RCODE_NOTIMPL);
204 return query_error(q, LDNS_RCODE_REFUSED);
219 return query_error(q, LDNS_RCODE_NOTAUTH);
229 query_parse_soa(
buffer_type* buffer, uint32_t* serial)
231 ldns_rr_type type = 0;
238 if (type != LDNS_RR_TYPE_SOA) {
271 query_process_notify(
query_type* q, ldns_rr_type qtype,
void* engine)
276 uint16_t rrcount = 0;
280 if (!e || !q || !q->
zone) {
297 qtype != LDNS_RR_TYPE_SOA) {
298 return query_formerr(q);
301 ods_log_error(
"[%s] zone %s is not configured to have input dns "
303 return query_notauth(q);
309 ods_log_info(
"[%s] unauthorized notify for zone %s from client %s: "
312 ods_log_info(
"[%s] unauthorized notify for zone %s from unknown "
315 return query_notauth(q);
321 for (rrcount = 0; rrcount < count; rrcount++) {
323 ods_log_error(
"[%s] dropped packet: zone %s received bad notify "
334 !query_parse_soa(q->
buffer, &serial)) {
335 ods_log_error(
"[%s] dropped packet: zone %s received bad notify "
344 ods_log_debug(
"[%s] ignore notify: already got zone %s serial "
391 ods_log_error(
"[%s] dropped packet: zone %s received bad ixfr "
403 ods_log_error(
"[%s] dropped packet: zone %s received bad ixfr "
424 ldns_pkt_section section)
426 if (!r || !rrset || !section) {
442 response_encode_rr(
query_type* q, ldns_rr* rr, ldns_pkt_section section)
444 uint8_t *data = NULL;
446 ldns_status status = LDNS_STATUS_OK;
450 status = ldns_rr2wire(&data, rr, section, &size);
451 if (status != LDNS_STATUS_OK) {
452 ods_log_error(
"[%s] unable to send good response: ldns_rr2wire() "
453 "failed (%s)",
query_str, ldns_get_errorstr_by_id(status));
475 for (i = 0; i < rrset->
rr_count; i++) {
476 added += response_encode_rr(q, rrset->
rrs[i].
rr, section);
480 added += response_encode_rr(q, rrset->
rrsigs[i].
rr, section);
495 uint16_t counts[LDNS_SECTION_ANY];
496 ldns_pkt_section s = LDNS_SECTION_QUESTION;
500 for (s = LDNS_SECTION_ANSWER; s < LDNS_SECTION_ANY; s++) {
503 for (s = LDNS_SECTION_ANSWER; s < LDNS_SECTION_ANY; s++) {
506 counts[s] += response_encode_rrset(q, r->
rrsets[i], s);
524 query_response(
query_type* q, ldns_rr_type qtype)
528 if (!q || !q->
zone) {
535 if (!response_add_rrset(&r, rrset, LDNS_SECTION_ANSWER)) {
537 return query_servfail(q);
542 if (!response_add_rrset(&r, rrset, LDNS_SECTION_AUTHORITY)) {
544 return query_servfail(q);
547 }
else if (qtype != LDNS_RR_TYPE_SOA) {
550 if (!response_add_rrset(&r, rrset, LDNS_SECTION_AUTHORITY)) {
552 return query_servfail(q);
557 return query_servfail(q);
561 response_encode(q, &r);
600 if (!q || !q->
zone) {
609 return query_formerr(q);
614 return query_formerr(q);
618 ods_log_error(
"[%s] zone %s is not configured to have output dns "
620 return query_refused(q);
626 return query_refused(q);
629 if (qtype == LDNS_RR_TYPE_IXFR) {
632 return query_formerr(q);
636 ods_log_debug(
"[%s] incoming ixfr request serial=%u for zone %s",
638 return ixfr(q, engine);
643 if (qtype == LDNS_RR_TYPE_AXFR) {
647 return axfr(q, engine);
650 return query_response(q, qtype);
661 if (!q || !q->
zone) {
665 return query_notimpl(q);
673 static ldns_pkt_rcode
677 return LDNS_RCODE_SERVFAIL;
680 return LDNS_RCODE_FORMERR;
685 return LDNS_RCODE_REFUSED;
693 return LDNS_RCODE_NOTAUTH;
696 return LDNS_RCODE_NOERROR;
704 static ldns_pkt_rcode
708 return LDNS_RCODE_SERVFAIL;
712 return LDNS_RCODE_FORMERR;
728 return LDNS_RCODE_NOERROR;
739 size_t saved_pos = 0;
754 for (i=0; i < rrcount; i++) {
801 ldns_status status = LDNS_STATUS_OK;
802 ldns_pkt* pkt = NULL;
804 ldns_pkt_rcode rcode = LDNS_RCODE_NOERROR;
805 ldns_pkt_opcode opcode = LDNS_PACKET_QUERY;
806 ldns_rr_type qtype = LDNS_RR_TYPE_SOA;
811 if (!e || !q || !q->
buffer) {
826 if (status != LDNS_STATUS_OK) {
828 ldns_get_errorstr_by_id(status));
829 return query_formerr(q);
831 rr = ldns_rr_list_rr(ldns_pkt_question(pkt), 0);
836 ldns_rr_get_class(rr));
846 return query_servfail(q);
849 if (!query_find_tsig(q)) {
850 return query_formerr(q);
854 rcode = query_process_tsig(q);
855 if (rcode != LDNS_RCODE_NOERROR) {
856 return query_error(q, rcode);
859 rcode = query_process_edns(q);
860 if (rcode != LDNS_RCODE_NOERROR) {
865 return query_error(q, LDNS_RCODE_NOERROR);
869 opcode = ldns_pkt_get_opcode(pkt);
870 qtype = ldns_rr_get_type(rr);
874 case LDNS_PACKET_NOTIFY:
875 return query_process_notify(q, qtype, engine);
876 case LDNS_PACKET_QUERY:
877 return query_process_query(q, qtype, engine);
878 case LDNS_PACKET_UPDATE:
879 return query_process_update(q);
883 return query_notimpl(q);
990 size_t rdlength_pos = 0;
991 uint16_t rdlength = 0;
1001 goto query_add_rr_tc;
1005 sizeof(uint32_t) +
sizeof(rdlength))) {
1006 goto query_add_rr_tc;
1015 for (i=0; i < ldns_rr_rd_count(rr); i++) {
1017 goto query_add_rr_tc;
1022 if (!query_overflow(q)) {