Lines Matching refs:q

55 				 struct query     *q,
63 static void answer_lookup_zone(struct nsd *nsd, struct query *q,
70 query_put_dname_offset(struct query *q, domain_type *domain, uint16_t offset) in query_put_dname_offset() argument
72 assert(q); in query_put_dname_offset()
78 if (q->compressed_dname_count >= MAX_COMPRESSED_DNAMES) in query_put_dname_offset()
81 q->compressed_dname_offsets[domain->number] = offset; in query_put_dname_offset()
82 q->compressed_dnames[q->compressed_dname_count] = domain; in query_put_dname_offset()
83 ++q->compressed_dname_count; in query_put_dname_offset()
87 query_clear_dname_offsets(struct query *q, size_t max_offset) in query_clear_dname_offsets() argument
89 while (q->compressed_dname_count > 0 in query_clear_dname_offsets()
90 && (q->compressed_dname_offsets[q->compressed_dnames[q->compressed_dname_count - 1]->number] in query_clear_dname_offsets()
93 q->compressed_dname_offsets[q->compressed_dnames[q->compressed_dname_count - 1]->number] = 0; in query_clear_dname_offsets()
94 --q->compressed_dname_count; in query_clear_dname_offsets()
99 query_clear_compression_tables(struct query *q) in query_clear_compression_tables() argument
103 for (i = 0; i < q->compressed_dname_count; ++i) { in query_clear_compression_tables()
104 assert(q->compressed_dnames); in query_clear_compression_tables()
105 q->compressed_dname_offsets[q->compressed_dnames[i]->number] = 0; in query_clear_compression_tables()
107 q->compressed_dname_count = 0; in query_clear_compression_tables()
111 query_add_compression_domain(struct query *q, domain_type *domain, uint16_t offset) in query_add_compression_domain() argument
119 query_put_dname_offset(q, domain, offset); in query_add_compression_domain()
129 query_error (struct query *q, nsd_rc_type rcode) in query_error() argument
135 buffer_clear(q->packet); in query_error()
137 QR_SET(q->packet); /* This is an answer. */ in query_error()
138 AD_CLR(q->packet); in query_error()
139 RCODE_SET(q->packet, (int) rcode); /* Error code. */ in query_error()
142 QDCOUNT_SET(q->packet, 0); in query_error()
143 ANCOUNT_SET(q->packet, 0); in query_error()
144 NSCOUNT_SET(q->packet, 0); in query_error()
145 ARCOUNT_SET(q->packet, 0); in query_error()
146 buffer_set_position(q->packet, QHEADERSZ); in query_error()
207 query_reset(query_type *q, size_t maxlen, int is_tcp) in query_reset() argument
220 region_free_all(q->region); in query_reset()
221 q->remote_addrlen = (socklen_t)sizeof(q->remote_addr); in query_reset()
222 q->client_addrlen = (socklen_t)sizeof(q->client_addr); in query_reset()
223 q->is_proxied = 0; in query_reset()
224 q->maxlen = maxlen; in query_reset()
225 q->reserved_space = 0; in query_reset()
226 buffer_clear(q->packet); in query_reset()
227 edns_init_record(&q->edns); in query_reset()
228 tsig_init_record(&q->tsig, NULL, NULL); in query_reset()
229 q->tsig_prepare_it = 1; in query_reset()
230 q->tsig_update_it = 1; in query_reset()
231 q->tsig_sign_it = 1; in query_reset()
232 q->tcp = is_tcp; in query_reset()
233 q->qname = NULL; in query_reset()
234 q->qtype = 0; in query_reset()
235 q->qclass = 0; in query_reset()
236 q->zone = NULL; in query_reset()
237 q->opcode = 0; in query_reset()
238 q->cname_count = 0; in query_reset()
239 q->delegation_domain = NULL; in query_reset()
240 q->delegation_rrset = NULL; in query_reset()
241 q->compressed_dname_count = 0; in query_reset()
242 q->number_temporary_domains = 0; in query_reset()
244 q->axfr_is_done = 0; in query_reset()
245 q->axfr_zone = NULL; in query_reset()
246 q->axfr_current_domain = NULL; in query_reset()
247 q->axfr_current_rrset = NULL; in query_reset()
248 q->axfr_current_rr = 0; in query_reset()
250 q->ixfr_is_done = 0; in query_reset()
251 q->ixfr_data = NULL; in query_reset()
252 q->ixfr_count_newsoa = 0; in query_reset()
253 q->ixfr_count_oldsoa = 0; in query_reset()
254 q->ixfr_count_del = 0; in query_reset()
255 q->ixfr_count_add = 0; in query_reset()
258 q->wildcard_domain = NULL; in query_reset()
264 query_get_tempdomain(struct query *q) in query_get_tempdomain() argument
267 if(q->number_temporary_domains >= EXTRA_DOMAIN_NUMBERS) in query_get_tempdomain()
269 q->number_temporary_domains ++; in query_get_tempdomain()
270 memset(&d[q->number_temporary_domains-1], 0, sizeof(domain_type)); in query_get_tempdomain()
271 d[q->number_temporary_domains-1].number = q->compressed_dname_offsets_size + in query_get_tempdomain()
272 q->number_temporary_domains - 1; in query_get_tempdomain()
273 return &d[q->number_temporary_domains-1]; in query_get_tempdomain()
277 query_addtxt(struct query *q, in query_addtxt() argument
289 if (dname >= buffer_begin(q->packet) in query_addtxt()
290 && dname <= buffer_current(q->packet)) in query_addtxt()
292 buffer_write_u16(q->packet, in query_addtxt()
293 0xc000 | (dname - buffer_begin(q->packet))); in query_addtxt()
295 buffer_write(q->packet, dname + 1, *dname); in query_addtxt()
298 buffer_write_u16(q->packet, TYPE_TXT); in query_addtxt()
299 buffer_write_u16(q->packet, klass); in query_addtxt()
300 buffer_write_u32(q->packet, ttl); in query_addtxt()
301 buffer_write_u16(q->packet, len + 1); in query_addtxt()
302 buffer_write_u8(q->packet, len); in query_addtxt()
303 buffer_write(q->packet, txt, len); in query_addtxt()
335 process_edns(nsd_type* nsd, struct query *q) in process_edns() argument
337 if (q->edns.status == EDNS_ERROR) { in process_edns()
342 if (q->edns.status == EDNS_OK) { in process_edns()
344 if (!q->tcp && q->edns.maxlen > UDP_MAX_MESSAGE_LEN) { in process_edns()
347 if (q->client_addr.ss_family == AF_INET6) { in process_edns()
353 if (q->edns.maxlen < edns_size) { in process_edns()
354 q->maxlen = q->edns.maxlen; in process_edns()
356 q->maxlen = edns_size; in process_edns()
366 if (q->client_addr.ss_family == AF_INET6 in process_edns()
367 && q->maxlen > IPV6_MIN_MTU) in process_edns()
369 q->maxlen = IPV6_MIN_MTU; in process_edns()
375 buffer_set_position(q->packet, q->edns.position); in process_edns()
376 buffer_set_limit(q->packet, q->edns.position); in process_edns()
377 ARCOUNT_SET(q->packet, ARCOUNT(q->packet) - 1); in process_edns()
387 process_tsig(struct query* q) in process_tsig() argument
389 if(q->tsig.status == TSIG_ERROR) in process_tsig()
391 if(q->tsig.status == TSIG_OK) { in process_tsig()
392 if(!tsig_from_query(&q->tsig)) { in process_tsig()
394 addr2str(&q->client_addr, a, sizeof(a)); in process_tsig()
396 tsig_error(q->tsig.error_code), in process_tsig()
397 dname_to_string(q->tsig.key_name, NULL), a); in process_tsig()
400 buffer_set_limit(q->packet, q->tsig.position); in process_tsig()
401 ARCOUNT_SET(q->packet, ARCOUNT(q->packet) - 1); in process_tsig()
402 tsig_prepare(&q->tsig); in process_tsig()
403 tsig_update(&q->tsig, q->packet, buffer_limit(q->packet)); in process_tsig()
404 if(!tsig_verify(&q->tsig)) { in process_tsig()
406 addr2str(&q->client_addr, a, sizeof(a)); in process_tsig()
408 dname_to_string(q->tsig.key->name, NULL), a); in process_tsig()
412 dname_to_string(q->tsig.key->name, NULL))); in process_tsig()
552 answer_chaos(struct nsd *nsd, query_type *q) in answer_chaos() argument
554 AA_CLR(q->packet); in answer_chaos()
555 switch (q->qtype) { in answer_chaos()
558 if ((q->qname->name_size == 11 in answer_chaos()
559 && memcmp(dname_name(q->qname), "\002id\006server", 11) == 0) || in answer_chaos()
560 (q->qname->name_size == 15 in answer_chaos()
561 && memcmp(dname_name(q->qname), "\010hostname\004bind", 15) == 0)) in answer_chaos()
565 query_addtxt(q, in answer_chaos()
566 buffer_begin(q->packet) + QHEADERSZ, in answer_chaos()
570 ANCOUNT_SET(q->packet, ANCOUNT(q->packet) + 1); in answer_chaos()
572 RCODE_SET(q->packet, RCODE_REFUSE); in answer_chaos()
575 q->edns.ede = EDE_PROHIBITED; in answer_chaos()
577 } else if ((q->qname->name_size == 16 in answer_chaos()
578 && memcmp(dname_name(q->qname), "\007version\006server", 16) == 0) || in answer_chaos()
579 (q->qname->name_size == 14 in answer_chaos()
580 && memcmp(dname_name(q->qname), "\007version\004bind", 14) == 0)) in answer_chaos()
584 query_addtxt(q, in answer_chaos()
585 buffer_begin(q->packet) + QHEADERSZ, in answer_chaos()
589 ANCOUNT_SET(q->packet, ANCOUNT(q->packet) + 1); in answer_chaos()
591 RCODE_SET(q->packet, RCODE_REFUSE); in answer_chaos()
594 q->edns.ede = EDE_PROHIBITED; in answer_chaos()
597 RCODE_SET(q->packet, RCODE_REFUSE); in answer_chaos()
600 q->edns.ede = EDE_NOT_SUPPORTED; in answer_chaos()
605 RCODE_SET(q->packet, RCODE_REFUSE); in answer_chaos()
608 q->edns.ede = EDE_NOT_SUPPORTED; in answer_chaos()
809 query_synthesize_cname(struct query* q, struct answer* answer, const dname_type* from_name, in query_synthesize_cname() argument
823 assert(q && answer && from_name && to_name && src && to_closest_encloser); in query_synthesize_cname()
834 …Y,2, (LOG_INFO, "loop for synthesized CNAME rrset for query %s", dname_to_string(q->qname, NULL))); in query_synthesize_cname()
842 domain_type* newdom = query_get_tempdomain(q); in query_synthesize_cname()
852 = dname_partial_copy(q->region, in query_synthesize_cname()
854 if(dname_compare(domain_dname(newdom), q->qname) == 0) { in query_synthesize_cname()
869 domain_type* newdom = query_get_tempdomain(q); in query_synthesize_cname()
879 = dname_partial_copy(q->region, in query_synthesize_cname()
889 rrset = (rrset_type*) region_alloc(q->region, sizeof(rrset_type)); in query_synthesize_cname()
891 rrset->zone = q->zone; in query_synthesize_cname()
893 rrset->rrs = (rr_type*) region_alloc(q->region, sizeof(rr_type)); in query_synthesize_cname()
900 rrset->rrs->rdatas = (rdata_atom_type*)region_alloc(q->region, in query_synthesize_cname()
904 if(!add_rrset(q, answer, ANSWER_SECTION, cname_domain, rrset)) { in query_synthesize_cname()
905 … "could not add synthesized CNAME rrset to packet for query %s", dname_to_string(q->qname, NULL))); in query_synthesize_cname()
1012 answer_domain(struct nsd* nsd, struct query *q, answer_type *answer, in answer_domain() argument
1017 if (q->qtype == TYPE_ANY) { in answer_domain()
1028 for (rrset = domain_find_any_rrset(domain, q->zone); rrset; rrset = rrset->next) { in answer_domain()
1029 if (rrset->zone == q->zone in answer_domain()
1038 && !(q->edns.dnssec_ok in answer_domain()
1039 && zone_is_secure(q->zone) in answer_domain()
1062 add_rrset(q, answer, ANSWER_SECTION, domain, preferred_rrset); in answer_domain()
1064 add_rrset(q, answer, ANSWER_SECTION, domain, normal_rrset); in answer_domain()
1066 add_rrset(q, answer, ANSWER_SECTION, domain, non_preferred_rrset); in answer_domain()
1068 answer_nodata(q, answer, original); in answer_domain()
1072 } else if (q->qtype == TYPE_NSEC3) { in answer_domain()
1073 answer_nodata(q, answer, original); in answer_domain()
1076 } else if ((rrset = domain_find_rrset(domain, q->zone, q->qtype))) { in answer_domain()
1077 add_rrset(q, answer, ANSWER_SECTION, domain, rrset); in answer_domain()
1078 } else if ((rrset = domain_find_rrset(domain, q->zone, TYPE_CNAME))) { in answer_domain()
1086 added = add_rrset(q, answer, ANSWER_SECTION, domain, rrset); in answer_domain()
1092 zone_type* origzone = q->zone; in answer_domain()
1093 ++q->cname_count; in answer_domain()
1095 answer_lookup_zone(nsd, q, answer, closest_match->number, in answer_domain()
1099 q->zone = origzone; in answer_domain()
1103 answer_nodata(q, answer, original); in answer_domain()
1107 if (q->qclass != CLASS_ANY && q->zone->ns_rrset && answer_needs_ns(q) in answer_domain()
1109 add_rrset(q, answer, OPTIONAL_AUTHORITY_SECTION, q->zone->apex, in answer_domain()
1110 q->zone->ns_rrset); in answer_domain()
1126 struct query *q, in answer_authoritative() argument
1141 if(exact && domain_has_only_NSEC3(closest_match, q->zone)) { in answer_authoritative()
1147 if((dname_ce = find_dname_above(closest_encloser, q->zone)) != NULL) { in answer_authoritative()
1155 } else if ((rrset=domain_find_rrset(closest_encloser, q->zone, TYPE_DNAME))) { in answer_authoritative()
1162 zone_type* origzone = q->zone; in answer_authoritative()
1171 if(!add_rrset(q, answer, ANSWER_SECTION, closest_encloser, rrset)) { in answer_authoritative()
1177 newname = dname_replace(q->region, name, in answer_authoritative()
1179 ++q->cname_count; in answer_authoritative()
1181 RCODE_SET(q->packet, RCODE_YXDOMAIN); in answer_authoritative()
1184 ASSIGN_EDE_CODE_AND_STRING_LITERAL(q->edns.ede, in answer_authoritative()
1192 newnum = query_synthesize_cname(q, answer, name, newname, in answer_authoritative()
1199 if(q->qtype == TYPE_CNAME) { in answer_authoritative()
1206 answer_lookup_zone(nsd, q, answer, newnum, in answer_authoritative()
1209 q->zone = origzone; in answer_authoritative()
1215 q->wildcard_domain = wildcard_child; in answer_authoritative()
1218 match = (domain_type *) region_alloc(q->region, in answer_authoritative()
1242 if (q->edns.dnssec_ok && q->zone->nsec3_param) { in answer_authoritative()
1244 nsec3_answer_wildcard(q, answer, wildcard_child, qname); in answer_authoritative()
1261 if (q->edns.dnssec_ok && q->zone->nsec3_param) { in answer_authoritative()
1262 nsec3_answer_authoritative(&match, q, answer, in answer_authoritative()
1266 if (q->edns.dnssec_ok && zone_is_secure(q->zone)) { in answer_authoritative()
1275 nsec_domain = find_covering_nsec(closest_match, q->zone, &nsec_rrset); in answer_authoritative()
1277 add_rrset(q, answer, AUTHORITY_SECTION, nsec_domain, nsec_rrset); in answer_authoritative()
1290 wildcard_child_closest_match, q->zone, in answer_authoritative()
1292 add_rrset(q, answer, AUTHORITY_SECTION, nsec_domain, nsec_rrset); in answer_authoritative()
1298 if (RCODE(q->packet)!=RCODE_OK) { in answer_authoritative()
1303 answer_domain(nsd, q, answer, match, original); in answer_authoritative()
1305 answer_nxdomain(q, answer); in answer_authoritative()
1313 answer_lookup_zone(struct nsd *nsd, struct query *q, answer_type *answer, in answer_lookup_zone() argument
1317 zone_type* origzone = q->zone; in answer_lookup_zone()
1318 q->zone = domain_find_zone(nsd->db, closest_encloser); in answer_lookup_zone()
1319 if (!q->zone) { in answer_lookup_zone()
1321 if(q->cname_count == 0) { in answer_lookup_zone()
1322 RCODE_SET(q->packet, RCODE_REFUSE); in answer_lookup_zone()
1325 q->edns.ede = EDE_NOT_AUTHORITATIVE; in answer_lookup_zone()
1330 if(q->zone->opts && q->zone->opts->pattern in answer_lookup_zone()
1331 && q->zone->opts->pattern->allow_query) { in answer_lookup_zone()
1335 if(q->is_proxied && acl_check_incoming_block_proxy( in answer_lookup_zone()
1336 q->zone->opts->pattern->allow_query, q, &why) == -1) { in answer_lookup_zone()
1340 addr2str(&q->client_addr, address, sizeof(address)); in answer_lookup_zone()
1341 addr2str(&q->remote_addr, proxy, sizeof(proxy)); in answer_lookup_zone()
1343 dname_to_string(q->qname, NULL), in answer_lookup_zone()
1352 if(q->cname_count == 0) { in answer_lookup_zone()
1353 RCODE_SET(q->packet, RCODE_REFUSE); in answer_lookup_zone()
1356 q->edns.ede = EDE_PROHIBITED; in answer_lookup_zone()
1361 q->zone->opts->pattern->allow_query, q, &why) != -1) { in answer_lookup_zone()
1364 dname_to_string(q->qname, NULL), in answer_lookup_zone()
1368 } else if(q->qtype == TYPE_SOA in answer_lookup_zone()
1369 && 0 == dname_compare(q->qname, in answer_lookup_zone()
1370 (const dname_type*)q->zone->opts->node.key) in answer_lookup_zone()
1372 q->zone->opts->pattern->provide_xfr, q,&why)) { in answer_lookup_zone()
1376 dname_to_string(q->qname, NULL), in answer_lookup_zone()
1383 addr2str(&q->client_addr, address, sizeof(address)); in answer_lookup_zone()
1385 dname_to_string(q->qname, NULL), in answer_lookup_zone()
1394 if(q->cname_count == 0) { in answer_lookup_zone()
1395 RCODE_SET(q->packet, RCODE_REFUSE); in answer_lookup_zone()
1398 q->edns.ede = EDE_PROHIBITED; in answer_lookup_zone()
1403 if(!q->zone->apex || !q->zone->soa_rrset) { in answer_lookup_zone()
1405 if(q->cname_count == 0) { in answer_lookup_zone()
1406 RCODE_SET(q->packet, RCODE_SERVFAIL); in answer_lookup_zone()
1409 q->edns.ede = EDE_NOT_READY; in answer_lookup_zone()
1410 ASSIGN_EDE_CODE_AND_STRING_LITERAL(q->edns.ede, in answer_lookup_zone()
1421 …(origzone != NULL && dname_compare(domain_dname(origzone->apex), domain_dname(q->zone->apex)) != 0… in answer_lookup_zone()
1438 if (exact && q->qtype == TYPE_DS && closest_encloser == q->zone->apex) { in answer_lookup_zone()
1444 zone_type *zone = domain_find_parent_zone(nsd->db, q->zone); in answer_lookup_zone()
1446 q->zone = zone; in answer_lookup_zone()
1447 if(!q->zone->apex || !q->zone->soa_rrset) { in answer_lookup_zone()
1449 if(q->cname_count == 0) { in answer_lookup_zone()
1450 RCODE_SET(q->packet, RCODE_SERVFAIL); in answer_lookup_zone()
1454 q->edns.ede, EDE_NOT_READY, in answer_lookup_zone()
1463 if(q->zone && q->zone->opts && q->zone->opts->pattern && in answer_lookup_zone()
1464 q->zone->opts->pattern->request_xfr != 0 && !q->zone->is_ok) { in answer_lookup_zone()
1465 if(q->cname_count == 0) { in answer_lookup_zone()
1466 RCODE_SET(q->packet, RCODE_SERVFAIL); in answer_lookup_zone()
1469 ASSIGN_EDE_CODE_AND_STRING_LITERAL(q->edns.ede, in answer_lookup_zone()
1475 if (exact && q->qtype == TYPE_DS && closest_encloser == q->zone->apex) { in answer_lookup_zone()
1480 if (q->qclass == CLASS_ANY) { in answer_lookup_zone()
1481 AA_CLR(q->packet); in answer_lookup_zone()
1483 AA_SET(q->packet); in answer_lookup_zone()
1485 answer_nodata(q, answer, closest_encloser); in answer_lookup_zone()
1487 q->delegation_domain = domain_find_ns_rrsets( in answer_lookup_zone()
1488 closest_encloser, q->zone, &q->delegation_rrset); in answer_lookup_zone()
1489 if(q->delegation_domain && find_dname_above(q->delegation_domain, q->zone)) { in answer_lookup_zone()
1490 q->delegation_domain = NULL; /* use higher DNAME */ in answer_lookup_zone()
1493 if (!q->delegation_domain in answer_lookup_zone()
1494 || !q->delegation_rrset in answer_lookup_zone()
1495 || (exact && q->qtype == TYPE_DS && closest_encloser == q->delegation_domain)) in answer_lookup_zone()
1497 if (q->qclass == CLASS_ANY) { in answer_lookup_zone()
1498 AA_CLR(q->packet); in answer_lookup_zone()
1500 AA_SET(q->packet); in answer_lookup_zone()
1502 answer_authoritative(nsd, q, answer, domain_number, exact, in answer_lookup_zone()
1506 answer_delegation(q, answer); in answer_lookup_zone()
1512 answer_query(struct nsd *nsd, struct query *q) in answer_query() argument
1522 exact = namedb_lookup(nsd->db, q->qname, &closest_match, &closest_encloser); in answer_query()
1524 answer_lookup_zone(nsd, q, &answer, 0, exact, closest_match, in answer_query()
1525 closest_encloser, q->qname); in answer_query()
1526 ZTATUP2(nsd, q->zone, opcode, q->opcode); in answer_query()
1527 ZTATUP2(nsd, q->zone, qtype, q->qtype); in answer_query()
1528 ZTATUP2(nsd, q->zone, qclass, q->qclass); in answer_query()
1530 …offset = dname_label_offsets(q->qname)[domain_dname(closest_encloser)->label_count - 1] + QHEADERS… in answer_query()
1531 query_add_compression_domain(q, closest_encloser, offset); in answer_query()
1532 encode_answer(q, &answer); in answer_query()
1533 query_clear_compression_tables(q); in answer_query()
1537 query_prepare_response(query_type *q) in query_prepare_response() argument
1544 buffer_set_position(q->packet, buffer_limit(q->packet)); in query_prepare_response()
1545 buffer_set_limit(q->packet, buffer_capacity(q->packet)); in query_prepare_response()
1550 q->reserved_space = edns_reserved_space(&q->edns); in query_prepare_response()
1551 q->reserved_space += tsig_reserved_space(&q->tsig); in query_prepare_response()
1554 flags = FLAGS(q->packet); in query_prepare_response()
1558 FLAGS_SET(q->packet, flags); in query_prepare_response()
1566 query_process(query_type *q, nsd_type *nsd, uint32_t *now_p) in query_process() argument
1574 if (buffer_limit(q->packet) < QHEADERSZ) { in query_process()
1579 if (QR(q->packet)) { in query_process()
1586 q->opcode = OPCODE(q->packet); in query_process()
1587 if(q->opcode != OPCODE_QUERY && q->opcode != OPCODE_NOTIFY) { in query_process()
1590 if(nsd->options->drop_updates && q->opcode == OPCODE_UPDATE) in query_process()
1592 return query_error(q, NSD_RC_IMPL); in query_process()
1595 if (RCODE(q->packet) != RCODE_OK || !process_query_section(q)) { in query_process()
1596 return query_formerr(q, nsd); in query_process()
1600 STATUP2(nsd, opcode, q->opcode); in query_process()
1601 STATUP2(nsd, qtype, q->qtype); in query_process()
1602 STATUP2(nsd, qclass, q->qclass); in query_process()
1604 if (q->opcode != OPCODE_QUERY) { in query_process()
1605 if (q->opcode == OPCODE_NOTIFY) { in query_process()
1606 return answer_notify(nsd, q); in query_process()
1610 return query_error(q, NSD_RC_IMPL); in query_process()
1615 if (QDCOUNT(q->packet) != 1) { in query_process()
1616 if(QDCOUNT(q->packet) == 0 && ANCOUNT(q->packet) == 0 && in query_process()
1617 NSCOUNT(q->packet) == 0 && ARCOUNT(q->packet) == 1 && in query_process()
1618 buffer_limit(q->packet) >= QHEADERSZ+OPT_LEN+ in query_process()
1621 buffer_set_position(q->packet, QHEADERSZ); in query_process()
1622 if (edns_parse_record(&q->edns, q->packet, q, nsd)) { in query_process()
1623 if(process_edns(nsd, q) == NSD_RC_OK) { in query_process()
1624 int opcode = OPCODE(q->packet); in query_process()
1625 (void)query_error(q, NSD_RC_FORMAT); in query_process()
1626 query_add_optional(q, nsd, now_p); in query_process()
1627 FLAGS_SET(q->packet, FLAGS(q->packet) & 0x0100U); in query_process()
1629 OPCODE_SET(q->packet, opcode); in query_process()
1630 QR_SET(q->packet); in query_process()
1635 FLAGS_SET(q->packet, 0); in query_process()
1636 return query_formerr(q, nsd); in query_process()
1642 if (ANCOUNT(q->packet) != 0 || in query_process()
1643 (q->qtype!=TYPE_IXFR && NSCOUNT(q->packet) != 0)) { in query_process()
1644 return query_formerr(q, nsd); in query_process()
1646 if(q->qtype==TYPE_IXFR && NSCOUNT(q->packet) > 0) { in query_process()
1648 unsigned int nscount = (unsigned)NSCOUNT(q->packet); in query_process()
1654 if(nscount > 64) return query_formerr(q, nsd); in query_process()
1656 if(!packet_skip_rr(q->packet, 0)) in query_process()
1657 return query_formerr(q, nsd); in query_process()
1660 arcount = ARCOUNT(q->packet); in query_process()
1674 if (edns_parse_record(&q->edns, q->packet, q, nsd)) in query_process()
1678 if (arcount > 0 && q->tsig.status == TSIG_NOT_PRESENT) { in query_process()
1680 if (!tsig_parse_rr(&q->tsig, q->packet)) in query_process()
1681 return query_formerr(q, nsd); in query_process()
1682 if(q->tsig.status != TSIG_NOT_PRESENT) in query_process()
1687 return query_formerr(q, nsd); in query_process()
1692 if (buffer_remaining(q->packet) > 0) { in query_process()
1694 return query_formerr(q, nsd); in query_process()
1698 buffer_set_limit(q->packet, buffer_position(q->packet)); in query_process()
1700 rc = process_tsig(q); in query_process()
1702 return query_error(q, rc); in query_process()
1704 rc = process_edns(nsd, q); in query_process()
1710 RCODE_SET(q->packet, NSD_RC_OK); in query_process()
1711 buffer_clear(q->packet); in query_process()
1712 buffer_set_position(q->packet, in query_process()
1713 QHEADERSZ + 4 + q->qname->name_size); in query_process()
1714 QR_SET(q->packet); in query_process()
1715 AD_CLR(q->packet); in query_process()
1716 QDCOUNT_SET(q->packet, 1); in query_process()
1717 ANCOUNT_SET(q->packet, 0); in query_process()
1718 NSCOUNT_SET(q->packet, 0); in query_process()
1719 ARCOUNT_SET(q->packet, 0); in query_process()
1723 if (q->edns.cookie_status == COOKIE_UNVERIFIED) in query_process()
1724 cookie_verify(q, nsd, now_p); in query_process()
1726 query_prepare_response(q); in query_process()
1728 if (q->qclass != CLASS_IN && q->qclass != CLASS_ANY) { in query_process()
1729 if (q->qclass == CLASS_CH) { in query_process()
1730 return answer_chaos(nsd, q); in query_process()
1734 q->edns.ede = EDE_NOT_SUPPORTED; in query_process()
1735 return query_error(q, RCODE_REFUSE); in query_process()
1738 query_state = answer_axfr_ixfr(nsd, q); in query_process()
1743 if(q->qtype == TYPE_ANY && nsd->options->refuse_any && !q->tcp) { in query_process()
1744 TC_SET(q->packet); in query_process()
1745 return query_error(q, NSD_RC_OK); in query_process()
1748 answer_query(nsd, q); in query_process()
1754 query_add_optional(query_type *q, nsd_type *nsd, uint32_t *now_p) in query_add_optional() argument
1758 if (q->client_addr.ss_family == AF_INET6) { in query_add_optional()
1762 if (RCODE(q->packet) == RCODE_FORMAT) { in query_add_optional()
1765 switch (q->edns.status) { in query_add_optional()
1769 if (q->edns.dnssec_ok) edns->ok[7] = 0x80; in query_add_optional()
1771 buffer_write(q->packet, edns->ok, OPT_LEN); in query_add_optional()
1775 if (q->edns.ede >= 0) in query_add_optional()
1776 q->edns.opt_reserved_space += in query_add_optional()
1777 6 + ( q->edns.ede_text_len in query_add_optional()
1778 ? q->edns.ede_text_len : 0); in query_add_optional()
1780 if(q->edns.opt_reserved_space == 0 || !buffer_available( in query_add_optional()
1781 q->packet, 2+q->edns.opt_reserved_space)) { in query_add_optional()
1783 buffer_write(q->packet, edns->rdata_none, OPT_RDATA); in query_add_optional()
1786 buffer_write_u16(q->packet, q->edns.opt_reserved_space); in query_add_optional()
1788 if(q->edns.nsid) { in query_add_optional()
1790 buffer_write(q->packet, edns->nsid, OPT_HDR); in query_add_optional()
1792 buffer_write(q->packet, nsd->nsid, nsd->nsid_len); in query_add_optional()
1794 if(q->edns.cookie_status != COOKIE_NOT_PRESENT) { in query_add_optional()
1796 buffer_write(q->packet, edns->cookie, OPT_HDR); in query_add_optional()
1798 cookie_create(q, nsd, now_p); in query_add_optional()
1799 buffer_write(q->packet, q->edns.cookie, 24); in query_add_optional()
1802 if (q->edns.ede >= 0) { /* < 0 means no EDE */ in query_add_optional()
1804 buffer_write_u16(q->packet, EDE_CODE); in query_add_optional()
1806 buffer_write_u16(q->packet, in query_add_optional()
1807 2 + ( q->edns.ede_text_len in query_add_optional()
1808 ? q->edns.ede_text_len : 0)); in query_add_optional()
1810 buffer_write_u16(q->packet, q->edns.ede); in query_add_optional()
1812 if (q->edns.ede_text_len) in query_add_optional()
1813 buffer_write(q->packet, in query_add_optional()
1814 q->edns.ede_text, in query_add_optional()
1815 q->edns.ede_text_len); in query_add_optional()
1818 ARCOUNT_SET(q->packet, ARCOUNT(q->packet) + 1); in query_add_optional()
1820 ZTATUP(nsd, q->zone, edns); in query_add_optional()
1823 if (q->edns.dnssec_ok) edns->error[7] = 0x80; in query_add_optional()
1825 buffer_write(q->packet, edns->error, OPT_LEN); in query_add_optional()
1826 buffer_write(q->packet, edns->rdata_none, OPT_RDATA); in query_add_optional()
1827 ARCOUNT_SET(q->packet, ARCOUNT(q->packet) + 1); in query_add_optional()
1829 ZTATUP(nsd, q->zone, ednserr); in query_add_optional()
1833 if (q->tsig.status != TSIG_NOT_PRESENT) { in query_add_optional()
1834 if (q->tsig.status == TSIG_ERROR || in query_add_optional()
1835 q->tsig.error_code != TSIG_ERROR_NOERROR) { in query_add_optional()
1836 tsig_error_reply(&q->tsig); in query_add_optional()
1837 tsig_append_rr(&q->tsig, q->packet); in query_add_optional()
1838 ARCOUNT_SET(q->packet, ARCOUNT(q->packet) + 1); in query_add_optional()
1839 } else if(q->tsig.status == TSIG_OK && in query_add_optional()
1840 q->tsig.error_code == TSIG_ERROR_NOERROR) in query_add_optional()
1842 if(q->tsig_prepare_it) in query_add_optional()
1843 tsig_prepare(&q->tsig); in query_add_optional()
1844 if(q->tsig_update_it) in query_add_optional()
1845 tsig_update(&q->tsig, q->packet, buffer_position(q->packet)); in query_add_optional()
1846 if(q->tsig_sign_it) { in query_add_optional()
1847 tsig_sign(&q->tsig); in query_add_optional()
1848 tsig_append_rr(&q->tsig, q->packet); in query_add_optional()
1849 ARCOUNT_SET(q->packet, ARCOUNT(q->packet) + 1); in query_add_optional()