Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

flow_stat.c

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 #ifdef HAVE_CONFIG_H
00004 #include "config.h"
00005 #endif
00006 
00007 #include <string.h>
00008 
00009 #include "flow.h"
00010 #include "flow_cache.h"
00011 #include "flow_stat.h"
00012 #include "flow_packet.h"
00013 
00014 /** 
00015  * Reinitialize the flowstats
00016  * 
00017  * @param fsp flowstat pointer
00018  * 
00019  * @return 0 on success, else failure
00020  */
00021 int flowstat_clear(FLOWSTATS *fsp)
00022 {
00023     if(fsp == NULL)
00024     {
00025         return 1;
00026     }
00027 
00028     memset(fsp, 0, sizeof(FLOWSTATS));
00029     
00030     return 0;
00031 }
00032 
00033 int flowstat_print(FLOWSTATS *fsp)
00034 {
00035     if(!fsp)
00036     {
00037         return 1;
00038     }
00039          
00040     flow_printf("fsp: %p fp: %u lp: %u bs: %u br: %u ps: %u pr: %u flags: %u ft: %x lt: %x ac: %u",
00041                 fsp,
00042                 (unsigned int) fsp->first_packet,
00043                 (unsigned int) fsp->last_packet,
00044                 fsp->bytes_sent,
00045                 fsp->bytes_recv,
00046                 fsp->packets_sent,
00047                 fsp->packets_recv,
00048                 fsp->flow_flags,
00049                 fsp->first_talker,
00050                 fsp->last_talker,
00051                 fsp->alerts_seen);
00052     return 0;
00053 }
00054 
00055 int flowstat_increment(FLOWSTATS *fsp, int direction, time_t cur, u_int32_t bytes)
00056 {
00057     switch(direction)
00058     {
00059     case FROM_INITIATOR:
00060         fsp->bytes_sent += bytes;
00061         fsp->packets_sent++;
00062 
00063         if(fsp->first_talker == 0)
00064         {
00065             fsp->first_talker = FROM_INITIATOR;
00066             fsp->first_packet = cur;
00067         }
00068         else
00069         {
00070             /* not a typo - only update once */
00071             fsp->last_talker = FROM_INITIATOR;
00072         }        
00073         break;
00074     case FROM_RESPONDER:
00075         fsp->bytes_recv += bytes;
00076         fsp->packets_recv++;
00077         fsp->last_talker = FROM_RESPONDER;
00078         break;
00079     default:
00080         flow_printf("flowstat_increment: unable to handle\n");
00081         return -1;
00082     }
00083 
00084     
00085     fsp->last_packet = cur;            
00086         
00087     return 0;
00088 }
00089 
00090 /** 
00091 * The callback for the flowstats processor
00092 * 
00093 * @param position where in the flow module this is being called from
00094 * @param flow the flow that the stats are kept for
00095 * @param direction the direction of the flow
00096 * @param cur the current time
00097 * @param p the current packet (may be NULL)
00098 * 
00099 * @return TBD
00100 */
00101 int flowstat_callback(FLOW_POSITION position, FLOW *flowp, int direction,
00102                       time_t cur, FLOWPACKET *p)
00103 {
00104     int dsize;
00105 
00106     switch(position)
00107     {
00108     case FLOW_SHUTDOWN:
00109         /* 
00110            flow_printf("flow:");
00111            flowkey_print(&flowp->key);
00112            flowstat_print(&flowp->stats);
00113            flow_printf("\n");
00114         */
00115         break;
00116     case FLOW_NEW:
00117     case FLOW_ADDITIONAL:
00118         if(p)
00119         {
00120             dsize = GetIPv4Len(p);            
00121             flowstat_increment(&flowp->stats, direction, cur, dsize);
00122         }
00123     default:                        
00124     case FLOW_FIRST_BIDIRECTIONAL:
00125         break;
00126     }
00127 
00128     return 0;
00129 }

Generated on Sun May 14 14:51:15 2006 by  doxygen 1.4.2