private.h
Go to the documentation of this file.
1 
61 #ifndef _FB_PRIVATE_H_
62 #define _FB_PRIVATE_H_
63 #include <fixbuf/public.h>
64 
65 #if HAVE_SPREAD
66 #include <sp.h>
67 #include <pthread.h>
68 #endif
69 
70 
83 #define IPFIX_ENTERPRISE_BIT 0x8000
84 
86 #define IPFIX_REVERSE_PEN 29305
87 
90 #define FB_MSGLEN_MAX 65535
91 
92 #if HAVE_SPREAD
93 
94 typedef struct sp_groupname_st
95 {
96  char name[MAX_GROUP_NAME];
97 } sp_groupname_t;
98 
99 #define FB_SPREAD_NUM_GROUPS 16
100 #define FB_SPREAD_MTU 8192
101 
102 typedef struct fbSpreadSpec_st {
105  fbSession_t *session;
108  char * daemon;
110  sp_groupname_t *groups;
112  int num_groups;
114  sp_groupname_t *groups_to_send;
115  int num_groups_to_send;
117  mailbox mbox;
119  char privgroup[MAX_GROUP_NAME + 2];
121  pthread_mutex_t write_lock;
123  pthread_t recv_thread;
125  mailbox recv_mbox;
127  char recv_privgroup[MAX_GROUP_NAME + 2];
129  GError *recv_err;
131  int recv_exit;
133  int recv_max_groups;
135  int recv_num_groups;
137  sp_groupname_t *recv_groups;
139  int recv_max;
141  char *recv_mess;
142 } fbSpreadSpec_t;
143 
144 #endif /* HAVE_SPREAD */
145 
152 typedef struct fbUDPConnSpec_st {
156  void *ctx;
158  union {
159  struct sockaddr so;
160  struct sockaddr_in ip4;
161  struct sockaddr_in6 ip6;
162  } peer;
164  size_t peerlen;
170  time_t last_seen;
172  uint32_t obdomain;
174  gboolean reject;
176 
177 
178 /* Template metadata template */
179 static fbInfoElementSpec_t template_metadata_spec[] = {
180  /* {"templateInformationElementList", 0, 0 }, */
181  {"templateName", 0, 0 },
182  {"templateDescription", 0, 0 },
183  {"templateId", 0, 0 },
185 };
186 
191 typedef struct fbTemplateOptRec_st {
193  /* fbSubTemplateList_t info_element_list; */
199  uint16_t template_id;
201 
213  uint16_t ie_count;
218  uint16_t scope_count;
225  uint16_t ie_len;
231  uint16_t ie_internal_len;
236  uint16_t tmpl_len;
238  gboolean is_varlen;
242  GHashTable *indices;
244  uint16_t *off_cache;
246  gboolean active;
247 
248  fbTemplateOptRec_t *metadata_rec;
253  void *tmpl_ctx;
261  void *app_ctx;
262 };
263 
270 void fBufRewind(
271  fBuf_t *fbuf);
272 
284 gboolean fBufAppendTemplate(
285  fBuf_t *fbuf,
286  uint16_t tmpl_id,
287  fbTemplate_t *tmpl,
288  gboolean revoked,
289  GError **err);
290 
291 #if HAVE_SPREAD
292 
298 void fBufSetExportGroups(
299  fBuf_t *fbuf,
300  char **groups,
301  int num_groups,
302  GError **err);
303 
304 
305 #endif
306 
313  fBuf_t *fbuf,
314  fbTemplate_t *tmpl);
315 
320 void fBufSetSession(
321  fBuf_t *fbuf,
322  fbSession_t *session);
323 
328 uint16_t fBufGetExportTemplate(
329  fBuf_t *fbuf);
330 
331 
336 uint16_t fBufGetInternalTemplate(
337  fBuf_t *fbuf);
338 
346 uint32_t fbInfoElementHash(
347  fbInfoElement_t *ie);
348 
357 gboolean fbInfoElementEqual(
358  const fbInfoElement_t *a,
359  const fbInfoElement_t *b);
360 
368 void fbInfoElementDebug(
369  gboolean tmpl,
370  fbInfoElement_t *ie);
371 
380  fbInfoModel_t *model,
381  fbInfoElement_t *ex_ie);
382 
392  fbInfoModel_t *model,
393  fbInfoElement_t *ex_ie,
394  fbInfoElement_t *tmpl_ie);
395 
407  fbInfoModel_t *model,
408  const char *name,
409  uint16_t len_override,
410  fbInfoElement_t *tmpl_ie);
411 
421  fbInfoModel_t *model,
422  fbInfoElement_t *ex_ie);
423 
431 void fbTemplateRetain(
432  fbTemplate_t *tmpl);
433 
441 void fbTemplateRelease(
442  fbTemplate_t *tmpl);
443 
451 void fbTemplateFree(
452  fbTemplate_t *tmpl);
453 
462 void fbTemplateDebug(
463  const char *label,
464  uint16_t tid,
465  fbTemplate_t *tmpl);
466 
474  fbSession_t *session);
475 
483  fbSession_t *session);
484 
493  fbSession_t *session);
494 
502  fbSession_t *base);
503 
511 uint32_t fbSessionGetSequence(
512  fbSession_t *session);
513 
522  fbSession_t *session,
523  uint32_t sequence);
524 
533  fbSession_t *session,
534  fBuf_t *fbuf);
535 
544  fbSession_t *session,
545  fbCollector_t *collector);
546 
547 #if HAVE_SPREAD
548 
552 void fbSessionSetGroupParams(
553  fbSession_t *session,
554  sp_groupname_t *groups,
555  int num_groups);
556 
562 void fbSessionSetPrivateGroup(
563  fbSession_t *session,
564  char *group,
565  char *privgroup);
566 
571 void fbSessionSetGroup(
572  fbSession_t *session,
573  char *group);
574 
579 unsigned int fbSessionGetGroupOffset(
580  fbSession_t *session,
581  char *group);
582 
587 unsigned int fbSessionGetGroup(
588  fbSession_t *session);
589 #endif
590 
591 void fbSessionClearIntTmplTableFlag(
592  fbSession_t *session);
593 
594 void fbSessionClearExtTmplTableFlag(
595  fbSession_t *session);
596 
597 int fbSessionIntTmplTableFlagIsSet(
598  fbSession_t *session);
599 
600 int fbSessionExtTmplTableFlagIsSet(
601  fbSession_t *session);
610 gboolean fbConnSpecLookupAI(
611  fbConnSpec_t *spec,
612  gboolean passive,
613  GError **err);
614 
623 gboolean fbConnSpecInitTLS(
624  fbConnSpec_t *spec,
625  gboolean passive,
626  GError **err);
627 
636  fbConnSpec_t *spec);
637 
645 void fbConnSpecFree(
646  fbConnSpec_t *spec);
647 
648 #if HAVE_SPREAD
649 
656 fbSpreadSpec_t *fbConnSpreadCopy(
657  fbSpreadParams_t *spec);
658 
666 void fbConnSpreadFree(
667  fbSpreadSpec_t *spec);
668 
677 const char * fbConnSpreadError(
678  int err );
679 
680 
690 void fbExporterSetGroupsToSend(
691  fbExporter_t *exporter,
692  char **groups,
693  int num_groups);
694 
695 
705 gboolean fbExporterCheckGroups(
706  fbExporter_t *exporter,
707  char **groups,
708  int num_groups);
709 
710 
711 #endif /* HAVE_SPREAD */
712 
720 uint16_t fbExporterGetMTU(
721  fbExporter_t *exporter);
722 
732 gboolean fbExportMessage(
733  fbExporter_t *exporter,
734  uint8_t *msgbase,
735  size_t msglen,
736  GError **err);
737 
745 void fbExporterFree(
746  fbExporter_t *exporter);
747 
756  fBuf_t *fbuf,
757  fbCollector_t *collector);
758 
770  fbListener_t *listener,
771  void *ctx,
772  int fd,
773  struct sockaddr *peer,
774  size_t peerlen);
775 
788  fbListener_t *listener,
789  void *ctx,
790  int fd,
791  struct sockaddr *peer,
792  size_t peerlen,
793  GError **err);
794 
804 gboolean fbCollectMessage(
805  fbCollector_t *collector,
806  uint8_t *msgbase,
807  size_t *msglen,
808  GError **err);
809 
817 int fbCollectorGetFD(
818  fbCollector_t *collector);
819 
826 void fbCollectorSetFD(
827  fbCollector_t *collector,
828  int fd);
829 
837 void fbCollectorFree(
838  fbCollector_t *collector);
839 
847 gboolean fbCollectorHasTranslator(
848  fbCollector_t *collector);
849 
850 
864 gboolean fbCollectMessageBuffer(
865  uint8_t *hdr,
866  size_t b_len,
867  size_t *m_len,
868  GError **err);
869 
870 
871 #if HAVE_SPREAD
872 
879 gboolean fbCollectorTestGroupMembership(
880  fbCollector_t *collector,
881  int group_offset);
882 
883 #endif
884 
892 void fbListenerAppFree(
893  fbListener_t *listener,
894  void *ctx);
895 
904  fBuf_t *fbuf,
905  fbListener_t *listener);
906 
914 void fbListenerRemove(
915  fbListener_t *listener,
916  int fd);
917 
926  fbListener_t *listener);
927 
935  fbCollector_t *collector);
936 
941 gboolean fbListenerCallAppInit(
942  fbListener_t *listener,
943  fbUDPConnSpec_t *spec,
944  GError **err);
945 
952  fbListener_t *listener,
953  fbSession_t *session);
954 
955 #endif
gboolean reject
reject flag
Definition: private.h:174
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:197
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:1507
struct fbTemplateOptRec_st fbTemplateOptRec_t
Template metadata options record structure.
A variable-length field value.
Definition: public.h:1053
void * ctx
application context.
Definition: private.h:156
struct fbUDPConnSpec_st * prev
doubly linked to timeout faster
Definition: private.h:168
const fbInfoElement_t * fbInfoModelGetElement(fbInfoModel_t *model, fbInfoElement_t *ex_ie)
fbInfoModelGetElement
size_t peerlen
size of peer
Definition: private.h:164
struct fbCollector_st fbCollector_t
IPFIX Collecting Process endpoint.
Definition: public.h:1646
struct fbExporter_st fbExporter_t
IPFIX Exporting Process endpoint.
Definition: public.h:1636
int fbCollectorGetFD(fbCollector_t *collector)
fbCollectorGetFD
struct fbSession_st fbSession_t
An IPFIX Transport Session state container.
Definition: public.h:1538
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:1655
uint32_t fbInfoElementHash(fbInfoElement_t *ie)
fbInfoElementHash
gboolean active
TRUE if this template has been activated (is no longer mutable)
Definition: private.h:246
gboolean fbListenerCallAppInit(fbListener_t *listener, fbUDPConnSpec_t *spec, GError **err)
call appinit from UDP
time_t last_seen
last seen time
Definition: private.h:170
uint16_t template_id
Template ID.
Definition: private.h:199
uint16_t ie_count
Count of information elements in template.
Definition: private.h:213
fbInfoModel_t * model
Information model (for looking up information elements by spec)
Definition: private.h:209
gboolean fBufAppendTemplate(fBuf_t *fbuf, uint16_t tmpl_id, fbTemplate_t *tmpl, gboolean revoked, GError **err)
fBufAppendTemplate
fbNewTemplateCallback_fn fbSessionTemplateCallback(fbSession_t *session)
Returns the callback function for a given session.
An UDP Connection specifier.
Definition: private.h:152
uint16_t fBufGetExportTemplate(fBuf_t *fbuf)
fBufGetExportTemplate
void fbCollectorRemoveListenerLastBuf(fBuf_t *fbuf, fbCollector_t *collector)
fbCollectorRemoveListenerLastBuf
Template metadata options record structure.
Definition: private.h:191
gboolean fbConnSpecInitTLS(fbConnSpec_t *spec, gboolean passive, GError **err)
fbConnSpecInitTLS
void(* fbNewTemplateCallback_fn)(fbSession_t *session, uint16_t tid, fbTemplate_t *tmpl)
The callback function to be called when the session receives a new external template from the connect...
Definition: public.h:1717
uint16_t ie_internal_len
Total length required to store this template in a data structure.
Definition: private.h:231
struct fbUDPConnSpec_st * next
link to next one in list
Definition: private.h:166
Fixbuf IPFIX protocol library public interface.
void fbTemplateRetain(fbTemplate_t *tmpl)
fbTemplateRetain
void fbListenerRemove(fbListener_t *listener, int fd)
fbListenerRemove
void(* fbTemplateCtxCallback2_fn)(fbSession_t *session, uint16_t tid, fbTemplate_t *tmpl, void *app_ctx, void **tmpl_ctx, fbTemplateCtxFree2_fn *fn)
A callback function that will be called when the session receives a new external template.
Definition: public.h:1803
gboolean fbConnSpecLookupAI(fbConnSpec_t *spec, gboolean passive, GError **err)
fbConnSpecLookupAI
gboolean fbExportMessage(fbExporter_t *exporter, uint8_t *msgbase, size_t msglen, GError **err)
fbExportMessage
int ref_count
Reference count.
Definition: private.h:211
uint32_t obdomain
with peer address this is the key
Definition: private.h:172
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
uint16_t tmpl_len
Total length of the template record or options template record defining this template.
Definition: private.h:236
struct fbInfoModel_st fbInfoModel_t
An IPFIX information model.
Definition: public.h:1071
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:225
void fbConnSpecFree(fbConnSpec_t *spec)
fbConnSpecFree
uint16_t * off_cache
Field offset cache.
Definition: private.h:244
void fBufRewind(fBuf_t *fbuf)
fBufRewind
void * app_ctx
The application&#39;s Context pointer for the ctx_free function.
Definition: private.h:261
void fbListenerRemoveLastBuf(fBuf_t *fbuf, fbListener_t *listener)
fbListenerRemoveLastBuf
GHashTable * indices
Map of information element to index in ie_ary.
Definition: private.h:242
fbTemplateCtxFree2_fn ctx_free
Callback to free the ctx pointer when template is freed.
Definition: private.h:257
void fbSessionSetTemplateBuffer(fbSession_t *session, fBuf_t *fbuf)
fbSessionSetTemplateBuffer
void * fbSessionTemplateCtxCallbackAppCtx(fbSession_t *session)
Return the ctx callback function&#39;s application context for a given session.
gboolean is_varlen
Set to TRUE if this template contains any variable length IEs.
Definition: private.h:238
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:195
gboolean fbInfoElementEqual(const fbInfoElement_t *a, const fbInfoElement_t *b)
fbInfoElementEqual
fbTemplateCtxCallback2_fn fbSessionTemplateCtxCallback(fbSession_t *session)
Return the ctx callback function for a given session.
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:253
uint32_t fbSessionGetSequence(fbSession_t *session)
fbSessionGetSequence
uint16_t fbExporterGetMTU(fbExporter_t *exporter)
fbExporterGetMTU
An IPFIX template or options template structure.
Definition: private.h:207
fbConnSpec_t * fbConnSpecCopy(fbConnSpec_t *spec)
fbConnSpecCopy
void fbInfoElementDebug(gboolean tmpl, fbInfoElement_t *ie)
fbInfoElementDebug
fbInfoElement_t ** ie_ary
Ordered array of pointers to information elements in this template.
Definition: private.h:240
fbCollector_t * fbCollectorAllocTLS(fbListener_t *listener, void *ctx, int fd, struct sockaddr *peer, size_t peerlen, GError **err)
fbCollectorAllocTLS
Connection specifier.
Definition: public.h:1574
void fbSessionSetCollector(fbSession_t *session, fbCollector_t *collector)
fbSessionSetCollector
struct fBuf_st fBuf_t
An IPFIX message buffer.
Definition: public.h:1045
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:1399
void(* fbTemplateCtxFree2_fn)(void *tmpl_ctx, void *app_ctx)
A callback function that is called when a template is freed.
Definition: public.h:1741
uint16_t scope_count
Count of scope information elements in template.
Definition: private.h:218
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:1514
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:154
void fBufRemoveTemplateTcplan(fBuf_t *fbuf, fbTemplate_t *tmpl)
fBufRemoveTemplateTcplan