private.h
Go to the documentation of this file.
1 
42 #ifndef _FB_PRIVATE_H_
43 #define _FB_PRIVATE_H_
44 #include <fixbuf/public.h>
45 
46 #if HAVE_SPREAD
47 #include <sp.h>
48 #include <pthread.h>
49 #endif
50 
51 
64 #define IPFIX_ENTERPRISE_BIT 0x8000
65 
68 #define FB_MSGLEN_MAX 65535
69 
70 #if HAVE_SPREAD
71 
72 typedef struct sp_groupname_st
73 {
74  char name[MAX_GROUP_NAME];
75 } sp_groupname_t;
76 
77 #define FB_SPREAD_NUM_GROUPS 16
78 #define FB_SPREAD_MTU 8192
79 
80 typedef struct fbSpreadSpec_st {
83  fbSession_t *session;
86  char * daemon;
88  sp_groupname_t *groups;
90  int num_groups;
92  sp_groupname_t *groups_to_send;
93  int num_groups_to_send;
95  mailbox mbox;
97  char privgroup[MAX_GROUP_NAME + 2];
99  pthread_mutex_t write_lock;
101  pthread_t recv_thread;
103  mailbox recv_mbox;
105  char recv_privgroup[MAX_GROUP_NAME + 2];
107  GError *recv_err;
109  int recv_exit;
111  int recv_max_groups;
113  int recv_num_groups;
115  sp_groupname_t *recv_groups;
117  int recv_max;
119  char *recv_mess;
120 } fbSpreadSpec_t;
121 
122 #endif /* HAVE_SPREAD */
123 
130 typedef struct fbUDPConnSpec_st {
134  void *ctx;
136  union {
137  struct sockaddr so;
138  struct sockaddr_in ip4;
139  struct sockaddr_in6 ip6;
140  } peer;
142  size_t peerlen;
148  time_t last_seen;
150  uint32_t obdomain;
152  gboolean reject;
154 
155 
156 #ifdef DEFINE_TEMPLATE_METADATA_SPEC
157 /* Template metadata template */
158 static fbInfoElementSpec_t template_metadata_spec[] = {
159  /* {"templateInformationElementList", FB_IE_VARLEN, 0 }, */
160  {"templateName", FB_IE_VARLEN, 0 },
161  {"templateDescription", FB_IE_VARLEN, 0 },
162  {"templateId", 2, 0 },
164 };
165 #endif
166 
171 typedef struct fbTemplateOptRec_st {
173  /* fbSubTemplateList_t info_element_list; */
179  uint16_t template_id;
181 
193  uint16_t ie_count;
198  uint16_t scope_count;
205  uint16_t ie_len;
211  uint16_t ie_internal_len;
216  uint16_t tmpl_len;
218  gboolean is_varlen;
222  GHashTable *indices;
224  uint16_t *off_cache;
226  gboolean active;
231  gboolean default_length;
232 
233  fbTemplateOptRec_t *metadata_rec;
238  void *tmpl_ctx;
246  void *app_ctx;
247 };
248 
255 void fBufRewind(
256  fBuf_t *fbuf);
257 
269 gboolean fBufAppendTemplate(
270  fBuf_t *fbuf,
271  uint16_t tmpl_id,
272  fbTemplate_t *tmpl,
273  gboolean revoked,
274  GError **err);
275 
276 #if HAVE_SPREAD
277 
283 void fBufSetExportGroups(
284  fBuf_t *fbuf,
285  char **groups,
286  int num_groups,
287  GError **err);
288 
289 
290 #endif
291 
298  fBuf_t *fbuf,
299  fbTemplate_t *tmpl);
300 
305 void fBufSetSession(
306  fBuf_t *fbuf,
307  fbSession_t *session);
308 
313 uint16_t fBufGetExportTemplate(
314  fBuf_t *fbuf);
315 
316 
321 uint16_t fBufGetInternalTemplate(
322  fBuf_t *fbuf);
323 
331 uint32_t fbInfoElementHash(
332  fbInfoElement_t *ie);
333 
342 gboolean fbInfoElementEqual(
343  const fbInfoElement_t *a,
344  const fbInfoElement_t *b);
345 
353 void fbInfoElementDebug(
354  gboolean tmpl,
355  fbInfoElement_t *ie);
356 
365  fbInfoModel_t *model,
366  fbInfoElement_t *ex_ie);
367 
377  fbInfoModel_t *model,
378  fbInfoElement_t *ex_ie,
379  fbInfoElement_t *tmpl_ie);
380 
392  fbInfoModel_t *model,
393  const char *name,
394  uint16_t len_override,
395  fbInfoElement_t *tmpl_ie);
396 
406  fbInfoModel_t *model,
407  fbInfoElement_t *ex_ie);
408 
416 void fbTemplateRetain(
417  fbTemplate_t *tmpl);
418 
426 void fbTemplateRelease(
427  fbTemplate_t *tmpl);
428 
436 void fbTemplateFree(
437  fbTemplate_t *tmpl);
438 
447 void fbTemplateDebug(
448  const char *label,
449  uint16_t tid,
450  fbTemplate_t *tmpl);
451 
459  fbSession_t *session);
460 
469  fbSession_t *session);
470 
478  fbSession_t *base);
479 
487 uint32_t fbSessionGetSequence(
488  fbSession_t *session);
489 
498  fbSession_t *session,
499  uint32_t sequence);
500 
509  fbSession_t *session,
510  fBuf_t *fbuf);
511 
520  fbSession_t *session,
521  fbCollector_t *collector);
522 
523 #if HAVE_SPREAD
524 
528 void fbSessionSetGroupParams(
529  fbSession_t *session,
530  sp_groupname_t *groups,
531  int num_groups);
532 
538 void fbSessionSetPrivateGroup(
539  fbSession_t *session,
540  char *group,
541  char *privgroup);
542 
547 void fbSessionSetGroup(
548  fbSession_t *session,
549  char *group);
550 
555 unsigned int fbSessionGetGroupOffset(
556  fbSession_t *session,
557  char *group);
558 
563 unsigned int fbSessionGetGroup(
564  fbSession_t *session);
565 #endif
566 
567 void fbSessionClearIntTmplTableFlag(
568  fbSession_t *session);
569 
570 void fbSessionClearExtTmplTableFlag(
571  fbSession_t *session);
572 
573 int fbSessionIntTmplTableFlagIsSet(
574  fbSession_t *session);
575 
576 int fbSessionExtTmplTableFlagIsSet(
577  fbSession_t *session);
586 gboolean fbConnSpecLookupAI(
587  fbConnSpec_t *spec,
588  gboolean passive,
589  GError **err);
590 
599 gboolean fbConnSpecInitTLS(
600  fbConnSpec_t *spec,
601  gboolean passive,
602  GError **err);
603 
612  fbConnSpec_t *spec);
613 
621 void fbConnSpecFree(
622  fbConnSpec_t *spec);
623 
624 #if HAVE_SPREAD
625 
632 fbSpreadSpec_t *fbConnSpreadCopy(
633  fbSpreadParams_t *spec);
634 
642 void fbConnSpreadFree(
643  fbSpreadSpec_t *spec);
644 
653 const char * fbConnSpreadError(
654  int err );
655 
656 
666 void fbExporterSetGroupsToSend(
667  fbExporter_t *exporter,
668  char **groups,
669  int num_groups);
670 
671 
681 gboolean fbExporterCheckGroups(
682  fbExporter_t *exporter,
683  char **groups,
684  int num_groups);
685 
686 
687 #endif /* HAVE_SPREAD */
688 
696 uint16_t fbExporterGetMTU(
697  fbExporter_t *exporter);
698 
708 gboolean fbExportMessage(
709  fbExporter_t *exporter,
710  uint8_t *msgbase,
711  size_t msglen,
712  GError **err);
713 
721 void fbExporterFree(
722  fbExporter_t *exporter);
723 
732  fBuf_t *fbuf,
733  fbCollector_t *collector);
734 
746  fbListener_t *listener,
747  void *ctx,
748  int fd,
749  struct sockaddr *peer,
750  size_t peerlen);
751 
764  fbListener_t *listener,
765  void *ctx,
766  int fd,
767  struct sockaddr *peer,
768  size_t peerlen,
769  GError **err);
770 
780 gboolean fbCollectMessage(
781  fbCollector_t *collector,
782  uint8_t *msgbase,
783  size_t *msglen,
784  GError **err);
785 
793 int fbCollectorGetFD(
794  fbCollector_t *collector);
795 
802 void fbCollectorSetFD(
803  fbCollector_t *collector,
804  int fd);
805 
813 void fbCollectorFree(
814  fbCollector_t *collector);
815 
823 gboolean fbCollectorHasTranslator(
824  fbCollector_t *collector);
825 
826 
840 gboolean fbCollectMessageBuffer(
841  uint8_t *hdr,
842  size_t b_len,
843  size_t *m_len,
844  GError **err);
845 
846 
847 #if HAVE_SPREAD
848 
855 gboolean fbCollectorTestGroupMembership(
856  fbCollector_t *collector,
857  int group_offset);
858 
859 #endif
860 
868 void fbListenerAppFree(
869  fbListener_t *listener,
870  void *ctx);
871 
880  fBuf_t *fbuf,
881  fbListener_t *listener);
882 
890 void fbListenerRemove(
891  fbListener_t *listener,
892  int fd);
893 
902  fbListener_t *listener);
903 
911  fbCollector_t *collector);
912 
917 gboolean fbListenerCallAppInit(
918  fbListener_t *listener,
919  fbUDPConnSpec_t *spec,
920  GError **err);
921 
928  fbListener_t *listener,
929  fbSession_t *session);
930 
931 #endif
gboolean reject
reject flag
Definition: private.h:152
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:177
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
struct fbTemplateOptRec_st fbTemplateOptRec_t
Template metadata options record structure.
A variable-length field value.
Definition: public.c:1059
void * ctx
application context.
Definition: private.h:134
struct fBuf_st fBuf_t
An IPFIX message buffer.
Definition: public.c:1051
struct fbUDPConnSpec_st * prev
doubly linked to timeout faster
Definition: private.h:146
struct fbCollector_st fbCollector_t
IPFIX Collecting Process endpoint.
Definition: public.c:1737
const fbInfoElement_t * fbInfoModelGetElement(fbInfoModel_t *model, fbInfoElement_t *ex_ie)
fbInfoModelGetElement
struct fbInfoModel_st fbInfoModel_t
An IPFIX information model.
Definition: public.c:1077
size_t peerlen
size of peer
Definition: private.h:142
int fbCollectorGetFD(fbCollector_t *collector)
fbCollectorGetFD
fbCollector_t * fbCollectorAllocSocket(fbListener_t *listener, void *ctx, int fd, struct sockaddr *peer, size_t peerlen)
fbCollectorAllocSocket
struct fbExporter_st fbExporter_t
IPFIX Exporting Process endpoint.
Definition: public.c:1727
struct fbListener_st fbListener_t
IPFIX Collecting Process session listener.
Definition: public.c:1746
uint32_t fbInfoElementHash(fbInfoElement_t *ie)
fbInfoElementHash
gboolean active
TRUE if this template has been activated (is no longer mutable)
Definition: private.h:226
gboolean fbListenerCallAppInit(fbListener_t *listener, fbUDPConnSpec_t *spec, GError **err)
call appinit from UDP
time_t last_seen
last seen time
Definition: private.h:148
uint16_t template_id
Template ID.
Definition: private.h:179
uint16_t ie_count
Count of information elements in template.
Definition: private.h:193
fbInfoModel_t * model
Information model (for looking up information elements by spec)
Definition: private.h:189
gboolean fBufAppendTemplate(fBuf_t *fbuf, uint16_t tmpl_id, fbTemplate_t *tmpl, gboolean revoked, GError **err)
fBufAppendTemplate
An UDP Connection specifier.
Definition: private.h:130
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:231
Template metadata options record structure.
Definition: private.h:171
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:211
struct fbUDPConnSpec_st * next
link to next one in list
Definition: private.h:144
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
int ref_count
Reference count.
Definition: private.h:191
uint32_t obdomain
with peer address this is the key
Definition: private.h:150
void fbTemplateDebug(const char *label, uint16_t tid, fbTemplate_t *tmpl)
fbTemplateDebug
void(* fbTemplateCtxFree_fn)(void *tmpl_ctx, void *app_ctx)
A callback function that is called when a template is freed.
Definition: public.c:1801
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:216
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:205
void fbConnSpecFree(fbConnSpec_t *spec)
fbConnSpecFree
uint16_t * off_cache
Field offset cache.
Definition: private.h:224
void fBufRewind(fBuf_t *fbuf)
fBufRewind
void * app_ctx
The application&#39;s Context pointer for the ctx_free function.
Definition: private.h:246
#define FB_IESPEC_NULL
Convenience macro defining a null information element specification initializer to terminate a consta...
Definition: public.c:1591
void fbListenerRemoveLastBuf(fBuf_t *fbuf, fbListener_t *listener)
fbListenerRemoveLastBuf
GHashTable * indices
Map of information element to index in ie_ary.
Definition: private.h:222
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:218
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:175
gboolean fbInfoElementEqual(const fbInfoElement_t *a, const fbInfoElement_t *b)
fbInfoElementEqual
#define FB_IE_VARLEN
Information element length constant for variable-length IE.
Definition: public.c:1322
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:238
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:187
struct fbSession_st fbSession_t
An IPFIX Transport Session state container.
Definition: public.c:1629
fbConnSpec_t * fbConnSpecCopy(fbConnSpec_t *spec)
fbConnSpecCopy
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.c:1828
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:220
fbCollector_t * fbCollectorAllocTLS(fbListener_t *listener, void *ctx, int fd, struct sockaddr *peer, size_t peerlen, GError **err)
fbCollectorAllocTLS
Connection specifier.
Definition: public.c:1665
void fbSessionSetCollector(fbSession_t *session, fbCollector_t *collector)
fbSessionSetCollector
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.c:1483
uint16_t scope_count
Count of scope information elements in template.
Definition: private.h:198
fbConnSpec_t * fbListenerGetConnSpec(fbListener_t *listener)
fbListenerGetConnSpec
void fBufSetSession(fBuf_t *fbuf, fbSession_t *session)
fBufSetSession
A single IPFIX Information Element specification.
Definition: public.c:1598
fbTemplateCtxFree_fn ctx_free
Callback to free the ctx pointer when template is freed.
Definition: private.h:242
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:132
void fBufRemoveTemplateTcplan(fBuf_t *fbuf, fbTemplate_t *tmpl)
fBufRemoveTemplateTcplan