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

sp_stickydrop.c

Go to the documentation of this file.
00001 /* $Id: sp_template.c,v 1.5 2004/02/13 16:19:03 roesch Exp $ */
00002 /* Snort Detection Plugin Source File Template */
00003 
00004 /* sp_template 
00005  *
00006  * Purpose:
00007  *
00008  * Detection engine plugins test an aspect of the current packet and report
00009  * their findings.  The function may be called many times per packet with 
00010  * different arguments.  These functions are acccessed from the rules file
00011  * as standard rule options.  When adding a plugin to the system, be sure to 
00012  * add the "Setup" function to the InitPlugins() function call in 
00013  * plugbase.c!
00014  *
00015  * Arguments:
00016  *
00017  * This is the type of arguements that the detection plugin can take when
00018  * referenced as a rule option
00019  *
00020  * Effect:
00021  *
00022  * What the plugin does.
00023  *
00024  * Comments:
00025  *
00026  * Any comments?
00027  *
00028  */
00029 
00030 
00031 /* stickydrop is only used in inline mode */
00032 #ifdef GIDS
00033 
00034 
00035 #include <sys/types.h>
00036 #include <stdlib.h>
00037 #include <ctype.h>
00038 
00039 #include "rules.h"
00040 #include "decode.h"
00041 #include "plugbase.h"
00042 #include "parser.h"
00043 #include "debug.h"
00044 #include "util.h"
00045 #include "mstring.h"
00046 #include "plugin_enum.h"
00047 #include "spp_stickydrop.h"
00048 #include "sp_stickydrop.h"
00049 /* 
00050  * don't forget to include the name of this file in plugbase.c! 
00051  */
00052 
00053 /* 
00054  * setup any data structs here 
00055  */
00056 //typedef struct _StickyDSp
00057 //{
00058 //    int stickyd_timeout;     
00059 //    char stickyd_direction;
00060 //} StickyDSp;
00061 
00062 /* function prototypes go here */
00063 void StickyDSpInit(char *, OptTreeNode *, int);
00064 static void StickyDSpRuleParseFunction(char *, OptTreeNode *, StickyDSp *);
00065 static int StickyDSpFunction(Packet *, struct _OptTreeNode *, 
00066         OptFpList *);
00067 
00068 /*
00069  * 
00070  * Function: SetupTemplate()
00071  *
00072  * Purpose: Generic detection engine plugin template.  Registers the
00073  *          configuration function and links it to a rule keyword.  This is
00074  *          the function that gets called from InitPlugins in plugbase.c.
00075  *
00076  * Arguments: None.
00077  *
00078  * Returns: void function
00079  *
00080  */
00081 void SetupStickyDSp()
00082 {
00083     /* map the keyword to an initialization/processing function */
00084     RegisterPlugin("sticky-drop", StickyDSpInit);
00085 
00086     DEBUG_WRAP(DebugMessage(DEBUG_PLUGIN,"Plugin: StickyDSp Setup\n"););
00087 }
00088 
00089 
00090 /*
00091  * 
00092  * Function: TemplateInit(char *, OptTreeNode *)
00093  *
00094  * Purpose: Generic rule configuration function.  Handles parsing the rule 
00095  *          information and attaching the associated detection function to
00096  *          the OTN.
00097  *
00098  * Arguments: data => rule arguments/data
00099  *            otn => pointer to the current rule option list node
00100  *
00101  * Returns: void function
00102  *
00103  */
00104 void StickyDSpInit(char *data, OptTreeNode *otn, int protocol)
00105 {
00106     StickyDSp *stickydsp_d;
00107     OptFpList *ofl;
00108 
00109     if(!SppStickydIsRunning())
00110     {
00111         FatalError("dude, you can't have a sticky-drop plugin without the sticky-drop preproc\n");
00112     }
00113     stickydsp_d = (StickyDSp *) SnortAlloc(sizeof(StickyDSp));
00114     StickyDSpRuleParseFunction(data, otn, stickydsp_d);
00115 
00116     ofl = AddOptFuncToList(StickyDSpFunction, otn);
00117     ofl->context = (void *) stickydsp_d;
00118     otn->ds_list[PLUGIN_STICKYDSP]=(StickyDSp *)stickydsp_d;
00119 }
00120 
00121 
00122 
00123 /*
00124  * 
00125  * Function: TemplateRuleParseFunction(char *, OptTreeNode *)
00126  *
00127  * Purpose: This is the function that is used to process the option keyword's
00128  *          arguments and attach them to the rule's data structures.
00129  *
00130  * Arguments: data => argument data
00131  *            otn => pointer to the current rule's OTN
00132  *            td => pointer to the configuration storage struct
00133  *
00134  * Returns: void function
00135  *
00136  */
00137 static void StickyDSpRuleParseFunction(char *data, OptTreeNode *otn, StickyDSp *sd) 
00138 {
00139    char **toks;
00140    int numToks;
00141    char *direction;
00142    toks = mSplit(data, ",", 2, &numToks, 0);
00143 
00144       if(numToks > 2)
00145          FatalError("ERROR %s (%d): Bad arguments to sticky-drop: %s\n", file_name,
00146                  file_line, data);
00147   
00148            if(isdigit((char)toks[0][1]))
00149            {
00150                sd->stickyd_timeout = atoi(toks[0]);
00151            }
00152            else
00153            {
00154                FatalError("ERROR %s (%d): Bad arguments to sticky-drop: %s\n", file_name,
00155                      file_line, data);
00156            }
00157 
00158         
00159       if(numToks > 1)
00160       {
00161           direction = toks[1];
00162 
00163           while(isspace((int)*direction)) {direction++;}
00164 
00165           if(!strcasecmp(direction, "src"))
00166           {           
00167               sd->stickyd_direction = 0;
00168           }         
00169           else if(!strcasecmp(direction, "dst"))
00170           {                
00171               sd->stickyd_direction = 1;
00172           }
00173           else
00174           {
00175    
00176                FatalError("%s(%d):we need a direction either src or dst%s\n",file_name,file_line,toks[1]);
00177           }
00178       }
00179 
00180        mSplitFree(&toks, numToks);
00181 }
00182 
00183 
00184 /*
00185  * 
00186  * Function: TemplateDetectorFunction(char *, OptTreeNode *, OptFpList *)
00187  *
00188  * Purpose: Use this function to perform the particular detection routine
00189  *          that this rule keyword is supposed to encompass.
00190  *
00191  * Arguments: data => argument data
00192  *            otn => pointer to the current rule's OTN
00193  *            fp_list => pointer to the function pointer list current node
00194  *
00195  * Returns: If the detection test fails, this function *must* return a zero!
00196  *          On success, it calls the next function in the detection list 
00197  *
00198  */
00199 static int StickyDSpFunction(Packet *p, struct _OptTreeNode *otn, OptFpList *fp_list)
00200 {
00201 //    StickyDSp *sd;   /* ptr to the detection option's data */
00202 //
00203 //    sd = (StickyDSp *) fp_list->context;
00204 //
00205 //    AddIpToBlockTree(p, sd->stickyd_direction, sd->stickyd_timeout);
00206     return 1;
00207 }
00208 
00209 
00210 #endif /* GIDS */

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