Skip to content
Snippets Groups Projects
Commit 417d9ecb authored by Lubos Slovak's avatar Lubos Slovak
Browse files

Additonal data for MX queries handling.

Added zdb_adjust_mx() for searching and saving A/AAAA RRSets
  corresponding to MX records in a node.
Added ns_put_additional() for adding additional RRSets into the
  response. Currently supports only MX.
Bugfix in skip_first() - was returning head instead of the first
  real item.
parent 6add3650
No related branches found
No related tags found
No related merge requests found
......@@ -321,7 +321,7 @@ int skip_empty( const skip_list *list )
const skip_node *skip_first( const skip_list *list )
{
return list->head;
return list->head->forward[0];
}
/*----------------------------------------------------------------------------*/
......
......@@ -180,6 +180,39 @@ static inline void ns_put_answer( const zn_node *node, ldns_rr_type type,
/*----------------------------------------------------------------------------*/
void ns_put_additional( const zn_node *node, ldns_rr_type type,
ldns_pkt *response )
{
debug_ns("ADDITIONAL SECTION PROCESSING\n");
switch (type) {
case LDNS_RR_TYPE_MX: {
skip_list *mx_refs = zn_get_ref_mx(node);
if (mx_refs != NULL) {
debug_ns("Adding RRSets for MX\n");
// simply add all RRSets to the additional section
const skip_node *mx = skip_first(mx_refs);
while (mx != NULL) {
zn_ar_rrsets *rrsets = (zn_ar_rrsets *)mx->value;
if (rrsets != NULL) {
ldns_pkt_push_rr_list(response, LDNS_SECTION_ADDITIONAL,
rrsets->a);
ldns_pkt_push_rr_list(response, LDNS_SECTION_ADDITIONAL,
rrsets->aaaa);
}
mx = skip_next(mx);
}
}
break; }
case LDNS_RR_TYPE_NS:
log_error("Putting additional records for NS not implemented yet!\n");
break;
default:
return;
}
}
/*----------------------------------------------------------------------------*/
static inline void ns_put_authority_ns( const zdb_zone *zone, ldns_pkt *resp )
{
ns_put_rrset(zone->apex, LDNS_RR_TYPE_NS, LDNS_SECTION_AUTHORITY, resp);
......@@ -257,6 +290,7 @@ void ns_answer( zdb_database *zdb, const ldns_rr *question, ldns_pkt *response )
//assert(ldns_dname_compare(node->owner, qname) == 0);
ns_put_answer(node, ldns_rr_get_type(question), response);
ns_put_authority_ns(zone, response);
ns_put_additional(node, ldns_rr_get_type(question), response);
} else { // only part of QNAME found
// if we ended in the zone apex, the name is not in the zone
if (zone->apex == node) {
......
......@@ -209,6 +209,50 @@ void zdb_adjust_cname( zdb_zone *zone, zn_node *node )
}
}
/*----------------------------------------------------------------------------*/
void zdb_adjust_mx( zdb_zone *zone, zn_node *node )
{
ldns_rr_list *mx_rrset = zn_find_rrset(node, LDNS_RR_TYPE_MX);
if (mx_rrset != NULL) {
// for each MX RR find the appropriate node in the zone (if any)
// and save a reference to it in the zone node
debug_zdb("Found MX, searching for corresponding A/AAAA records...\n");
int count = ldns_rr_list_rr_count(mx_rrset);
for (int i = 0; i < count; ++i) {
ldns_rdf *mx = ldns_rr_mx_exchange(ldns_rr_list_rr(mx_rrset, i));
assert(mx != NULL);
debug_zdb("Searching for A/AAAA record for MX name %s.\n",
ldns_rdf2str(mx));
zn_node *mx_node = zdb_find_name_in_list(zone, mx);
if (mx_node != NULL) {
debug_zdb("Found node: %p\n", mx_node);
ldns_rr_list *rrset = zn_find_rrset(mx_node, LDNS_RR_TYPE_A);
if (rrset != NULL) {
debug_zdb("Found A RRSet within the node, saving.\n");
if (zn_add_ref_mx(node, rrset) != 0) {
log_error("Error occured while saving A RRSet for MX"
"record in node %s\n",
ldns_rdf2str(node->owner));
return;
}
}
rrset = zn_find_rrset(mx_node, LDNS_RR_TYPE_AAAA);
if (rrset != NULL) {
debug_zdb("Found AAAA RRSet within the node, saving.\n");
if (zn_add_ref_mx(node, rrset) != 0) {
log_error("Error occured while saving AAAA RRSet for MX"
"record in node %s\n",
ldns_rdf2str(node->owner));
return;
}
}
debug_zdb("Done.\n\n");
}
}
}
}
/*----------------------------------------------------------------------------*/
/*!
* @retval 0 if found, -1 or 1 if not found.
......@@ -503,10 +547,13 @@ int zdb_adjust_zone( zdb_zone *zone )
ldns_rdf2str(zone->zone_name));
// walk through the nodes in the list and check for delegations and CNAMEs
zn_node *node = zone->apex;
zdb_adjust_mx(zone, node);
while (node->next != zone->apex) {
node = node->next;
zdb_adjust_cname(zone, node);
zdb_adjust_delegation_point(&node);
zdb_adjust_mx(zone, node);
}
debug_zdb("\nDone.\n");
......
......@@ -384,20 +384,29 @@ int zn_add_ref_mx( zn_node *node, ldns_rr_list *ref_rrset )
if (node->ref.mx == NULL) {
node->ref.mx = skip_create_list(zn_compare_ar_keys);
if (node->ref.mx == NULL) {
return -2;
}
zn_flags_set(&node->flags, FLAGS_HAS_MX);
}
zn_ar_rrsets *ar = zn_create_ar_rrsets_for_ref(ref_rrset);
if (ar == NULL) {
return -2;
return -3;
}
int res = 0;
res = skip_insert(node->ref.mx, ldns_rr_list_owner(ref_rrset), ar,
zn_merge_ar_values);
debug_zn("zn_add_ref_mx(%p, %p)\n", node, ref_rrset);
debug_zn("First item in the skip list: key: %s, value: %p\n",
ldns_rdf2str((ldns_rdf *)skip_first(node->ref.mx)->key),
skip_first(node->ref.mx)->value);
if (res < 0) {
free(ar);
return -3;
return -4;
}
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment