actions/action_bns.c

Go to the documentation of this file.
00001 #include "action_bns.h"
00002 #include <stdio.h>
00003 #include "../engine/message.h"
00004 #include "../decoders/decode_ip.h"
00005 #include "../routes/route_bns.h"
00006 #include "../actions/action.h"
00007 #include <stdlib.h>
00008 #include <string.h>
00009 #ifdef _SOLARIS_
00010 #include <strings.h>
00011 #endif
00012 #include <netinet/in.h>
00013 #include <arpa/inet.h>
00014 
00015 //#define DEBUG
00016 
00017 typedef struct action_bns{
00018         NumList*        GreenList;
00019         int                     TimeOut;
00020 } ActionBNSRec;
00021 
00022 extern GlobalVars       Globals;
00023 int IPDecoderID;
00024 
00025 /******************************************
00026 * Parse the args for this action
00027 ******************************************/
00028 void* BNSParseArgs(char* Args){
00029         ActionBNSRec*           data;
00030         char*                           c;
00031         char*                           c2;
00032 
00033 #ifdef DEBUGPATH
00034         printf("In BNSParseArgs\n");
00035 #endif
00036 
00037 #ifdef DEBUG
00038         printf("Parsing args for action_bns\n");
00039 #endif  
00040 
00041         data=(ActionBNSRec*)calloc(sizeof(ActionBNSRec),1);
00042         data->GreenList=InitNumList(LIST_TYPE_NORMAL);
00043 
00044         c=Args;
00045         while ((*c==' ') && (*c!=0x00)) c++;
00046 
00047         /*The first arg is the timeout length*/
00048         c2=strchr(c, ',');
00049         if (!c2){
00050                 printf("Expected \",\"\n");
00051                 printf("Usage response=bns(<timeout>, <GreenList>)\n");
00052                 free(data);
00053                 return NULL;
00054         }
00055         *c2=0x00;
00056         c2++;
00057         data->TimeOut=atoi(c);
00058         
00059 #ifdef DEBUG
00060         printf("Timeout set to %i\n",data->TimeOut);
00061 #endif  
00062 
00063         /*The second arg is the green list*/
00064         c=c2;
00065         while ((*c==' ') && (*c!=0x00)) c++;
00066         if (!AddIPRanges(data->GreenList, c)){
00067                 printf("Couldn't understand Green List (%s)\n",c);
00068                 free(data);
00069                 return NULL;
00070         }
00071         
00072         return data;
00073 }
00074 
00075 
00076 /******************************************
00077 * handle informational messages
00078 ******************************************/
00079 int BNSMessage(char* Message, void* Data){
00080 
00081 #ifdef DEBUGPATH
00082         printf("In BNSMessage\n");
00083 #endif
00084 
00085         return TRUE;
00086 }
00087 
00088 /******************************************
00089 * Reroute this IP
00090 ******************************************/
00091 int BNSAction(int RuleNum, int PacketSlot, void* Data){
00092         ActionBNSRec*           data;
00093         PacketRec*                      p;
00094         IPData*                         IP;
00095         char                            Message[512];
00096         
00097 #ifdef DEBUGPATH
00098         printf("In BNSAction\n");
00099 #endif
00100 
00101 #ifdef DEBUG
00102         printf("Applying an BNS action\n");
00103 #endif
00104 
00105         if (!Data){
00106 #ifdef DEBUG
00107                 printf("I must have somewhere to route to\n");
00108 #endif  
00109                 return FALSE;
00110         }
00111                 
00112         if (!GetDataByID(PacketSlot, IPDecoderID, (void**)&IP)){
00113                 printf("This packet has no IP header\n");
00114                 return FALSE;
00115         }
00116         
00117         p=&Globals.Packets[PacketSlot];
00118         data=(ActionBNSRec*)Data;
00119 
00120         if (IsInList(data->GreenList, ntohl(IP->Header->saddr))){
00121 #ifdef DEBUG
00122                 printf("This is in the green list\n");
00123 #endif  
00124                 return FALSE;
00125         }
00126                                                 
00127         snprintf(Message, 512,"Rerouting %s to Honeypot for %i seconds",inet_ntoa(*(struct in_addr*)&IP->Header->saddr),data->TimeOut);
00128         LogMessageAllActions(Message);
00129                                 
00130         return AddRangeTime(BNSRerouteList, ntohl(IP->Header->saddr), ntohl(IP->Header->saddr), p->tv.tv_sec+data->TimeOut);
00131 }
00132 
00133 /********************************
00134 * Set up the bns routing stuff
00135 ********************************/
00136 int InitActionBNS(){
00137         int ActionID;
00138 
00139 #ifdef DEBUGPATH
00140         printf("In InitActionBNS\n");
00141 #endif
00142 
00143         ActionID=CreateAction("bns");
00144         if (ActionID==ACTION_NONE){
00145 #ifdef DEBUG
00146                 printf("Couldn't allocation action BNS\n");
00147 #endif  
00148                 return FALSE;
00149         }
00150         
00151         Globals.ActionItems[ActionID].ActionFunc=BNSAction;
00152         Globals.ActionItems[ActionID].MessageFunc=BNSMessage;
00153         Globals.ActionItems[ActionID].ParseArgs=BNSParseArgs;
00154 
00155         IPDecoderID=GetDecoderByName("IP");
00156 
00157         return TRUE;
00158 }

Generated on Sat Jul 7 23:33:09 2007 for HLBR by  doxygen 1.5.2