yaftab.h
Go to the documentation of this file.
1/*
2 * Copyright 2006-2025 Carnegie Mellon University
3 * See license information in LICENSE.txt.
4 */
5/*
6 * yaftab.h
7 * YAF Active Flow Table
8 *
9 * ------------------------------------------------------------------------
10 * Authors: Brian Trammell
11 * ------------------------------------------------------------------------
12 * @DISTRIBUTION_STATEMENT_BEGIN@
13 * YAF 2.18
14 *
15 * Copyright 2025 Carnegie Mellon University.
16 *
17 * NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING
18 * INSTITUTE MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON
19 * UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
20 * AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR
21 * PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF
22 * THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF
23 * ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT
24 * INFRINGEMENT.
25 *
26 * Licensed under a GNU GPL 2.0-style license, please see LICENSE.txt or
27 * contact permission@sei.cmu.edu for full terms.
28 *
29 * [DISTRIBUTION STATEMENT A] This material has been approved for public
30 * release and unlimited distribution. Please see Copyright notice for
31 * non-US Government use and distribution.
32 *
33 * This Software includes and/or makes use of Third-Party Software each
34 * subject to its own license.
35 *
36 * DM25-1281
37 * @DISTRIBUTION_STATEMENT_END@
38 * ------------------------------------------------------------------------
39 */
40
41/*
42 * This is the documentation for the _old_ yaftab.h; it is no longer current,
43 * and should not be read by anyone.
44 *
45 * Flow generation interface for YAF. This facility works by maintaining a
46 * current flow table. Packets may be added to the active flows within this
47 * table using the yfFlowPkt() call. Completed flows may be written to an
48 * IPFIX message buffer using yfFlowFlush().
49 *
50 * The flow table is configured by a number of global variables.
51 *
52 * <tt>yaf_idle</tt> sets
53 * the idle timeout in seconds. A flow that receives no packets for the idle
54 * timeout is assumed to be complete. The idle timeout is set to 300 seconds
55 * (five minutes) by default.
56 *
57 * <tt>yaf_active</tt> sets the active timeout in seconds.
58 * The maximum duration of a flow is the active timeout; additional packets
59 * for the same flow will be counted as part of a new flow. The active timeout
60 * is set to 1800 seconds (half an hour) by default.
61 *
62 * <tt>yaf_flowlim</tt> sets the maximum size of the flow table; flows
63 * exceeding
64 * this limit will be expired in least-recent order, as if they were idle. The
65 * flow limit defaults to zero, for no limit. Use this global to limit resource
66 * usage by the flow table.
67 *
68 * <tt>yaf_paylen</tt> sets the number of bytes of payload to capture from the
69 * start of each flow. The payload length defaults to zero, which disables
70 * payload capture.
71 *
72 * <tt>yaf_uniflow</tt>, if TRUE, exports flows in uniflow mode, using the
73 * record adjacency export method described in section 3 of
74 * draft-ietf-ipfix-biflow. Defaults to FALSE.
75 *
76 * <tt>yaf_macmode</tt>, if TRUE, exports layer 2 information with each flow;
77 * presently this is limited to VLAN tags but may be expanded to include the
78 * MPLS stack and MAC addresses in the future. Defaults to FALSE.
79 *
80 * <tt>yaf_silkmode</tt>, if TRUE, enables SiLK compatibility mode. In this
81 * mode, totalOctetCount and reverseTotalOctetCount are clamped to 32 bits.
82 * Any packet that would cause either of these counters to overflow 32 bits
83 * will force an active timeout. The high-order bit of the flowEndReason IE
84 * is set on any flow created on a counter overflow, as above, or on an active
85 * timeout. Defaults to FALSE.
86 *
87 * <tt>yaf_reqtype</tt> limits the flow table to collecting IPv4 or IPv6 flows
88 * only. Set to YF_TYPE_IPv4 for IPv4 flows only, YF_TYPE_IPv6 for IPv6 flows
89 * only, or YF_TYPE_IPANY (the default) to collect both IPv4 and IPv6 flows.
90 *
91 * This facility is used by YAF to assemble packets into flows.
92 */
93
101
102#ifndef _YAF_TAB_H_
103#define _YAF_TAB_H_
104
105#include <yaf/autoinc.h>
106#include <yaf/yafcore.h>
107#include <yaf/decode.h>
108
109
116#define YAF_STAT_CLOSED_SIZE 6
117
118
123typedef struct yfFlowTab_st yfFlowTab_t;
124
129typedef struct yfFlowTabConfig_st {
135 int32_t active_sec;
140 int32_t idle_sec;
147 uint32_t max_flows;
154 uint32_t max_payload;
161
166 const char *ndpi_proto_file;
167
171 const char *pcap_dir;
175 const char *pcap_meta_file;
179 uint64_t pcap_max;
187 const char *pcap_search_stime;
188
200
206
219 gboolean entropy_mode;
238 gboolean mac_mode;
242 gboolean ndpi;
252 gboolean p0f_mode;
257 gboolean pcap_index;
269 gboolean silk_mode;
281 gboolean uniflow_mode;
282
284
285
290typedef struct yfFlowTabStats_st {
294 uint64_t stat_octets;
298 uint64_t stat_packets;
302 uint64_t stat_seqrej;
306 uint64_t stat_flows;
314 uint64_t stat_opened;
322 uint32_t stat_peak;
326 uint32_t stat_flush;
330 uint32_t stat_count;
331#if YAF_MPLS
335 uint32_t max_mpls_labels;
339 uint32_t stat_mpls_labels;
340#endif
342
356 const yfFlowTabConfig_t *ftconfig,
357 void **hfctx);
358
366void
368 yfFlowTab_t *flowtab);
369
370
377void
379 yfFlowTab_t *flowtab,
380 char *new_file_name);
381
388void
390 const yfFlowTab_t *flowtab,
391 yfFlowTabStats_t *tabstats);
392
404void
406 yfFlowTab_t *flowtab,
407 size_t pbuflen,
408 yfPBuf_t *pbuf);
409
423gboolean
425 void *yfContext,
426 gboolean close,
427 GError **err);
428
435void
437 const yfFlowTab_t *flowtab,
438 yfTime_t *yftime);
439
448uint64_t
450 yfFlowTab_t *flowtab,
451 GTimer *timer);
452
453#endif /* ifndef _YAF_TAB_H_ */
Configuration settings used to initalize the flow table in yfFlowTabAlloc().
Definition yaftab.h:129
gboolean pcap_index
If TRUE, print one line per packet we export.
Definition yaftab.h:257
gboolean flowstats_mode
If TRUE, then YAF will do some extra calculations on flows.
Definition yaftab.h:223
uint32_t max_payload
Maximum octets of payload to capture per flow direction.
Definition yaftab.h:154
gboolean silk_mode
If TRUE, clamp totalOctetCount and maxTotalOctetCount to 32 bits and force active timeout on overflow...
Definition yaftab.h:269
gboolean entropy_mode
If TRUE, then a Shannon Entropy measurement is made over the captured payload (as limited by max_payl...
Definition yaftab.h:219
const char * pcap_meta_file
File for pcap meta output.
Definition yaftab.h:175
uint32_t applabel_check_early
A non-zero value enables early appLabel detection.
Definition yaftab.h:160
gboolean ndpi
If TRUE, enable nDPI application labeling with standard protocols.
Definition yaftab.h:242
const char * ndpi_proto_file
If not NULL, and ndpi is TRUE, use the provided protocol file to expand the sub-protocols list and po...
Definition yaftab.h:166
gboolean p0f_mode
If TRUE, then this will enable passive OS finger printing using the p0f engine based mostly on TCP ne...
Definition yaftab.h:252
GArray * applabel_max_paylen
Max payload length to store per appLabel.
Definition yaftab.h:199
gboolean fpexport_mode
If TRUE, then this will enable exporting of full packet banners of the TCP negotiations for the first...
Definition yaftab.h:234
gboolean uniflow_mode
If TRUE, export biflows using record adjacency (two uniflows exported back-to-back.
Definition yaftab.h:281
const char * pcap_dir
Directory to put pcap-per-flow files.
Definition yaftab.h:171
gboolean no_vlan_in_key
If TRUE, this will remove the vlan in the calculation of the flow key hash.
Definition yaftab.h:247
gboolean applabel_mode
If TRUE, then the payload, (as limited by max_payload,) is sent through various plugins and code in o...
Definition yaftab.h:213
uint16_t udp_uniflow_port
If not 0, then this will enable exporting a single UDP packet with this src/dst port as a flow.
Definition yaftab.h:205
gboolean pcap_per_flow
If TRUE, then pcap_dir will be set to the directory to place pcap-per-flow files.
Definition yaftab.h:262
uint32_t max_flows
Maximum number of active flows.
Definition yaftab.h:147
gboolean mac_mode
If TRUE, collect and export source and destination Mac Addresses.
Definition yaftab.h:238
int32_t idle_sec
Idle timeout in seconds.
Definition yaftab.h:140
uint32_t pcap_search_flowkey
The flow key hash to create a PCAP for.
Definition yaftab.h:183
int32_t active_sec
Active timeout in seconds.
Definition yaftab.h:135
uint64_t pcap_max
Maximum size [in bytes] of a pcap file before rotating.
Definition yaftab.h:179
gboolean udp_multipkt_payload
If TRUE, then this will enable capturing payload for all UDP packets in a flow (instead of just the f...
Definition yaftab.h:275
gboolean force_read_all
If TRUE, then yaf will process files that are out of sequence.
Definition yaftab.h:228
const char * pcap_search_stime
The start time to create a PCAP for.
Definition yaftab.h:187
Flow table statistics.
Definition yaftab.h:290
uint32_t stat_peak
Peak number of active flows ever held in the flow table.
Definition yaftab.h:322
uint64_t stat_opened
Number of flow records created.
Definition yaftab.h:314
uint64_t stat_uniflows
Subset of stat_flows that were uniflow (had no reverse data).
Definition yaftab.h:310
uint64_t stat_flows
Total number of flow records created.
Definition yaftab.h:306
uint64_t stat_closed[YAF_STAT_CLOSED_SIZE]
Number of flow records closed for various YAF_END_* reasons.
Definition yaftab.h:318
uint64_t stat_seqrej
Number of packets rejected because they were out of sequence.
Definition yaftab.h:302
uint32_t stat_flush
Number of flow table flush events.
Definition yaftab.h:326
uint32_t stat_count
Current number of active flow records.
Definition yaftab.h:330
uint64_t stat_octets
Sum of lengths for all packets read.
Definition yaftab.h:294
uint64_t stat_packets
Number of packets read.
Definition yaftab.h:298
YAF Core Library.
void yfFlowTabGetStats(const yfFlowTab_t *flowtab, yfFlowTabStats_t *tabstats)
Fills tabstats with a copy of the current statistics for the flow table.
void yfUpdateRollingPcapFile(yfFlowTab_t *flowtab, char *new_file_name)
Update the Pcap Filename in the Flowtab for pcap meta data output.
void yfFlowTabCurrentTime(const yfFlowTab_t *flowtab, yfTime_t *yftime)
Get the current packet clock from a flow table.
void yfFlowTabFree(yfFlowTab_t *flowtab)
Free a previously allocated flow table.
gboolean yfFlowTabFlush(void *yfContext, gboolean close, GError **err)
Flush closed flows in the given flow table to the given IPFIX Message Buffer.
#define YAF_STAT_CLOSED_SIZE
Size of yfFlowTabStats_t.stat_closed[] table for holding YAF_END_* reasons.
Definition yaftab.h:116
struct yfFlowTabConfig_st yfFlowTabConfig_t
Configuration settings used to initalize the flow table in yfFlowTabAlloc().
void yfFlowPBuf(yfFlowTab_t *flowtab, size_t pbuflen, yfPBuf_t *pbuf)
Add a decoded packet buffer to a given flow table.
struct yfFlowTabStats_st yfFlowTabStats_t
Flow table statistics.
uint64_t yfFlowTabDumpStats(yfFlowTab_t *flowtab, GTimer *timer)
Print flow table statistics to the log.
struct yfFlowTab_st yfFlowTab_t
A flow table.
Definition yaftab.h:123
yfFlowTab_t * yfFlowTabAlloc(const yfFlowTabConfig_t *ftconfig, void **hfctx)
yfFlowTabAlloc