Skip to Content
The Cooperative Association for Internet Data Analysis
DONATE
CONTACT US
HOME
RESEARCH
DATA
TOOLS
PUBLICATIONS
WORKSHOPS
PROJECTS
FUNDING
www.caida.org
>
tools
:
measurement
:
corsaro
: docs
corsaro_flowtuple.h
Go to the documentation of this file.
1
/*
2
* corsaro
3
*
4
* Alistair King, CAIDA, UC San Diego
5
* corsaro-info@caida.org
6
*
7
* Copyright (C) 2012 The Regents of the University of California.
8
*
9
* This file is part of corsaro.
10
*
11
* corsaro is free software: you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation, either version 3 of the License, or
14
* (at your option) any later version.
15
*
16
* corsaro is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
20
*
21
* You should have received a copy of the GNU General Public License
22
* along with corsaro. If not, see <http://www.gnu.org/licenses/>.
23
*
24
*/
25
26
#ifndef __CORSARO_FLOWTUPLE_H
27
#define __CORSARO_FLOWTUPLE_H
28
29
#include "khash.h"
30
#include "ksort.h"
31
32
#include "
corsaro_plugin.h
"
33
42
CORSARO_PLUGIN_GENERATE_PROTOS
(
corsaro_flowtuple
)
43
44
68
typedef struct
corsaro_flowtuple
69
{
71
uint32_t
src_ip
;
72
74
#ifdef CORSARO_SLASH_EIGHT
75
struct
76
{
78
uint8_t b;
80
uint8_t c;
82
uint8_t d;
83
} dst_ip;
84
#else
85
uint32_t
dst_ip
;
86
#endif
87
89
uint16_t
src_port
;
90
92
uint16_t
dst_port
;
93
95
uint8_t
protocol
;
96
98
uint8_t
ttl
;
99
101
uint8_t
tcp_flags
;
102
104
uint16_t
ip_len
;
105
108
uint32_t
packet_cnt
;
109
} PACKED
corsaro_flowtuple_t
;
110
112
typedef
enum
corsaro_flowtuple_class_type
113
{
115
CORSARO_FLOWTUPLE_CLASS_BACKSCATTER
= 0,
116
118
CORSARO_FLOWTUPLE_CLASS_ICMPREQ
= 1,
119
121
CORSARO_FLOWTUPLE_CLASS_OTHER
= 2,
122
124
CORSARO_FLOWTUPLE_CLASS_MAX
=
CORSARO_FLOWTUPLE_CLASS_OTHER
,
125
126
}
corsaro_flowtuple_class_type_t
;
127
132
typedef
struct
corsaro_flowtuple_class_start
133
{
135
uint32_t
magic
;
137
uint16_t
class_type
;
139
uint32_t
count
;
140
} PACKED
corsaro_flowtuple_class_start_t
;
141
146
typedef
struct
corsaro_flowtuple_class_end
147
{
149
uint32_t
magic
;
151
uint16_t
class_type
;
152
} PACKED
corsaro_flowtuple_class_end_t
;
153
171
uint32_t
corsaro_flowtuple_get_source_ip
(
corsaro_flowtuple_t
*flowtuple);
172
178
uint32_t
corsaro_flowtuple_get_destination_ip
(
corsaro_flowtuple_t
*flowtuple);
179
187
off_t
corsaro_flowtuple_fprint
(
corsaro_t
*
corsaro
,
corsaro_file_t
*file,
188
corsaro_flowtuple_t
*flowtuple);
189
194
void
corsaro_flowtuple_print
(
corsaro_flowtuple_t
*flowtuple);
195
203
off_t
corsaro_flowtuple_class_start_fprint
(
corsaro_t
*
corsaro
,
corsaro_file_t
*file,
204
corsaro_flowtuple_class_start_t
*
class
);
205
210
void
corsaro_flowtuple_class_start_print
(
corsaro_flowtuple_class_start_t
*flowtuple);
211
219
off_t
corsaro_flowtuple_class_end_fprint
(
corsaro_t
*
corsaro
,
corsaro_file_t
*file,
220
corsaro_flowtuple_class_end_t
*
class
);
221
226
void
corsaro_flowtuple_class_end_print
(
corsaro_flowtuple_class_end_t
*flowtuple);
227
236
off_t
corsaro_flowtuple_record_fprint
(
corsaro_t
*
corsaro
,
corsaro_file_t
*file,
237
corsaro_in_record_type_t
record_type,
238
corsaro_in_record_t
*record);
239
246
int
corsaro_flowtuple_record_print
(
corsaro_in_record_type_t
record_type,
247
corsaro_in_record_t
*record);
248
278
#define CORSARO_FLOWTUPLE_BYTECNT (sizeof(corsaro_flowtuple_t))
/* (4+3+2+2+1+1+1+2)+4*/
279
281
/* is this platform independent? */
282
#ifdef CORSARO_SLASH_EIGHT
283
#define CORSARO_FLOWTUPLE_IP_TO_SIXT(n32, flowtuple) \
284
{ \
285
(flowtuple)->dst_ip.b = ((n32 & htonl(0x00FF0000)) >> 8); \
286
(flowtuple)->dst_ip.c = ((n32 & htonl(0x0000FF00)) >> 16); \
287
(flowtuple)->dst_ip.d = ((n32 & htonl(0x000000FF)) >> 24); \
288
}
289
#else
290
#define CORSARO_FLOWTUPLE_IP_TO_SIXT(n32, flowtuple) \
291
{ \
292
(flowtuple)->dst_ip = n32; \
293
}
294
#endif
295
297
#ifdef CORSARO_SLASH_EIGHT
298
#define CORSARO_FLOWTUPLE_SIXT_TO_IP(flowtuple) \
299
( \
300
CORSARO_SLASH_EIGHT | \
301
(flowtuple)->dst_ip.b << 8 | \
302
(flowtuple)->dst_ip.c << 16 | \
303
(flowtuple)->dst_ip.d << 24 \
304
)
305
#else
306
#define CORSARO_FLOWTUPLE_SIXT_TO_IP(flowtuple) \
307
((flowtuple)->dst_ip)
308
#endif
309
311
#define CORSARO_FLOWTUPLE_SHIFT_AND_XOR(value) h ^= (h<<5) + (h>>27) + (value)
312
338
static
inline
khint32_t
corsaro_flowtuple_hash_func
(
corsaro_flowtuple_t
*t)
339
{
340
khint32_t h = (khint32_t)t->
src_ip
*59;
341
#ifdef CORSARO_SLASH_EIGHT
342
CORSARO_FLOWTUPLE_SHIFT_AND_XOR
((t->
dst_ip
.b<<24)|(t->
dst_ip
.c<<16)|
343
(t->
dst_ip
.d<<8)|(t->
protocol
));
344
#else
345
CORSARO_FLOWTUPLE_SHIFT_AND_XOR
(t->
dst_ip
);
346
#endif
347
CORSARO_FLOWTUPLE_SHIFT_AND_XOR
(t->
src_port
<<16);
348
CORSARO_FLOWTUPLE_SHIFT_AND_XOR
(t->
dst_port
);
349
CORSARO_FLOWTUPLE_SHIFT_AND_XOR
((t->
ttl
<<24)|(t->
tcp_flags
<<16));
350
#ifdef CORSARO_SLASH_EIGHT
351
CORSARO_FLOWTUPLE_SHIFT_AND_XOR
(t->
ip_len
);
352
#else
353
CORSARO_FLOWTUPLE_SHIFT_AND_XOR
((t->
protocol
<<8)|(t->
ip_len
));
354
#endif
355
return
h;
356
}
357
359
#ifdef CORSARO_SLASH_EIGHT
360
#define corsaro_flowtuple_hash_equal(alpha, bravo) \
361
( \
362
(alpha)->src_ip == (bravo)->src_ip && \
363
(alpha)->dst_ip.b == (bravo)->dst_ip.b && \
364
(alpha)->dst_ip.c == (bravo)->dst_ip.c && \
365
(alpha)->dst_ip.d == (bravo)->dst_ip.d && \
366
(alpha)->src_port == (bravo)->src_port && \
367
(alpha)->dst_port == (bravo)->dst_port && \
368
(alpha)->protocol == (bravo)->protocol && \
369
(alpha)->ttl == (bravo)->ttl && \
370
(alpha)->tcp_flags == (bravo)->tcp_flags && \
371
(alpha)->ip_len == (bravo)->ip_len \
372
)
373
#else
374
#define corsaro_flowtuple_hash_equal(alpha, bravo) \
375
( \
376
(alpha)->src_ip == (bravo)->src_ip && \
377
(alpha)->dst_ip == (bravo)->dst_ip && \
378
(alpha)->src_port == (bravo)->src_port && \
379
(alpha)->dst_port == (bravo)->dst_port && \
380
(alpha)->protocol == (bravo)->protocol && \
381
(alpha)->ttl == (bravo)->ttl && \
382
(alpha)->tcp_flags == (bravo)->tcp_flags && \
383
(alpha)->ip_len == (bravo)->ip_len \
384
)
385
#endif
386
392
#ifdef CORSARO_SLASH_EIGHT
393
#define corsaro_flowtuple_lt(alpha, bravo) \
394
( \
395
((alpha)->protocol < (bravo)->protocol) || \
396
( \
397
((alpha)->protocol == (bravo)->protocol) && \
398
( \
399
((alpha)->ttl < (bravo)->ttl) || \
400
( \
401
((alpha)->ttl == (bravo)->ttl) && \
402
( \
403
((alpha)->tcp_flags < (bravo)->tcp_flags) || \
404
( \
405
((alpha)->tcp_flags == (bravo)->tcp_flags) && \
406
( \
407
((alpha)->src_ip < (bravo)->src_ip) || \
408
( \
409
((alpha)->src_ip == (bravo)->src_ip) && \
410
( \
411
((alpha)->dst_ip.b < (bravo)->dst_ip.b) || \
412
( \
413
((alpha)->dst_ip.b == (bravo)->dst_ip.b) && \
414
( \
415
((alpha)->dst_ip.c < (bravo)->dst_ip.c) || \
416
( \
417
((alpha)->dst_ip.c == (bravo)->dst_ip.c) && \
418
( \
419
((alpha)->dst_ip.d < (bravo)->dst_ip.d) || \
420
( \
421
((alpha)->dst_ip.d == (bravo)->dst_ip.d) && \
422
( \
423
((alpha)->src_port < (bravo)->src_port) || \
424
( \
425
((alpha)->src_port == (bravo)->src_port) && \
426
( \
427
((alpha)->dst_port < (bravo)->dst_port) || \
428
( \
429
((alpha)->dst_port == (bravo)->dst_port) && \
430
( \
431
((alpha)->ip_len < (bravo)->ip_len) \
432
) \
433
) \
434
) \
435
) \
436
) \
437
) \
438
) \
439
) \
440
) \
441
) \
442
) \
443
) \
444
) \
445
) \
446
) \
447
) \
448
) \
449
) \
450
)
451
#else
452
#define corsaro_flowtuple_lt(alpha, bravo) \
453
( \
454
((alpha)->protocol < (bravo)->protocol) || \
455
( \
456
((alpha)->protocol == (bravo)->protocol) && \
457
( \
458
((alpha)->ttl < (bravo)->ttl) || \
459
( \
460
((alpha)->ttl == (bravo)->ttl) && \
461
( \
462
((alpha)->tcp_flags < (bravo)->tcp_flags) || \
463
( \
464
((alpha)->tcp_flags == (bravo)->tcp_flags) && \
465
( \
466
((alpha)->src_ip < (bravo)->src_ip) || \
467
( \
468
((alpha)->src_ip == (bravo)->src_ip) && \
469
( \
470
((alpha)->dst_ip < (bravo)->dst_ip) || \
471
( \
472
((alpha)->dst_ip == (bravo)->dst_ip) && \
473
( \
474
((alpha)->src_port < (bravo)->src_port) || \
475
( \
476
((alpha)->src_port == (bravo)->src_port) && \
477
( \
478
((alpha)->dst_port < (bravo)->dst_port) || \
479
( \
480
((alpha)->dst_port == (bravo)->dst_port) && \
481
( \
482
((alpha)->ip_len < (bravo)->ip_len) \
483
) \
484
) \
485
) \
486
) \
487
) \
488
) \
489
) \
490
) \
491
) \
492
) \
493
) \
494
) \
495
) \
496
) \
497
)
498
#endif
499
504
void
corsaro_flowtuple_free
(
corsaro_flowtuple_t
*t);
505
512
int
corsaro_flowtuple_add_inc
(
void
*hash,
corsaro_flowtuple_t
*t,
int
increment);
513
516
#endif
/* __CORSARO_FLOWTUPLE_H */
517