summaryrefslogtreecommitdiff
path: root/src/libknot/nameserver
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2012-06-13 15:30:30 +0200
committerOndřej Surý <ondrej@sury.org>2012-06-13 15:30:30 +0200
commit4355eafde2b6a80d2b8feaba30b6a884aff070d9 (patch)
treecaf5094e9fa899a889b3059e650e77529083cf33 /src/libknot/nameserver
parent61aecee532a9da6d7acc277051142e393872eaa4 (diff)
downloadknot-4355eafde2b6a80d2b8feaba30b6a884aff070d9.tar.gz
Imported Upstream version 1.0.6upstream/1.0.6
Diffstat (limited to 'src/libknot/nameserver')
-rw-r--r--src/libknot/nameserver/name-server.c89
1 files changed, 79 insertions, 10 deletions
diff --git a/src/libknot/nameserver/name-server.c b/src/libknot/nameserver/name-server.c
index d938683..7a6bc4d 100644
--- a/src/libknot/nameserver/name-server.c
+++ b/src/libknot/nameserver/name-server.c
@@ -298,6 +298,14 @@ static void ns_follow_cname(const knot_node_t **node,
add_rrset_to_resp(resp, rrset, tc, 0, 0, 1);
ns_add_rrsigs(cname_rrset, resp, *qname,
add_rrset_to_resp, tc);
+
+ int ret = knot_response_add_wildcard_node(
+ resp, *node, *qname);
+
+ /*! \todo Fix when return values are handled! */
+ if (ret != KNOT_EOK) {
+ assert(0);
+ }
} else {
add_rrset_to_resp(resp, rrset, tc, 0, 0, 1);
ns_add_rrsigs(rrset, resp, *qname, add_rrset_to_resp,
@@ -1346,6 +1354,32 @@ static int ns_put_nsec_nsec3_wildcard_answer(const knot_node_t *node,
}
/*----------------------------------------------------------------------------*/
+
+static int ns_put_nsec_nsec3_wildcard_nodes(knot_packet_t *response,
+ const knot_zone_contents_t *zone)
+{
+ assert(response != NULL);
+ assert(zone != NULL);
+
+ int ret = 0;
+
+ for (int i = 0; i < response->wildcard_nodes.count; ++i) {
+ ret = ns_put_nsec_nsec3_wildcard_answer(
+ response->wildcard_nodes.nodes[i],
+ knot_node_parent(
+ response->wildcard_nodes.nodes[i]),
+ NULL, zone,
+ response->wildcard_nodes.snames[i],
+ response);
+ if (ret != KNOT_EOK) {
+ return ret;
+ }
+ }
+
+ return KNOT_EOK;
+}
+
+/*----------------------------------------------------------------------------*/
/*!
* \brief Creates a referral response.
*
@@ -1470,7 +1504,7 @@ static inline int ns_referral(const knot_node_t *node,
}
if (ret == KNOT_EOK) {
- ns_put_additional(resp);
+// ns_put_additional(resp);
knot_response_set_rcode(resp, KNOT_RCODE_NOERROR);
}
return ret;
@@ -1536,14 +1570,35 @@ static int ns_answer_from_node(const knot_node_t *node,
} else { // else put authority NS
// if wildcard answer, add NSEC / NSEC3
dbg_ns("Adding NSEC/NSEC3 for wildcard answer.\n");
+
+// char *n = knot_dname_to_str(knot_node_owner(node));
+// char *ce = (closest_encloser)
+// ? knot_dname_to_str(knot_node_owner(closest_encloser))
+// : "(nil)";
+// char *prev = (previous)
+// ? knot_dname_to_str(knot_node_owner(previous))
+// : "(nil)";
+// printf("Node: %s, closest encloser: %s, previous: %s\n",
+// n, ce, prev);
+// free(n);
+// if (closest_encloser) {
+// free(ce);
+// }
+// if (previous) {
+// free(prev);
+// }
+ assert(previous == NULL);
+ assert(closest_encloser == knot_node_parent(node)
+ || !knot_dname_is_wildcard(knot_node_owner(node)));
+
ret = ns_put_nsec_nsec3_wildcard_answer(node, closest_encloser,
previous, zone, qname, resp);
ns_put_authority_ns(zone, resp);
}
- if (ret == KNOT_EOK) {
- ns_put_additional(resp);
- }
+// if (ret == KNOT_EOK) {
+// ns_put_additional(resp);
+// }
return ret;
}
@@ -1740,10 +1795,10 @@ dbg_ns_exec(
char *name;
if (node) {
name = knot_dname_to_str(node->owner);
- dbg_ns("zone_find_dname() returned node %s ", name);
+ dbg_ns("zone_find_dname() returned node %s \n", name);
free(name);
} else {
- dbg_ns("zone_find_dname() returned no node,");
+ dbg_ns("zone_find_dname() returned no node,\n");
}
if (closest_encloser != NULL) {
@@ -1806,14 +1861,15 @@ have_node:
// return NXDOMAIN
knot_response_set_rcode(resp,
KNOT_RCODE_NXDOMAIN);
- if (ns_put_nsec_nsec3_nxdomain(zone, previous,
- closest_encloser, qname, resp) != 0) {
- return NS_ERR_SERVFAIL;
- }
} else {
knot_response_set_rcode(resp,
KNOT_RCODE_NOERROR);
}
+
+ if (ns_put_nsec_nsec3_nxdomain(zone, previous,
+ closest_encloser, qname, resp) != 0) {
+ return NS_ERR_SERVFAIL;
+ }
knot_response_set_aa(resp);
goto finalize;
}
@@ -1896,6 +1952,13 @@ finalize:
ns_put_authority_soa(zone, resp);
}
+ // add all missing NSECs/NSEC3s for wildcard nodes
+ ret = ns_put_nsec_nsec3_wildcard_nodes(resp, zone);
+
+ if (ret == KNOT_EOK) {
+ ns_put_additional(resp);
+ }
+
return ret;
}
@@ -2468,6 +2531,8 @@ static int ns_ixfr_from_zone(knot_ns_xfr_t *xfr)
assert(xfr->response != NULL);
assert(knot_packet_authority_rrset_count(xfr->query) > 0);
assert(xfr->data != NULL);
+
+ rcu_read_lock();
knot_changesets_t *chgsets = (knot_changesets_t *)xfr->data;
knot_zone_contents_t *contents = knot_zone_get_contents(xfr->zone);
@@ -2487,6 +2552,7 @@ static int ns_ixfr_from_zone(knot_ns_xfr_t *xfr)
/*! \todo Probably rename the function. */
ns_xfr_send_and_clear(xfr, 1);
// socket_close(xfr->session); /*! \todo Remove for UDP.*/
+ rcu_read_unlock();
return res;
}
@@ -2495,6 +2561,7 @@ static int ns_ixfr_from_zone(knot_ns_xfr_t *xfr)
res = ns_ixfr_put_changeset(xfr, &chgsets->sets[i]);
if (res != KNOT_EOK) {
// answer is sent
+ rcu_read_unlock();
return res;
}
}
@@ -2510,6 +2577,8 @@ static int ns_ixfr_from_zone(knot_ns_xfr_t *xfr)
// return 1;
}
+ rcu_read_unlock();
+
return KNOT_EOK;
}