Commit fa7a190b authored by Jan Kadlec's avatar Jan Kadlec

DDNS rewritten to use new RRSet.

- Small changes in other files, mostly reenabling disabled calls.
- new RRSet API function: delete all rrs from RRSet using other RRSet, but do not create RRSet that contains removed RDATA.
parent 6580736f
......@@ -75,6 +75,8 @@ src/common/libtap/tap.h
src/common/libtap/tap_unit.h
src/common/mempattern.c
src/common/mempattern.h
src/common/descriptor_new.c
src/common/descriptor_new.h
src/common/lists.h
src/common/lists.c
src/common/heap.h
......
......@@ -18,7 +18,7 @@ knot_zcompile_SOURCES = \
knot/server/zones.h \
libknot/packet/packet.h \
libknot/packet/packet.c \
libknot/packet/query.c \
libknot/packet/query.c
libknot/packet/query.h \
libknot/packet/response.h \
libknot/packet/response.c \
......@@ -55,6 +55,8 @@ knot_zcompile_SOURCES = \
libknot/updates/changesets.h \
libknot/updates/xfr-in.c \
libknot/updates/xfr-in.h \
libknot/updates/ddns.h \
libknot/updates/ddns.c \
libknot/dname.c \
libknot/dname.h \
libknot/nsec3.h \
......@@ -135,6 +137,8 @@ knot_zcompile_SOURCES = \
knot/server/tcp-handler.h \
knot/server/udp-handler.c \
knot/server/udp-handler.h \
knot/server/xfr-handler.h \
knot/server/xfr-handler.c \
knot/server/server.h \
knot/server/server.c \
knot/ctl/process.c \
......
......@@ -135,3 +135,13 @@ int descriptor_item_is_remainder(int item)
}
}
int knot_rrtype_is_metatype(uint16_t type)
{
/*! \todo Check if there are some other metatypes. */
return (type == KNOT_RRTYPE_ANY
|| type == KNOT_RRTYPE_AXFR
|| type == KNOT_RRTYPE_IXFR
|| type == KNOT_RRTYPE_OPT);
}
......@@ -132,6 +132,7 @@ int descriptor_item_is_dname(int item);
int descriptor_item_is_fixed(int item);
int descriptor_item_is_remainder(int item);
int descriptor_item_is_compr_dname(int item);
int knot_rrtype_is_metatype(uint16_t type);
#endif // _KNOT_DESCRIPTOR_NEW_H_
......
......@@ -422,8 +422,7 @@ server_t *server_create()
OpenSSL_add_all_digests();
// Create XFR handler
// server->xfr_h = xfr_create(XFR_THREADS_COUNT, server->nameserver);
server->xfr_h = 0x1; //TODO
server->xfr_h = xfr_create(XFR_THREADS_COUNT, server->nameserver);
if (!server->xfr_h) {
knot_ns_destroy(&server->nameserver);
free(server);
......
......@@ -39,6 +39,7 @@
#include "libknot/tsig-op.h"
#include "common/evsched.h"
#include "common/prng.h"
#include "common/descriptor_new.h"
/* Constants */
#define XFR_SWEEP_INTERVAL 2 /*! [seconds] between sweeps. */
......@@ -82,13 +83,13 @@ static int xfr_xfrin_cleanup(xfrworker_t *w, knot_ns_xfr_t *data)
case XFR_TYPE_AIN:
if (data->flags & XFR_FLAG_AXFR_FINISHED) {
knot_zone_contents_deep_free(
&data->new_contents, 1);
&data->new_contents);
} else {
if (data->data) {
xfrin_constructed_zone_t *constr_zone =
(xfrin_constructed_zone_t *)data->data;
knot_zone_contents_deep_free(
&(constr_zone->contents), 0);
&(constr_zone->contents));
xfrin_free_orphan_rrsigs(&(constr_zone->rrsigs));
free(data->data);
data->data = 0;
......
......@@ -30,6 +30,7 @@
#include "common/log.h"
#include "knot/server/notify.h"
#include "knot/server/server.h"
#include "knot/server/xfr-handler.h"
#include "libknot/updates/xfr-in.h"
#include "knot/server/zones.h"
#include "knot/zone/zone-dump.h"
......@@ -1099,7 +1100,7 @@ int zones_changesets_from_binary(knot_changesets_t *chgsets)
/* Parse next RRSet. */
rrset = 0;
stream = chs->data + (chs->size - remaining);
ret = knot_zload_rrset_deserialize(&rrset, stream, &remaining);
ret = rrset_deserialize(stream, &remaining, &rrset);
if (ret != KNOT_EOK) {
dbg_xfr("xfr: failed to deserialize data "
"from changeset, %s\n",
......
......@@ -3969,15 +3969,15 @@ int knot_ns_process_axfrin(knot_nameserver_t *nameserver, knot_ns_xfr_t *xfr)
knot_zone_contents_t *zone = constr_zone->contents;
assert(zone != NULL);
/* Create and fill hash table */
dbg_ns_verb("ns_process_axfrin: filling hash table.\n");
int rc = knot_zone_contents_create_and_fill_hash_table(zone);
if (rc != KNOT_EOK) {
return KNOT_ERROR; // TODO: change error code
}
// /* Create and fill hash table */
// dbg_ns_verb("ns_process_axfrin: filling hash table.\n");
// int rc = knot_zone_contents_create_and_fill_hash_table(zone);
// if (rc != KNOT_EOK) {
// return KNOT_ERROR; // TODO: change error code
// }
dbg_ns_verb("ns_process_axfrin: adjusting zone.\n");
rc = knot_zone_contents_adjust(zone);
int rc = knot_zone_contents_adjust(zone);
if (rc != KNOT_EOK) {
return rc;
}
......
......@@ -2160,7 +2160,7 @@ static int knot_rrset_find_rr_pos(const knot_rrset_t *rr_search,
size_t *pos_out)
{
int found = 0;
for (uint16_t i = 0; i < rr_search->rdata_count && !found; i++) {
for (uint16_t i = 0; i < rr_search->rdata_count && !found; ++i) {
if (rrset_rdata_compare_one(rr_search, rr_input, i, pos) == 0) {
*pos_out = i;
found = 1;
......@@ -2288,3 +2288,79 @@ int knot_rrset_add_rr_from_rrset(knot_rrset_t *dest, const knot_rrset_t *source,
return KNOT_EOK;
}
int knot_rrset_remove_rr_using_rrset(knot_rrset_t *from,
const knot_rrset_t *what,
knot_rrset_t **rr_deleted, int ddns_check)
{
knot_rrset_t *return_rr = NULL;
int ret = knot_rrset_shallow_copy(what, &return_rr);
if (ret != KNOT_EOK) {
dbg_xfrin("xfr: remove_rdata: Could not copy RRSet (%s).\n",
knot_strerror(ret));
return ret;
}
/* Reset RDATA. */
knot_rrset_rdata_reset(return_rr);
for (uint16_t i = 0; i < what->rdata_count; ++i) {
/*
* DDNS special handling - last apex NS should remain in the
* zone.
*
* TODO: this is not correct, the last NS from the 'what' RRSet
* may not even be in the zone.
*/
//TODO REVIEW LS : relevant?
if (ddns_check && i == what->rdata_count - 1) {
assert(knot_rrset_type(from) == KNOT_RRTYPE_NS);
*rr_deleted = return_rr;
return KNOT_EOK;
}
ret = knot_rrset_remove_rr(from, what, i);
if (ret == KNOT_EOK) {
/* RR was removed, can be added to 'return' RRSet. */
ret = knot_rrset_add_rr_from_rrset(return_rr, what, i);
if (ret != KNOT_EOK) {
knot_rrset_deep_free(&return_rr, 0, 0);
dbg_xfrin("xfr: Could not add RR (%s).\n",
knot_strerror(ret));
return ret;
}
} else if (ret != KNOT_ENOENT) {
/* NOENT is OK, but other errors are not. */
dbg_xfrin("xfr: RRSet removal failed (%s).\n",
knot_strerror(ret));
knot_rrset_deep_free(&return_rr, 0, 0);
return ret;
}
}
*rr_deleted = return_rr;
return KNOT_EOK;
}
int knot_rrset_remove_rr_using_rrset_del(knot_rrset_t *from,
const knot_rrset_t *what)
{
for (uint16_t i = 0; i < what->rdata_count; ++i) {
int ret = knot_rrset_remove_rr(from, what, i);
if (ret != KNOT_ENOENT || ret != KNOT_EOK) {
/* NOENT is OK, but other errors are not. */
dbg_xfrin("xfr: RRSet removal failed (%s).\n",
knot_strerror(ret));
return ret;
}
}
return KNOT_EOK;
}
void knot_rrset_set_class(knot_rrset_t *rrset, uint16_t rclass)
{
if (!rrset) {
return;
}
rrset->rclass = rclass;
}
......@@ -448,6 +448,13 @@ int knot_rrset_rdata_reset(knot_rrset_t *rrset);
int knot_rrset_add_rr_from_rrset(knot_rrset_t *dest, const knot_rrset_t *source,
size_t rdata_pos);
int knot_rrset_remove_rr_using_rrset(knot_rrset_t *from,
const knot_rrset_t *what,
knot_rrset_t **rr_deleted, int ddns_check);
int knot_rrset_remove_rr_using_rrset_del(knot_rrset_t *from,
const knot_rrset_t *what);
#endif /* _KNOT_RRSET_H_ */
/*! @} */
......
This diff is collapsed.
......@@ -1253,59 +1253,6 @@ static void xfrin_zone_contents_free(knot_zone_contents_t **contents)
/*----------------------------------------------------------------------------*/
static int xfrin_remove_rdata(knot_rrset_t *from, const knot_rrset_t *what,
knot_rrset_t **rr_deleted, int ddns_check)
{
knot_rrset_t *return_rr = NULL;
int ret = knot_rrset_shallow_copy(what, &return_rr);
if (ret != KNOT_EOK) {
dbg_xfrin("xfr: remove_rdata: Could not copy RRSet (%s).\n",
knot_strerror(ret));
return ret;
}
/* Reset RDATA. */
knot_rrset_rdata_reset(return_rr);
for (uint16_t i = 0; i < what->rdata_count; ++i) {
/*
* DDNS special handling - last apex NS should remain in the
* zone.
*
* TODO: this is not correct, the last NS from the 'what' RRSet
* may not even be in the zone.
*/
//TODO REVIEW LS : relevant?
if (ddns_check && i == what->rdata_count - 1) {
assert(knot_rrset_type(from) == KNOT_RRTYPE_NS);
*rr_deleted = return_rr;
return KNOT_EOK;
}
ret = knot_rrset_remove_rr(from, what, i);
if (ret == KNOT_EOK) {
/* RR was removed, can be added to 'return' RRSet. */
ret = knot_rrset_add_rr_from_rrset(return_rr, what, i);
if (ret != KNOT_EOK) {
knot_rrset_deep_free(&return_rr, 0, 0);
dbg_xfrin("xfr: Could not add RR (%s).\n",
knot_strerror(ret));
return ret;
}
} else if (ret != KNOT_ENOENT) {
/* NOENT is OK, but other errors are not. */
dbg_xfrin("xfr: RRSet removal failed (%s).\n",
knot_strerror(ret));
knot_rrset_deep_free(&return_rr, 0, 0);
return ret;
}
}
*rr_deleted = return_rr;
return KNOT_EOK;
}
/*----------------------------------------------------------------------------*/
int xfrin_copy_old_rrset(knot_rrset_t *old, knot_rrset_t **copy,
knot_changes_t *changes, int save_new)
{
......@@ -1536,7 +1483,7 @@ static int xfrin_apply_remove_rrsigs(knot_changes_t *changes,
// and in 'rrsigs' we have the copy of the RRSIGs
knot_rrset_t *rr_removed = NULL;
ret = xfrin_remove_rdata(rrsigs, remove, &rr_removed, 0);
ret = knot_rrset_remove_rr_using_rrset(rrsigs, remove, &rr_removed, 0);
if (ret != KNOT_EOK) {
dbg_xfrin("Failed to remove RDATA from RRSet: %s.\n",
knot_strerror(ret));
......@@ -1680,7 +1627,7 @@ dbg_xfrin_exec_detail(
((chflags & KNOT_CHANGESET_TYPE_DDNS) && is_apex
&& knot_rrset_type(*rrset) == KNOT_RRTYPE_NS);
knot_rrset_t *rr_remove = NULL;
ret = xfrin_remove_rdata(*rrset, remove, &rr_remove,
ret = knot_rrset_remove_rr_using_rrset(*rrset, remove, &rr_remove,
ddns_remove_ns_from_apex);
if (ret != KNOT_EOK) {
dbg_xfrin("xfr: remove_normal: Could not remove RR (%s).\n",
......
......@@ -187,16 +187,6 @@ int knot_zone_contents_remove_node(knot_zone_contents_t *contents,
int knot_zone_contents_remove_nsec3_node(knot_zone_contents_t *contents,
const knot_node_t *node, knot_zone_tree_node_t **removed);
/*!
* \warning Always call knot_zone_adjust_dnames() prior to calling this
* function. Otherwise the node count would not be set.
*
* \note Currently, all nodes (even non-authoritative) are inserted into the
* hash table.
*/
int knot_zone_contents_create_and_fill_hash_table(
knot_zone_contents_t *contents);
/*!
* \brief Tries to find a node with the specified name in the zone.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment