fixbuf - API Documentation
Documentation | Downloads

public.h

Go to the documentation of this file.
00001 /*
00002  ** public.h
00003  ** fixbuf IPFIX Implementation Public Interface
00004  **
00005  ** ------------------------------------------------------------------------
00006  ** Copyright (C) 2006-2008 Carnegie Mellon University. All Rights Reserved.
00007  ** ------------------------------------------------------------------------
00008  ** Authors: Brian Trammell <bht@cert.org>
00009  ** ------------------------------------------------------------------------
00010  ** GNU Lesser GPL Rights pursuant to Version 2.1, February 1999 
00011  ** Government Purpose License Rights (GPLR) pursuant to DFARS 252.225-7013
00012  ** ------------------------------------------------------------------------
00013  */
00014 
00257 #ifndef _FB_PUBLIC_H_
00258 #define _FB_PUBLIC_H_
00259 #include <fixbuf/autoinc.h>
00260 
00261 /* 
00262  * Error Handling Definitions
00263  */
00264 
00266 #define FB_ERROR_DOMAIN             g_quark_from_string("fixbufError")
00267 
00268 #define FB_ERROR_TMPL               1
00269 
00273 #define FB_ERROR_EOM                2
00274 
00279 #define FB_ERROR_EOF                3
00280 
00284 #define FB_ERROR_IPFIX              4
00285 
00290 #define FB_ERROR_BUFSZ              5
00291 
00292 #define FB_ERROR_IMPL               6
00293 
00294 #define FB_ERROR_IO                 7
00295 
00299 #define FB_ERROR_NLREAD             8
00300 
00305 #define FB_ERROR_NLWRITE            9
00306 
00309 #define FB_ERROR_NOELEMENT          10
00310 
00313 #define FB_ERROR_CONN               11
00314 
00315 /*
00316  * Public Datatypes and Constants
00317  */
00318  
00319 struct fBuf_st;
00325 typedef struct fBuf_st fBuf_t;
00326 
00333 typedef struct fbVarfield_st {
00335     size_t      len;
00342     uint8_t     *buf;
00343 } fbVarfield_t;
00344 
00345 struct fbInfoModel_st;
00350 typedef struct fbInfoModel_st fbInfoModel_t;
00351 
00357 #define FB_IE_INIT(_name_, _ent_, _num_, _len_, _flags_) \
00358     { {.name = _name_}, 0, _ent_, _num_, _len_, _flags_ }
00359 
00365 #define FB_IE_NULL \
00366     { {.name = NULL}, 0, 0, 0, 0, 0 }
00367 
00372 #define FB_IE_F_NONE                            0x00000000
00373 
00378 #define FB_IE_F_ENDIAN                          0x00000001
00379 
00389 #define FB_IE_F_REVERSIBLE                      0x00000040
00390 
00398 #define FB_IE_F_ALIEN                           0x00000080
00399 
00403 #define FB_IE_VARLEN                            65535
00404 
00412 #define FB_IE_PEN_REVERSE                       29305
00413 
00422 #define FB_IE_VENDOR_BIT_REVERSE                0x4000
00423 
00429 #define FB_IE_REVERSE_STR                       "reverse"
00430 
00432 #define FB_IE_REVERSE_STRLEN                    7
00433 
00442 typedef struct fbInfoElement_st {
00444     union {
00450         const struct fbInfoElement_st *canon;
00455         char                    *name;
00456     } 
00457                         ref;
00463     uint32_t            midx;
00465     uint32_t            ent;
00470     uint16_t            num;
00472     uint16_t            len;
00474     uint32_t            flags;
00475 } fbInfoElement_t;
00476 
00481 #define FB_TID_AUTO         0
00482 
00486 #define FB_TID_TS           2
00487 
00491 #define FB_TID_OTS          3
00492 
00496 #define FB_TID_MIN_DATA     256
00497 
00498 struct fbTemplate_st;
00504 typedef struct fbTemplate_st fbTemplate_t;
00505 
00511 #define FB_IESPEC_NULL { NULL, 0, 0 }
00512 
00518 typedef struct fbInfoElementSpec_st {
00520     char                *name;
00525     uint16_t            len_override;
00532     uint32_t            flags;
00533 } fbInfoElementSpec_t;
00534 
00535 struct fbSession_st;
00542 typedef struct fbSession_st fbSession_t;
00543 
00545 typedef enum fbTransport_en {
00550     FB_SCTP,
00552     FB_TCP,
00554     FB_UDP,
00560     FB_DTLS_SCTP,
00565     FB_TLS_TCP,
00571     FB_DTLS_UDP,
00572 } fbTransport_t;
00573 
00578 typedef struct fbConnSpec_st {
00580     fbTransport_t       transport;
00582     char                *host;
00584     char                *svc;
00586     char                *ssl_ca_file;
00588     char                *ssl_cert_file;
00590     char                *ssl_key_file;
00592     char                *ssl_key_pass;
00597     void                *vai;
00602     void                *vssl_ctx;
00603 } fbConnSpec_t;
00604 
00608 #define FB_CONNSPEC_INIT { FB_SCTP, NULL, NULL,         \
00609                            NULL, NULL, NULL, NULL,      \
00610                            NULL, NULL }
00611 
00612 struct fbExporter_st;
00618 typedef struct fbExporter_st fbExporter_t;
00619 
00620 struct fbCollector_st;
00628 typedef struct fbCollector_st fbCollector_t;
00629 
00630 struct fbListener_st;
00637 typedef struct fbListener_st fbListener_t;
00638  
00648 typedef gboolean        (*fbListenerAppInit_fn) (
00649     fbListener_t                *listener,
00650     void                        **ctx,
00651     int                         fd,
00652     struct sockaddr             *peer,
00653     size_t                      peerlen,
00654     GError                      **err);
00655 
00660 typedef void            (*fbListenerAppFree_fn) (
00661     void                        *ctx);
00662 
00663 /*
00664  * Public Function Calls. These calls will remain available and retain 
00665  * their functionality in all subsequent versions of libfixbuf.
00666  */
00667 
00668 
00685 gboolean            fBufSetInternalTemplate(
00686     fBuf_t              *fbuf,
00687     uint16_t            int_tid,
00688     GError              **err);
00689 
00707 gboolean            fBufSetExportTemplate(
00708     fBuf_t              *fbuf,
00709     uint16_t            ext_tid,
00710     GError              **err);
00711 
00726 void                fBufSetAutomaticMode(
00727     fBuf_t              *fbuf,
00728     gboolean            automatic);
00729 
00737 fbSession_t         *fBufGetSession(
00738     fBuf_t              *fbuf);
00739 
00748 void                fBufFree(
00749     fBuf_t              *fbuf);
00750 
00762 fBuf_t              *fBufAllocForExport(
00763     fbSession_t         *session,
00764     fbExporter_t        *exporter);
00765 
00775 fbExporter_t        *fBufGetExporter(
00776     fBuf_t              *fbuf);
00777 
00788 void                fBufSetExporter(
00789     fBuf_t              *fbuf,
00790     fbExporter_t        *exporter);
00791 
00815 gboolean            fBufAppend(
00816     fBuf_t              *fbuf,
00817     uint8_t             *recbase,
00818     size_t              recsize,
00819     GError              **err);
00820 
00830 gboolean            fBufEmit(
00831     fBuf_t              *fbuf,
00832     GError              **err);
00833 
00845 void                fBufSetExportTime(
00846     fBuf_t              *fbuf,
00847     uint32_t            extime);
00848 
00860 fBuf_t              *fBufAllocForCollection(
00861     fbSession_t         *session,
00862     fbCollector_t       *collector);
00863     
00873 fbCollector_t       *fBufGetCollector(
00874     fBuf_t              *fbuf);
00875 
00886 void                fBufSetCollector(
00887     fBuf_t              *fbuf,
00888     fbCollector_t       *collector);
00889 
00919 gboolean            fBufNext(
00920     fBuf_t              *fbuf,
00921     uint8_t             *recbase,
00922     size_t              *recsize,
00923     GError              **err);
00924 
00938 gboolean            fBufNextMessage(
00939     fBuf_t              *fbuf,
00940     GError              **err);
00941     
00949 uint32_t            fBufGetExportTime(
00950     fBuf_t              *fbuf);
00951 
00971 fbTemplate_t    *fBufGetCollectionTemplate(
00972     fBuf_t          *fbuf,
00973     uint16_t        *ext_tid);
00974 
00993 fbTemplate_t    *fBufNextCollectionTemplate(
00994     fBuf_t          *fbuf,
00995     uint16_t        *ext_tid,
00996     GError          **err);
00997 
01009 fbInfoModel_t       *fbInfoModelAlloc();
01010 
01019 void                fbInfoModelFree(
01020     fbInfoModel_t       *model);
01021 
01036 void                fbInfoModelAddElement(
01037     fbInfoModel_t       *model,
01038     fbInfoElement_t     *ie);
01039 
01054 void                fbInfoModelAddElementArray(
01055     fbInfoModel_t       *model,
01056     fbInfoElement_t     *ie);
01057 
01069 const fbInfoElement_t     *fbInfoModelGetElementByName(
01070     fbInfoModel_t       *model,
01071     const char          *name);
01072 
01073 
01091 fbTemplate_t        *fbTemplateAlloc(
01092     fbInfoModel_t       *model);
01093 
01110 gboolean            fbTemplateAppend(
01111     fbTemplate_t        *tmpl,
01112     fbInfoElement_t     *ex_ie,
01113     GError              **err);
01114 
01130 gboolean            fbTemplateAppendSpec(
01131     fbTemplate_t        *tmpl,
01132     fbInfoElementSpec_t *spec,
01133     uint32_t            flags,
01134     GError              **err);
01135 
01153 gboolean            fbTemplateAppendSpecArray(
01154     fbTemplate_t        *tmpl,
01155     fbInfoElementSpec_t *spec,
01156     uint32_t            flags,
01157     GError              **err);
01158 
01166 uint32_t            fbTemplateCountElements(
01167     fbTemplate_t        *tmpl);
01168 
01178 void                fbTemplateSetOptionsScope(
01179     fbTemplate_t        *tmpl,
01180     uint16_t            scope_count);
01181 
01189 uint32_t            fbTemplateGetOptionsScope(
01190     fbTemplate_t        *tmpl);
01191 
01203 gboolean           fbTemplateContainsElement(
01204     fbTemplate_t            *tmpl,
01205     const fbInfoElement_t   *ex_ie);
01206 
01216 gboolean           fbTemplateContainsElementByName(
01217     fbTemplate_t        *tmpl,
01218     fbInfoElementSpec_t *spec);
01219 
01229 gboolean           fbTemplateContainsAllElementsByName(
01230     fbTemplate_t        *tmpl,
01231     fbInfoElementSpec_t *spec);
01232 
01240 void                fbTemplateFreeUnused(
01241     fbTemplate_t        *tmpl);
01242 
01255 fbSession_t         *fbSessionAlloc(
01256     fbInfoModel_t       *model);
01257 
01267 void                fbSessionFree(
01268     fbSession_t         *session);
01269 
01282 void                fbSessionResetExternal(
01283     fbSession_t         *session);
01284 
01300 void                fbSessionSetDomain(
01301     fbSession_t         *session,
01302     uint32_t            domain);
01303 
01311 uint32_t            fbSessionGetDomain(
01312     fbSession_t         *session);
01313 
01326 gboolean            fbSessionExportTemplate(
01327     fbSession_t         *session,
01328     uint16_t            tid,
01329     GError              **err);
01330 
01342 gboolean            fbSessionExportTemplates(
01343     fbSession_t         *session,
01344     GError              **err);
01345 
01361 uint16_t            fbSessionAddTemplate(
01362     fbSession_t         *session,
01363     gboolean            internal,
01364     uint16_t            tid,
01365     fbTemplate_t        *tmpl,
01366     GError              **err);
01367 
01380 gboolean            fbSessionRemoveTemplate(
01381     fbSession_t         *session,
01382     gboolean            internal,
01383     uint16_t            tid,
01384     GError              **err);
01385 
01397 fbTemplate_t        *fbSessionGetTemplate(
01398     fbSession_t         *session,
01399     gboolean            internal,
01400     uint16_t            tid,
01401     GError              **err);
01402 
01413 fbExporter_t        *fbExporterAllocNet(
01414     fbConnSpec_t        *spec);
01415 
01426 fbExporter_t        *fbExporterAllocFile(
01427     const char          *path);
01428 
01436 fbExporter_t        *fbExporterAllocFP(
01437     FILE                *fp);
01438     
01451 void                fbExporterSetStream(
01452     fbExporter_t        *exporter,
01453     int                 sctp_stream);
01454 
01467 void                fbExporterAutoStream(
01468     fbExporter_t        *exporter);
01469 
01477 void                fbExporterClose(
01478     fbExporter_t       *exporter);
01479 
01491 fbCollector_t       *fbCollectorAllocFile(
01492     void                *ctx,
01493     const char          *path,
01494     GError              **err);
01495 
01505 fbCollector_t       *fbCollectorAllocFP(
01506     void                *ctx,
01507     FILE                *fp);
01508 
01519 void                *fbCollectorGetContext(
01520     fbCollector_t       *collector);
01521 
01532 void                fbCollectorClose(
01533     fbCollector_t       *collector);
01534 
01558 fbListener_t        *fbListenerAlloc(
01559     fbConnSpec_t            *spec,
01560     fbSession_t             *session,
01561     fbListenerAppInit_fn    appinit,
01562     fbListenerAppFree_fn    appfree,
01563     GError                  **err);
01564 
01572 void                fbListenerFree(
01573     fbListener_t            *listener);
01574 
01596 fBuf_t              *fbListenerWait(
01597     fbListener_t            *listener,
01598     GError                  **err);
01599 
01607 void                fbListenerInterrupt(
01608     fbListener_t            *listener);
01609 
01610 #endif