private.h
Go to the documentation of this file.
1 /*
2  * Copyright 2006-2022 Carnegie Mellon University
3  * See license information in LICENSE.txt.
4  */
15 /*
16  * ------------------------------------------------------------------------
17  * Authors: Brian Trammell
18  * ------------------------------------------------------------------------
19  */
20 
21 #ifndef _FB_PRIVATE_H_
22 #define _FB_PRIVATE_H_
23 #include <fixbuf/public.h>
24 
25 
27 #define IPFIX_ENTERPRISE_BIT 0x8000
28 
31 #define FB_MSGLEN_MAX 65535
32 
34 #define FB_SSL_ERR_BUFSIZ 512
35 
42 typedef struct fbUDPConnSpec_st {
46  void *ctx;
48  union {
49  struct sockaddr so;
50  struct sockaddr_in ip4;
51  struct sockaddr_in6 ip6;
52  } peer;
54  size_t peerlen;
60  time_t last_seen;
62  uint32_t obdomain;
64  gboolean reject;
66 
67 
74 /* TODO...add a way to say if this field is this value, it highlights these
75  * records...thus removing app label spec...or screw it and leave it specific
76  */
77 typedef struct fbTemplateInfoRecord_st {
79  uint16_t tid;
80  uint16_t appLabel;
81  uint16_t parentTid;
82  uint8_t padding[2];
90 
91 
96 typedef struct fbElementPositions_st {
98  uint16_t count;
100  uint16_t *positions;
102 
114  GHashTable *indices;
116  uint16_t *off_cache;
120  uint16_t ie_count;
125  uint16_t scope_count;
132  uint16_t ie_len;
138  uint16_t ie_internal_len;
143  uint16_t tmpl_len;
147  gboolean is_varlen;
151  gboolean contains_list;
155  gboolean active;
160  gboolean default_length;
165  void *tmpl_ctx;
173  void *app_ctx;
174 
187 };
188 
195 void
197  fBuf_t *fbuf);
198 
210 gboolean
212  fBuf_t *fbuf,
213  uint16_t tmpl_id,
214  const fbTemplate_t *tmpl,
215  gboolean revoked,
216  GError **err);
217 
223 void
225  fBuf_t *fbuf,
226  const fbTemplate_t *tmpl);
227 
232 void
234  fBuf_t *fbuf,
235  fbSession_t *session);
236 
241 uint16_t
243  const fBuf_t *fbuf);
244 
245 
250 uint16_t
252  const fBuf_t *fbuf);
253 
261 uint32_t
263  const fbInfoElement_t *ie);
264 
273 gboolean
275  const fbInfoElement_t *a,
276  const fbInfoElement_t *b);
277 
285 void
287  gboolean tmpl,
288  const fbInfoElement_t *ie);
289 
297 const fbInfoElement_t *
299  const fbInfoModel_t *model,
300  const fbInfoElement_t *ex_ie);
301 
320 gboolean
322  fbInfoModel_t *model,
323  const fbInfoElement_t *ex_ie,
324  fbTemplateField_t *tmpl_ie,
325  GError **err);
326 
344 gboolean
346  const fbInfoModel_t *model,
347  const char *name,
348  uint16_t len_override,
349  fbTemplateField_t *tmpl_ie,
350  GError **err);
351 
372 gboolean
374  const fbInfoModel_t *model,
375  uint32_t enterprise_id,
376  uint16_t element_id,
377  uint16_t len_override,
378  fbTemplateField_t *tmpl_ie,
379  GError **err);
380 
389 const fbInfoElement_t *
391  fbInfoModel_t *model,
392  const fbInfoElement_t *ex_ie);
393 
402 fbTemplate_t *
404  fbInfoModel_t *model,
405  gboolean internal,
406  GError **err);
407 
413 gboolean
415  const fbTemplate_t *tmpl);
416 
417 
425 void
427  fbTemplate_t *tmpl);
428 
436 void
438  fbTemplate_t *tmpl);
439 
448 void
450  const char *label,
451  uint16_t tid,
452  const fbTemplate_t *tmpl);
453 
467  const fbTemplateInfoRecord_t *mdRec,
468  unsigned int mdRecVersion,
469  GError **err);
470 
480 void
482  const fbTemplateInfo_t *mdInfo,
483  fbTemplateInfoRecord_t *mdRec,
484  const fbTemplate_t *stlTemplate,
485  uint16_t stlTid);
486 
493 void
495  fbTemplateInfo_t *mdInfo,
496  uint16_t tid);
497 
505 void
507  fbTemplateInfoRecord_t *mdRec);
508 
515 void
517  fbTemplateInfoRecord_t *mdRec);
518 
531 gboolean
533  fbInfoModel_t *model,
534  fbTemplate_t **tmplinfo_v3_tmpl,
535  fbTemplate_t **bl_ie_metadata_tmpl,
536  GError **err);
537 
546  const fbSession_t *session);
547 
555 void *
557  const fbSession_t *session);
558 
565 fbSession_t *
567  const fbSession_t *base);
568 
576 uint32_t
578  const fbSession_t *session);
579 
587 void
589  fbSession_t *session,
590  uint32_t sequence);
591 
599 void
601  fbSession_t *session,
602  fBuf_t *fbuf);
603 
640 gboolean
642  const fbSession_t *session,
643  uint16_t ext_tid,
644  uint16_t *int_tid,
645  fbTemplate_t **ext_tmpl,
646  fbTemplate_t **int_tmpl,
647  GError **err);
648 
658 void
660  fbSession_t *session,
661  gboolean disabled);
662 
670 void
672  fbSession_t *session,
673  fbCollector_t *collector);
674 
681 void
683  fbSession_t *session);
684 
691 void
693  fbSession_t *session);
694 
701 int
703  fbSession_t *session);
704 
711 int
713  fbSession_t *session);
714 
722 void
724  fbSession_t *session,
725  fbTemplateInfo_t *mdInfo);
726 
737 gboolean
739  fbSession_t *session,
740  GError **err);
741 
753 fbTemplate_t *
755  fbSession_t *session,
756  uint16_t *tid,
757  GError **err);
758 
774 gboolean
776  fbSession_t *session,
777  GError **err);
778 
790 fbTemplate_t *
792  fbSession_t *session,
793  uint16_t *tid,
794  GError **err);
795 
804 gboolean
806  fbConnSpec_t *spec,
807  gboolean passive,
808  GError **err);
809 
818 gboolean
820  fbConnSpec_t *spec,
821  gboolean passive,
822  GError **err);
823 
831 fbConnSpec_t *
833  const fbConnSpec_t *spec);
834 
842 void
844  fbConnSpec_t *spec);
845 
853 uint16_t
855  const fbExporter_t *exporter);
856 
866 gboolean
868  fbExporter_t *exporter,
869  uint8_t *msgbase,
870  size_t msglen,
871  GError **err);
872 
880 void
882  fbExporter_t *exporter);
883 
891 void
893  fBuf_t *fbuf,
894  fbCollector_t *collector);
895 
909  fbListener_t *listener,
910  void *ctx,
911  int fd,
912  struct sockaddr *peer,
913  size_t peerlen,
914  GError **err);
915 
929  fbListener_t *listener,
930  void *ctx,
931  int fd,
932  struct sockaddr *peer,
933  size_t peerlen,
934  GError **err);
935 
945 gboolean
947  fbCollector_t *collector,
948  uint8_t *msgbase,
949  size_t *msglen,
950  GError **err);
951 
959 int
961  const fbCollector_t *collector);
962 
969 void
971  fbCollector_t *collector,
972  int fd);
973 
981 void
983  fbCollector_t *collector);
984 
992 gboolean
994  fbCollector_t *collector);
995 
996 
1010 gboolean
1012  uint8_t *hdr,
1013  size_t b_len,
1014  size_t *m_len,
1015  GError **err);
1016 
1024 void
1026  fbListener_t *listener,
1027  void *ctx);
1028 
1036 void
1038  fBuf_t *fbuf,
1039  fbListener_t *listener);
1040 
1048 void
1050  fbListener_t *listener,
1051  int fd);
1052 
1060 fbConnSpec_t *
1062  const fbListener_t *listener);
1063 
1070 void
1072  fbCollector_t *collector);
1073 
1078 gboolean
1080  fbListener_t *listener,
1081  fbUDPConnSpec_t *spec,
1082  GError **err);
1083 
1089 fbSession_t *
1091  fbListener_t *listener,
1092  fbSession_t *session);
1093 
1094 
1095 #endif /* _FB_PRIVATE_H_ */
1096 
1097 /*
1098  * @DISTRIBUTION_STATEMENT_BEGIN@
1099  * libfixbuf 3.0.0
1100  *
1101  * Copyright 2022 Carnegie Mellon University.
1102  *
1103  * NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING
1104  * INSTITUTE MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON
1105  * UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
1106  * AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR
1107  * PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF
1108  * THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF
1109  * ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT
1110  * INFRINGEMENT.
1111  *
1112  * Released under a GNU GPL 2.0-style license, please see LICENSE.txt or
1113  * contact permission@sei.cmu.edu for full terms.
1114  *
1115  * [DISTRIBUTION STATEMENT A] This material has been approved for public
1116  * release and unlimited distribution. Please see Copyright notice for
1117  * non-US Government use and distribution.
1118  *
1119  * Carnegie Mellon(R) and CERT(R) are registered in the U.S. Patent and
1120  * Trademark Office by Carnegie Mellon University.
1121  *
1122  * This Software includes and/or makes use of the following Third-Party
1123  * Software subject to its own license:
1124  *
1125  * 1. GLib-2.0 (https://gitlab.gnome.org/GNOME/glib/-/blob/main/COPYING)
1126  * Copyright 1995 GLib-2.0 Team.
1127  *
1128  * 2. Doxygen (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
1129  * Copyright 2021 Dimitri van Heesch.
1130  *
1131  * DM22-0006
1132  * @DISTRIBUTION_STATEMENT_END@
1133  */
struct fbCollector_st fbCollector_t
IPFIX Collecting Process endpoint.
Definition: public.h:2036
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:2118
void fbSessionSetCollector(fbSession_t *session, fbCollector_t *collector)
fbSessionSetCollector
uint16_t * positions
The list of positions; resized as needed.
Definition: private.h:100
void fBufSetSession(fBuf_t *fbuf, fbSession_t *session)
fBufSetSession
uint16_t scope_count
Count of scope information elements in template.
Definition: private.h:125
struct fbElementPositions_st fbElementPositions_t
fbElementPositions_t supports a variable-sized array that is used to store the index positions of a p...
A single IPFIX Information Element definition.
Definition: public.h:793
uint16_t fBufGetInternalTemplate(const fBuf_t *fbuf)
fBufGetInternalTemplate
void fbTemplateInfoSetTemplateId(fbTemplateInfo_t *mdInfo, uint16_t tid)
fbTemplateInfoSetTemplateId
void fbCollectorInterruptSocket(fbCollector_t *collector)
Interrupt the socket for a given collector to stop it from reading more data.
gboolean fbInfoElementCopyToTemplateByIdent(const fbInfoModel_t *model, uint32_t enterprise_id, uint16_t element_id, uint16_t len_override, fbTemplateField_t *tmpl_ie, GError **err)
fbInfoElementCopyToTemplateByIdent
int ref_count
Reference count.
Definition: private.h:118
fbConnSpec_t * fbListenerGetConnSpec(const fbListener_t *listener)
fbListenerGetConnSpec
int fbSessionExtTmplTableFlagIsSet(fbSession_t *session)
fbSessionExtTmplTableFlagIsSet
fbElementPositions_t stml
Index positions of the FB_SUB_TMPL_MULTI_LIST elements.
Definition: private.h:186
void fbTemplateDebug(const char *label, uint16_t tid, const fbTemplate_t *tmpl)
fbTemplateDebug
fbElementPositions_t supports a variable-sized array that is used to store the index positions of a p...
Definition: private.h:96
size_t peerlen
size of peer
Definition: private.h:54
void fbCollectorRemoveListenerLastBuf(fBuf_t *fbuf, fbCollector_t *collector)
fbCollectorRemoveListenerLastBuf
gboolean active
TRUE if this template has been activated (is no longer mutable).
Definition: private.h:155
fbTemplateField_t represents an fbInfoElement_t that has been added to an fbTemplate_t.
Definition: public.h:1037
gboolean fBufAppendTemplate(fBuf_t *fbuf, uint16_t tmpl_id, const fbTemplate_t *tmpl, gboolean revoked, GError **err)
fBufAppendTemplate
gboolean fbSessionAddInternalRfc5610Template(fbSession_t *session, GError **err)
fbSessionAddInternalRfc5610Template
int fbSessionIntTmplTableFlagIsSet(fbSession_t *session)
fbSessionIntTmplTableFlagIsSet
fbVarfield_t name
Template name.
Definition: private.h:84
An IPFIX template or options template structure.
Definition: private.h:108
fbElementPositions_t bl
Index positions of the FB_BASIC_LIST elements.
Definition: private.h:178
uint16_t fBufGetExportTemplate(const fBuf_t *fbuf)
fBufGetExportTemplate
An UDP Connection specifier.
Definition: private.h:42
void fbTemplateRetain(fbTemplate_t *tmpl)
fbTemplateRetain
uint16_t * off_cache
Field offset cache.
Definition: private.h:116
struct fBuf_st fBuf_t
An IPFIX message buffer.
Definition: public.h:129
Fixbuf IPFIX protocol library public interface.
void fbSessionSaveTemplateInfo(fbSession_t *session, fbTemplateInfo_t *mdInfo)
fbSessionSaveTemplateInfo
void fbInfoElementDebug(gboolean tmpl, const fbInfoElement_t *ie)
fbInfoElementDebug
gboolean fbSessionAddInternalTemplateInfoTemplate(fbSession_t *session, GError **err)
fbSessionAddInternalTemplateInfoTemplate
gboolean fbSessionGetTemplatePair(const fbSession_t *session, uint16_t ext_tid, uint16_t *int_tid, fbTemplate_t **ext_tmpl, fbTemplate_t **int_tmpl, GError **err)
Checks for a template pair and finds the associated external and internal templates.
fbNewTemplateCallback_fn fbSessionGetNewTemplateCallback(const fbSession_t *session)
Returns the callback function for a given session.
fbConnSpec_t * fbConnSpecCopy(const fbConnSpec_t *spec)
fbConnSpecCopy
gboolean fbListenerCallAppInit(fbListener_t *listener, fbUDPConnSpec_t *spec, GError **err)
call appinit from UDP
fbSession_t * fbSessionClone(const fbSession_t *base)
fbSessionClone
uint16_t ie_internal_len
Total length required to store this template in memory.
Definition: private.h:138
gboolean fbInfoElementCopyToTemplateByName(const fbInfoModel_t *model, const char *name, uint16_t len_override, fbTemplateField_t *tmpl_ie, GError **err)
fbInfoElementCopyToTemplateByName
struct fbInfoModel_st fbInfoModel_t
An IPFIX information model.
Definition: public.h:154
fbTemplate_t * fbSessionGetInternalTemplateInfoTemplate(fbSession_t *session, uint16_t *tid, GError **err)
fbSessionGetInternalTemplateInfoTemplate
union fbUDPConnSpec_st::@0 peer
key to this conn spec
struct fbUDPConnSpec_st * next
link to next one in list
Definition: private.h:56
Connection specifier.
Definition: public.h:1697
gboolean fbExportMessage(fbExporter_t *exporter, uint8_t *msgbase, size_t msglen, GError **err)
fbExportMessage
void fbSessionClearIntTmplTableFlag(fbSession_t *session)
fbSessionClearIntTmplTableFlag
fbSubTemplateList_t blInfoList
List of PEN, IE num pairs.
Definition: private.h:88
void * ctx
application context.
Definition: private.h:46
struct fbUDPConnSpec_st * prev
doubly linked to timeout faster
Definition: private.h:58
int fbCollectorGetFD(const fbCollector_t *collector)
fbCollectorGetFD
void fbConnSpecFree(fbConnSpec_t *spec)
fbConnSpecFree
void fbCollectorFree(fbCollector_t *collector)
fbCollectorFree
fbTemplateField_t ** ie_ary
Ordered array of pointers to information elements in this template.
Definition: private.h:112
void * fbSessionGetNewTemplateCallbackAppCtx(const fbSession_t *session)
Returns the callback function's application context for a given session.
fbSubTemplateList_t provides the internal representation of an fbInfoElement_t of type subTemplateLis...
Definition: public.h:2521
gboolean is_varlen
TRUE if this template contains any variable length IEs.
Definition: private.h:147
fbInfoModel_t * model
Information model (for looking up information elements by spec)
Definition: private.h:110
gboolean fbCollectorHasTranslator(fbCollector_t *collector)
fbCollectorHasTranslator
A variable-length field value.
Definition: public.h:137
fbTemplateInfo_t * fbTemplateInfoCreateFromRecord(const fbTemplateInfoRecord_t *mdRec, unsigned int mdRecVersion, GError **err)
fbTemplateInfoCreateFromRecord
void fbListenerRemoveLastBuf(fBuf_t *fbuf, fbListener_t *listener)
fbListenerRemoveLastBuf
uint16_t ie_len
Total length of information elements in records described by this template.
Definition: private.h:132
struct fbTemplateInfo_st fbTemplateInfo_t
fbTemplateInfo_t describes an fbTemplate_t.
Definition: public.h:1732
gboolean fbInfoElementEqual(const fbInfoElement_t *a, const fbInfoElement_t *b)
fbInfoElementEqual
void fbSessionSetTemplatePairsDisabled(fbSession_t *session, gboolean disabled)
Sets the flag on a Session that says whether the template-pairs lookup table should be ignored.
void fbSessionSetTemplateBuffer(fbSession_t *session, fBuf_t *fbuf)
fbSessionSetTemplateBuffer
gboolean fbConnSpecInitTLS(fbConnSpec_t *spec, gboolean passive, GError **err)
fbConnSpecInitTLS
fbTemplate_t * fbSessionGetInternalRfc5610Template(fbSession_t *session, uint16_t *tid, GError **err)
fbSessionGetInternalRfc5610Template
void fBufRewind(fBuf_t *fbuf)
fBufRewind
void fbListenerRemove(fbListener_t *listener, int fd)
fbListenerRemove
uint32_t fbInfoElementHash(const fbInfoElement_t *ie)
fbInfoElementHash
void fbTemplateInfoFillRecord(const fbTemplateInfo_t *mdInfo, fbTemplateInfoRecord_t *mdRec, const fbTemplate_t *stlTemplate, uint16_t stlTid)
fbTemplateInfoFillRecord
void * tmpl_ctx
Template context.
Definition: private.h:165
TemplateInfo options record structure.
Definition: private.h:77
gboolean fbConnSpecLookupAI(fbConnSpec_t *spec, gboolean passive, GError **err)
fbConnSpecLookupAI
const fbInfoElement_t * fbInfoModelAddAlienElement(fbInfoModel_t *model, const fbInfoElement_t *ex_ie)
fbInfoModelAddAlienElement
void fbCollectorSetFD(fbCollector_t *collector, int fd)
fbCollectorSetFD
gboolean fbInfoModelIsTemplateElementType(const fbTemplate_t *tmpl)
fbInfoModelIsTemplateElementType
fbCollector_t * fbCollectorAllocSocket(fbListener_t *listener, void *ctx, int fd, struct sockaddr *peer, size_t peerlen, GError **err)
fbCollectorAllocSocket
fbVarfield_t description
Template description (optional)
Definition: private.h:86
uint16_t fbExporterGetMTU(const fbExporter_t *exporter)
fbExporterGetMTU
struct fbListener_st fbListener_t
IPFIX Collecting Process session listener.
Definition: public.h:2044
uint32_t obdomain
with peer address this is the key
Definition: private.h:62
GHashTable * indices
Map of information element to index in ie_ary.
Definition: private.h:114
fbCollector_t * fbCollectorAllocTLS(fbListener_t *listener, void *ctx, int fd, struct sockaddr *peer, size_t peerlen, GError **err)
fbCollectorAllocTLS
fbElementPositions_t stl
Index positions of the FB_SUB_TMPL_LIST elements.
Definition: private.h:182
uint16_t tid
Template ID.
Definition: private.h:79
struct fbUDPConnSpec_st fbUDPConnSpec_t
An UDP Connection specifier.
void fbListenerAppFree(fbListener_t *listener, void *ctx)
fbListenerAppFree
gboolean fbTemplateAllocTemplateInfoTemplates(fbInfoModel_t *model, fbTemplate_t **tmplinfo_v3_tmpl, fbTemplate_t **bl_ie_metadata_tmpl, GError **err)
Allocates new Templates to describe records that hold TemplateInfo.
void fbExporterFree(fbExporter_t *exporter)
fbExporterFree
gboolean default_length
TRUE if any field was created using an fbInfoElementSpec_t with a defaulted length.
Definition: private.h:160
uint16_t tmpl_len
Total length of the template record or options template record defining this template.
Definition: private.h:143
gboolean contains_list
TRUE if this template contains any structured data (lists).
Definition: private.h:151
struct fbExporter_st fbExporter_t
IPFIX Exporting Process endpoint.
Definition: public.h:2027
void(* fbTemplateCtxFree_fn)(void *tmpl_ctx, void *app_ctx)
A callback function that is called when a template is freed.
Definition: public.h:2091
gboolean reject
reject flag
Definition: private.h:64
struct fbSession_st fbSession_t
An IPFIX Transport Session state container.
Definition: public.h:1661
void fbTemplateInfoRecordClear(fbTemplateInfoRecord_t *mdRec)
Clears any list data used by a fbTemplateInfoRecord_t.
gboolean fbCollectMessage(fbCollector_t *collector, uint8_t *msgbase, size_t *msglen, GError **err)
fbCollectMessage
void fbSessionClearExtTmplTableFlag(fbSession_t *session)
fbSessionClearExtTmplTableFlag
fbTemplate_t * fbInfoElementAllocTypeTemplate2(fbInfoModel_t *model, gboolean internal, GError **err)
fbInfoElementAllocTypeTemplate2
gboolean fbCollectMessageBuffer(uint8_t *hdr, size_t b_len, size_t *m_len, GError **err)
fbCollectMessageBuffer
uint32_t fbSessionGetSequence(const fbSession_t *session)
fbSessionGetSequence
fbSession_t * session
pointer to the session for this peer address
Definition: private.h:44
fbSession_t * fbListenerSetPeerSession(fbListener_t *listener, fbSession_t *session)
Set the session on the fbuf and listener.
uint16_t ie_count
Count of information elements in template.
Definition: private.h:120
void fBufRemoveTemplateTcplan(fBuf_t *fbuf, const fbTemplate_t *tmpl)
fBufRemoveTemplateTcplan
fbTemplateCtxFree_fn ctx_free
Callback to free the ctx pointer when template is freed.
Definition: private.h:169
void * app_ctx
The application's Context pointer for the ctx_free function.
Definition: private.h:173
const fbInfoElement_t * fbInfoModelGetElement(const fbInfoModel_t *model, const fbInfoElement_t *ex_ie)
fbInfoModelGetElement
void fbTemplateInfoRecordInit(fbTemplateInfoRecord_t *mdRec)
fbTemplateInfoRecordInit
time_t last_seen
last seen time
Definition: private.h:60
void fbSessionSetSequence(fbSession_t *session, uint32_t sequence)
fbSessionSetSequence
struct fbTemplateInfoRecord_st fbTemplateInfoRecord_t
TemplateInfo options record structure.
gboolean fbInfoElementCopyToTemplate(fbInfoModel_t *model, const fbInfoElement_t *ex_ie, fbTemplateField_t *tmpl_ie, GError **err)
fbInfoElementCopyToTemplate
void fbTemplateRelease(fbTemplate_t *tmpl)
fbTemplateRelease
uint16_t count
The length of the array of positions.
Definition: private.h:98