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

flow_callback.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 <stdio.h>
00008 #include <time.h>
00009 
00010 
00011 #include "packet_time.h"
00012 
00013 #include "flow_callback.h"
00014 #include "flow_cache.h"
00015 
00016 /* needed for flow stats callback */
00017 #include "flow_stat.h"
00018 
00019 /* portscan detector */
00020 #include "portscan/flowps_snort.h"
00021 
00022 static int s_debug = 0;
00023 
00024 int flow_callbacks(FLOW_POSITION position, FLOW *flowp, int direction, Packet *p)
00025 {
00026     time_t now;
00027     
00028     if(flowp == NULL)
00029     {
00030         return FLOW_ENULL;
00031     }
00032 
00033     if(position < FLOW_NEW || position >= FLOW_MAX)
00034     {
00035         return FLOW_EINVALID;
00036     }
00037 
00038     if(s_debug > 5)
00039     {
00040 #ifndef WIN32
00041         flow_printf("DEBUG: %s called at postition %s on flow: %p ",__func__,
00042                flowcache_pname(position), flowp);
00043 #else
00044         flow_printf("DEBUG: %s(%d) called at postition %s on flow: %p ",__FILE__,__LINE__,
00045                flowcache_pname(position), flowp);
00046 #endif
00047         flowkey_print(&flowp->key);
00048         flow_printf("\n");
00049     }
00050 
00051     /* we have to be prepared to get rid of a flow without a packet */   
00052     now = packet_timeofday();
00053     
00054     switch(position)
00055     {
00056     case FLOW_NEW:
00057         flowps_newflow_callback(position, flowp, direction, now ,p);        
00058         flowstat_callback(position, flowp, direction, now, p);
00059         break;
00060     case FLOW_ADDITIONAL:
00061         flowstat_callback(position, flowp, direction, now, p);
00062         break;
00063     case FLOW_FIRST_BIDIRECTIONAL:
00064         /* be careful putting callbacks here because this is really
00065          * used in addition to the FLOW_ADDITIONAL stage.
00066          */
00067         break;        
00068     case FLOW_SHUTDOWN:
00069         flowstat_callback(position, flowp, direction, now, p);
00070         break;
00071     default:
00072         flow_printf("Unknown position: %d\n", position);
00073         return 1;
00074     }
00075     
00076     return FLOW_SUCCESS;
00077 }
00078 /** 
00079  * Install a new flow plugin
00080  * 
00081  * This will install a new plugin for callbacks and install the plugin
00082  * at the correct location for that.
00083  *
00084  * 
00085  * @param position where to add this callback
00086  * @param flowp what tp match
00087  * @param direction which direction to match
00088  * @param fire_once only trigger on
00089  * @param timeout when this callback is no longer valid (0) means forever.
00090  */
00091 /* int fcb_register(FLOW_POSITION position, FLOW *flowp, int direction, int order, int fire_once, int timeout) */
00092 /* { */
00093     
00094 /* } */
00095                  

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