1/* 2 * xfrd-catalog-zones.h -- catalog zone implementation for NSD 3 * 4 * Copyright (c) 2024, NLnet Labs. All rights reserved. 5 * 6 * See LICENSE for the license. 7 */ 8#ifndef XFRD_CATALOG_ZONES_H 9#define XFRD_CATALOG_ZONES_H 10#include "xfrd.h" 11struct xfrd_producer_member; 12struct xfrd_producer_xfr; 13 14/** 15 * Catalog zones withing the xfrd context 16 */ 17struct xfrd_catalog_consumer_zone { 18 /* For indexing in struc xfrd_state { rbtree_type* catalog_consumer_zones; } */ 19 rbnode_type node; 20 21 /* Associated zone options with this catalog consumer zone */ 22 struct zone_options* options; 23 24 /* Member zones indexed by member_id */ 25 rbtree_type member_ids; 26 27 /* Last time processed, compare with zone->mtime to see if we need to process */ 28 struct timespec mtime; 29 30 /* The reason for this zone to be invalid, or NULL if it is valid */ 31 char *invalid; 32} ATTR_PACKED; 33 34/** 35 * Catalog producer zones withing the xfrd context 36 */ 37struct xfrd_catalog_producer_zone { 38 /* For indexing in struc xfrd_state { rbtree_type* catalog_producer_zones; } */ 39 rbnode_type node; 40 41 /* Associated zone options with this catalog consumer zone */ 42 struct zone_options* options; 43 44 /* Member zones indexed by member_id */ 45 rbtree_type member_ids; 46 47 /* SOA serial for this zone */ 48 uint32_t serial; 49 50 /* Stack of members to delete from this catalog producer zone */ 51 struct xfrd_producer_member* to_delete; 52 53 /* Stack of member zones to add to this catalog producer zone */ 54 struct xfrd_producer_member* to_add; 55 56 /* To cleanup on disk xfr files */ 57 struct xfrd_producer_xfr* latest_pxfr; 58 59 /* Set if next generated xfr for the producer zone should be axfr */ 60 unsigned axfr: 1; 61} ATTR_PACKED; 62 63/** 64 * Data to add or remove from a catalog producer zone 65 */ 66struct xfrd_producer_member { 67 const dname_type* member_id; 68 const dname_type* member_zone_name; 69 const char* group_name; 70 struct xfrd_producer_member* next; 71} ATTR_PACKED; 72 73/** 74 * To track applied generated transfers from catalog producer zones 75 */ 76struct xfrd_producer_xfr { 77 uint32_t serial; 78 uint64_t xfrfilenumber; 79 struct xfrd_producer_xfr** prev_next_ptr; 80 struct xfrd_producer_xfr* next; 81} ATTR_PACKED; 82 83/* Initialize as a catalog consumer zone */ 84void xfrd_init_catalog_consumer_zone(xfrd_state_type* xfrd, 85 struct zone_options* zone); 86 87/* To be called if and a zone is no longer a catalog zone (changed pattern) */ 88void xfrd_deinit_catalog_consumer_zone(xfrd_state_type* xfrd, 89 const dname_type* dname); 90 91/* make the catalog consumer zone invalid for given reason */ 92void make_catalog_consumer_invalid( 93 struct xfrd_catalog_consumer_zone *consumer_zone, 94 const char *format, ...) ATTR_FORMAT(printf, 2, 3); 95 96/* Return the reason a zone is invalid, or NULL on a valid catalog */ 97const char *invalid_catalog_consumer_zone(struct zone_options* zone); 98 99/* make the catalog consumer zone valid again */ 100void make_catalog_consumer_valid( 101 struct xfrd_catalog_consumer_zone *consumer_zone); 102 103/* Check the catalog consumer zone files (or file if zone is given) */ 104void xfrd_check_catalog_consumer_zonefiles(const dname_type* name); 105 106/* process the catalog consumer zones, load if needed */ 107void xfrd_process_catalog_consumer_zones(); 108 109 110/* Add (or change) <member_id> PTR <member_zone_name>, and 111 * group.<member_id> TXT <pattern->pname> to the associated producer zone by 112 * constructed xfr. make cmz->member_id if needed. */ 113void xfrd_add_catalog_producer_member(struct catalog_member_zone* cmz); 114 115/* Delete <member_id> PTR <member_zone_name>, and 116 * group.<member_id> TXT <pattern->pname> from the associated producer zone by 117 * constructed xfr. Return 1 if zone is deleted. In this case, member_zone_name 118 * is taken over by xfrd and cannot be recycled by the caller. member_zone_name 119 * must have been allocated int the xfrd->nsd->options->region 120 */ 121int xfrd_del_catalog_producer_member(xfrd_state_type* xfrd, 122 const dname_type* dname); 123 124/* process the catalog producer zones */ 125void xfrd_process_catalog_producer_zones(); 126 127#endif 128 129