summaryrefslogtreecommitdiffstats
path: root/usr.sbin/nsd/query.c
diff options
context:
space:
mode:
authorflorian <florian@openbsd.org>2016-10-24 09:44:43 +0000
committerflorian <florian@openbsd.org>2016-10-24 09:44:43 +0000
commitc1e73312a458f25fd5a1e1b0758b325481e8a455 (patch)
tree46814ca605975ccb37db9481af5061a918912dba /usr.sbin/nsd/query.c
parentfix SEE ALSO; (diff)
downloadwireguard-openbsd-c1e73312a458f25fd5a1e1b0758b325481e8a455.tar.xz
wireguard-openbsd-c1e73312a458f25fd5a1e1b0758b325481e8a455.zip
Update to 4.1.13
Testing millert, brad and myself. OK millert@
Diffstat (limited to 'usr.sbin/nsd/query.c')
-rw-r--r--usr.sbin/nsd/query.c56
1 files changed, 41 insertions, 15 deletions
diff --git a/usr.sbin/nsd/query.c b/usr.sbin/nsd/query.c
index 7256449d38d..fc2d45e9b86 100644
--- a/usr.sbin/nsd/query.c
+++ b/usr.sbin/nsd/query.c
@@ -580,7 +580,11 @@ find_covering_nsec(domain_type *closest_match,
assert(nsec_rrset);
/* loop away temporary created domains. For real ones it is &RBTREE_NULL */
+#ifdef USE_RADIX_TREE
while (closest_match->rnode == NULL)
+#else
+ while (closest_match->node.parent == NULL)
+#endif
closest_match = closest_match->parent;
while (closest_match) {
*nsec_rrset = domain_find_rrset(closest_match, zone, TYPE_NSEC);
@@ -656,8 +660,13 @@ add_additional_rrsets(struct query *query, answer_type *answer,
domain_type *wildcard_child = domain_wildcard_child(match);
domain_type *temp = (domain_type *) region_alloc(
query->region, sizeof(domain_type));
+#ifdef USE_RADIX_TREE
temp->rnode = NULL;
temp->dname = additional->dname;
+#else
+ memcpy(&temp->node, &additional->node, sizeof(rbnode_t));
+ temp->node.parent = NULL;
+#endif
temp->number = additional->number;
temp->parent = match;
temp->wildcard_child_closest_match = temp;
@@ -728,6 +737,10 @@ add_rrset(struct query *query,
add_additional_rrsets(query, answer, rrset, 1, 0,
rt_additional_rr_types);
break;
+ case TYPE_SRV:
+ add_additional_rrsets(query, answer, rrset, 3, 0,
+ default_additional_rr_types);
+ break;
default:
break;
}
@@ -764,7 +777,11 @@ query_synthesize_cname(struct query* q, struct answer* answer, const dname_type*
return 0;
newdom->is_existing = 1;
newdom->parent = lastparent;
+#ifdef USE_RADIX_TREE
newdom->dname
+#else
+ newdom->node.key
+#endif
= dname_partial_copy(q->region,
from_name, domain_dname(src)->label_count + i + 1);
if(dname_compare(domain_dname(newdom), q->qname) == 0) {
@@ -787,7 +804,11 @@ query_synthesize_cname(struct query* q, struct answer* answer, const dname_type*
return 0;
newdom->is_existing = 0;
newdom->parent = lastparent;
+#ifdef USE_RADIX_TREE
newdom->dname
+#else
+ newdom->node.key
+#endif
= dname_partial_copy(q->region,
to_name, domain_dname(to_closest_encloser)->label_count + i + 1);
DEBUG(DEBUG_QUERY,2, (LOG_INFO, "created temp domain dest %d. %s nr %d", i,
@@ -1088,8 +1109,13 @@ answer_authoritative(struct nsd *nsd,
match = (domain_type *) region_alloc(q->region,
sizeof(domain_type));
+#ifdef USE_RADIX_TREE
match->rnode = NULL;
match->dname = wildcard_child->dname;
+#else
+ memcpy(&match->node, &wildcard_child->node, sizeof(rbnode_t));
+ match->node.parent = NULL;
+#endif
match->parent = closest_encloser;
match->wildcard_child_closest_match = match;
match->number = domain_number;
@@ -1284,7 +1310,7 @@ answer_query(struct nsd *nsd, struct query *q)
}
void
-query_prepare_response(query_type *q, nsd_type *nsd)
+query_prepare_response(query_type *q)
{
uint16_t flags;
@@ -1299,9 +1325,6 @@ query_prepare_response(query_type *q, nsd_type *nsd)
*/
q->reserved_space = edns_reserved_space(&q->edns);
q->reserved_space += tsig_reserved_space(&q->tsig);
- if(q->edns.nsid == 1 && nsd->nsid_len > 0 &&
- q->edns.status != EDNS_NOT_PRESENT)
- q->reserved_space += OPT_HDR + nsd->nsid_len;
/* Update the flags. */
flags = FLAGS(q->packet);
@@ -1401,7 +1424,7 @@ query_process(query_type *q, nsd_type *nsd)
}
/* See if there is an OPT RR. */
if (arcount > 0) {
- if (edns_parse_record(&q->edns, q->packet))
+ if (edns_parse_record(&q->edns, q->packet, q, nsd))
--arcount;
}
/* See if there is a TSIG RR. */
@@ -1440,7 +1463,7 @@ query_process(query_type *q, nsd_type *nsd)
return query_error(q, NSD_RC_OK);
}
- query_prepare_response(q, nsd);
+ query_prepare_response(q);
if (q->qclass != CLASS_IN && q->qclass != CLASS_ANY) {
if (q->qclass == CLASS_CH) {
@@ -1479,17 +1502,20 @@ query_add_optional(query_type *q, nsd_type *nsd)
if (q->edns.dnssec_ok) edns->ok[7] = 0x80;
else edns->ok[7] = 0x00;
buffer_write(q->packet, edns->ok, OPT_LEN);
- if (nsd->nsid_len > 0 && q->edns.nsid == 1 && buffer_available(
- q->packet, OPT_RDATA+OPT_HDR+nsd->nsid_len)) {
- /* rdata length */
- buffer_write(q->packet, edns->rdata_nsid, OPT_RDATA);
- /* nsid opt header */
- buffer_write(q->packet, edns->nsid, OPT_HDR);
- /* nsid payload */
- buffer_write(q->packet, nsd->nsid, nsd->nsid_len);
- } else {
+ if(q->edns.opt_reserved_space == 0 || !buffer_available(
+ q->packet, 2+q->edns.opt_reserved_space)) {
/* fill with NULLs */
buffer_write(q->packet, edns->rdata_none, OPT_RDATA);
+ } else {
+ /* rdata length */
+ buffer_write_u16(q->packet, q->edns.opt_reserved_space);
+ /* edns options */
+ if(q->edns.nsid) {
+ /* nsid opt header */
+ buffer_write(q->packet, edns->nsid, OPT_HDR);
+ /* nsid payload */
+ buffer_write(q->packet, nsd->nsid, nsd->nsid_len);
+ }
}
ARCOUNT_SET(q->packet, ARCOUNT(q->packet) + 1);
STATUP(nsd, edns);