diff --git a/src/FTL.h b/src/FTL.h index 08401d7a..1215e3db 100644 --- a/src/FTL.h +++ b/src/FTL.h @@ -107,124 +107,7 @@ enum { TYPE_A = 1, TYPE_AAAA, TYPE_ANY, TYPE_SRV, TYPE_SOA, TYPE_PTR, TYPE_TXT, enum { REPLY_UNKNOWN, REPLY_NODATA, REPLY_NXDOMAIN, REPLY_CNAME, REPLY_IP, REPLY_DOMAIN, REPLY_RRNAME, REPLY_SERVFAIL, REPLY_REFUSED, REPLY_NOTIMP, REPLY_OTHER }; enum { PRIVACY_SHOW_ALL = 0, PRIVACY_HIDE_DOMAINS, PRIVACY_HIDE_DOMAINS_CLIENTS, PRIVACY_MAXIMUM, PRIVACY_NOSTATS }; enum { MODE_IP, MODE_NX, MODE_NULL, MODE_IP_NODATA_AAAA, MODE_NODATA }; -enum { REGEX_UNKNOWN, REGEX_BLOCKED, REGEX_NOTBLOCKED }; -enum { BLOCKING_DISABLED, BLOCKING_ENABLED, BLOCKING_UNKNOWN }; enum { GRAVITY_LIST, BLACK_LIST, WHITE_LIST, REGEX_LIST, UNKNOWN_LIST }; -enum { - DEBUG_DATABASE = (1 << 0), /* 00000000 00000001 */ - DEBUG_NETWORKING = (1 << 1), /* 00000000 00000010 */ - DEBUG_LOCKS = (1 << 2), /* 00000000 00000100 */ - DEBUG_QUERIES = (1 << 3), /* 00000000 00001000 */ - DEBUG_FLAGS = (1 << 4), /* 00000000 00010000 */ - DEBUG_SHMEM = (1 << 5), /* 00000000 00100000 */ - DEBUG_GC = (1 << 6), /* 00000000 01000000 */ - DEBUG_ARP = (1 << 7), /* 00000000 10000000 */ - DEBUG_REGEX = (1 << 8), /* 00000001 00000000 */ - DEBUG_API = (1 << 9), /* 00000010 00000000 */ - DEBUG_OVERTIME = (1 << 10), /* 00000100 00000000 */ - DEBUG_EXTBLOCKED = (1 << 11), /* 00001000 00000000 */ - DEBUG_CAPS = (1 << 12), /* 00010000 00000000 */ -}; - -// Database table "ftl" -enum { DB_VERSION, DB_LASTTIMESTAMP, DB_FIRSTCOUNTERTIMESTAMP }; -// Database table "counters" -enum { DB_TOTALQUERIES, DB_BLOCKEDQUERIES }; - -// Static structs - -typedef struct { - int queries; - int blocked; - int cached; - int unknown; - int forwarded; - int clients; - int domains; - int queries_MAX; - int forwarded_MAX; - int clients_MAX; - int domains_MAX; - int strings_MAX; - int gravity; - int gravity_conf; - int querytype[TYPE_MAX-1]; - int forwardedqueries; - int reply_NODATA; - int reply_NXDOMAIN; - int reply_CNAME; - int reply_IP; - int reply_domain; -} countersStruct; - -// Dynamic structs -typedef struct { - unsigned char magic; - unsigned char type; - unsigned char status; - unsigned char privacylevel; - unsigned char reply; - unsigned char dnssec; - time_t timestamp; - int domainID; - int clientID; - int forwardID; - int id; // the ID is a (signed) int in dnsmasq, so no need for a long int here - unsigned long response; // saved in units of 1/10 milliseconds (1 = 0.1ms, 2 = 0.2ms, 2500 = 250.0ms, etc.) - int64_t db; - unsigned int timeidx; - bool complete; -} queriesData; - -typedef struct { - unsigned char magic; - size_t ippos; - size_t namepos; - int count; - int failed; - bool new; -} forwardedData; - -typedef struct { - unsigned char magic; - size_t ippos; - size_t namepos; - time_t lastQuery; - int count; - int blockedcount; - int overTime[OVERTIME_SLOTS]; - unsigned int numQueriesARP; - bool new; -} clientsData; - -typedef struct { - unsigned char magic; - unsigned char regexmatch; - size_t domainpos; - int count; - int blockedcount; -} domainsData; - -typedef struct { - unsigned char magic; - time_t timestamp; - int total; - int blocked; - int cached; - int forwarded; - int querytypedata[TYPE_MAX-1]; -} overTimeData; - -typedef struct { - char **domains; - int count; -} whitelistStruct; - -typedef struct { - int version; - unsigned int global_shm_counter; - unsigned int next_str_pos; -} ShmSettings; // Use out own memory handling functions that will detect possible errors // and report accordingly in the log. This will make debugging FTL crashs @@ -244,14 +127,4 @@ extern pthread_t DBthread; extern pthread_t GCthread; extern pthread_t DNSclientthread; -// Pointer getter functions -#define getQuery(queryID, checkMagic) _getQuery(queryID, checkMagic, __LINE__, __FUNCTION__, __FILE__) -queriesData* _getQuery(int queryID, bool checkMagic, int line, const char * function, const char * file); -#define getClient(clientID, checkMagic) _getClient(clientID, checkMagic, __LINE__, __FUNCTION__, __FILE__) -clientsData* _getClient(int clientID, bool checkMagic, int line, const char * function, const char * file); -#define getDomain(domainID, checkMagic) _getDomain(domainID, checkMagic, __LINE__, __FUNCTION__, __FILE__) -domainsData* _getDomain(int domainID, bool checkMagic, int line, const char * function, const char * file); -#define getForward(forwardID, checkMagic) _getForward(forwardID, checkMagic, __LINE__, __FUNCTION__, __FILE__) -forwardedData* _getForward(int forwardID, bool checkMagic, int line, const char * function, const char * file); - #endif // FTL_H diff --git a/src/api/api.c b/src/api/api.c index 6b0aa16e..565d390b 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -23,6 +23,8 @@ #include "overTime.h" #include "api.h" #include "version.h" +// enum REGEX +#include "regex_r.h" #define min(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; }) diff --git a/src/config.h b/src/config.h index 3f43127d..64ebc959 100644 --- a/src/config.h +++ b/src/config.h @@ -51,4 +51,20 @@ typedef struct { extern ConfigStruct config; extern FTLFileNamesStruct FTLfiles; +enum { + DEBUG_DATABASE = (1 << 0), /* 00000000 00000001 */ + DEBUG_NETWORKING = (1 << 1), /* 00000000 00000010 */ + DEBUG_LOCKS = (1 << 2), /* 00000000 00000100 */ + DEBUG_QUERIES = (1 << 3), /* 00000000 00001000 */ + DEBUG_FLAGS = (1 << 4), /* 00000000 00010000 */ + DEBUG_SHMEM = (1 << 5), /* 00000000 00100000 */ + DEBUG_GC = (1 << 6), /* 00000000 01000000 */ + DEBUG_ARP = (1 << 7), /* 00000000 10000000 */ + DEBUG_REGEX = (1 << 8), /* 00000001 00000000 */ + DEBUG_API = (1 << 9), /* 00000010 00000000 */ + DEBUG_OVERTIME = (1 << 10), /* 00000100 00000000 */ + DEBUG_EXTBLOCKED = (1 << 11), /* 00001000 00000000 */ + DEBUG_CAPS = (1 << 12), /* 00010000 00000000 */ +}; + #endif //CONFIG_H diff --git a/src/database/common.h b/src/database/common.h index 6debe210..48970f04 100644 --- a/src/database/common.h +++ b/src/database/common.h @@ -47,4 +47,9 @@ extern bool DBdeleteoldqueries; }\ } +// Database table "ftl" +enum { DB_VERSION, DB_LASTTIMESTAMP, DB_FIRSTCOUNTERTIMESTAMP }; +// Database table "counters" +enum { DB_TOTALQUERIES, DB_BLOCKEDQUERIES }; + #endif //DATABASE_COMMON_H diff --git a/src/datastructure.c b/src/datastructure.c index c3482704..e671b317 100644 --- a/src/datastructure.c +++ b/src/datastructure.c @@ -13,6 +13,8 @@ #include "memory.h" #include "shmem.h" #include "log.h" +// enum REGEX +#include "regex_r.h" // converts upper to lower case, and leaves other characters unchanged void strtolower(char *str) diff --git a/src/datastructure.h b/src/datastructure.h index 7cead939..6bd61885 100644 --- a/src/datastructure.h +++ b/src/datastructure.h @@ -20,4 +20,61 @@ const char *getDomainString(const int queryID); const char *getClientIPString(const int queryID); const char *getClientNameString(const int queryID); +typedef struct { + unsigned char magic; + unsigned char type; + unsigned char status; + unsigned char privacylevel; + unsigned char reply; + unsigned char dnssec; + time_t timestamp; + int domainID; + int clientID; + int forwardID; + int id; // the ID is a (signed) int in dnsmasq, so no need for a long int here + unsigned long response; // saved in units of 1/10 milliseconds (1 = 0.1ms, 2 = 0.2ms, 2500 = 250.0ms, etc.) + int64_t db; + unsigned int timeidx; + bool complete; +} queriesData; + +typedef struct { + unsigned char magic; + size_t ippos; + size_t namepos; + int count; + int failed; + bool new; +} forwardedData; + +typedef struct { + unsigned char magic; + size_t ippos; + size_t namepos; + time_t lastQuery; + int count; + int blockedcount; + int overTime[OVERTIME_SLOTS]; + unsigned int numQueriesARP; + bool new; +} clientsData; + +typedef struct { + unsigned char magic; + unsigned char regexmatch; + size_t domainpos; + int count; + int blockedcount; +} domainsData; + +// Pointer getter functions +#define getQuery(queryID, checkMagic) _getQuery(queryID, checkMagic, __LINE__, __FUNCTION__, __FILE__) +queriesData* _getQuery(int queryID, bool checkMagic, int line, const char * function, const char * file); +#define getClient(clientID, checkMagic) _getClient(clientID, checkMagic, __LINE__, __FUNCTION__, __FILE__) +clientsData* _getClient(int clientID, bool checkMagic, int line, const char * function, const char * file); +#define getDomain(domainID, checkMagic) _getDomain(domainID, checkMagic, __LINE__, __FUNCTION__, __FILE__) +domainsData* _getDomain(int domainID, bool checkMagic, int line, const char * function, const char * file); +#define getForward(forwardID, checkMagic) _getForward(forwardID, checkMagic, __LINE__, __FUNCTION__, __FILE__) +forwardedData* _getForward(int forwardID, bool checkMagic, int line, const char * function, const char * file); + #endif //DATASTRUCTURE_H diff --git a/src/gc.c b/src/gc.c index bc619f73..3e46183c 100644 --- a/src/gc.c +++ b/src/gc.c @@ -20,6 +20,8 @@ #include "memory.h" // global variable killed #include "signals.h" +// data getter functions +#include "datastructure.h" bool doGC = false; diff --git a/src/memory.c b/src/memory.c index d9cb87ee..99e7fb63 100644 --- a/src/memory.c +++ b/src/memory.c @@ -13,9 +13,7 @@ #include "memory.h" #include "log.h" -// Fixed size structs countersStruct *counters = NULL; -overTimeData *overTime = NULL; // The special memory handling routines have to be the last ones in this source file // as we restore the original definition of the strdup, free, calloc, and realloc diff --git a/src/memory.h b/src/memory.h index 394756df..7919387c 100644 --- a/src/memory.h +++ b/src/memory.h @@ -16,6 +16,30 @@ void *FTLcalloc(size_t nmemb, size_t size, const char *file, const char *functio void *FTLrealloc(void *ptr_in, size_t size, const char *file, const char *function, const int line) __attribute__((alloc_size(2))); void FTLfree(void *ptr, const char* file, const char *function, const int line); +typedef struct { + int queries; + int blocked; + int cached; + int unknown; + int forwarded; + int clients; + int domains; + int queries_MAX; + int forwarded_MAX; + int clients_MAX; + int domains_MAX; + int strings_MAX; + int gravity; + int gravity_conf; + int querytype[TYPE_MAX-1]; + int forwardedqueries; + int reply_NODATA; + int reply_NXDOMAIN; + int reply_CNAME; + int reply_IP; + int reply_domain; +} countersStruct; + extern countersStruct *counters; #endif //MEMORY_H diff --git a/src/overTime.c b/src/overTime.c index d35d8d95..9449f820 100644 --- a/src/overTime.c +++ b/src/overTime.c @@ -15,6 +15,10 @@ #include "log.h" // global variable counters #include "memory.h" +// data getter functions +#include "datastructure.h" + +overTimeData *overTime = NULL; /** * Initialize the overTime slot diff --git a/src/overTime.h b/src/overTime.h index 8fbd5eab..d94ff433 100644 --- a/src/overTime.h +++ b/src/overTime.h @@ -22,6 +22,16 @@ unsigned int getOverTimeID(const time_t timestamp); */ void moveOverTimeMemory(const time_t mintime); +typedef struct { + unsigned char magic; + time_t timestamp; + int total; + int blocked; + int cached; + int forwarded; + int querytypedata[TYPE_MAX-1]; +} overTimeData; + extern overTimeData *overTime; #endif //OVERTIME_H diff --git a/src/regex.c b/src/regex.c index 2f0a1346..e6a5c85b 100644 --- a/src/regex.c +++ b/src/regex.c @@ -15,6 +15,8 @@ #include "memory.h" #include "log.h" #include "config.h" +// data getter functions +#include "datastructure.h" #include static int num_regex; diff --git a/src/regex_r.h b/src/regex_r.h index b7eae13b..f3e68a8d 100644 --- a/src/regex_r.h +++ b/src/regex_r.h @@ -15,4 +15,6 @@ void free_regex(void); void read_regex_from_database(void); void log_regex(const double time); +enum { REGEX_UNKNOWN, REGEX_BLOCKED, REGEX_NOTBLOCKED }; + #endif //REGEX_H diff --git a/src/setupVars.h b/src/setupVars.h index 7588be64..af3279f6 100644 --- a/src/setupVars.h +++ b/src/setupVars.h @@ -22,4 +22,6 @@ void check_blocking_status(void); extern unsigned char blockingstatus; +enum { BLOCKING_DISABLED, BLOCKING_ENABLED, BLOCKING_UNKNOWN }; + #endif //SETUPVARS_H diff --git a/src/shmem.c b/src/shmem.c index 47c9e791..171b9e57 100644 --- a/src/shmem.c +++ b/src/shmem.c @@ -14,6 +14,8 @@ #include "log.h" #include "memory.h" #include "config.h" +// data getter functions +#include "datastructure.h" /// The version of shared memory used #define SHARED_MEMORY_VERSION 6 diff --git a/src/shmem.h b/src/shmem.h index 77542850..2426592f 100644 --- a/src/shmem.h +++ b/src/shmem.h @@ -21,6 +21,12 @@ typedef struct { void *ptr; } SharedMemory; +typedef struct { + int version; + unsigned int global_shm_counter; + unsigned int next_str_pos; +} ShmSettings; + /// Create shared memory /// /// \param name the name of the shared memory