yafcore.h
Go to the documentation of this file.
1/*
2 * Copyright 2006-2026 Carnegie Mellon University
3 * See license information in LICENSE.txt.
4 */
5/*
6 *
7 * yafcore.h
8 * YAF core I/O routines
9 *
10 * ------------------------------------------------------------------------
11 * Authors: Brian Trammell
12 * ------------------------------------------------------------------------
13 * @DISTRIBUTION_STATEMENT_BEGIN@
14 * YAF 2.19
15 *
16 * Copyright 2026 Carnegie Mellon University.
17 *
18 * NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING
19 * INSTITUTE MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON
20 * UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
21 * AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR
22 * PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF
23 * THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF
24 * ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT
25 * INFRINGEMENT.
26 *
27 * Licensed under a GNU GPL 2.0-style license, please see LICENSE.txt or
28 * contact permission@sei.cmu.edu for full terms.
29 *
30 * [DISTRIBUTION STATEMENT A] This material has been approved for public
31 * release and unlimited distribution. Please see Copyright notice for
32 * non-US Government use and distribution.
33 *
34 * This Software includes and/or makes use of Third-Party Software each
35 * subject to its own license.
36 *
37 * DM26-0194
38 * @DISTRIBUTION_STATEMENT_END@
39 * ------------------------------------------------------------------------
40 */
41
74
81
82#ifndef _YAF_CORE_H_
83#define _YAF_CORE_H_
84
85#include <yaf/autoinc.h>
86#include <fixbuf/public.h>
87#include <yaf/yaftime.h>
88
89
95#define CERT_PEN 6871
96
102#define YAF_ERROR_DOMAIN (g_quark_from_string("certYAFError"))
104#define YAF_ERROR_HEADER 1
106#define YAF_ERROR_ARGUMENT 2
108#define YAF_ERROR_IO 3
110#define YAF_ERROR_IPFIX 4
112#define YAF_ERROR_IMPL 5
114#define YAF_ERROR_INTERNAL 6
116#define YAF_ERROR_LIMIT 7
118#define YAF_ERROR_EOF 8
120#define YAF_ERROR_ALIGNMENT 9
122#define YAF_ERROR_PACKET_PAYLOAD 10
123
124
125
126/* The YAF_END_* values are used as indexes into the
127 * yfFlowTabStats_t.stat_closed[] array in yaftab.h. */
128
133#define YAF_FLOW_ACTIVE 0
135#define YAF_END_IDLE 1
137#define YAF_END_ACTIVE 2
139#define YAF_END_CLOSED 3
141#define YAF_END_FORCED 4
143#define YAF_END_RESOURCE 5
145#define YAF_END_UDPFORCE 0x1F
147#define YAF_END_MASK 0x7F
149#define YAF_ENDF_ISCONT 0x80
150
152/* YAF_ATTR_SAME_SIZE in yaf-3 */
153#define YAF_SAME_SIZE 0x01
155/* YAF_ATTR_OUT_OF_SEQUENCE in yaf-3 */
156#define YAF_OUT_OF_SEQUENCE 0x02
158/* YAF_ATTR_MP_CAPABLE in yaf-3 */
159#define YAF_MP_CAPABLE 0x04
161/* YAF_ATTR_FRAGMENTS in yaf-3 */
162#define YAF_FRAGMENTS 0x08
164#define YAF_PARTIAL_FRAGS 0x10
166#define YAF_FRAG_ACTIVE 0x03
168#define YAF_FRAG_PASSIVE 0x04
169
171#define YAF_IP_ICMP 1
173#define YAF_IP_TCP 6
175#define YAF_IP_UDP 17
176
180#define YFP_IPTCPHEADER_SIZE 128
182#define ETHERNET_MAC_ADDR_LENGTH 6
184#define YAF_MAX_HOOKS 4
185
188#define YAF_HOOKS_MAX_EXPORT 1500
190#define YAF_MAX_PKT_BOUNDARY 25
192#define YAF_PCAP_MAX 5000000
194#define YAF_MAX_MPLS_LABELS 3
195
198#define YAF_SMALL_PKT_BOUND 60
201#define YAF_LARGE_PKT_BOUND 225
202
203
207typedef struct yfConfig_st yfConfig_t;
208
212typedef struct yfContext_st yfContext_t;
213
214
228
230#define YF_TIME_IE__FIRST YF_TIME_IE_MILLI
231
233#define YF_TIME_IE__LAST YF_TIME_IE_NANO
234
236#define YF_TIME_IE__DEFAULT (YF_TIME_IE_MILLI | YF_TIME_IE_MICRO)
237
241#define yfRecordTimeIEBitSet(t_) (1 << ((t_) - 1))
242
246#define yfRecordTimeIEBitCheck(bits_, t_) ((bits_) & yfRecordTimeIEBitSet(t_))
247
248
256typedef struct yfFlowKey_st {
258 uint16_t sp;
260 uint16_t dp;
262 uint8_t proto;
264 uint8_t version;
266 uint16_t vlanId;
268 uint8_t tos;
272#if YAF_ENABLE_DAG_SEPARATE_INTERFACES || YAF_ENABLE_SEPARATE_INTERFACES
273 uint8_t netIf;
274#endif
276 uint32_t layer2Id;
278 union {
279 struct {
281 uint32_t sip;
283 uint32_t dip;
284 } v4;
285 struct {
287 uint8_t sip[16];
289 uint8_t dip[16];
290 } v6;
293
297typedef struct yfFlowStats_st {
299 uint64_t iaarray[10];
301 uint32_t pktsize[10];
303 uint64_t payoct;
305 yfTime_t ltime;
307 uint32_t tcpurgct;
309 uint32_t smallpktct;
313 uint32_t largepktct;
315 uint32_t aitime;
317 uint32_t firstpktsize;
319 uint32_t maxpktsize;
321
326typedef struct yfFlowVal_st {
328 uint64_t oct;
330 uint64_t pkt;
331#if YAF_ENABLE_PAYLOAD
336 uint32_t *paybounds;
340 uint8_t *payload;
347 uint32_t paylen;
348#endif /* if YAF_ENABLE_PAYLOAD */
350 uint32_t isn;
352 uint32_t lsn;
356 uint16_t attributes;
358 uint16_t vlan;
360 uint8_t iflags;
362 uint8_t uflags;
364 uint8_t appkt;
367#if YAF_ENABLE_SEPARATE_INTERFACES
368 uint8_t netIf;
369#endif
370#if YAF_ENABLE_ENTROPY
372 uint8_t entropy;
373#endif /* if YAF_ENABLE_ENTROPY */
374#if YAF_ENABLE_P0F
376 const char *osname;
378 const char *osver;
380 char *osFingerPrint;
381#endif /* if YAF_ENABLE_P0F */
382#if YAF_ENABLE_FPEXPORT
384 uint32_t firstPacketLen;
386 uint32_t secondPacketLen;
388 uint8_t *firstPacket;
390 uint8_t *secondPacket;
391#endif /* if YAF_ENABLE_FPEXPORT */
395
396#if YAF_MPLS
397typedef struct yfMPLSNode_st {
399 GHashTable *tab;
401 uint32_t mpls_label[YAF_MAX_MPLS_LABELS];
403 int tab_count;
404} yfMPLSNode_t;
405#endif /* if YAF_MPLS */
406
407typedef struct yaf_mptcp_st {
409 uint64_t idsn;
411 uint32_t token;
413 uint16_t mss;
415 uint8_t addrid;
417 uint8_t flags;
418} yaf_mptcp_t;
419
420
427typedef struct yfFlow_st {
429 yfTime_t stime;
431 yfTime_t etime;
432#ifdef YAF_ENABLE_HOOKS
437 void *hfctx[YAF_MAX_HOOKS];
438#endif
439 /*
440 * Reverse flow delta start time. Equivalent to initial packet round-trip
441 * time; useful for decomposing biflows into uniflows.
442 */
443 yfDiffTime_t rdtime;
444#if YAF_ENABLE_APPLABEL
446 uint16_t appLabel;
447#endif
448#if YAF_ENABLE_NDPI
449 uint16_t ndpi_master;
450 uint16_t ndpi_sub;
451#endif
453 uint8_t reason;
455 uint8_t pcap_serial;
463 uint8_t pktdir;
465 uint8_t rtos;
467 pcap_dumper_t *pcap;
468#if YAF_MPLS
470 yfMPLSNode_t *mpls;
471#endif
473 yaf_mptcp_t mptcp;
481
490void
492 void);
493
494
503void
505 yfFlow_t *flow);
506
514void
516 yfFlow_t *flow);
517
528fBuf_t *
530 const char *path,
531 const yfConfig_t *yfConfig,
532 GError **err);
533
546fBuf_t *
548 FILE *fp,
549 const yfConfig_t *yfConfig,
550 GError **err);
551
560fBuf_t *
562 fbConnSpec_t *spec,
563 const yfConfig_t *yfConfig,
564 GError **err);
565
566
567#ifdef HAVE_SPREAD
579fBuf_t *
580yfWriterForSpread(
581 fbSpreadParams_t *params,
582 uint16_t *spreadGroupIndex,
583 const yfConfig_t *yfConfig,
584 GError **err);
585#endif /* HAVE_SPREAD */
586
599gboolean
601 yfContext_t *yfContext,
602 uint32_t pcap_drop,
603 GTimer *timer,
604 GError **err);
605
620gboolean
622 yfContext_t *yfContext,
623 uint32_t pcap_drop,
624 GTimer *timer,
625 GError **err);
626
638gboolean
640 yfContext_t *yfContext,
641 GError **err);
642
654gboolean
656 yfContext_t *yfContext,
657 yfFlow_t *flow,
658 GError **err);
659
671gboolean
673 fBuf_t *fbuf,
674 gboolean flush,
675 GError **err);
676
689fBuf_t *
691 fBuf_t *fbuf,
692 FILE *fp,
693 GError **err);
694
710fbListener_t *
712 fbConnSpec_t *spec,
713 fbListenerAppInit_fn appinit,
714 fbListenerAppFree_fn appfree,
715 GError **err);
716
733gboolean
735 fBuf_t *fbuf,
736 yfFlow_t *flow,
737 GError **err);
738
756gboolean
758 fBuf_t *fbuf,
759 yfFlow_t *flow,
760 GError **err);
761
772void
774 GString *rstr,
775 const yfFlow_t *flow);
776
788void
790 GString *rstr,
791 const yfFlow_t *flow,
792 gboolean yaft_mac);
793
806gboolean
808 FILE *out,
809 const yfFlow_t *flow,
810 GError **err);
811
825gboolean
827 FILE *out,
828 const yfFlow_t *flow,
829 gboolean yaft_mac,
830 GError **err);
831
840void
842 FILE *out,
843 gboolean yaft_mac,
844 GError **err);
845
846#if YAF_ENABLE_HOOKS
852fbInfoModel_t *
853yfDPIInfoModel(
854 void);
855#endif /* if YAF_ENABLE_HOOKS */
856
857#endif /* ifndef _YAF_CORE_H_ */
Definition yafcore.h:407
uint64_t idsn
initial data seq no.
Definition yafcore.h:409
uint16_t mss
max segment size
Definition yafcore.h:413
uint8_t flags
hash_flags
Definition yafcore.h:417
uint32_t token
receiver token
Definition yafcore.h:411
uint8_t addrid
addr id
Definition yafcore.h:415
A YAF flow.
Definition yafcore.h:427
yfFlowVal_t rval
Reverse value.
Definition yafcore.h:477
yaf_mptcp_t mptcp
MPTCP Flow.
Definition yafcore.h:473
uint8_t pcap_serial
Keep track of number of pcap files for this flow.
Definition yafcore.h:455
yfTime_t etime
Flow end time.
Definition yafcore.h:431
yfTime_t stime
Flow start time.
Definition yafcore.h:429
uint8_t rtos
reverse ToS (fwd in flowKey)
Definition yafcore.h:465
uint8_t pktdir
non empty packet directions, 1, or 0
Definition yafcore.h:463
yfFlowKey_t key
Flow key.
Definition yafcore.h:479
uint8_t destinationMacAddr[ETHERNET_MAC_ADDR_LENGTH]
destination Mac Address
Definition yafcore.h:459
uint8_t sourceMacAddr[ETHERNET_MAC_ADDR_LENGTH]
src Mac Address
Definition yafcore.h:457
pcap_dumper_t * pcap
Pcap File Ptr.
Definition yafcore.h:467
yfFlowVal_t val
Forward value.
Definition yafcore.h:475
uint8_t pcap_file_no
Pcap File "ID" so we know when to make entries in metadata file.
Definition yafcore.h:461
uint8_t reason
Flow termination reason (YAF_END_ macros, per IPFIX standard)
Definition yafcore.h:453
A YAF flow key.
Definition yafcore.h:256
uint8_t tos
Type of Service/Traffic Class.
Definition yafcore.h:268
uint8_t version
IP Version.
Definition yafcore.h:264
uint32_t sip
Source IPv4 address.
Definition yafcore.h:281
uint32_t dip
Destination IPv4 address.
Definition yafcore.h:283
uint16_t sp
Source transport port.
Definition yafcore.h:258
uint16_t dp
Destination transport port.
Definition yafcore.h:260
uint16_t vlanId
VLAN Tag - only fwd.
Definition yafcore.h:266
union yfFlowKey_st::@126120373134135171060051037243273255243002257276 addr
IP address two-tuple union.
uint8_t proto
IP protocol.
Definition yafcore.h:262
uint32_t layer2Id
for DAG cards need to record the interface, may only be seeing unidirectional flows on each interface...
Definition yafcore.h:276
yaf enhanced flow statistics, used in flowstats_mode (yaf –flow-stats)
Definition yafcore.h:297
uint32_t smallpktct
Number of packets with fewer than YAF_SMALL_PKT_BOUND bytes of data.
Definition yafcore.h:309
uint32_t nonemptypktct
total number of non empty pkts
Definition yafcore.h:311
uint64_t iaarray[10]
to calculate inter-packet delay
Definition yafcore.h:299
uint32_t maxpktsize
largest pkt size
Definition yafcore.h:319
uint32_t largepktct
Number of packets with more than YAF_LARGE_PKT_BOUND bytes of data.
Definition yafcore.h:313
uint32_t aitime
average interarrival time in milliseconds
Definition yafcore.h:315
uint32_t firstpktsize
payload length of first non-empty pkt
Definition yafcore.h:317
uint32_t tcpurgct
Number of urgent packets.
Definition yafcore.h:307
uint32_t pktsize[10]
to calculate distribution of packet payload size
Definition yafcore.h:301
uint64_t payoct
total amount of payload data
Definition yafcore.h:303
yfTime_t ltime
used to calculate interarrival time
Definition yafcore.h:305
A YAF uniflow value.
Definition yafcore.h:326
uint64_t pkt
Packet count.
Definition yafcore.h:330
uint32_t lsn
Last TCP sequence number.
Definition yafcore.h:352
uint8_t appkt
Packets with payload, used when determining YAF_ATTR_SAME_SIZE.
Definition yafcore.h:364
uint8_t iflags
Initial TCP flags.
Definition yafcore.h:360
yfFlowStats_t * stats
Detailed yaf flow statistics used in flowstats_mode.
Definition yafcore.h:393
bool applabel_tried
Whether appLabel has been attempted for this uniflow.
Definition yafcore.h:366
uint64_t oct
Octet count.
Definition yafcore.h:328
uint16_t first_pkt_size
First Packet Size - to determine whether to set YAF_ATTR_SAME_SIZE.
Definition yafcore.h:354
uint16_t attributes
flowAttributes
Definition yafcore.h:356
uint8_t uflags
Union of remaining TCP flags.
Definition yafcore.h:362
uint16_t vlan
VLAN TAG (also in key, but want to record both sides)
Definition yafcore.h:358
uint32_t isn
Initial TCP sequence number.
Definition yafcore.h:350
fBuf_t * yfWriterForSpec(fbConnSpec_t *spec, const yfConfig_t *yfConfig, GError **err)
Get an IPFIX message buffer for writing YAF flows to a socket.
#define YAF_MAX_MPLS_LABELS
Maximum number of labels we're going to keep around.
Definition yafcore.h:194
struct yfFlowKey_st yfFlowKey_t
A YAF flow key.
enum yfRecordTimeIE_en yfRecordTimeIE_t
Type to specify which timestamps are included.
#define YAF_MAX_HOOKS
maximum number of hooks (plugins) allowed at one time
Definition yafcore.h:184
gboolean yfReadFlowExtended(fBuf_t *fbuf, yfFlow_t *flow, GError **err)
Read a single flow from an IPFIX message buffer.
gboolean yfPrint(FILE *out, const yfFlow_t *flow, GError **err)
Print a textual representation of a YAF flow to a file.
gboolean yfWriteStatsFlow(yfContext_t *yfContext, uint32_t pcap_drop, GTimer *timer, GError **err)
Write a statistics options data record to an IPFIX Message buffer.
struct yfConfig_st yfConfig_t
YAF Configuration Settings.
Definition yafcore.h:207
gboolean yfReadFlow(fBuf_t *fbuf, yfFlow_t *flow, GError **err)
Read a single flow from an IPFIX message buffer.
void yfPrintString(GString *rstr, const yfFlow_t *flow)
Print a YAF flow to a GString.
gboolean yfWriteFlow(yfContext_t *yfContext, yfFlow_t *flow, GError **err)
Write a single flow to an IPFIX message buffer.
void yfAlignmentCheck(void)
yfAlignmentCheck
yfRecordTimeIE_en
Type to specify which timestamps are included.
Definition yafcore.h:218
@ YF_TIME_IE_NANO
Include flowStartNanoseconds, etc in the export template.
Definition yafcore.h:226
@ YF_TIME_IE_MICRO
Include flowStartMicrioseconds, etc in the export template.
Definition yafcore.h:224
@ YF_TIME_IE_MILLI
Include flowStartMilliseconds, etc in the export template.
Definition yafcore.h:222
@ YF_TIME_IE__UNSET
Unset value.
Definition yafcore.h:220
fBuf_t * yfWriterForFile(const char *path, const yfConfig_t *yfConfig, GError **err)
Get an IPFIX message buffer for writing YAF flows to a named file.
void yfFlowCleanup(yfFlow_t *flow)
Clean up after a static flow buffer prepared by yfFlowPrepare().
fBuf_t * yfWriterForFP(FILE *fp, const yfConfig_t *yfConfig, GError **err)
Get an IPFIX message buffer for writing YAF flows to an open file pointer.
void yfPrintDelimitedString(GString *rstr, const yfFlow_t *flow, gboolean yaft_mac)
Print a YAF flow to a GString in pipe-delimited (columnar) format.
void yfFlowPrepare(yfFlow_t *flow)
Prepare a static flow buffer for use with yfReadFlow().
gboolean yfPrintDelimited(FILE *out, const yfFlow_t *flow, gboolean yaft_mac, GError **err)
Print a YAF flow to a file in pipe-delimited (columnar) format.
struct yfFlowVal_st yfFlowVal_t
A YAF uniflow value.
#define ETHERNET_MAC_ADDR_LENGTH
length of Ethernet MAC Address
Definition yafcore.h:182
gboolean yfWriteTombstoneFlow(yfContext_t *yfContext, GError **err)
Write a tombstone options data record to an IPFIX Message buffer.
fBuf_t * yfReaderForFP(fBuf_t *fbuf, FILE *fp, GError **err)
Get an IPFIX message buffer for reading YAF flows from an open file pointer.
gboolean yfWriteOptionsDataFlows(yfContext_t *yfContext, uint32_t pcap_drop, GTimer *timer, GError **err)
A wrapper that calls both yfWriteStatsFlow and yfWriteDataFlow with appropriate condition checking.
struct yfFlow_st yfFlow_t
A YAF flow.
gboolean yfWriterClose(fBuf_t *fbuf, gboolean flush, GError **err)
Close the connection underlying an IPFIX message buffer created by yfWriterForFP() or yfWriterForSpec...
void yfPrintColumnHeaders(FILE *out, gboolean yaft_mac, GError **err)
Print column headers for the pipe-delimited (columnar) format.
fbListener_t * yfListenerForSpec(fbConnSpec_t *spec, fbListenerAppInit_fn appinit, fbListenerAppFree_fn appfree, GError **err)
Get an IPFIX connection listener for collecting YAF flows via IPFIX from the network.
struct yfFlowStats_st yfFlowStats_t
yaf enhanced flow statistics, used in flowstats_mode (yaf –flow-stats)
struct yfContext_st yfContext_t
YAF Context Settings.
Definition yafcore.h:212