/* cache.h - Definitions for the dns cache
Copyright (C) 2000 Thomas Moestl
Copyright (C) 2003, 2004, 2005, 2010, 2011 Paul A. Rombouts
This file is part of the pdnsd package.
pdnsd is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
pdnsd is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pdnsd; see the file COPYING. If not, see
.
*/
#ifndef _CACHE_H_
#define _CACHE_H_
#include
#include "ipvers.h"
#include
#include "list.h"
#include "dns.h"
#include "conff.h"
struct rr_lent_s;
/*
* These values are converted to host byte order. the data is _not_.
*/
typedef struct rr_b_s {
struct rr_b_s *next; /* this is the next pointer in the dns_cent_t list. */
unsigned rdlen;
#if ALLOW_LOCAL_AAAA || defined(ENABLE_IPV6)
struct in6_addr data[0]; /* dummy for alignment */
#else
struct in_addr data[0];
#endif
} rr_bucket_t;
typedef struct {
struct rr_lent_s *lent; /* this points to the list entry */
time_t ttl;
time_t ts;
unsigned short flags;
rr_bucket_t *rrs;
} rr_set_t;
typedef struct {
unsigned char *qname; /* Name of the domain in length byte - string notation. */
size_t cs; /* Size of the cache entry, including RR sets. */
unsigned short num_rrs; /* The number of RR sets. When this decreases to 0, the cent is deleted. */
unsigned short flags; /* Flags for the whole domain. */
union {
struct { /* Fields used only for negatively cached domains. */
struct rr_lent_s *lent; /* list entry for the whole cent. */
time_t ttl; /* TTL for negative caching. */
time_t ts; /* Timestamp. */
} neg;
struct { /* Fields used only for domains that actually exist. */
rr_set_t *(rrmu[NRRMU]); /* The most used records.
Use the the value obtained from rrlkuptab[] as index. */
rr_set_t **rrext; /* Pointer (may be NULL) to an array of size NNRREXT storing the
less frequently used records. */
} rr;
};
unsigned char c_ns,c_soa; /* Number of trailing name elements in qname to use to find NS or SOA
records to add to the authority section of a response. */
} dns_cent_t;
/* This value is used to represent an undefined c_ns or c_soa field. */
#define cundef 0xff
/*
* the flag values for RR sets in the cache
*/
#define CF_NEGATIVE 1 /* this one is for per-RRset negative caching*/
#define CF_LOCAL 2 /* Local zone entry */
#define CF_AUTH 4 /* authoritative record */
#define CF_NOCACHE 8 /* Only hold for the cache latency time period, then purge.
* Not really written to cache, but used by add_cache. */
#define CF_ADDITIONAL 16 /* This was fetched as an additional or "off-topic" record. */
#define CF_NOPURGE 32 /* Do not purge this record */
#define CF_ROOTSERV 64 /* This record was directly obtained from a root server */
#define CFF_NOINHERIT (CF_LOCAL|CF_AUTH|CF_ADDITIONAL|CF_ROOTSERV) /* not to be inherited on requery */
/*
* the flag values for whole domains in the cache
*/
#define DF_NEGATIVE 1 /* this one is for whole-domain negative caching (created on NXDOMAIN)*/
#define DF_LOCAL 2 /* local record (in conj. with DF_NEGATIVE) */
#define DF_AUTH 4 /* authoritative record */
#define DF_NOCACHE 8 /* Only hold for the cache latency time period, then purge.
* Only used for negatively cached domains.
* Not really written to cache, but used by add_cache. */
#define DF_WILD 16 /* subdomains of this domain have wildcard records */
/* #define DFF_NOINHERIT (DF_NEGATIVE) */ /* not to be inherited on requery */
enum {w_wild=1, w_neg, w_locnerr}; /* Used to distinguish different types of wildcard records. */
#if DEBUG>0
#define NCFLAGS 7
#define NDFLAGS 5
#define CFLAGSTRLEN (NCFLAGS*4)
#define DFLAGSTRLEN (NDFLAGS*4)
extern const char cflgnames[];
extern const char dflgnames[];
char *flags2str(unsigned flags,char *buf,int nflags,const char *flgnames);
#define cflags2str(flags,buf) flags2str(flags,buf,NCFLAGS,cflgnames)
#define dflags2str(flags,buf) flags2str(flags,buf,NDFLAGS,dflgnames)
#endif
/*
* This is the time in secs any record remains at least in the cache before it is purged.
* (exception is that the cache is full)
*/
#define CACHE_LAT 120
#define CLAT_ADJ(ttl) ((ttl)ts+CLAT_ADJ((rrset)->ttl)