// If configured, add reverse records to zone contents
const knot_dname_t *fail_fwd = NULL;
- ret = zones_reverse(&zone->reverse_from, zf_conts, &fail_fwd);
+ ret = zones_reverse(&zone->include_from, zf_conts, &fail_fwd);
if (ret == KNOT_ETRYAGAIN) {
knot_dname_txt_storage_t forw_str;
(void)knot_dname_to_str(forw_str, fail_fwd, sizeof(forw_str));
int zones_reverse(list_t *zones, zone_contents_t *to_conts, const knot_dname_t **fail_fwd)
{
int ret = KNOT_EOK;
- ptrnode_t *n;
+ zone_include_t *n;
WALK_LIST(n, *zones) {
- zone_t *z = n->d;
+ zone_t *z = n->include;
+ assert(n->method == ZONE_INCLUDE_REVERSE);
rcu_read_lock();
if (z->contents == NULL) {
ret = KNOT_ETRYAGAIN;
// Initialize query modules list.
init_list(&zone->query_modules);
- init_list(&zone->reverse_from);
+ init_list(&zone->include_from);
init_list(&zone->internal_notify);
ATOMIC_INIT(zone->backup_ctx, NULL);
conf_deactivate_modules(&zone->query_modules, &zone->query_plan);
- ptrlist_free(&zone->reverse_from, NULL);
+ zone_includes_clear(zone);
ptrlist_free(&zone->internal_notify, NULL);
ATOMIC_DEINIT(zone->backup_ctx);
return zonefile_write_skip(target, zone->contents, conf);
}
+int zone_includes_add(zone_t *zone, zone_t *include, zone_include_method_t method)
+{
+ zone_include_t *n = calloc(1, sizeof(*n));
+ if (n == NULL) {
+ return KNOT_ENOMEM;
+ }
+ n->include = include;
+ n->method = method;
+ add_tail(&zone->include_from, &n->n);
+ return KNOT_EOK;
+}
+
+void zone_includes_rem(zone_t *zone, zone_t *include)
+{
+ zone_include_t *n, *nxt;
+ WALK_LIST_DELSAFE(n, nxt, zone->include_from) {
+ if (n->include == include) {
+ rem_node(&n->n);
+ free(n);
+ }
+ }
+}
+
+void zone_includes_clear(zone_t *zone)
+{
+ zone_include_t *n, *next;
+ WALK_LIST_DELSAFE(n, next, zone->include_from) {
+ free(n);
+ }
+ init_list(&zone->include_from);
+}
+
void zone_local_notify_subscribe(zone_t *zone, zone_t *subscribe)
{
ptrlist_add(&zone->internal_notify, subscribe, NULL);
const char *catalog_group;
/*! \brief Auto-generated reverse zones... */
- list_t reverse_from;
+ list_t include_from;
list_t internal_notify;
/*! \brief Preferred master lock. Also used for flags access. */
struct query_plan *query_plan;
} zone_t;
+typedef enum {
+ ZONE_INCLUDE_REVERSE,
+} zone_include_method_t;
+
+typedef struct {
+ node_t n;
+ zone_t *include;
+ zone_include_method_t method;
+} zone_include_t;
+
/*!
* \brief Creates new zone with empty zone content.
*
/*! \brief Write zone contents to zonefile, but into different directory. */
int zone_dump_to_dir(conf_t *conf, zone_t *zone, const char *dir);
+/*!
+ * \brief Zone inclusion (reverse generation) related ops.
+ */
+int zone_includes_add(zone_t *zone, zone_t *include, zone_include_method_t method);
+void zone_includes_rem(zone_t *zone, zone_t *include);
+void zone_includes_clear(zone_t *zone);
+
void zone_local_notify_subscribe(zone_t *zone, zone_t *subscribe);
void zone_local_notify_unsubscribe(zone_t *zone, zone_t *subscribe);
void zone_local_notify(zone_t *zone);
return;
}
- ptrnode_t *n;
- WALK_LIST(n, zone->reverse_from) {
- zone_local_notify_unsubscribe(n->d, zone);
+ zone_include_t *n;
+ WALK_LIST(n, zone->include_from) {
+ zone_local_notify_unsubscribe(n->include, zone);
}
- ptrlist_free(&zone->reverse_from, NULL);
+ zone_includes_clear(zone);
conf_val_t val = conf_zone_get(conf, C_REVERSE_GEN, zone->name);
while (val.code == KNOT_EOK) {
log_zone_warning(zone->name, "zone to reverse %s does not exist",
forw_str);
} else {
- ptrlist_add(&zone->reverse_from, forw, NULL);
+ (void)zone_includes_add(zone, forw, ZONE_INCLUDE_REVERSE);
zone_local_notify_subscribe(forw, zone);
}
conf_val_next(&val);
return;
}
- ptrnode_t *n;
- WALK_LIST(n, zone->reverse_from) {
- zone_local_notify_unsubscribe(n->d, zone);
+ zone_include_t *in;
+ WALK_LIST(in, zone->include_from) {
+ zone_local_notify_unsubscribe(in->include, zone);
}
- ptrlist_free(&zone->reverse_from, NULL);
+ zone_includes_clear(zone);
+ ptrnode_t *n;
WALK_LIST(n, zone->internal_notify) {
zone_t *reverse = n->d;
- ptrlist_find_rem(&reverse->reverse_from, zone, NULL);
+ zone_includes_rem(reverse, zone);
}
ptrlist_free(&zone->internal_notify, NULL);
}