-
-
Notifications
You must be signed in to change notification settings - Fork 185
/
datastructure.h
122 lines (108 loc) · 3.94 KB
/
datastructure.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* Pi-hole: A black hole for Internet advertisements
* (c) 2019 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* FTL Engine
* Datastructure prototypes
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
#ifndef DATASTRUCTURE_H
#define DATASTRUCTURE_H
// Definition of sqlite3_stmt
#include "database/sqlite3.h"
// enum privacy_level
#include "enums.h"
extern const char *querytypes[TYPE_MAX];
typedef struct {
unsigned char magic;
enum query_status status;
enum query_types type;
enum privacy_level privacylevel;
enum reply_type reply;
enum dnssec_status dnssec;
time_t timestamp;
int domainID;
int clientID;
int upstreamID;
int id; // the ID is a (signed) int in dnsmasq, so no need for a long int here
int CNAME_domainID; // only valid if query has a CNAME blocking status
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 whitelisted;
bool complete;
} queriesData;
typedef struct {
unsigned char magic;
bool new;
in_addr_t port;
int count;
int failed;
size_t ippos;
size_t namepos;
time_t lastQuery;
} upstreamsData;
typedef struct {
unsigned char magic;
unsigned char reread_groups;
char hwlen;
unsigned char hwaddr[16]; // See DHCP_CHADDR_MAX in dnsmasq/dhcp-protocol.h
bool new;
bool found_group;
bool aliasclient;
int count;
int blockedcount;
int aliasclient_id;
int overTime[OVERTIME_SLOTS];
unsigned int id;
unsigned int numQueriesARP;
size_t groupspos;
size_t ippos;
size_t namepos;
size_t ifacepos;
time_t lastQuery;
time_t firstSeen;
} clientsData;
typedef struct {
unsigned char magic;
size_t domainpos;
int count;
int blockedcount;
} domainsData;
typedef struct {
unsigned char magic;
enum domain_client_status blocking_status;
unsigned char force_reply;
enum query_types query_type;
int domainID;
int clientID;
int black_regex_idx;
} DNSCacheData;
void strtolower(char *str);
int findQueryID(const int id);
int findUpstreamID(const char * upstream, const in_port_t port, const bool count);
int findDomainID(const char *domain, const bool count);
int findClientID(const char *client, const bool count, const bool aliasclient);
int findCacheID(int domainID, int clientID, enum query_types query_type);
bool isValidIPv4(const char *addr);
bool isValidIPv6(const char *addr);
void FTL_reload_all_domainlists(void);
void FTL_reset_per_client_domain_data(void);
const char *getDomainString(const queriesData* query);
const char *getCNAMEDomainString(const queriesData* query);
const char *getClientIPString(const queriesData* query);
const char *getClientNameString(const queriesData* query);
void change_clientcount(clientsData *client, int total, int blocked, int overTimeIdx, int overTimeMod);
// 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 getUpstream(upstreamID, checkMagic) _getUpstream(upstreamID, checkMagic, __LINE__, __FUNCTION__, __FILE__)
upstreamsData* _getUpstream(int upstreamID, bool checkMagic, int line, const char * function, const char * file);
#define getDNSCache(cacheID, checkMagic) _getDNSCache(cacheID, checkMagic, __LINE__, __FUNCTION__, __FILE__)
DNSCacheData* _getDNSCache(int cacheID, bool checkMagic, int line, const char * function, const char * file);
#endif //DATASTRUCTURE_H