#pragma module NETFLOW_RMS "NETFLOW_RMS-1-D" #define __MODULE__ "NETFLOW_RMS" /* **++ ** FACILITY: NetFlow Host Collector ** ** MODULE DESCRIPTION: ** ** This module contains a set of routines to store Netflow Data records ** in the RMS files. ** ** AUTHORS: ** ** Ruslan R. Laishev ** ** CREATION DATE: 10-AUG-2009 ** ** ** USAGE: ** DEFINE /SYS NETFLOW_DB dev:[dir]NETFLOW_RMS.EXE ** ** MODIFICATION HISTORY: ** ** {@tbs@}... **-- */ /* ** ** INCLUDE FILES ** */ #include #include #include #include #include #include #include #include #include #include #define __NEW_STARLET 1 #include "netflowdef.h" int exit_flag = 0, debug_flag = 1; #define DEBUG if(debug_flag)printf("%-24.24s:%-08.0u ",__MODULE__,__LINE__);if(debug_flag)printf $DESCRIPTOR(dsc_fdl, "NETFLOW_FDL"); /* [.FDL] */ struct FAB *fab = NULL; struct RAB *rab = NULL; int netflow_dbinit (void ** ctx) { debug_flag = (NULL != getenv("NETFLOW$DEBUG")); return SS$_NORMAL; } int netflow_dbshut (void * ctx) { int status; if ( fab ) { status = sys$close (fab); status = fdl$release(&fab,&rab); } return SS$_NORMAL; } int netflow_dbsave ( void * ctx, NF_RECV5 * rec ) { int status; char fext [32]; unsigned short fextlen = 0,timbuf[7]; static unsigned short day = 0, rcount = 0; /* ** Get a current system time to store it as time stamp of the data records */ if ( !(1 & (status = sys$numtim (&timbuf,&rec->nf_rec$q_timestamp))) ) lib$signal(status); /* ** Check that it's a time to switch to other file */ if ( day != timbuf[2] ) { /* ** Close current file if need */ if ( day ) if ( !(1 & (status = sys$close(fab))) || !(1 & (status = fdl$release(&fab,&rab))) ) lib$signal(status); /* ** Read and parse FDL file allocating and initializing RAB and ** and FAB accordingly, returning pointers to the FAB & RAB-> */ if ( !(1 & (status = fdl$parse(&dsc_fdl,&fab,&rab))) ) sys$exit(status); /* ** Initialize FAB & RAB structures */ fab->fab$b_fac = FAB$M_PUT; fab->fab$v_sqo = rab->rab$v_eof = 1; /* ** Store current day and generate new file extension */ day = timbuf[2]; fextlen = sprintf(fext,"NETFLOW.%04u%02u%02u",timbuf[0],timbuf[1],timbuf[2]); fab->fab$l_fna = fext; fab->fab$b_fns = fextlen; if ( !(1 & (status = sys$create(fab))) ) lib$signal(status); if ( !(1 & (status = sys$connect(rab))) ) lib$signal(status,rab->rab$l_stv); } rab->rab$l_rbf = rec; rab->rab$w_rsz = sizeof(NF_RECV5); if ( !(1 & (status = sys$put (rab))) ) lib$signal(status,rab->rab$l_stv); if ( !((++rcount)%512) && !(1 & (status = sys$flush (rab))) ) lib$signal(status,rab->rab$l_stv); return status; }