/* The NSD runtime states and NSD ipc command values */
#define NSD_RUN 0
#define NSD_RELOAD 1
#define NSD_SHUTDOWN 2
#define NSD_STATS 3
#define NSD_REAP_CHILDREN 4
#define NSD_QUIT 5
/*
* PASS_TO_XFRD is followed by the u16(len in network order) and
* then network packet contents. packet is a notify(acl checked), or
* xfr reply from a master(acl checked).
* followed by u32(acl number that matched from notify/xfr acl).
*/
#define NSD_PASS_TO_XFRD 6
/*
* RELOAD_REQ is sent when parent receives a SIGHUP and tells
* xfrd that it wants to initiate a reload (and thus task swap).
*/
#define NSD_RELOAD_REQ 7
/*
* RELOAD_DONE is sent at the end of a reload pass.
* xfrd then knows that reload phase is over.
*/
#define NSD_RELOAD_DONE 8
/*
* QUIT_SYNC is sent to signify a synchronisation of ipc
* channel content during reload
*/
#define NSD_QUIT_SYNC 9
/*
* QUIT_CHILD is sent at exit, to make sure the child has exited so that
* port53 is free when all of nsd's processes have exited at shutdown time
*/
#define NSD_QUIT_CHILD 11
/*
* This is the exit code of a nsd "new master" child process to indicate to
* the master process that some zones failed verification and that it should
* reload again, reprocessing the difffiles. The master process will resend
* the command to xfrd so it will not reload from xfrd yet.
*/
#define NSD_RELOAD_FAILED 14
/* NSD configuration and run-time variables */
typedef struct nsd nsd_type;
struct nsd
{
/*
* Global region that is not deallocated until NSD shuts down.
*/
region_type *region;
size_t child_count;
struct nsd_child *children;
int restart_children;
int reload_failed;
/* NULL if this is the parent process. */
struct nsd_child *this_child;
/* mmaps with data exchange from xfrd and reload */
struct udb_base* task[2];
int mytask;
/* the base used by this (child)process */
struct event_base* event_base;
/* the server_region used by this (child)process */
region_type* server_region;
struct netio_handler* xfrd_listener;
struct daemon_remote* rc;
/* Interfaces used for zone verification */
size_t verify_ifs;
struct nsd_socket *verify_tcp;
struct nsd_socket *verify_udp;
struct zone *next_zone_to_verify;
size_t verifier_count; /* Number of active verifiers */
size_t verifier_limit; /* Maximum number of active verifiers */
int verifier_pipe[2]; /* Pipe to trigger verifier exit handler */
struct verifier *verifiers;
int maximum_tcp_count;
int current_tcp_count;
int tcp_query_count;
int tcp_timeout;
int tcp_mss;
int outgoing_tcp_mss;
size_t ipv4_edns_size;
size_t ipv6_edns_size;
#ifdef BIND8_STATS
/* statistics for this server */
struct nsdst* st;
/* Produce statistics dump every st_period seconds */
int st_period;
/* per zone stats, each an array per zone-stat-idx, stats per zone is
* add of [0][zoneidx] and [1][zoneidx]. */
struct nsdst* zonestat[2];
/* fd for zonestat mapping (otherwise mmaps cannot be shared between
* processes and resized) */
int zonestatfd[2];
/* filenames */
char* zonestatfname[2];
/* size of the mmapped zone stat array (number of array entries) */
size_t zonestatsize[2], zonestatdesired, zonestatsizenow;
/* current zonestat array to use */
struct nsdst* zonestatnow;
/* filenames for stat file mappings */
char* statfname;
/* fd for stat mapping (otherwise mmaps cannot be shared between
* processes and resized) */
int statfd;
/* statistics array, of size child_count*2, twice for old and new
* server processes. */
struct nsdst* stat_map;
/* statistics array of size child_count, twice */
struct nsdst* stats_per_child[2];
/* current stats_per_child array that is in use for the child set */
int stat_current;
/* start value for per process statistics printout, to clear it */
struct nsdst stat_proc;
#endif /* BIND8_STATS */
#ifdef USE_DNSTAP
/* the dnstap collector process info */
struct dt_collector* dt_collector;
/* the pipes from server processes to the dt_collector,
* arrays of size child_count * 2. Kept open for (re-)forks. */
int *dt_collector_fd_send, *dt_collector_fd_recv;
/* the pipes from server processes to the dt_collector. Initially
* these point halfway into dt_collector_fd_send, but during reload
* the pointer is swapped with dt_collector_fd_send in order to
* to prevent writing to the dnstap collector by old serve childs
* simultaneous with new serve childs. */
int *dt_collector_fd_swap;
#endif /* USE_DNSTAP */
/* ratelimit for errors, time value */
time_t err_limit_time;
/* ratelimit for errors, packet count */
unsigned int err_limit_count;
/** do answer with server cookie when request contained cookie option */
int do_answer_cookie;
/** how many cookies are there in the cookies array */
size_t cookie_count;
/* keep track of the last `NSD_COOKIE_HISTORY_SIZE`
* cookies as per rfc requirement .*/
cookie_secret_type cookie_secrets[NSD_COOKIE_HISTORY_SIZE];