"Fossies" - the Fresh Open Source Software Archive

Member "knot-2.9.2/src/knot/zone/zone.h" (12 Dec 2019, 5488 Bytes) of package /linux/misc/dns/knot-2.9.2.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "zone.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.9.1_vs_2.9.2.

    1 /*  Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
    2 
    3     This program is free software: you can redistribute it and/or modify
    4     it under the terms of the GNU General Public License as published by
    5     the Free Software Foundation, either version 3 of the License, or
    6     (at your option) any later version.
    7 
    8     This program is distributed in the hope that it will be useful,
    9     but WITHOUT ANY WARRANTY; without even the implied warranty of
   10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11     GNU General Public License for more details.
   12 
   13     You should have received a copy of the GNU General Public License
   14     along with this program.  If not, see <https://www.gnu.org/licenses/>.
   15  */
   16 
   17 #pragma once
   18 
   19 #include "contrib/semaphore.h"
   20 #include "knot/conf/conf.h"
   21 #include "knot/conf/confio.h"
   22 #include "knot/journal/journal_basic.h"
   23 #include "knot/events/events.h"
   24 #include "knot/updates/changesets.h"
   25 #include "knot/zone/contents.h"
   26 #include "knot/zone/timers.h"
   27 #include "libknot/dname.h"
   28 #include "libknot/packet/pkt.h"
   29 
   30 struct zone_update;
   31 
   32 /*!
   33  * \brief Zone flags.
   34  */
   35 typedef enum zone_flag_t {
   36     ZONE_FORCE_AXFR     = 1 << 0, /*!< Force AXFR as next transfer. */
   37     ZONE_FORCE_RESIGN   = 1 << 1, /*!< Force zone re-sign. */
   38     ZONE_FORCE_FLUSH    = 1 << 2, /*!< Force zone flush. */
   39     ZONE_FORCE_KSK_ROLL = 1 << 3, /*!< Force KSK/CSK rollover. */
   40     ZONE_FORCE_ZSK_ROLL = 1 << 4, /*!< Force ZSK rollover. */
   41 } zone_flag_t;
   42 
   43 /*!
   44  * \brief Structure for holding DNS zone.
   45  */
   46 typedef struct zone
   47 {
   48     knot_dname_t *name;
   49     zone_contents_t *contents;
   50     zone_flag_t flags;
   51 
   52     /*! \brief Dynamic configuration zone change type. */
   53     conf_io_type_t change_type;
   54 
   55     /*! \brief Zonefile parameters. */
   56     struct {
   57         struct timespec mtime;
   58         uint32_t serial;
   59         bool exists;
   60         bool resigned;
   61         bool retransfer;
   62     } zonefile;
   63 
   64     /*! \brief Zone events. */
   65     zone_timers_t timers;      //!< Persistent zone timers.
   66     zone_events_t events;      //!< Zone events timers.
   67 
   68     /*! \brief DDNS queue and lock. */
   69     pthread_mutex_t ddns_lock;
   70     size_t ddns_queue_size;
   71     list_t ddns_queue;
   72 
   73     /*! \brief Control update context. */
   74     struct zone_update *control_update;
   75 
   76     /*! \brief Ensue one COW tramsaction on zone's trees at a time. */
   77     knot_sem_t cow_lock;
   78 
   79     /*! \brief Ptr to journal DB (in struct server) */
   80     knot_lmdb_db_t *journaldb;
   81 
   82     /*! \brief Ptr to journal DB (in struct server) */
   83     knot_lmdb_db_t *kaspdb;
   84 
   85     /*! \brief Preferred master lock. */
   86     pthread_mutex_t preferred_lock;
   87     /*! \brief Preferred master for remote operation. */
   88     struct sockaddr_storage *preferred_master;
   89 
   90     /*! \brief Query modules. */
   91     list_t query_modules;
   92     struct query_plan *query_plan;
   93 } zone_t;
   94 
   95 /*!
   96  * \brief Creates new zone with emtpy zone content.
   97  *
   98  * \param name  Zone name.
   99  *
  100  * \return The initialized zone structure or NULL if an error occurred.
  101  */
  102 zone_t* zone_new(const knot_dname_t *name);
  103 
  104 /*!
  105  * \brief Deallocates the zone structure.
  106  *
  107  * \note The function also deallocates all bound structures (contents, etc.).
  108  *
  109  * \param zone_ptr Zone to be freed.
  110  */
  111 void zone_free(zone_t **zone_ptr);
  112 
  113 /*!
  114  * \brief Clears possible control update transaction.
  115  *
  116  * \param zone Zone to be cleared.
  117  */
  118 void zone_control_clear(zone_t *zone);
  119 
  120 inline static zone_journal_t zone_journal(zone_t *zone)
  121 {
  122     zone_journal_t j = { zone->journaldb, zone->name };
  123     return j;
  124 }
  125 
  126 int zone_change_store(conf_t *conf, zone_t *zone, changeset_t *change, changeset_t *extra);
  127 int zone_changes_clear(conf_t *conf, zone_t *zone);
  128 int zone_in_journal_store(conf_t *conf, zone_t *zone, zone_contents_t *new_contents);
  129 
  130 /*! \brief Synchronize zone file with journal. */
  131 int zone_flush_journal(conf_t *conf, zone_t *zone, bool verbose);
  132 
  133 bool zone_journal_has_zij(zone_t *zone);
  134 
  135 /*!
  136  * \brief Atomically switch the content of the zone.
  137  */
  138 zone_contents_t *zone_switch_contents(zone_t *zone, zone_contents_t *new_contents);
  139 
  140 /*! \brief Checks if the zone is slave. */
  141 bool zone_is_slave(conf_t *conf, const zone_t *zone);
  142 
  143 /*! \brief Sets the address as a preferred master address. */
  144 void zone_set_preferred_master(zone_t *zone, const struct sockaddr_storage *addr);
  145 
  146 /*! \brief Clears the current preferred master address. */
  147 void zone_clear_preferred_master(zone_t *zone);
  148 
  149 /*! \brief Get zone SOA RR. */
  150 const knot_rdataset_t *zone_soa(const zone_t *zone);
  151 
  152 /*! \brief Check if zone is expired according to timers. */
  153 bool zone_expired(const zone_t *zone);
  154 
  155 typedef int (*zone_master_cb)(conf_t *conf, zone_t *zone, const conf_remote_t *remote,
  156                               void *data);
  157 
  158 /*!
  159  * \brief Perform an action with a first working master server.
  160  *
  161  * The function iterates over available masters. For each master, the callback
  162  * function is called. If the callback function succeeds (\ref KNOT_EOK is
  163  * returned), the iteration is terminated.
  164  *
  165  * \return Error code from the last callback.
  166  */
  167 int zone_master_try(conf_t *conf, zone_t *zone, zone_master_cb callback,
  168                     void *callback_data, const char *err_str);
  169 
  170 /*! \brief Write zone contents to zonefile, but into different directory. */
  171 int zone_dump_to_dir(conf_t *conf, zone_t *zone, const char *dir);
  172 
  173 int zone_set_master_serial(zone_t *zone, uint32_t serial);
  174 
  175 int zone_get_master_serial(zone_t *zone, uint32_t *serial);
  176 
  177 int zone_set_lastsigned_serial(zone_t *zone, uint32_t serial);
  178 
  179 int zone_get_lastsigned_serial(zone_t *zone, uint32_t *serial);
  180 
  181 int slave_zone_serial(zone_t *zone, conf_t *conf, uint32_t *serial);