-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathf2k.h
316 lines (242 loc) · 6.5 KB
/
f2k.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
Copyright (C) 2016 Eneo Tecnologia S.L.
Author: Eugenio Perez <eupm90@gmail.com>
Based on Luca Deri nprobe 6.22 collector
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
/* *************************** */
#include "rb_listener.h"
#include "config.h"
#include "netflow.h"
#if defined(linux) || defined(__linux__)
/*
* This allows to hide the (minimal) differences between Linux and BSD
*/
#include <features.h>
#ifndef __FAVOR_BSD
#define __FAVOR_BSD
#endif
#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif
#endif /* linux || __linux__ */
#include <limits.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/ip.h>
#include <netinet/ip6.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <netinet/ip_icmp.h>
#include <stdbool.h>
#include "pcap.h"
/* GeoIP */
#ifdef HAVE_GEOIP
#include "GeoIP.h"
#include "GeoIPCity.h"
#endif
#ifdef HAVE_LIBRDKAFKA
#include "librdkafka/rdkafka.h"
#endif
#ifdef HAVE_ZOOKEEPER
#include <zookeeper/zookeeper.h>
#endif
#ifdef HAVE_UDNS
#include <udns.h>
#endif
#include "template.h"
/*
* Structure of a 10Mb/s Ethernet header.
*/
struct eth_header {
uint8_t ether_dhost[6];
uint8_t ether_shost[6];
uint16_t ether_type;
};
#define PREFIX "/usr/local"
#include "collect.h"
#include "version.h"
/* ********* NETFLOW ****************** */
/*
For more info see:
http://www.cisco.com/warp/public/cc/pd/iosw/ioft/neflct/tech/napps_wp.htm
ftp://ftp.net.ohio-state.edu/users/maf/cisco/
*/
/* NetFlow v9/IPFIX */
#define STANDARD_ENTERPRISE_ID 0
#define NTOP_ENTERPRISE_ID 0x00008B30 /* IANA assignment for ntop */
#define CISCO_ENTERPRISE_ID 9
#define QUOTE_OUTPUT true
#define DONT_QUOTE_OUTPUT false
#define FLOW_TEMPLATE 0
#define OPTION_TEMPLATE 1
typedef struct flow_ver9_template_field {
const V9V10TemplateElementId *v9_template;
uint16_t fieldId;
uint16_t fieldLen;
} V9V10TemplateField;
typedef struct flow_ver9_ipfix_simple_template {
uint32_t netflow_device_ip, observation_domain_id;
/* V9TemplateDef */
uint16_t templateId;
uint16_t fieldCount, scope_field_len;
bool is_option_template;
} V9IpfixSimpleTemplate;
typedef struct flowSetV9Ipfix {
V9IpfixSimpleTemplate templateInfo;
V9V10TemplateField *fields;
LIST_ENTRY(flowSetV9Ipfix) entry;
} FlowSetV9Ipfix;
/* ******************************************* */
#define NETFLOW_BUFFER_LEN (16*1024)
#define ACT_NUM_PCAP_THREADS 2
#define MAX_NUM_PCAP_THREADS 32
typedef unsigned long long ticks;
/* It must stay here as it needs the definition of v9 types */
#include "util.h"
#ifdef HAVE_PF_RING
#include "pro/pf_ring.h"
#define CHECKSUM
#endif
#ifndef DARWIN
#include <getopt.h>
#endif
/* **************************************************************** */
#define MAX_NUM_COLLECTOR_THREADS MAX_NUM_PCAP_THREADS
#define MAX_NUM_OPTIONS 128
/* ********************************************* */
struct fileList {
char *path;
struct fileList *next;
};
typedef struct {
bool becomeDaemon;
// will transform L2, L3 and L4 src/dst into lan/wan
bool normalize_directions;
/* Expanded copy of CLI arguments */
int argc;
char **argv;
size_t capture_num_packet_and_quit;
bool promisc_mode, enableGeoIP;
bool separate_long_flows;
char *unprivilegedUser;
#ifdef linux
char *cpuAffinity; /* NULL means no affinity */
#endif
char f2kId[255+1];
struct fileList *pcapFileList;
char *pcapFile, *pidPath;
pcap_t *pcapPtr;
#ifdef HAVE_NETFILTER
struct {
struct nfq_handle *h;
struct nfq_q_handle *qh;
int queueId, fd;
uint32_t nf_verdict, nf_mark;
unsigned long thread_id;
} nf;
#endif
#ifdef HAVE_PF_RING
int cluster_id;
#endif
int datalink;
char *captureDev;
uint16_t snaplen;
bool do_not_drop_privileges;
/* Logging */
char *eventLogPath;
/* Export Options */
size_t numProcessThreads;
bool useSyslog;
int traceLevel;
worker_t **packetProcessThread;
#ifdef HAVE_GEOIP
/* GeoIP */
GeoIP *geo_ip_asn_db, *geo_ip_asn_db_v6;
GeoIP *geo_ip_country_db, *geo_ip_country_db_v6;
#endif
/* Collector */
listener_list listeners;
/* Status */
bool f2k_up; // TODO delete this!
/* Performance test */
bool tracePerformance;
pthread_rwlock_t ticksLock;
ticks decodeTicks;
unsigned long f2kPid; /* 0 on Windows */
bool enable_debug,
reproduceDumpAtRealSpeed,reforgeTimestamps,dontReforgeFarTimestamp;
#ifdef HAVE_LIBRDKAFKA
struct {
rd_kafka_t *rk;
rd_kafka_topic_t *rkt;
bool use_client_mac_partitioner;
} kafka;
struct {
rd_kafka_t *rk;
rd_kafka_topic_t *rkt;
} kafka_discarder;
struct {
rd_kafka_conf_t *conf;
char *topic;
} kafka_consumer;
#endif
#ifdef HAVE_ZOOKEEPER
struct {
pthread_rwlock_t rwlock;
zhandle_t *zh;
char *zk_host;
/* @TODO ZK handler will write to this log some times */
size_t log_buffer_size;
char *log_buffer;
FILE *log_buffer_f;
// Time with the last template get.
bool need_to_reconnect;
volatile time_t last_template_get_timestamp;
double update_template_timeout;
pthread_t zk_wathcher;
} zk;
#endif
#ifdef HAVE_UDNS
struct {
struct dns_cache *cache;
char *csv_dns_servers;
struct rb_dns_info *dns_info_array;
rd_thread_t **dns_poll_threads;
} udns;
#endif
struct rb_databases rb_databases;
char templates_database_path[PATH_MAX];
} ReadOnlyGlobals;
typedef struct {
bool shutdownInProgress, stopPacketCapture, endOfPcapReached;
#ifdef HAVE_GEOIP
pthread_rwlock_t geoipRwLock;
#endif
#ifdef HAVE_ZOOKEEPER
/* Collector */
struct {
atomic_uint64_t num_zk_templates_received;
} collectionStats;
#endif
bool syslog_opened;
#ifdef HAVE_PF_RING
bool ring_enabled;
pfring *ring;
#endif
/* Stats */
uint64_t last_ps_recv, last_ps_drop;
} ReadWriteGlobals;
extern ReadOnlyGlobals readOnlyGlobals;
extern ReadWriteGlobals *readWriteGlobals;