126 query_error(
query_type* q, ldns_pkt_rcode rcode)
151 ldns_pkt_opcode opcode = LDNS_PACKET_QUERY;
161 return query_error(q, LDNS_RCODE_FORMERR);
179 return query_error(q, LDNS_RCODE_SERVFAIL);
194 return query_error(q, LDNS_RCODE_NOTIMPL);
209 return query_error(q, LDNS_RCODE_REFUSED);
224 return query_error(q, LDNS_RCODE_NOTAUTH);
234 query_parse_soa(
buffer_type* buffer, uint32_t* serial)
236 ldns_rr_type type = 0;
243 if (type != LDNS_RR_TYPE_SOA) {
276 query_process_notify(
query_type* q, ldns_rr_type qtype,
void* engine)
281 uint16_t rrcount = 0;
285 if (!e || !q || !q->
zone) {
302 qtype != LDNS_RR_TYPE_SOA) {
303 return query_formerr(q);
306 ods_log_error(
"[%s] zone %s is not configured to have input dns "
308 return query_notauth(q);
314 ods_log_info(
"[%s] unauthorized notify for zone %s from client %s: "
317 ods_log_info(
"[%s] unauthorized notify for zone %s from unknown "
320 return query_notauth(q);
326 for (rrcount = 0; rrcount < count; rrcount++) {
328 ods_log_error(
"[%s] dropped packet: zone %s received bad notify "
339 !query_parse_soa(q->
buffer, &serial)) {
340 ods_log_error(
"[%s] dropped packet: zone %s received bad notify "
349 ods_log_debug(
"[%s] ignore notify: already got zone %s serial "
396 ods_log_error(
"[%s] dropped packet: zone %s received bad ixfr "
408 ods_log_error(
"[%s] dropped packet: zone %s received bad ixfr "
429 ldns_pkt_section section)
431 if (!r || !rrset || !section) {
447 response_encode_rr(
query_type* q, ldns_rr* rr, ldns_pkt_section section)
449 uint8_t *data = NULL;
451 ldns_status status = LDNS_STATUS_OK;
455 status = ldns_rr2wire(&data, rr, section, &size);
456 if (status != LDNS_STATUS_OK) {
457 ods_log_error(
"[%s] unable to send good response: ldns_rr2wire() "
458 "failed (%s)",
query_str, ldns_get_errorstr_by_id(status));
480 for (i = 0; i < rrset->
rr_count; i++) {
481 added += response_encode_rr(q, rrset->
rrs[i].
rr, section);
485 added += response_encode_rr(q, rrset->
rrsigs[i].
rr, section);
500 uint16_t counts[LDNS_SECTION_ANY];
501 ldns_pkt_section s = LDNS_SECTION_QUESTION;
505 for (s = LDNS_SECTION_ANSWER; s < LDNS_SECTION_ANY; s++) {
508 for (s = LDNS_SECTION_ANSWER; s < LDNS_SECTION_ANY; s++) {
511 counts[s] += response_encode_rrset(q, r->
rrsets[i], s);
529 query_response(
query_type* q, ldns_rr_type qtype)
533 if (!q || !q->
zone) {
540 if (!response_add_rrset(&r, rrset, LDNS_SECTION_ANSWER)) {
542 return query_servfail(q);
547 if (!response_add_rrset(&r, rrset, LDNS_SECTION_AUTHORITY)) {
549 return query_servfail(q);
552 }
else if (qtype != LDNS_RR_TYPE_SOA) {
555 if (!response_add_rrset(&r, rrset, LDNS_SECTION_AUTHORITY)) {
557 return query_servfail(q);
562 return query_servfail(q);
566 response_encode(q, &r);
605 if (!q || !q->
zone) {
614 return query_formerr(q);
619 return query_formerr(q);
623 ods_log_error(
"[%s] zone %s is not configured to have output dns "
625 return query_refused(q);
633 return query_refused(q);
636 if (qtype == LDNS_RR_TYPE_IXFR) {
639 return query_formerr(q);
643 ods_log_debug(
"[%s] incoming ixfr request serial=%u for zone %s",
645 return ixfr(q, engine);
650 if (qtype == LDNS_RR_TYPE_AXFR) {
654 return axfr(q, engine, 0);
657 if (qtype == LDNS_RR_TYPE_SOA) {
664 return query_response(q, qtype);
675 if (!q || !q->
zone) {
679 return query_notimpl(q);
687 static ldns_pkt_rcode
691 return LDNS_RCODE_SERVFAIL;
694 return LDNS_RCODE_FORMERR;
699 return LDNS_RCODE_REFUSED;
707 return LDNS_RCODE_NOTAUTH;
710 return LDNS_RCODE_NOERROR;
718 static ldns_pkt_rcode
722 return LDNS_RCODE_SERVFAIL;
726 return LDNS_RCODE_FORMERR;
742 return LDNS_RCODE_NOERROR;
753 size_t saved_pos = 0;
768 for (i=0; i < rrcount; i++) {
815 ldns_status status = LDNS_STATUS_OK;
816 ldns_pkt* pkt = NULL;
818 ldns_pkt_rcode rcode = LDNS_RCODE_NOERROR;
819 ldns_pkt_opcode opcode = LDNS_PACKET_QUERY;
820 ldns_rr_type qtype = LDNS_RR_TYPE_SOA;
825 if (!e || !q || !q->
buffer) {
840 if (status != LDNS_STATUS_OK) {
842 ldns_get_errorstr_by_id(status));
843 return query_formerr(q);
845 rr = ldns_rr_list_rr(ldns_pkt_question(pkt), 0);
850 ldns_rr_get_class(rr));
860 return query_servfail(q);
863 if (!query_find_tsig(q)) {
864 return query_formerr(q);
868 rcode = query_process_tsig(q);
869 if (rcode != LDNS_RCODE_NOERROR) {
870 return query_error(q, rcode);
873 rcode = query_process_edns(q);
874 if (rcode != LDNS_RCODE_NOERROR) {
879 return query_error(q, LDNS_RCODE_NOERROR);
883 opcode = ldns_pkt_get_opcode(pkt);
884 qtype = ldns_rr_get_type(rr);
888 case LDNS_PACKET_NOTIFY:
889 return query_process_notify(q, qtype, engine);
890 case LDNS_PACKET_QUERY:
891 return query_process_query(q, qtype, engine);
892 case LDNS_PACKET_UPDATE:
893 return query_process_update(q);
897 return query_notimpl(q);
1004 size_t rdlength_pos = 0;
1005 uint16_t rdlength = 0;
1015 goto query_add_rr_tc;
1019 sizeof(uint32_t) +
sizeof(rdlength))) {
1020 goto query_add_rr_tc;
1029 for (i=0; i < ldns_rr_rd_count(rr); i++) {
1031 goto query_add_rr_tc;
1036 if (!query_overflow(q)) {
ldns_pkt_opcode buffer_pkt_opcode(buffer_type *buffer)
query_type * query_create(void)
void tsig_rr_update(tsig_rr_type *trr, buffer_type *buffer, size_t length)
int edns_rr_parse(edns_rr_type *err, buffer_type *buffer)
int buffer_pkt_rd(buffer_type *buffer)
const char * rrset_type2str(ldns_rr_type type)
void query_cleanup(query_type *q)
void ods_log_debug(const char *format,...)
#define UDP_MAX_MESSAGE_LEN
int tsig_rr_parse(tsig_rr_type *trr, buffer_type *buffer)
uint16_t buffer_pkt_arcount(buffer_type *buffer)
#define BUFFER_PKT_HEADER_SIZE
void * allocator_alloc(allocator_type *allocator, size_t size)
void edns_rr_reset(edns_rr_type *err)
uint16_t buffer_pkt_qdcount(buffer_type *buffer)
void buffer_skip(buffer_type *buffer, ssize_t count)
void buffer_pkt_set_flags(buffer_type *buffer, uint16_t flags)
uint16_t buffer_read_u16(buffer_type *buffer)
int buffer_skip_rr(buffer_type *buffer, unsigned qrr)
void buffer_pkt_set_qdcount(buffer_type *buffer, uint16_t count)
void buffer_clear(buffer_type *buffer)
void ods_log_info(const char *format,...)
time_t serial_notify_acquired
lock_basic_type zone_lock
void ods_log_error(const char *format,...)
void query_reset(query_type *q, size_t maxlen, int is_tcp)
int buffer_pkt_qr(buffer_type *buffer)
void tsig_rr_reset(tsig_rr_type *trr, tsig_algo_type *algo, tsig_key_type *key)
void tsig_rr_append(tsig_rr_type *trr, buffer_type *buffer)
void buffer_write(buffer_type *buffer, const void *data, size_t count)
struct sockaddr_storage addr
rrset_type * rrsets[QUERY_RESPONSE_MAX_RRSET]
lock_basic_type serial_lock
uint8_t * buffer_current(buffer_type *buffer)
adapter_type * adoutbound
int util_serial_gt(uint32_t serial_new, uint32_t serial_old)
buffer_type * buffer_create(allocator_type *allocator, size_t capacity)
uint16_t buffer_pkt_ancount(buffer_type *buffer)
size_t buffer_limit(buffer_type *buffer)
edns_rr_type * edns_rr_create(allocator_type *allocator)
void tsig_rr_prepare(tsig_rr_type *trr)
void buffer_pkt_set_ancount(buffer_type *buffer, uint16_t count)
#define lock_basic_lock(lock)
const char * tsig_status2str(tsig_status status)
void buffer_pkt_set_nscount(buffer_type *buffer, uint16_t count)
allocator_type * allocator
void buffer_set_limit(buffer_type *buffer, size_t limit)
allocator_type * allocator_create(void *(*allocator)(size_t size), void(*deallocator)(void *))
zone_type * zonelist_lookup_zone_by_dname(zonelist_type *zonelist, ldns_rdf *dname, ldns_rr_class klass)
uint16_t buffer_pkt_flags(buffer_type *buffer)
query_state axfr(query_type *q, engine_type *engine, int fallback)
void tsig_rr_cleanup(tsig_rr_type *trr)
query_state query_process(query_type *q, void *engine)
size_t buffer_capacity(buffer_type *buffer)
int buffer_skip_dname(buffer_type *buffer)
uint32_t buffer_read_u32(buffer_type *buffer)
void buffer_pkt_set_opcode(buffer_type *buffer, ldns_pkt_opcode opcode)
enum query_enum query_state
#define PACKET_BUFFER_SIZE
#define EDNS_MAX_MESSAGE_LEN
int tsig_rr_verify(tsig_rr_type *trr)
void buffer_write_u16(buffer_type *buffer, uint16_t data)
void buffer_write_u32(buffer_type *buffer, uint32_t data)
void buffer_pkt_set_aa(buffer_type *buffer)
tsig_rr_type * tsig_rr_create(allocator_type *allocator)
void tsig_rr_error(tsig_rr_type *trr)
int buffer_pkt_aa(buffer_type *buffer)
query_state ixfr(query_type *q, engine_type *engine)
uint16_t buffer_pkt_nscount(buffer_type *buffer)
acl_type * acl_find(acl_type *acl, struct sockaddr_storage *addr, tsig_rr_type *trr)
rrset_type * zone_lookup_rrset(zone_type *zone, ldns_rdf *owner, ldns_rr_type type)
void buffer_write_u16_at(buffer_type *buffer, size_t at, uint16_t data)
void buffer_set_position(buffer_type *buffer, size_t pos)
void ods_fclose(FILE *fd)
void xfrd_set_timer_now(xfrd_type *xfrd)
int buffer_available(buffer_type *buffer, size_t count)
int buffer_pkt_ad(buffer_type *buffer)
void allocator_cleanup(allocator_type *allocator)
int tsig_rr_lookup(tsig_rr_type *trr)
size_t buffer_remaining(buffer_type *buffer)
void buffer_pkt_set_rcode(buffer_type *buffer, ldns_pkt_rcode rcode)
query_state soa_request(query_type *q, engine_type *engine)
void buffer_write_rdf(buffer_type *buffer, ldns_rdf *rdf)
int buffer_pkt_ra(buffer_type *buffer)
void tsig_rr_sign(tsig_rr_type *trr)
void query_prepare(query_type *q)
void allocator_deallocate(allocator_type *allocator, void *data)
int query_add_rr(query_type *q, ldns_rr *rr)
size_t edns_rr_reserved_space(edns_rr_type *err)
size_t buffer_position(buffer_type *buffer)
unsigned char error[OPT_LEN]
void buffer_cleanup(buffer_type *buffer, allocator_type *allocator)
unsigned char ok[OPT_LEN]
void buffer_pkt_set_arcount(buffer_type *buffer, uint16_t count)
#define ods_log_assert(x)
int buffer_pkt_cd(buffer_type *buffer)
ldns_pkt_section sections[QUERY_RESPONSE_MAX_RRSET]
void dnshandler_fwd_notify(dnshandler_type *dnshandler, uint8_t *pkt, size_t len)
int addr2ip(struct sockaddr_storage addr, char *ip, size_t len)
#define lock_basic_unlock(lock)
void ods_log_warning(const char *format,...)
unsigned char rdata_none[OPT_RDATA]
void buffer_pkt_set_qr(buffer_type *buffer)
uint8_t * buffer_begin(buffer_type *buffer)
ldns_pkt_rcode buffer_pkt_rcode(buffer_type *buffer)
dnshandler_type * dnshandler
int buffer_pkt_tc(buffer_type *buffer)
size_t tsig_rr_reserved_space(tsig_rr_type *trr)
void query_add_optional(query_type *q, void *engine)