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

spp_template.c

Go to the documentation of this file.
00001 /* $Id$ */
00002 /* Snort Preprocessor Plugin Source File Template */
00003 
00004 /* spp_template 
00005  * 
00006  * Purpose:
00007  *
00008  * Preprocessors perform some function *once* for *each* packet.  This is
00009  * different from detection plugins, which are accessed depending on the
00010  * standard rules.  When adding a plugin to the system, be sure to 
00011  * add the "Setup" function to the InitPreprocessors() function call in 
00012  * plugbase.c!
00013  *
00014  * Arguments:
00015  *   
00016  * This is the list of arguements that the plugin can take at the 
00017  * "preprocessor" line in the rules file
00018  *
00019  * Effect:
00020  *
00021  * What the preprocessor does.  Check out some of the default ones 
00022  * (e.g. spp_frag2) for a good example of this description.
00023  *
00024  * Comments:
00025  *
00026  * Any comments?
00027  *
00028  */
00029 
00030 #include <sys/types.h>
00031 #include <stdlib.h>
00032 #include <ctype.h>
00033 #include <rpc/types.h>
00034 
00035 /*
00036  * If you're going to issue any alerts from this preproc you 
00037  * should include generators.h and event_wrapper.h
00038  */
00039 #include "generators.h"
00040 #include "event_wrapper.h"
00041 
00042 #include "util.h"
00043 #include "plugbase.h"
00044 #include "parser.h"
00045 
00046 /*
00047  * put in other inculdes as necessary
00048  */
00049 
00050 /* 
00051  * your preprocessor header file goes here if necessary, don't forget
00052  * to include the header file in plugbase.h too!
00053  */
00054 #include "spp_template.h"
00055 
00056 /*
00057  * define any needed data structs for things like configuration
00058  */
00059 typedef struct _TemplateData
00060 {
00061     /* Your struct members here */
00062 } TemplateData;
00063 
00064 /* 
00065  * If you need to instantiate the preprocessor's 
00066  * data structure, do it here 
00067  */
00068 TemplateData SomeData;
00069 
00070 /* 
00071  * function prototypes go here
00072  */
00073 
00074 static void TemplateInit(u_char *);
00075 static void ParseTemplateArgs(char *);
00076 static void PreprocFunction(Packet *);
00077 static void PreprocCleanExitFunction(int, void *);
00078 static void PreprocRestartFunction(int, void *);
00079 
00080 /*
00081  * Function: SetupTemplate()
00082  *
00083  * Purpose: Registers the preprocessor keyword and initialization 
00084  *          function into the preprocessor list.  This is the function that
00085  *          gets called from InitPreprocessors() in plugbase.c.
00086  *
00087  * Arguments: None.
00088  *
00089  * Returns: void function
00090  *
00091  */
00092 void SetupTemplate()
00093 {
00094     /* 
00095      * link the preprocessor keyword to the init function in 
00096      * the preproc list 
00097      */
00098     RegisterPreprocessor("keyword", TemplateInit);
00099 
00100     DebugMessage(DEBUG_PLUGIN,"Preprocessor: Template is setup...\n");
00101 }
00102 
00103 
00104 /*
00105  * Function: TemplateInit(u_char *)
00106  *
00107  * Purpose: Calls the argument parsing function, performs final setup on data
00108  *          structs, links the preproc function into the function list.
00109  *
00110  * Arguments: args => ptr to argument string
00111  *
00112  * Returns: void function
00113  *
00114  */
00115 static void TemplateInit(u_char *args)
00116 {
00117     DebugMessage(DEBUG_PLUGIN,"Preprocessor: Template Initialized\n");
00118 
00119     /* 
00120      * parse the argument list from the rules file 
00121      */
00122     ParseTemplateArgs(args);
00123 
00124     /* 
00125      * perform any other initialization functions that are required here
00126      */
00127 
00128     /* 
00129      * Set the preprocessor function into the function list 
00130      */
00131     AddFuncToPreprocList(PreprocFunction);
00132     AddFuncToCleanExitList(PreprocCleanExitFunction, NULL);
00133     AddFuncToRestartList(PreprocRestartFunction, NULL);
00134 }
00135 
00136 
00137 
00138 /*
00139  * Function: ParseTemplateArgs(char *)
00140  *
00141  * Purpose: Process the preprocessor arguements from the rules file and 
00142  *          initialize the preprocessor's data struct.  This function doesn't
00143  *          have to exist if it makes sense to parse the args in the init 
00144  *          function.
00145  *
00146  * Arguments: args => argument list
00147  *
00148  * Returns: void function
00149  *
00150  */
00151 static void ParseTemplateArgs(char *args)
00152 {
00153     /* your parsing function goes here, check out the other spp files
00154        for examples */
00155 }
00156 
00157 
00158 /*
00159  * Function: PreprocFunction(Packet *)
00160  *
00161  * Purpose: Perform the preprocessor's intended function.  This can be
00162  *          simple (statistics collection) or complex (IP defragmentation)
00163  *          as you like.  Try not to destroy the performance of the whole
00164  *          system by trying to do too much....
00165  *
00166  * Arguments: p => pointer to the current packet data struct 
00167  *
00168  * Returns: void function
00169  *
00170  */
00171 static void PreprocFunction(Packet *p)
00172 {
00173 
00174     /* your preproc function goes here.... */
00175 
00176     /* 
00177      * if you need to issue an alert from your preprocessor, check out 
00178      * event_wrapper.h, there are some useful helper functions there
00179      */
00180 }
00181 
00182 
00183 /* 
00184  * Function: PreprocCleanExitFunction(int, void *)
00185  *
00186  * Purpose: This function gets called when Snort is exiting, if there's
00187  *          any cleanup that needs to be performed (e.g. closing files)
00188  *          it should be done here.
00189  *
00190  * Arguments: signal => the code of the signal that was issued to Snort
00191  *            data => any arguments or data structs linked to this 
00192  *                    functioin when it was registered, may be
00193  *                    needed to properly exit
00194  *       
00195  * Returns: void function
00196  */                   
00197 static void PreprocCleanExitFunction(int signal, void *data)
00198 {
00199        /* clean exit code goes here */
00200 }
00201 
00202 
00203 /* 
00204  * Function: PreprocRestartFunction(int, void *)
00205  *
00206  * Purpose: This function gets called when Snort is restarting on a SIGHUP,
00207  *          if there's any initialization or cleanup that needs to happen
00208  *          it should be done here.
00209  *
00210  * Arguments: signal => the code of the signal that was issued to Snort
00211  *            data => any arguments or data structs linked to this 
00212  *                    functioin when it was registered, may be
00213  *                    needed to properly exit
00214  *       
00215  * Returns: void function
00216  */                   
00217 static void PreprocRestartFunction(int signal, void *foo)
00218 {
00219        /* restart code goes here */
00220 }

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