forked from blechschmidt/massdns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmassdns.h
165 lines (146 loc) · 3.66 KB
/
massdns.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#ifndef MASSDNS_MASSDNS_H
#define MASSDNS_MASSDNS_H
#include <stdint.h>
#include <time.h>
#include <sys/socket.h>
#include <sys/epoll.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "list.h"
#include "module.h"
#include "net.h"
#include "hashmap.h"
#include "dns.h"
#include "timed_ring.h"
#define MAXIMUM_MODULE_COUNT 0xFF
#define COMMON_UNPRIVILEGED_USER "nobody"
const uint32_t OUTPUT_BINARY_VERSION = 0x00;
typedef struct
{
size_t answers;
size_t noerr;
size_t formerr;
size_t servfail;
size_t nxdomain;
size_t notimp;
size_t refused;
size_t yxdomain;
size_t yxrrset;
size_t nxrrset;
size_t notauth;
size_t notzone;
size_t timeout;
size_t mismatch;
size_t other;
size_t qsent;
size_t numreplies;
size_t fakereplies; // used for resolver plausibility checks (wrong records)
} resolver_stats_t;
typedef struct
{
struct sockaddr_storage address;
resolver_stats_t stats; // To be used to track resolver bans or non-replying resolvers
} resolver_t;
typedef struct
{
char *domain;
dns_record_type type;
} lookup_key_t;
typedef struct
{
unsigned char tries;
uint16_t transaction;
void **ring_entry; // pointer to the entry within the timed ring for entry invalidation
resolver_t *resolver;
lookup_key_t *key;
} lookup_t;
typedef enum
{
STATE_WARMUP, // Before the hash map size has been reached
STATE_QUERYING,
STATE_COOLDOWN,
STATE_DONE
} state_t;
typedef enum
{
OUTPUT_TEXT_FULL,
OUTPUT_TEXT_SIMPLE,
OUTPUT_BINARY
} output_t;
const char *default_interfaces[] = {""};
typedef struct
{
buffer_t resolvers;
struct
{
massdns_module_t handlers[MAXIMUM_MODULE_COUNT]; // we only support up to 255 modules
size_t count;
} modules;
struct cmd_args
{
bool root;
char *resolvers;
char *domains;
uint8_t resolve_count;
size_t hashmap_size;
unsigned int interval_ms;
bool norecurse;
bool finalstats;
bool quiet;
int sndbuf;
int rcvbuf;
char *drop_user;
dns_record_type record_type;
size_t timed_ring_buckets;
int extreme; // Do not remove EPOLLOUT after warmup
output_t output;
bool retry_codes[0xFFFF]; // Fast lookup map for DNS reply codes that are unacceptable and require a retry
bool retry_codes_set;
single_list_t bind_addrs4;
single_list_t bind_addrs6;
bool sticky;
int argc;
char **argv;
void (*help_function)();
bool flush;
} cmd_args;
struct
{
buffer_t interfaces4; // Sockets used for receiving queries
buffer_t interfaces6; // Sockets used for receiving queries
buffer_t queries; // Sockets used for sending out queries
int *pipes;
socket_info_t read_pipe;
} sockets;
FILE* outfile;
FILE* logfile;
FILE* domainfile;
ssize_t domainfile_size;
int epollfd;
Hashmap *map;
state_t state;
timed_ring_t ring; // handles timeouts
size_t lookup_index;
size_t fork_index;
struct
{
struct timespec start_time;
size_t mismatch;
size_t other;
size_t qsent;
size_t numreplies;
size_t numparsed;
size_t numdomains;
struct timespec last_print;
size_t current_rate;
size_t timeouts[0x100];
size_t final_rcodes[0x10000];
size_t all_rcodes[0x10000];
size_t finished;
size_t finished_success;
size_t mismatch_id;
size_t mismatch_domain;
} stats;
} massdns_context_t;
massdns_context_t context;
#endif //MASSDNS_MASSDNS_H