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  {"templateId", 2, 0 },
170  {"paddingOctets", 6, 1 },
171  {"templateName", FB_IE_VARLEN, 0 },
172  {"templateDescription", FB_IE_VARLEN, 0 },
173  /* {"templateInformationElementList", FB_IE_VARLEN, 0 }, */
175 };
176 #endif
177 
182 typedef struct fbTemplateOptRec_st {
184  uint16_t template_id;
185  uint8_t template_padding[6];
191  /* fbSubTemplateList_t info_element_list; */
193 
205  uint16_t ie_count;
210  uint16_t scope_count;
217  uint16_t ie_len;
223  uint16_t ie_internal_len;
228  uint16_t tmpl_len;
230  gboolean is_varlen;
234  GHashTable *indices;
236  uint16_t *off_cache;
238  gboolean active;
243  gboolean default_length;
244 
245  fbTemplateOptRec_t *metadata_rec;
250  void *tmpl_ctx;
258  void *app_ctx;
259 };
260 
267 void fBufRewind(
268  fBuf_t *fbuf);
269 
281 gboolean fBufAppendTemplate(
282  fBuf_t *fbuf,
283  uint16_t tmpl_id,
284  fbTemplate_t *tmpl,
285  gboolean revoked,
286  GError **err);
287 
288 #if HAVE_SPREAD
289 
296  fBuf_t *fbuf,
297  char **groups,
298  int num_groups,
299  GError **err);
300 
301 
302 #endif
303 
310  fBuf_t *fbuf,
311  fbTemplate_t *tmpl);
312 
317 void fBufSetSession(
318  fBuf_t *fbuf,
319  fbSession_t *session);
320 
325 uint16_t fBufGetExportTemplate(
326  fBuf_t *fbuf);
327 
328 
333 uint16_t fBufGetInternalTemplate(
334  fBuf_t *fbuf);
335 
343 uint32_t fbInfoElementHash(
344  fbInfoElement_t *ie);
345 
354 gboolean fbInfoElementEqual(
355  const fbInfoElement_t *a,
356  const fbInfoElement_t *b);
357 
365 void fbInfoElementDebug(
366  gboolean tmpl,
367  fbInfoElement_t *ie);
368 
377  fbInfoModel_t *model,
378  fbInfoElement_t *ex_ie);
379 
390  fbInfoModel_t *model,
391  fbInfoElement_t *ex_ie,
392  fbInfoElement_t *tmpl_ie,
393  GError **err);
394 
407  fbInfoModel_t *model,
408  const char *name,
409  uint16_t len_override,
410  fbInfoElement_t *tmpl_ie,
411  GError **err);
412 
422  fbInfoModel_t *model,
423  fbInfoElement_t *ex_ie);
424 
434  fbInfoModel_t *model,
435  gboolean internal,
436  GError **err);
437 
445 void fbTemplateRetain(
446  fbTemplate_t *tmpl);
447 
455 void fbTemplateRelease(
456  fbTemplate_t *tmpl);
457 
465 void fbTemplateFree(
466  fbTemplate_t *tmpl);
467 
476 void fbTemplateDebug(
477  const char *label,
478  uint16_t tid,
479  fbTemplate_t *tmpl);
480 
493  fbInfoModel_t *model,
494  gboolean internal,
495  GError **err);
496 
510  fbTemplate_t *tmpl,
511  uint16_t tid,
512  const char *name,
513  const char *description);
514 
522  fbSession_t *session);
523 
532  fbSession_t *session);
533 
541  fbSession_t *base);
542 
550 uint32_t fbSessionGetSequence(
551  fbSession_t *session);
552 
561  fbSession_t *session,
562  uint32_t sequence);
563 
572  fbSession_t *session,
573  fBuf_t *fbuf);
574 
583  fbSession_t *session,
584  fbCollector_t *collector);
585 
586 #if HAVE_SPREAD
587 
592  fbSession_t *session,
593  sp_groupname_t *groups,
594  unsigned int num_groups);
595 
602  fbSession_t *session,
603  char *group,
604  char *privgroup);
605 
610 void fbSessionSetGroup(
611  fbSession_t *session,
612  char *group);
613 
618 unsigned int fbSessionGetGroupOffset(
619  fbSession_t *session,
620  char *group);
621 
628 unsigned int fbSessionGetGroup(
629  fbSession_t *session);
630 #endif
631 
639  fbSession_t *session);
640 
648  fbSession_t *session);
649 
657  fbSession_t *session);
658 
666  fbSession_t *session);
667 
676 gboolean fbConnSpecLookupAI(
677  fbConnSpec_t *spec,
678  gboolean passive,
679  GError **err);
680 
689 gboolean fbConnSpecInitTLS(
690  fbConnSpec_t *spec,
691  gboolean passive,
692  GError **err);
693 
702  fbConnSpec_t *spec);
703 
711 void fbConnSpecFree(
712  fbConnSpec_t *spec);
713 
714 #if HAVE_SPREAD
715 
723  fbSpreadParams_t *spec);
724 
732 void fbConnSpreadFree(
733  fbSpreadSpec_t *spec);
734 
743 const char * fbConnSpreadError(
744  int err );
745 
746 
757  fbExporter_t *exporter,
758  char **groups,
759  int num_groups);
760 
761 
771 gboolean fbExporterCheckGroups(
772  fbExporter_t *exporter,
773  char **groups,
774  int num_groups);
775 
776 
777 #endif /* HAVE_SPREAD */
778 
786 uint16_t fbExporterGetMTU(
787  fbExporter_t *exporter);
788 
798 gboolean fbExportMessage(
799  fbExporter_t *exporter,
800  uint8_t *msgbase,
801  size_t msglen,
802  GError **err);
803 
811 void fbExporterFree(
812  fbExporter_t *exporter);
813 
822  fBuf_t *fbuf,
823  fbCollector_t *collector);
824 
837  fbListener_t *listener,
838  void *ctx,
839  int fd,
840  struct sockaddr *peer,
841  size_t peerlen,
842  GError **err);
843 
856  fbListener_t *listener,
857  void *ctx,
858  int fd,
859  struct sockaddr *peer,
860  size_t peerlen,
861  GError **err);
862 
872 gboolean fbCollectMessage(
873  fbCollector_t *collector,
874  uint8_t *msgbase,
875  size_t *msglen,
876  GError **err);
877 
885 int fbCollectorGetFD(
886  fbCollector_t *collector);
887 
894 void fbCollectorSetFD(
895  fbCollector_t *collector,
896  int fd);
897 
905 void fbCollectorFree(
906  fbCollector_t *collector);
907 
915 gboolean fbCollectorHasTranslator(
916  fbCollector_t *collector);
917 
918 
932 gboolean fbCollectMessageBuffer(
933  uint8_t *hdr,
934  size_t b_len,
935  size_t *m_len,
936  GError **err);
937 
938 
939 #if HAVE_SPREAD
940 
948  fbCollector_t *collector,
949  int group_offset);
950 
951 #endif
952 
960 void fbListenerAppFree(
961  fbListener_t *listener,
962  void *ctx);
963 
972  fBuf_t *fbuf,
973  fbListener_t *listener);
974 
982 void fbListenerRemove(
983  fbListener_t *listener,
984  int fd);
985 
994  fbListener_t *listener);
995 
1003  fbCollector_t *collector);
1004 
1009 gboolean fbListenerCallAppInit(
1010  fbListener_t *listener,
1011  fbUDPConnSpec_t *spec,
1012  GError **err);
1013 
1020  fbListener_t *listener,
1021  fbSession_t *session);
1022 
1023 #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.
fbTemplate_t * fbInfoElementAllocTypeTemplate2(fbInfoModel_t *model, gboolean internal, GError **err)
fbInfoElementAllocTypeTemplate2
uint16_t ie_count
Count of information elements in template.
Definition: private.h:205
union fbUDPConnSpec_st::@0 peer
key to this conn spec
#define FB_IESPEC_NULL
Convenience macro defining a null information element specification initializer (fbInfoElementSpec_t)...
Definition: public.h:1746
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
Template name.
Definition: private.h:187
An IPFIX template or options template structure.
Definition: private.h:199
struct fbCollector_st fbCollector_t
IPFIX Collecting Process endpoint.
Definition: public.h:1894
struct fbExporter_st fbExporter_t
IPFIX Exporting Process endpoint.
Definition: public.h:1885
int fbCollectorGetFD(fbCollector_t *collector)
fbCollectorGetFD
struct fbSession_st fbSession_t
An IPFIX Transport Session state container.
Definition: public.h:1784
uint16_t * off_cache
Field offset cache.
Definition: private.h:236
struct fbListener_st fbListener_t
IPFIX Collecting Process session listener.
Definition: public.h:1902
int ref_count
Reference count.
Definition: private.h:203
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
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:238
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
gboolean fbInfoElementCopyToTemplateByName(fbInfoModel_t *model, const char *name, uint16_t len_override, fbInfoElement_t *tmpl_ie, GError **err)
fbInfoElementCopyToTemplateByName
void fbCollectorRemoveListenerLastBuf(fBuf_t *fbuf, fbCollector_t *collector)
fbCollectorRemoveListenerLastBuf
gboolean fbConnSpecInitTLS(fbConnSpec_t *spec, gboolean passive, GError **err)
fbConnSpecInitTLS
Connection specifier.
Definition: public.h:1820
void(* fbTemplateCtxFree_fn)(void *tmpl_ctx, void *app_ctx)
A callback function that is called when a template is freed.
Definition: public.h:1950
fbInfoElement_t ** ie_ary
Ordered array of pointers to information elements in this template.
Definition: private.h:232
gboolean fbInfoElementCopyToTemplate(fbInfoModel_t *model, fbInfoElement_t *ex_ie, fbInfoElement_t *tmpl_ie, GError **err)
fbInfoElementCopyToTemplate
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:223
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:230
Spread connection parameters.
Definition: public.h:1866
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:217
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:1438
void * tmpl_ctx
Template context.
Definition: private.h:250
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:1180
A single IPFIX Information Element definition.
Definition: public.h:1612
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'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:1197
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
char recv_privgroup[MAX_GROUP_NAME+2]
the connection private name for the receiver
Definition: private.h:115
void fbConnSpreadFree(fbSpreadSpec_t *spec)
fbConnSpreadFree
fbInfoModel_t * model
Information model (for looking up information elements by spec)
Definition: private.h:201
void fbListenerRemoveLastBuf(fBuf_t *fbuf, fbListener_t *listener)
fbListenerRemoveLastBuf
GHashTable * indices
Map of information element to index in ie_ary.
Definition: private.h:234
void fbTemplateAddMetadataRecord(fbTemplate_t *tmpl, uint16_t tid, const char *name, const char *description)
Sets the metadata_rec member of tmpl to a newly allocated fbTemplateOptRec_t, and sets its template I...
mailbox recv_mbox
the receiver's mailbox
Definition: private.h:113
void fbSessionSetGroupParams(fbSession_t *session, sp_groupname_t *groups, unsigned int num_groups)
fbSessionSetGroupParams
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:182
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
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:228
char privgroup[MAX_GROUP_NAME+2]
the connection private name
Definition: private.h:107
uint32_t fbSessionGetSequence(fbSession_t *session)
fbSessionGetSequence
fbTemplateCtxFree_fn ctx_free
Callback to free the ctx pointer when template is freed.
Definition: private.h:254
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
fbTemplate_t * fbTemplateAllocTemplateMetadataTmpl(fbInfoModel_t *model, gboolean internal, GError **err)
Allocates a new Template to describe a record that holds Template Metadata.
fbSession_t * session
pointer to the session for this peer address
Definition: private.h:142
void fbSessionClearExtTmplTableFlag(fbSession_t *session)
fbSessionClearExtTmplTableFlag
fbCollector_t * fbCollectorAllocSocket(fbListener_t *listener, void *ctx, int fd, struct sockaddr *peer, size_t peerlen, GError **err)
fbCollectorAllocSocket
fbVarfield_t template_description
Template description (optional)
Definition: private.h:189
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:184
void * app_ctx
The application's Context pointer for the ctx_free function.
Definition: private.h:258
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:1172
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:1977
void fbTemplateFree(fbTemplate_t *tmpl)
fbTemplateFree
fbSpreadSpec_t
Definition: private.h:89
A single IPFIX Information Element specification.
Definition: public.h:1754
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:243
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:210
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