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 
75 typedef struct sp_groupname_st
76 {
77  char name[MAX_GROUP_NAME];
79 
81 #define FB_SPREAD_NUM_GROUPS 16
82 
84 #define FB_SPREAD_MTU 8192
85 
89 typedef struct fbSpreadSpec_st {
95  char * daemon;
103  int num_groups_to_send;
105  mailbox mbox;
107  char privgroup[MAX_GROUP_NAME + 2];
109  pthread_mutex_t write_lock;
111  pthread_t recv_thread;
113  mailbox recv_mbox;
115  char recv_privgroup[MAX_GROUP_NAME + 2];
117  GError *recv_err;
127  int recv_max;
129  char *recv_mess;
131 
132 #endif /* HAVE_SPREAD */
133 
140 typedef struct fbUDPConnSpec_st {
144  void *ctx;
146  union {
147  struct sockaddr so;
148  struct sockaddr_in ip4;
149  struct sockaddr_in6 ip6;
150  } peer;
152  size_t peerlen;
158  time_t last_seen;
160  uint32_t obdomain;
162  gboolean reject;
164 
165 
166 #ifdef DEFINE_TEMPLATE_METADATA_SPEC
167 /* Template metadata template */
168 static fbInfoElementSpec_t template_metadata_spec[] = {
169  /* {"templateInformationElementList", FB_IE_VARLEN, 0 }, */
170  {"templateName", FB_IE_VARLEN, 0 },
171  {"templateDescription", FB_IE_VARLEN, 0 },
172  {"templateId", 2, 0 },
174 };
175 #endif
176 
181 typedef struct fbTemplateOptRec_st {
183  /* fbSubTemplateList_t info_element_list; */
189  uint16_t template_id;
191 
203  uint16_t ie_count;
208  uint16_t scope_count;
215  uint16_t ie_len;
221  uint16_t ie_internal_len;
226  uint16_t tmpl_len;
228  gboolean is_varlen;
232  GHashTable *indices;
234  uint16_t *off_cache;
236  gboolean active;
241  gboolean default_length;
242 
243  fbTemplateOptRec_t *metadata_rec;
248  void *tmpl_ctx;
256  void *app_ctx;
257 };
258 
265 void fBufRewind(
266  fBuf_t *fbuf);
267 
279 gboolean fBufAppendTemplate(
280  fBuf_t *fbuf,
281  uint16_t tmpl_id,
282  fbTemplate_t *tmpl,
283  gboolean revoked,
284  GError **err);
285 
286 #if HAVE_SPREAD
287 
294  fBuf_t *fbuf,
295  char **groups,
296  int num_groups,
297  GError **err);
298 
299 
300 #endif
301 
308  fBuf_t *fbuf,
309  fbTemplate_t *tmpl);
310 
315 void fBufSetSession(
316  fBuf_t *fbuf,
317  fbSession_t *session);
318 
323 uint16_t fBufGetExportTemplate(
324  fBuf_t *fbuf);
325 
326 
331 uint16_t fBufGetInternalTemplate(
332  fBuf_t *fbuf);
333 
341 uint32_t fbInfoElementHash(
342  fbInfoElement_t *ie);
343 
352 gboolean fbInfoElementEqual(
353  const fbInfoElement_t *a,
354  const fbInfoElement_t *b);
355 
363 void fbInfoElementDebug(
364  gboolean tmpl,
365  fbInfoElement_t *ie);
366 
375  fbInfoModel_t *model,
376  fbInfoElement_t *ex_ie);
377 
387  fbInfoModel_t *model,
388  fbInfoElement_t *ex_ie,
389  fbInfoElement_t *tmpl_ie);
390 
402  fbInfoModel_t *model,
403  const char *name,
404  uint16_t len_override,
405  fbInfoElement_t *tmpl_ie);
406 
416  fbInfoModel_t *model,
417  fbInfoElement_t *ex_ie);
418 
426 void fbTemplateRetain(
427  fbTemplate_t *tmpl);
428 
436 void fbTemplateRelease(
437  fbTemplate_t *tmpl);
438 
446 void fbTemplateFree(
447  fbTemplate_t *tmpl);
448 
457 void fbTemplateDebug(
458  const char *label,
459  uint16_t tid,
460  fbTemplate_t *tmpl);
461 
469  fbSession_t *session);
470 
479  fbSession_t *session);
480 
488  fbSession_t *base);
489 
497 uint32_t fbSessionGetSequence(
498  fbSession_t *session);
499 
508  fbSession_t *session,
509  uint32_t sequence);
510 
519  fbSession_t *session,
520  fBuf_t *fbuf);
521 
530  fbSession_t *session,
531  fbCollector_t *collector);
532 
533 #if HAVE_SPREAD
534 
539  fbSession_t *session,
540  sp_groupname_t *groups,
541  int num_groups);
542 
549  fbSession_t *session,
550  char *group,
551  char *privgroup);
552 
557 void fbSessionSetGroup(
558  fbSession_t *session,
559  char *group);
560 
565 unsigned int fbSessionGetGroupOffset(
566  fbSession_t *session,
567  char *group);
568 
575 unsigned int fbSessionGetGroup(
576  fbSession_t *session);
577 #endif
578 
586  fbSession_t *session);
587 
595  fbSession_t *session);
596 
604  fbSession_t *session);
605 
613  fbSession_t *session);
614 
623 gboolean fbConnSpecLookupAI(
624  fbConnSpec_t *spec,
625  gboolean passive,
626  GError **err);
627 
636 gboolean fbConnSpecInitTLS(
637  fbConnSpec_t *spec,
638  gboolean passive,
639  GError **err);
640 
649  fbConnSpec_t *spec);
650 
658 void fbConnSpecFree(
659  fbConnSpec_t *spec);
660 
661 #if HAVE_SPREAD
662 
670  fbSpreadParams_t *spec);
671 
679 void fbConnSpreadFree(
680  fbSpreadSpec_t *spec);
681 
690 const char * fbConnSpreadError(
691  int err );
692 
693 
704  fbExporter_t *exporter,
705  char **groups,
706  int num_groups);
707 
708 
718 gboolean fbExporterCheckGroups(
719  fbExporter_t *exporter,
720  char **groups,
721  int num_groups);
722 
723 
724 #endif /* HAVE_SPREAD */
725 
733 uint16_t fbExporterGetMTU(
734  fbExporter_t *exporter);
735 
745 gboolean fbExportMessage(
746  fbExporter_t *exporter,
747  uint8_t *msgbase,
748  size_t msglen,
749  GError **err);
750 
758 void fbExporterFree(
759  fbExporter_t *exporter);
760 
769  fBuf_t *fbuf,
770  fbCollector_t *collector);
771 
783  fbListener_t *listener,
784  void *ctx,
785  int fd,
786  struct sockaddr *peer,
787  size_t peerlen);
788 
801  fbListener_t *listener,
802  void *ctx,
803  int fd,
804  struct sockaddr *peer,
805  size_t peerlen,
806  GError **err);
807 
817 gboolean fbCollectMessage(
818  fbCollector_t *collector,
819  uint8_t *msgbase,
820  size_t *msglen,
821  GError **err);
822 
830 int fbCollectorGetFD(
831  fbCollector_t *collector);
832 
839 void fbCollectorSetFD(
840  fbCollector_t *collector,
841  int fd);
842 
850 void fbCollectorFree(
851  fbCollector_t *collector);
852 
860 gboolean fbCollectorHasTranslator(
861  fbCollector_t *collector);
862 
863 
877 gboolean fbCollectMessageBuffer(
878  uint8_t *hdr,
879  size_t b_len,
880  size_t *m_len,
881  GError **err);
882 
883 
884 #if HAVE_SPREAD
885 
893  fbCollector_t *collector,
894  int group_offset);
895 
896 #endif
897 
905 void fbListenerAppFree(
906  fbListener_t *listener,
907  void *ctx);
908 
917  fBuf_t *fbuf,
918  fbListener_t *listener);
919 
927 void fbListenerRemove(
928  fbListener_t *listener,
929  int fd);
930 
939  fbListener_t *listener);
940 
948  fbCollector_t *collector);
949 
954 gboolean fbListenerCallAppInit(
955  fbListener_t *listener,
956  fbUDPConnSpec_t *spec,
957  GError **err);
958 
965  fbListener_t *listener,
966  fbSession_t *session);
967 
968 #endif
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.
const char * fbConnSpreadError(int err)
fbConnSpreadError
size_t peerlen
size of peer
Definition: private.h:152
void fbCollectorInterruptSocket(fbCollector_t *collector)
Interrupt the socket for a given collector to stop it from reading more data.
uint16_t ie_count
Count of information elements in template.
Definition: private.h:203
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:1603
struct fbTemplateOptRec_st fbTemplateOptRec_t
Template metadata options record structure.
time_t last_seen
last seen time
Definition: private.h:158
int fbSessionIntTmplTableFlagIsSet(fbSession_t *session)
fbSessionIntTmplTableFlagIsSet
const fbInfoElement_t * fbInfoModelGetElement(fbInfoModel_t *model, fbInfoElement_t *ex_ie)
fbInfoModelGetElement
fbVarfield_t template_name
List of PEN, IE num pairs.
Definition: private.h:185
An IPFIX template or options template structure.
Definition: private.h:197
struct fbCollector_st fbCollector_t
IPFIX Collecting Process endpoint.
Definition: public.h:1750
struct fbExporter_st fbExporter_t
IPFIX Exporting Process endpoint.
Definition: public.h:1741
int fbCollectorGetFD(fbCollector_t *collector)
fbCollectorGetFD
struct fbSession_st fbSession_t
An IPFIX Transport Session state container.
Definition: public.h:1640
fbCollector_t * fbCollectorAllocSocket(fbListener_t *listener, void *ctx, int fd, struct sockaddr *peer, size_t peerlen)
fbCollectorAllocSocket
uint16_t * off_cache
Field offset cache.
Definition: private.h:234
struct fbListener_st fbListener_t
IPFIX Collecting Process session listener.
Definition: public.h:1758
int ref_count
Reference count.
Definition: private.h:201
void fBufSetExportGroups(fBuf_t *fbuf, char **groups, int num_groups, GError **err)
fBufSetExportGroups
int fbSessionExtTmplTableFlagIsSet(fbSession_t *session)
fbSessionExtTmplTableFlagIsSet
uint32_t fbInfoElementHash(fbInfoElement_t *ie)
fbInfoElementHash
struct fbUDPConnSpec_st * next
link to next one in list
Definition: private.h:154
void fbSessionSetGroupParams(fbSession_t *session, sp_groupname_t *groups, int num_groups)
fbSessionSetGroupParams
gboolean fbListenerCallAppInit(fbListener_t *listener, fbUDPConnSpec_t *spec, GError **err)
call appinit from UDP
gboolean active
TRUE if this template has been activated (is no longer mutable)
Definition: private.h:236
pthread_mutex_t write_lock
Spread write lock.
Definition: private.h:109
gboolean fBufAppendTemplate(fBuf_t *fbuf, uint16_t tmpl_id, fbTemplate_t *tmpl, gboolean revoked, GError **err)
fBufAppendTemplate
uint16_t fBufGetExportTemplate(fBuf_t *fbuf)
fBufGetExportTemplate
void fbCollectorRemoveListenerLastBuf(fBuf_t *fbuf, fbCollector_t *collector)
fbCollectorRemoveListenerLastBuf
gboolean fbConnSpecInitTLS(fbConnSpec_t *spec, gboolean passive, GError **err)
fbConnSpecInitTLS
Connection specifier.
Definition: public.h:1676
void(* fbTemplateCtxFree_fn)(void *tmpl_ctx, void *app_ctx)
A callback function that is called when a template is freed.
Definition: public.h:1806
fbInfoElement_t ** ie_ary
Ordered array of pointers to information elements in this template.
Definition: private.h:230
unsigned int fbSessionGetGroupOffset(fbSession_t *session, char *group)
fbSessionGetGroupOffset
Fixbuf IPFIX protocol library public interface.
void fbTemplateRetain(fbTemplate_t *tmpl)
fbTemplateRetain
gboolean fbCollectorTestGroupMembership(fbCollector_t *collector, int group_offset)
fbCollectorTestGroupMembership
uint16_t ie_internal_len
Total length required to store this template in memory.
Definition: private.h:221
void fbListenerRemove(fbListener_t *listener, int fd)
fbListenerRemove
gboolean is_varlen
Set to TRUE if this template contains any variable length IEs.
Definition: private.h:228
Spread connection parameters.
Definition: public.h:1722
gboolean fbConnSpecLookupAI(fbConnSpec_t *spec, gboolean passive, GError **err)
fbConnSpecLookupAI
gboolean fbExportMessage(fbExporter_t *exporter, uint8_t *msgbase, size_t msglen, GError **err)
fbExportMessage
uint16_t ie_len
Total length of information elements in records described by this template.
Definition: private.h:215
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:92
#define FB_IE_VARLEN
Information element length constant for variable-length IE.
Definition: public.h:1334
void * tmpl_ctx
Template context.
Definition: private.h:248
int recv_max_groups
max size of group name array
Definition: private.h:121
mailbox mbox
the mailbox for the connection
Definition: private.h:105
An UDP Connection specifier.
Definition: private.h:140
void fbTemplateDebug(const char *label, uint16_t tid, fbTemplate_t *tmpl)
fbTemplateDebug
struct fbUDPConnSpec_st * prev
doubly linked to timeout faster
Definition: private.h:156
void fbCollectorFree(fbCollector_t *collector)
fbCollectorFree
int num_groups
number of groups in groups
Definition: private.h:100
A variable-length field value.
Definition: public.h:1076
A single IPFIX Information Element definition.
Definition: public.h:1496
fbSession_t * fbSessionClone(fbSession_t *base)
fbSessionClone
char * daemon
pointer to the daemon host address, in Spread format.
Definition: private.h:95
void * fbSessionNewTemplateCallbackAppCtx(fbSession_t *session)
Return the callback function&#39;s application context for a given session.
uint32_t obdomain
with peer address this is the key
Definition: private.h:160
struct fbInfoModel_st fbInfoModel_t
An IPFIX information model.
Definition: public.h:1093
GError * recv_err
GError for thread errors, set by receiver, read by main.
Definition: private.h:117
gboolean fbCollectorHasTranslator(fbCollector_t *collector)
fbCollectorHasTranslator
void fbSessionSetGroup(fbSession_t *session, char *group)
fbSessionSetGroup
void fbListenerAppFree(fbListener_t *listener, void *ctx)
fbListenerAppFree
void fbSessionClearIntTmplTableFlag(fbSession_t *session)
fbSessionClearIntTmplTableFlag
void fbConnSpecFree(fbConnSpec_t *spec)
fbConnSpecFree
void * ctx
application context.
Definition: private.h:144
void fBufRewind(fBuf_t *fbuf)
fBufRewind
void fbConnSpreadFree(fbSpreadSpec_t *spec)
fbConnSpreadFree
fbInfoModel_t * model
Information model (for looking up information elements by spec)
Definition: private.h:199
void fbListenerRemoveLastBuf(fBuf_t *fbuf, fbListener_t *listener)
fbListenerRemoveLastBuf
GHashTable * indices
Map of information element to index in ie_ary.
Definition: private.h:232
mailbox recv_mbox
the receiver&#39;s mailbox
Definition: private.h:113
void fbSessionSetTemplateBuffer(fbSession_t *session, fBuf_t *fbuf)
fbSessionSetTemplateBuffer
sp_groupname_t * recv_groups
groups array for SP_receive
Definition: private.h:125
gboolean reject
reject flag
Definition: private.h:162
void fbExporterFree(fbExporter_t *exporter)
fbExporterFree
Template metadata options record structure.
Definition: private.h:181
gboolean fbCollectMessageBuffer(uint8_t *hdr, size_t b_len, size_t *m_len, GError **err)
fbCollectMessageBuffer
gboolean fbInfoElementEqual(const fbInfoElement_t *a, const fbInfoElement_t *b)
fbInfoElementEqual
gboolean fbExporterCheckGroups(fbExporter_t *exporter, char **groups, int num_groups)
fbExporterCheckGroups
void fbCollectorSetFD(fbCollector_t *collector, int fd)
fbCollectorSetFD
int recv_exit
flag to tell the thread to exit
Definition: private.h:119
gboolean fbInfoElementCopyToTemplate(fbInfoModel_t *model, fbInfoElement_t *ex_ie, fbInfoElement_t *tmpl_ie)
fbInfoElementCopyToTemplate
char * recv_mess
message buffer for receive
Definition: private.h:129
sp_groupname_t * groups_to_send
groups to send to
Definition: private.h:102
uint16_t tmpl_len
Total length of the template record or options template record defining this template.
Definition: private.h:226
uint32_t fbSessionGetSequence(fbSession_t *session)
fbSessionGetSequence
fbTemplateCtxFree_fn ctx_free
Callback to free the ctx pointer when template is freed.
Definition: private.h:252
uint16_t fbExporterGetMTU(fbExporter_t *exporter)
fbExporterGetMTU
fbNewTemplateCallback_fn fbSessionNewTemplateCallback(fbSession_t *session)
Returns the callback function for a given session.
sp_groupname_t * groups
pointer to array of group names, must have at least one, and must be null term array ...
Definition: private.h:98
fbConnSpec_t * fbConnSpecCopy(fbConnSpec_t *spec)
fbConnSpecCopy
fbSession_t * session
pointer to the session for this peer address
Definition: private.h:142
void fbSessionClearExtTmplTableFlag(fbSession_t *session)
fbSessionClearExtTmplTableFlag
fbVarfield_t template_description
Template description (optional)
Definition: private.h:187
void fbInfoElementDebug(gboolean tmpl, fbInfoElement_t *ie)
fbInfoElementDebug
struct sp_groupname_st sp_groupname_t
sp_groupname_t
uint16_t template_id
Template ID.
Definition: private.h:189
void * app_ctx
The application&#39;s Context pointer for the ctx_free function.
Definition: private.h:256
fbCollector_t * fbCollectorAllocTLS(fbListener_t *listener, void *ctx, int fd, struct sockaddr *peer, size_t peerlen, GError **err)
fbCollectorAllocTLS
void fbSessionSetCollector(fbSession_t *session, fbCollector_t *collector)
fbSessionSetCollector
int recv_num_groups
actual size of group name array
Definition: private.h:123
struct fBuf_st fBuf_t
An IPFIX message buffer.
Definition: public.h:1068
pthread_t recv_thread
the receiver thread
Definition: private.h:111
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:1833
void fbTemplateFree(fbTemplate_t *tmpl)
fbTemplateFree
fbSpreadSpec_t
Definition: private.h:89
A single IPFIX Information Element specification.
Definition: public.h:1610
void fbExporterSetGroupsToSend(fbExporter_t *exporter, char **groups, int num_groups)
fbExporterSetGroupToSend
const fbInfoElement_t * fbInfoModelAddAlienElement(fbInfoModel_t *model, fbInfoElement_t *ex_ie)
fbInfoModelAddAlienElement
uint16_t fBufGetInternalTemplate(fBuf_t *fbuf)
fBufGetInternalTemplate
fbSpreadSpec_t * fbConnSpreadCopy(fbSpreadParams_t *spec)
fbConnSpreadCopy
gboolean default_length
TRUE if any field was created using an fbInfoElementSpec_t with a defaulted length.
Definition: private.h:241
void fbSessionSetPrivateGroup(fbSession_t *session, char *group, char *privgroup)
fbSessionSetPrivateGroup
int recv_max
length of message buffer
Definition: private.h:127
fbConnSpec_t * fbListenerGetConnSpec(fbListener_t *listener)
fbListenerGetConnSpec
struct fbSpreadSpec_st fbSpreadSpec_t
fbSpreadSpec_t
void fBufSetSession(fBuf_t *fbuf, fbSession_t *session)
fBufSetSession
uint16_t scope_count
Count of scope information elements in template.
Definition: private.h:208
sp_groupname_t
Definition: private.h:75
struct fbUDPConnSpec_st fbUDPConnSpec_t
An UDP Connection specifier.
void fbSessionSetSequence(fbSession_t *session, uint32_t sequence)
fbSessionSetSequence
void fBufRemoveTemplateTcplan(fBuf_t *fbuf, fbTemplate_t *tmpl)
fBufRemoveTemplateTcplan
unsigned int fbSessionGetGroup(fbSession_t *session)
fbSessionGetGroup