private.h
Go to the documentation of this file.
1/*
2 * Copyright 2006-2025 Carnegie Mellon University
3 * See license information in LICENSE.txt.
4 */
15/*
16 * ------------------------------------------------------------------------
17 * Authors: Brian Trammell
18 * ------------------------------------------------------------------------
19 * @DISTRIBUTION_STATEMENT_BEGIN@
20 * libfixbuf 2.5
21 *
22 * Copyright 2024 Carnegie Mellon University.
23 *
24 * NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING
25 * INSTITUTE MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON
26 * UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR
27 * IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF
28 * FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS
29 * OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT
30 * MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT,
31 * TRADEMARK, OR COPYRIGHT INFRINGEMENT.
32 *
33 * Licensed under a GNU-Lesser GPL 3.0-style license, please see
34 * LICENSE.txt or contact permission@sei.cmu.edu for full terms.
35 *
36 * [DISTRIBUTION STATEMENT A] This material has been approved for public
37 * release and unlimited distribution. Please see Copyright notice for
38 * non-US Government use and distribution.
39 *
40 * This Software includes and/or makes use of Third-Party Software each
41 * subject to its own license.
42 *
43 * DM24-1020
44 * @DISTRIBUTION_STATEMENT_END@
45 * ------------------------------------------------------------------------
46 */
47
48#ifndef _FB_PRIVATE_H_
49#define _FB_PRIVATE_H_
50#include <fixbuf/public.h>
51
52#if HAVE_SPREAD
53#include <sp.h>
54#include <pthread.h>
55#endif
56
57
70#define IPFIX_ENTERPRISE_BIT 0x8000
71
74#define FB_MSGLEN_MAX 65535
75
77#define FB_SSL_ERR_BUFSIZ 512
78
79#if HAVE_SPREAD
80
84typedef struct sp_groupname_st {
85 char name[MAX_GROUP_NAME];
87
89#define FB_SPREAD_NUM_GROUPS 16
90
92#define FB_SPREAD_MTU 8192
93
97typedef struct fbSpreadSpec_st {
103 char *daemon;
111 int num_groups_to_send;
113 mailbox mbox;
115 char privgroup[MAX_GROUP_NAME + 2];
117 pthread_mutex_t write_lock;
119 pthread_t recv_thread;
121 mailbox recv_mbox;
123 char recv_privgroup[MAX_GROUP_NAME + 2];
125 GError *recv_err;
139
140#endif /* HAVE_SPREAD */
141
148typedef struct fbUDPConnSpec_st {
152 void *ctx;
154 union {
155 struct sockaddr so;
156 struct sockaddr_in ip4;
157 struct sockaddr_in6 ip6;
160 size_t peerlen;
166 time_t last_seen;
168 uint32_t obdomain;
170 gboolean reject;
172
173
174#ifdef DEFINE_TEMPLATE_METADATA_SPEC
175/* Template metadata template */
176static fbInfoElementSpec_t template_metadata_spec[] = {
177 {(char *)"templateId", 2, 0 },
178 {(char *)"paddingOctets", 6, 1 },
179 {(char *)"templateName", FB_IE_VARLEN, 0 },
180 {(char *)"templateDescription", FB_IE_VARLEN, 0 },
181 /* {"templateInformationElementList", FB_IE_VARLEN, 0 }, */
183};
184#endif /* ifdef DEFINE_TEMPLATE_METADATA_SPEC */
185
190typedef struct fbTemplateOptRec_st {
192 uint16_t template_id;
193 uint8_t template_padding[6];
199 /* fbSubTemplateList_t info_element_list; */
201
268
275void
277 fBuf_t *fbuf);
278
290gboolean
292 fBuf_t *fbuf,
293 uint16_t tmpl_id,
294 fbTemplate_t *tmpl,
295 gboolean revoked,
296 GError **err);
297
298#if HAVE_SPREAD
305void
307 fBuf_t *fbuf,
308 char **groups,
309 int num_groups,
310 GError **err);
311
312#endif /* if HAVE_SPREAD */
313
319void
321 fBuf_t *fbuf,
322 fbTemplate_t *tmpl);
323
328void
330 fBuf_t *fbuf,
331 fbSession_t *session);
332
337uint16_t
339 fBuf_t *fbuf);
340
341
346uint16_t
348 fBuf_t *fbuf);
349
357uint32_t
359 fbInfoElement_t *ie);
360
369gboolean
371 const fbInfoElement_t *a,
372 const fbInfoElement_t *b);
373
381void
383 gboolean tmpl,
384 fbInfoElement_t *ie);
385
393const fbInfoElement_t *
395 fbInfoModel_t *model,
396 fbInfoElement_t *ex_ie);
397
407gboolean
409 fbInfoModel_t *model,
410 fbInfoElement_t *ex_ie,
411 fbInfoElement_t *tmpl_ie,
412 GError **err);
413
425gboolean
427 fbInfoModel_t *model,
428 const char *name,
429 uint16_t len_override,
430 fbInfoElement_t *tmpl_ie,
431 GError **err);
432
441const fbInfoElement_t *
443 fbInfoModel_t *model,
444 fbInfoElement_t *ex_ie);
445
456 fbInfoModel_t *model,
457 gboolean internal,
458 GError **err);
459
467void
469 fbTemplate_t *tmpl);
470
478void
480 fbTemplate_t *tmpl);
481
489void
491 fbTemplate_t *tmpl);
492
501void
503 const char *label,
504 uint16_t tid,
505 fbTemplate_t *tmpl);
506
520 fbInfoModel_t *model,
521 gboolean internal,
522 GError **err);
523
536void
538 fbTemplate_t *tmpl,
539 uint16_t tid,
540 const char *name,
541 const char *description);
542
551 fbSession_t *session);
552
560void *
562 fbSession_t *session);
563
572 fbSession_t *base);
573
581uint32_t
583 fbSession_t *session);
584
592void
594 fbSession_t *session,
595 uint32_t sequence);
596
604void
606 fbSession_t *session,
607 fBuf_t *fbuf);
608
616void
618 fbSession_t *session,
619 fbCollector_t *collector);
620
621#if HAVE_SPREAD
626void
628 fbSession_t *session,
629 sp_groupname_t *groups,
630 unsigned int num_groups);
631
637void
639 fbSession_t *session,
640 char *group,
641 char *privgroup);
642
647void
649 fbSession_t *session,
650 char *group);
651
656unsigned int
658 fbSession_t *session,
659 char *group);
660
667unsigned int
669 fbSession_t *session);
670
671#endif /* if HAVE_SPREAD */
672
679void
681 fbSession_t *session);
682
689void
691 fbSession_t *session);
692
699int
701 fbSession_t *session);
702
709int
711 fbSession_t *session);
712
721gboolean
723 fbConnSpec_t *spec,
724 gboolean passive,
725 GError **err);
726
735gboolean
737 fbConnSpec_t *spec,
738 gboolean passive,
739 GError **err);
740
750 fbConnSpec_t *spec);
751
759void
761 fbConnSpec_t *spec);
762
763#if HAVE_SPREAD
773 fbSpreadParams_t *spec);
774
782void
784 fbSpreadSpec_t *spec);
785
794const char *
796 int err);
797
798
808void
810 fbExporter_t *exporter,
811 char **groups,
812 int num_groups);
813
814
824gboolean
826 fbExporter_t *exporter,
827 char **groups,
828 int num_groups);
829
830#endif /* HAVE_SPREAD */
831
839uint16_t
841 fbExporter_t *exporter);
842
852gboolean
854 fbExporter_t *exporter,
855 uint8_t *msgbase,
856 size_t msglen,
857 GError **err);
858
866void
868 fbExporter_t *exporter);
869
877void
879 fBuf_t *fbuf,
880 fbCollector_t *collector);
881
895 fbListener_t *listener,
896 void *ctx,
897 int fd,
898 struct sockaddr *peer,
899 size_t peerlen,
900 GError **err);
901
915 fbListener_t *listener,
916 void *ctx,
917 int fd,
918 struct sockaddr *peer,
919 size_t peerlen,
920 GError **err);
921
931gboolean
933 fbCollector_t *collector,
934 uint8_t *msgbase,
935 size_t *msglen,
936 GError **err);
937
945int
947 fbCollector_t *collector);
948
955void
957 fbCollector_t *collector,
958 int fd);
959
967void
969 fbCollector_t *collector);
970
978gboolean
980 fbCollector_t *collector);
981
982
996gboolean
998 uint8_t *hdr,
999 size_t b_len,
1000 size_t *m_len,
1001 GError **err);
1002
1003
1004#if HAVE_SPREAD
1012gboolean
1014 fbCollector_t *collector,
1015 int group_offset);
1016
1017#endif /* if HAVE_SPREAD */
1018
1026void
1028 fbListener_t *listener,
1029 void *ctx);
1030
1038void
1040 fBuf_t *fbuf,
1041 fbListener_t *listener);
1042
1050void
1052 fbListener_t *listener,
1053 int fd);
1054
1064 fbListener_t *listener);
1065
1072void
1074 fbCollector_t *collector);
1075
1080gboolean
1082 fbListener_t *listener,
1083 fbUDPConnSpec_t *spec,
1084 GError **err);
1085
1093 fbListener_t *listener,
1094 fbSession_t *session);
1095
1096#endif /* ifndef _FB_PRIVATE_H_ */
void * tmpl_ctx
Template context.
Definition private.h:258
fbNewTemplateCallback_fn fbSessionNewTemplateCallback(fbSession_t *session)
Returns the callback function for a given session.
void fbSessionSetCollector(fbSession_t *session, fbCollector_t *collector)
fbSessionSetCollector
unsigned int fbSessionGetGroup(fbSession_t *session)
fbSessionGetGroup
fbConnSpec_t * fbListenerGetConnSpec(fbListener_t *listener)
fbListenerGetConnSpec
uint32_t fbSessionGetSequence(fbSession_t *session)
fbSessionGetSequence
struct fbUDPConnSpec_st * next
link to next one in list
Definition private.h:162
pthread_t recv_thread
the receiver thread
Definition private.h:119
int fbCollectorGetFD(fbCollector_t *collector)
fbCollectorGetFD
void * ctx
application context.
Definition private.h:152
char * daemon
pointer to the daemon host address, in Spread format.
Definition private.h:103
void fbSessionClearIntTmplTableFlag(fbSession_t *session)
fbSessionClearIntTmplTableFlag
void fbSessionSetGroup(fbSession_t *session, char *group)
fbSessionSetGroup
void fBufRewind(fBuf_t *fbuf)
fBufRewind
fbVarfield_t template_description
Template description (optional)
Definition private.h:197
gboolean fbExporterCheckGroups(fbExporter_t *exporter, char **groups, int num_groups)
fbExporterCheckGroups
fbCollector_t * fbCollectorAllocSocket(fbListener_t *listener, void *ctx, int fd, struct sockaddr *peer, size_t peerlen, GError **err)
fbCollectorAllocSocket
gboolean fbInfoElementEqual(const fbInfoElement_t *a, const fbInfoElement_t *b)
fbInfoElementEqual
int fbSessionExtTmplTableFlagIsSet(fbSession_t *session)
fbSessionExtTmplTableFlagIsSet
void fbTemplateRelease(fbTemplate_t *tmpl)
fbTemplateRelease
fbTemplate_t * fbTemplateAllocTemplateMetadataTmpl(fbInfoModel_t *model, gboolean internal, GError **err)
Allocates a new Template to describe a record that holds Template Metadata.
gboolean reject
reject flag
Definition private.h:170
char privgroup[MAX_GROUP_NAME+2]
the connection private name
Definition private.h:115
int recv_max_groups
max size of group name array
Definition private.h:129
void fbTemplateFree(fbTemplate_t *tmpl)
fbTemplateFree
void fbSessionSetPrivateGroup(fbSession_t *session, char *group, char *privgroup)
fbSessionSetPrivateGroup
size_t peerlen
size of peer
Definition private.h:160
mailbox mbox
the mailbox for the connection
Definition private.h:113
GHashTable * indices
Map of information element to index in ie_ary.
Definition private.h:242
uint16_t template_id
Template ID.
Definition private.h:192
void fbListenerRemoveLastBuf(fBuf_t *fbuf, fbListener_t *listener)
fbListenerRemoveLastBuf
uint16_t * off_cache
Field offset cache.
Definition private.h:244
void fBufSetSession(fBuf_t *fbuf, fbSession_t *session)
fBufSetSession
void fbConnSpreadFree(fbSpreadSpec_t *spec)
fbConnSpreadFree
void fbExporterSetGroupsToSend(fbExporter_t *exporter, char **groups, int num_groups)
fbExporterSetGroupToSend
const fbInfoElement_t * fbInfoModelGetElement(fbInfoModel_t *model, fbInfoElement_t *ex_ie)
fbInfoModelGetElement
gboolean fbConnSpecInitTLS(fbConnSpec_t *spec, gboolean passive, GError **err)
fbConnSpecInitTLS
struct fbUDPConnSpec_st * prev
doubly linked to timeout faster
Definition private.h:164
void fbSessionClearExtTmplTableFlag(fbSession_t *session)
fbSessionClearExtTmplTableFlag
void fbCollectorInterruptSocket(fbCollector_t *collector)
Interrupt the socket for a given collector to stop it from reading more data.
void fbTemplateAddMetadataRecord(fbTemplate_t *tmpl, uint16_t tid, const char *name, const char *description)
Sets the metadata_rec member of tmpl to a newly allocated fbTemplateOptRec_t, and sets its template I...
uint16_t tmpl_len
Total length of the template record or options template record defining this template.
Definition private.h:236
char recv_privgroup[MAX_GROUP_NAME+2]
the connection private name for the receiver
Definition private.h:123
gboolean fbConnSpecLookupAI(fbConnSpec_t *spec, gboolean passive, GError **err)
fbConnSpecLookupAI
gboolean default_length
TRUE if any field was created using an fbInfoElementSpec_t with a defaulted length.
Definition private.h:251
fbInfoElement_t ** ie_ary
Ordered array of pointers to information elements in this template.
Definition private.h:240
const char * fbConnSpreadError(int err)
fbConnSpreadError
fbTemplate_t * fbInfoElementAllocTypeTemplate2(fbInfoModel_t *model, gboolean internal, GError **err)
fbInfoElementAllocTypeTemplate2
void fbTemplateRetain(fbTemplate_t *tmpl)
fbTemplateRetain
struct sp_groupname_st sp_groupname_t
sp_groupname_t
void * app_ctx
The application's Context pointer for the ctx_free function.
Definition private.h:266
gboolean fbCollectMessageBuffer(uint8_t *hdr, size_t b_len, size_t *m_len, GError **err)
fbCollectMessageBuffer
uint16_t ie_count
Count of information elements in template.
Definition private.h:213
struct fbUDPConnSpec_st fbUDPConnSpec_t
An UDP Connection specifier.
unsigned int fbSessionGetGroupOffset(fbSession_t *session, char *group)
fbSessionGetGroupOffset
gboolean fbCollectMessage(fbCollector_t *collector, uint8_t *msgbase, size_t *msglen, GError **err)
fbCollectMessage
gboolean is_varlen
Set to TRUE if this template contains any variable length IEs.
Definition private.h:238
GError * recv_err
GError for thread errors, set by receiver, read by main.
Definition private.h:125
fbSession_t * session
pointer to the session, this MUST be set to a valid session before the spec is passed to fbExporterAl...
Definition private.h:100
fbCollector_t * fbCollectorAllocTLS(fbListener_t *listener, void *ctx, int fd, struct sockaddr *peer, size_t peerlen, GError **err)
fbCollectorAllocTLS
gboolean fbCollectorHasTranslator(fbCollector_t *collector)
fbCollectorHasTranslator
int fbSessionIntTmplTableFlagIsSet(fbSession_t *session)
fbSessionIntTmplTableFlagIsSet
union fbUDPConnSpec_st::@0 peer
key to this conn spec
void fBufSetExportGroups(fBuf_t *fbuf, char **groups, int num_groups, GError **err)
fBufSetExportGroups
int ref_count
Reference count.
Definition private.h:211
uint32_t obdomain
with peer address this is the key
Definition private.h:168
struct fbTemplateOptRec_st fbTemplateOptRec_t
Template metadata options record structure.
sp_groupname_t * groups_to_send
groups to send to
Definition private.h:110
gboolean fbInfoElementCopyToTemplateByName(fbInfoModel_t *model, const char *name, uint16_t len_override, fbInfoElement_t *tmpl_ie, GError **err)
fbInfoElementCopyToTemplateByName
uint16_t ie_internal_len
Total length required to store this template in memory.
Definition private.h:231
int recv_exit
flag to tell the thread to exit
Definition private.h:127
gboolean active
TRUE if this template has been activated (is no longer mutable)
Definition private.h:246
uint16_t ie_len
Total length of information elements in records described by this template.
Definition private.h:225
void fbSessionSetSequence(fbSession_t *session, uint32_t sequence)
fbSessionSetSequence
void fbCollectorSetFD(fbCollector_t *collector, int fd)
fbCollectorSetFD
gboolean fBufAppendTemplate(fBuf_t *fbuf, uint16_t tmpl_id, fbTemplate_t *tmpl, gboolean revoked, GError **err)
fBufAppendTemplate
gboolean fbInfoElementCopyToTemplate(fbInfoModel_t *model, fbInfoElement_t *ex_ie, fbInfoElement_t *tmpl_ie, GError **err)
fbInfoElementCopyToTemplate
void fbListenerAppFree(fbListener_t *listener, void *ctx)
fbListenerAppFree
fbSession_t * fbListenerSetPeerSession(fbListener_t *listener, fbSession_t *session)
Set the session on the fbuf and listener.
fbInfoModel_t * model
Information model (for looking up information elements by spec)
Definition private.h:209
gboolean fbExportMessage(fbExporter_t *exporter, uint8_t *msgbase, size_t msglen, GError **err)
fbExportMessage
uint16_t scope_count
Count of scope information elements in template.
Definition private.h:218
sp_groupname_t * recv_groups
groups array for SP_receive
Definition private.h:133
void fbSessionSetGroupParams(fbSession_t *session, sp_groupname_t *groups, unsigned int num_groups)
fbSessionSetGroupParams
mailbox recv_mbox
the receiver's mailbox
Definition private.h:121
char * recv_mess
message buffer for receive
Definition private.h:137
void fbInfoElementDebug(gboolean tmpl, fbInfoElement_t *ie)
fbInfoElementDebug
int recv_max
length of message buffer
Definition private.h:135
const fbInfoElement_t * fbInfoModelAddAlienElement(fbInfoModel_t *model, fbInfoElement_t *ex_ie)
fbInfoModelAddAlienElement
void fbCollectorRemoveListenerLastBuf(fBuf_t *fbuf, fbCollector_t *collector)
fbCollectorRemoveListenerLastBuf
int recv_num_groups
actual size of group name array
Definition private.h:131
struct fbSpreadSpec_st fbSpreadSpec_t
fbSpreadSpec_t
gboolean fbListenerCallAppInit(fbListener_t *listener, fbUDPConnSpec_t *spec, GError **err)
call appinit from UDP
void fbTemplateDebug(const char *label, uint16_t tid, fbTemplate_t *tmpl)
fbTemplateDebug
void fbExporterFree(fbExporter_t *exporter)
fbExporterFree
uint16_t fBufGetExportTemplate(fBuf_t *fbuf)
fBufGetExportTemplate
uint16_t fBufGetInternalTemplate(fBuf_t *fbuf)
fBufGetInternalTemplate
fbSession_t * fbSessionClone(fbSession_t *base)
fbSessionClone
sp_groupname_t * groups
pointer to array of group names, must have at least one, and must be null term array
Definition private.h:106
int num_groups
number of groups in groups
Definition private.h:108
fbTemplateCtxFree_fn ctx_free
Callback to free the ctx pointer when template is freed.
Definition private.h:262
void fbCollectorFree(fbCollector_t *collector)
fbCollectorFree
time_t last_seen
last seen time
Definition private.h:166
void * fbSessionNewTemplateCallbackAppCtx(fbSession_t *session)
Return the callback function's application context for a given session.
fbConnSpec_t * fbConnSpecCopy(fbConnSpec_t *spec)
fbConnSpecCopy
gboolean fbCollectorTestGroupMembership(fbCollector_t *collector, int group_offset)
fbCollectorTestGroupMembership
fbSession_t * session
pointer to the session for this peer address
Definition private.h:150
void fbSessionSetTemplateBuffer(fbSession_t *session, fBuf_t *fbuf)
fbSessionSetTemplateBuffer
void fBufRemoveTemplateTcplan(fBuf_t *fbuf, fbTemplate_t *tmpl)
fBufRemoveTemplateTcplan
fbVarfield_t template_name
Template name.
Definition private.h:195
uint16_t fbExporterGetMTU(fbExporter_t *exporter)
fbExporterGetMTU
void fbListenerRemove(fbListener_t *listener, int fd)
fbListenerRemove
void fbConnSpecFree(fbConnSpec_t *spec)
fbConnSpecFree
pthread_mutex_t write_lock
Spread write lock.
Definition private.h:117
uint32_t fbInfoElementHash(fbInfoElement_t *ie)
fbInfoElementHash
fbSpreadSpec_t * fbConnSpreadCopy(fbSpreadParams_t *spec)
fbConnSpreadCopy
fbSpreadSpec_t
Definition private.h:97
An IPFIX template or options template structure.
Definition private.h:207
Template metadata options record structure.
Definition private.h:190
An UDP Connection specifier.
Definition private.h:148
sp_groupname_t
Definition private.h:84
Fixbuf IPFIX protocol library public interface.
void(* fbTemplateCtxFree_fn)(void *tmpl_ctx, void *app_ctx)
A callback function that is called when a template is freed.
Definition public.h:2027
struct fbExporter_st fbExporter_t
IPFIX Exporting Process endpoint.
Definition public.h:1962
void(* fbNewTemplateCallback_fn)(fbSession_t *session, uint16_t tid, fbTemplate_t *tmpl, void *app_ctx, void **tmpl_ctx, fbTemplateCtxFree_fn *tmpl_ctx_free_fn)
A callback function that will be called when the session receives a new external template.
Definition public.h:2054
struct fbListener_st fbListener_t
IPFIX Collecting Process session listener.
Definition public.h:1979
struct fbInfoModel_st fbInfoModel_t
An IPFIX information model.
Definition public.h:1263
struct fbSession_st fbSession_t
An IPFIX Transport Session state container.
Definition public.h:1860
struct fBuf_st fBuf_t
An IPFIX message buffer.
Definition public.h:1238
struct fbCollector_st fbCollector_t
IPFIX Collecting Process endpoint.
Definition public.h:1971
#define FB_IE_VARLEN
Information element length constant for variable-length IE.
Definition public.h:1509
#define FB_IESPEC_NULL
Convenience macro defining a null information element specification initializer (fbInfoElementSpec_t)...
Definition public.h:1822
Connection specifier.
Definition public.h:1896
A single IPFIX Information Element definition.
Definition public.h:1688
A single IPFIX Information Element specification.
Definition public.h:1830
Spread connection parameters.
Definition public.h:1943
A variable-length field value.
Definition public.h:1246