private.h
Go to the documentation of this file.
1 
43 #ifndef _FB_PRIVATE_H_
44 #define _FB_PRIVATE_H_
45 #include <fixbuf/public.h>
46 
47 #if HAVE_SPREAD
48 #include <sp.h>
49 #include <pthread.h>
50 #endif
51 
52 
65 #define IPFIX_ENTERPRISE_BIT 0x8000
66 
68 #define IPFIX_REVERSE_PEN 29305
69 
72 #define FB_MSGLEN_MAX 65535
73 
74 #if HAVE_SPREAD
75 
76 typedef struct sp_groupname_st
77 {
78  char name[MAX_GROUP_NAME];
79 } sp_groupname_t;
80 
81 #define FB_SPREAD_NUM_GROUPS 16
82 #define FB_SPREAD_MTU 8192
83 
84 typedef struct fbSpreadSpec_st {
87  fbSession_t *session;
90  char * daemon;
92  sp_groupname_t *groups;
94  int num_groups;
96  sp_groupname_t *groups_to_send;
97  int num_groups_to_send;
99  mailbox mbox;
101  char privgroup[MAX_GROUP_NAME + 2];
103  pthread_mutex_t write_lock;
105  pthread_t recv_thread;
107  mailbox recv_mbox;
109  char recv_privgroup[MAX_GROUP_NAME + 2];
111  GError *recv_err;
113  int recv_exit;
115  int recv_max_groups;
117  int recv_num_groups;
119  sp_groupname_t *recv_groups;
121  int recv_max;
123  char *recv_mess;
124 } fbSpreadSpec_t;
125 
126 #endif /* HAVE_SPREAD */
127 
134 typedef struct fbUDPConnSpec_st {
138  void *ctx;
140  union {
141  struct sockaddr so;
142  struct sockaddr_in ip4;
143  struct sockaddr_in6 ip6;
144  } peer;
146  size_t peerlen;
152  time_t last_seen;
154  uint32_t obdomain;
156  gboolean reject;
158 
159 
160 #ifdef DEFINE_TEMPLATE_METADATA_SPEC
161 /* Template metadata template */
162 static fbInfoElementSpec_t template_metadata_spec[] = {
163  /* {"templateInformationElementList", FB_IE_VARLEN, 0 }, */
164  {"templateName", FB_IE_VARLEN, 0 },
165  {"templateDescription", FB_IE_VARLEN, 0 },
166  {"templateId", 2, 0 },
168 };
169 #endif
170 
175 typedef struct fbTemplateOptRec_st {
177  /* fbSubTemplateList_t info_element_list; */
183  uint16_t template_id;
185 
197  uint16_t ie_count;
202  uint16_t scope_count;
209  uint16_t ie_len;
215  uint16_t ie_internal_len;
220  uint16_t tmpl_len;
222  gboolean is_varlen;
226  GHashTable *indices;
228  uint16_t *off_cache;
230  gboolean active;
235  gboolean default_length;
236 
237  fbTemplateOptRec_t *metadata_rec;
242  void *tmpl_ctx;
250  void *app_ctx;
251 };
252 
259 void fBufRewind(
260  fBuf_t *fbuf);
261 
273 gboolean fBufAppendTemplate(
274  fBuf_t *fbuf,
275  uint16_t tmpl_id,
276  fbTemplate_t *tmpl,
277  gboolean revoked,
278  GError **err);
279 
280 #if HAVE_SPREAD
281 
287 void fBufSetExportGroups(
288  fBuf_t *fbuf,
289  char **groups,
290  int num_groups,
291  GError **err);
292 
293 
294 #endif
295 
302  fBuf_t *fbuf,
303  fbTemplate_t *tmpl);
304 
309 void fBufSetSession(
310  fBuf_t *fbuf,
311  fbSession_t *session);
312 
317 uint16_t fBufGetExportTemplate(
318  fBuf_t *fbuf);
319 
320 
325 uint16_t fBufGetInternalTemplate(
326  fBuf_t *fbuf);
327 
335 uint32_t fbInfoElementHash(
336  fbInfoElement_t *ie);
337 
346 gboolean fbInfoElementEqual(
347  const fbInfoElement_t *a,
348  const fbInfoElement_t *b);
349 
357 void fbInfoElementDebug(
358  gboolean tmpl,
359  fbInfoElement_t *ie);
360 
369  fbInfoModel_t *model,
370  fbInfoElement_t *ex_ie);
371 
381  fbInfoModel_t *model,
382  fbInfoElement_t *ex_ie,
383  fbInfoElement_t *tmpl_ie);
384 
396  fbInfoModel_t *model,
397  const char *name,
398  uint16_t len_override,
399  fbInfoElement_t *tmpl_ie);
400 
410  fbInfoModel_t *model,
411  fbInfoElement_t *ex_ie);
412 
420 void fbTemplateRetain(
421  fbTemplate_t *tmpl);
422 
430 void fbTemplateRelease(
431  fbTemplate_t *tmpl);
432 
440 void fbTemplateFree(
441  fbTemplate_t *tmpl);
442 
451 void fbTemplateDebug(
452  const char *label,
453  uint16_t tid,
454  fbTemplate_t *tmpl);
455 
463  fbSession_t *session);
464 
473  fbSession_t *session);
474 
482  fbSession_t *base);
483 
491 uint32_t fbSessionGetSequence(
492  fbSession_t *session);
493 
502  fbSession_t *session,
503  uint32_t sequence);
504 
513  fbSession_t *session,
514  fBuf_t *fbuf);
515 
524  fbSession_t *session,
525  fbCollector_t *collector);
526 
527 #if HAVE_SPREAD
528 
532 void fbSessionSetGroupParams(
533  fbSession_t *session,
534  sp_groupname_t *groups,
535  int num_groups);
536 
542 void fbSessionSetPrivateGroup(
543  fbSession_t *session,
544  char *group,
545  char *privgroup);
546 
551 void fbSessionSetGroup(
552  fbSession_t *session,
553  char *group);
554 
559 unsigned int fbSessionGetGroupOffset(
560  fbSession_t *session,
561  char *group);
562 
567 unsigned int fbSessionGetGroup(
568  fbSession_t *session);
569 #endif
570 
571 void fbSessionClearIntTmplTableFlag(
572  fbSession_t *session);
573 
574 void fbSessionClearExtTmplTableFlag(
575  fbSession_t *session);
576 
577 int fbSessionIntTmplTableFlagIsSet(
578  fbSession_t *session);
579 
580 int fbSessionExtTmplTableFlagIsSet(
581  fbSession_t *session);
590 gboolean fbConnSpecLookupAI(
591  fbConnSpec_t *spec,
592  gboolean passive,
593  GError **err);
594 
603 gboolean fbConnSpecInitTLS(
604  fbConnSpec_t *spec,
605  gboolean passive,
606  GError **err);
607 
616  fbConnSpec_t *spec);
617 
625 void fbConnSpecFree(
626  fbConnSpec_t *spec);
627 
628 #if HAVE_SPREAD
629 
636 fbSpreadSpec_t *fbConnSpreadCopy(
637  fbSpreadParams_t *spec);
638 
646 void fbConnSpreadFree(
647  fbSpreadSpec_t *spec);
648 
657 const char * fbConnSpreadError(
658  int err );
659 
660 
670 void fbExporterSetGroupsToSend(
671  fbExporter_t *exporter,
672  char **groups,
673  int num_groups);
674 
675 
685 gboolean fbExporterCheckGroups(
686  fbExporter_t *exporter,
687  char **groups,
688  int num_groups);
689 
690 
691 #endif /* HAVE_SPREAD */
692 
700 uint16_t fbExporterGetMTU(
701  fbExporter_t *exporter);
702 
712 gboolean fbExportMessage(
713  fbExporter_t *exporter,
714  uint8_t *msgbase,
715  size_t msglen,
716  GError **err);
717 
725 void fbExporterFree(
726  fbExporter_t *exporter);
727 
736  fBuf_t *fbuf,
737  fbCollector_t *collector);
738 
750  fbListener_t *listener,
751  void *ctx,
752  int fd,
753  struct sockaddr *peer,
754  size_t peerlen);
755 
768  fbListener_t *listener,
769  void *ctx,
770  int fd,
771  struct sockaddr *peer,
772  size_t peerlen,
773  GError **err);
774 
784 gboolean fbCollectMessage(
785  fbCollector_t *collector,
786  uint8_t *msgbase,
787  size_t *msglen,
788  GError **err);
789 
797 int fbCollectorGetFD(
798  fbCollector_t *collector);
799 
806 void fbCollectorSetFD(
807  fbCollector_t *collector,
808  int fd);
809 
817 void fbCollectorFree(
818  fbCollector_t *collector);
819 
827 gboolean fbCollectorHasTranslator(
828  fbCollector_t *collector);
829 
830 
844 gboolean fbCollectMessageBuffer(
845  uint8_t *hdr,
846  size_t b_len,
847  size_t *m_len,
848  GError **err);
849 
850 
851 #if HAVE_SPREAD
852 
859 gboolean fbCollectorTestGroupMembership(
860  fbCollector_t *collector,
861  int group_offset);
862 
863 #endif
864 
872 void fbListenerAppFree(
873  fbListener_t *listener,
874  void *ctx);
875 
884  fBuf_t *fbuf,
885  fbListener_t *listener);
886 
894 void fbListenerRemove(
895  fbListener_t *listener,
896  int fd);
897 
906  fbListener_t *listener);
907 
915  fbCollector_t *collector);
916 
921 gboolean fbListenerCallAppInit(
922  fbListener_t *listener,
923  fbUDPConnSpec_t *spec,
924  GError **err);
925 
932  fbListener_t *listener,
933  fbSession_t *session);
934 
935 #endif
gboolean reject
reject flag
Definition: private.h:156
gboolean fbCollectMessage(fbCollector_t *collector, uint8_t *msgbase, size_t *msglen, GError **err)
fbCollectMessage
void fbTemplateRelease(fbTemplate_t *tmpl)
fbTemplateRelease
fbSession_t * fbListenerSetPeerSession(fbListener_t *listener, fbSession_t *session)
Set the session on the fbuf and listener.
fbVarfield_t template_description
Template description (optional)
Definition: private.h:181
void fbCollectorInterruptSocket(fbCollector_t *collector)
Interrupt the socket for a given collector to stop it from reading more data.
gboolean fbInfoElementCopyToTemplateByName(fbInfoModel_t *model, const char *name, uint16_t len_override, fbInfoElement_t *tmpl_ie)
fbInfoElementCopyToTemplateByName
#define FB_IESPEC_NULL
Convenience macro defining a null information element specification initializer to terminate a consta...
Definition: public.h:1501
struct fbTemplateOptRec_st fbTemplateOptRec_t
Template metadata options record structure.
A variable-length field value.
Definition: public.h:1033
void * ctx
application context.
Definition: private.h:138
struct fbUDPConnSpec_st * prev
doubly linked to timeout faster
Definition: private.h:150
const fbInfoElement_t * fbInfoModelGetElement(fbInfoModel_t *model, fbInfoElement_t *ex_ie)
fbInfoModelGetElement
size_t peerlen
size of peer
Definition: private.h:146
struct fbCollector_st fbCollector_t
IPFIX Collecting Process endpoint.
Definition: public.h:1647
struct fbExporter_st fbExporter_t
IPFIX Exporting Process endpoint.
Definition: public.h:1637
int fbCollectorGetFD(fbCollector_t *collector)
fbCollectorGetFD
struct fbSession_st fbSession_t
An IPFIX Transport Session state container.
Definition: public.h:1539
fbCollector_t * fbCollectorAllocSocket(fbListener_t *listener, void *ctx, int fd, struct sockaddr *peer, size_t peerlen)
fbCollectorAllocSocket
struct fbListener_st fbListener_t
IPFIX Collecting Process session listener.
Definition: public.h:1656
void(* fbNewTemplateCallback_fn)(fbSession_t *session, uint16_t tid, fbTemplate_t *tmpl, void *app_ctx, void **tmpl_ctx, fbTemplateCtxFree_fn *fn)
A callback function that will be called when the session receives a new external template.
Definition: public.h:1738
uint32_t fbInfoElementHash(fbInfoElement_t *ie)
fbInfoElementHash
gboolean active
TRUE if this template has been activated (is no longer mutable)
Definition: private.h:230
gboolean fbListenerCallAppInit(fbListener_t *listener, fbUDPConnSpec_t *spec, GError **err)
call appinit from UDP
time_t last_seen
last seen time
Definition: private.h:152
uint16_t template_id
Template ID.
Definition: private.h:183
uint16_t ie_count
Count of information elements in template.
Definition: private.h:197
fbInfoModel_t * model
Information model (for looking up information elements by spec)
Definition: private.h:193
gboolean fBufAppendTemplate(fBuf_t *fbuf, uint16_t tmpl_id, fbTemplate_t *tmpl, gboolean revoked, GError **err)
fBufAppendTemplate
An UDP Connection specifier.
Definition: private.h:134
uint16_t fBufGetExportTemplate(fBuf_t *fbuf)
fBufGetExportTemplate
void fbCollectorRemoveListenerLastBuf(fBuf_t *fbuf, fbCollector_t *collector)
fbCollectorRemoveListenerLastBuf
gboolean default_length
TRUE if any field was created using an fbInfoElementSpec_t with a defaulted length.
Definition: private.h:235
Template metadata options record structure.
Definition: private.h:175
gboolean fbConnSpecInitTLS(fbConnSpec_t *spec, gboolean passive, GError **err)
fbConnSpecInitTLS
uint16_t ie_internal_len
Total length required to store this template in a data structure.
Definition: private.h:215
void(* fbTemplateCtxFree_fn)(void *tmpl_ctx, void *app_ctx)
A callback function that is called when a template is freed.
Definition: public.h:1711
struct fbUDPConnSpec_st * next
link to next one in list
Definition: private.h:148
Fixbuf IPFIX protocol library public interface.
void fbTemplateRetain(fbTemplate_t *tmpl)
fbTemplateRetain
void fbListenerRemove(fbListener_t *listener, int fd)
fbListenerRemove
gboolean fbConnSpecLookupAI(fbConnSpec_t *spec, gboolean passive, GError **err)
fbConnSpecLookupAI
gboolean fbExportMessage(fbExporter_t *exporter, uint8_t *msgbase, size_t msglen, GError **err)
fbExportMessage
#define FB_IE_VARLEN
Information element length constant for variable-length IE.
Definition: public.h:1283
int ref_count
Reference count.
Definition: private.h:195
uint32_t obdomain
with peer address this is the key
Definition: private.h:154
void fbTemplateDebug(const char *label, uint16_t tid, fbTemplate_t *tmpl)
fbTemplateDebug
void fbCollectorFree(fbCollector_t *collector)
fbCollectorFree
fbSession_t * fbSessionClone(fbSession_t *base)
fbSessionClone
void * fbSessionNewTemplateCallbackAppCtx(fbSession_t *session)
Return the callback function&#39;s application context for a given session.
uint16_t tmpl_len
Total length of the template record or options template record defining this template.
Definition: private.h:220
struct fbInfoModel_st fbInfoModel_t
An IPFIX information model.
Definition: public.h:1051
gboolean fbCollectorHasTranslator(fbCollector_t *collector)
fbCollectorHasTranslator
void fbListenerAppFree(fbListener_t *listener, void *ctx)
fbListenerAppFree
uint16_t ie_len
Total length of information elements in records described by this template.
Definition: private.h:209
void fbConnSpecFree(fbConnSpec_t *spec)
fbConnSpecFree
uint16_t * off_cache
Field offset cache.
Definition: private.h:228
void fBufRewind(fBuf_t *fbuf)
fBufRewind
void * app_ctx
The application&#39;s Context pointer for the ctx_free function.
Definition: private.h:250
void fbListenerRemoveLastBuf(fBuf_t *fbuf, fbListener_t *listener)
fbListenerRemoveLastBuf
GHashTable * indices
Map of information element to index in ie_ary.
Definition: private.h:226
void fbSessionSetTemplateBuffer(fbSession_t *session, fBuf_t *fbuf)
fbSessionSetTemplateBuffer
gboolean is_varlen
Set to TRUE if this template contains any variable length IEs.
Definition: private.h:222
void fbExporterFree(fbExporter_t *exporter)
fbExporterFree
gboolean fbCollectMessageBuffer(uint8_t *hdr, size_t b_len, size_t *m_len, GError **err)
fbCollectMessageBuffer
fbVarfield_t template_name
List of PEN, IE num pairs.
Definition: private.h:179
gboolean fbInfoElementEqual(const fbInfoElement_t *a, const fbInfoElement_t *b)
fbInfoElementEqual
void fbCollectorSetFD(fbCollector_t *collector, int fd)
fbCollectorSetFD
gboolean fbInfoElementCopyToTemplate(fbInfoModel_t *model, fbInfoElement_t *ex_ie, fbInfoElement_t *tmpl_ie)
fbInfoElementCopyToTemplate
void * tmpl_ctx
Template context.
Definition: private.h:242
uint32_t fbSessionGetSequence(fbSession_t *session)
fbSessionGetSequence
uint16_t fbExporterGetMTU(fbExporter_t *exporter)
fbExporterGetMTU
fbNewTemplateCallback_fn fbSessionNewTemplateCallback(fbSession_t *session)
Returns the callback function for a given session.
An IPFIX template or options template structure.
Definition: private.h:191
fbConnSpec_t * fbConnSpecCopy(fbConnSpec_t *spec)
fbConnSpecCopy
void fbInfoElementDebug(gboolean tmpl, fbInfoElement_t *ie)
fbInfoElementDebug
union fbUDPConnSpec_st::@0 peer
key to this conn spec
fbInfoElement_t ** ie_ary
Ordered array of pointers to information elements in this template.
Definition: private.h:224
fbCollector_t * fbCollectorAllocTLS(fbListener_t *listener, void *ctx, int fd, struct sockaddr *peer, size_t peerlen, GError **err)
fbCollectorAllocTLS
Connection specifier.
Definition: public.h:1575
void fbSessionSetCollector(fbSession_t *session, fbCollector_t *collector)
fbSessionSetCollector
struct fBuf_st fBuf_t
An IPFIX message buffer.
Definition: public.h:1025
void fbTemplateFree(fbTemplate_t *tmpl)
fbTemplateFree
const fbInfoElement_t * fbInfoModelAddAlienElement(fbInfoModel_t *model, fbInfoElement_t *ex_ie)
fbInfoModelAddAlienElement
uint16_t fBufGetInternalTemplate(fBuf_t *fbuf)
fBufGetInternalTemplate
A single IPFIX Information Element definition.
Definition: public.h:1393
uint16_t scope_count
Count of scope information elements in template.
Definition: private.h:202
fbConnSpec_t * fbListenerGetConnSpec(fbListener_t *listener)
fbListenerGetConnSpec
void fBufSetSession(fBuf_t *fbuf, fbSession_t *session)
fBufSetSession
A single IPFIX Information Element specification.
Definition: public.h:1508
fbTemplateCtxFree_fn ctx_free
Callback to free the ctx pointer when template is freed.
Definition: private.h:246
struct fbUDPConnSpec_st fbUDPConnSpec_t
An UDP Connection specifier.
void fbSessionSetSequence(fbSession_t *session, uint32_t sequence)
fbSessionSetSequence
fbSession_t * session
pointer to the session for this peer address
Definition: private.h:136
void fBufRemoveTemplateTcplan(fBuf_t *fbuf, fbTemplate_t *tmpl)
fBufRemoveTemplateTcplan