00001 #include "test_udp_nocase.h"
00002 #include <stdio.h>
00003 #include <string.h>
00004 #include <stdlib.h>
00005 #include "../decoders/decode_udp.h"
00006 #include "../packets/packet.h"
00007 #include "../engine/jtree.h"
00008 #include <arpa/inet.h>
00009
00010 extern GlobalVars Globals;
00011
00012 typedef struct udp_nocase_data{
00013 unsigned char udp_content[MAX_CONTENT_LEN];
00014 } UDPNoCaseData;
00015
00016
00017
00018
00019 int UDPDecoderID;
00020 JTree UDPNoCaseTree;
00021
00022
00023
00024
00025 int TestUDPNoCase(int PacketSlot, TestNode* Nodes){
00026 PacketRec* p;
00027 #ifdef DEBUGMATCH
00028 int i;
00029 #endif
00030
00031 #ifdef DEBUGPATH
00032 printf("In TestUDPNoCase\n");
00033 #endif
00034
00035 #ifdef DEBUG
00036 printf("Testing UDP NoCase\n");
00037 #endif
00038
00039 p=&Globals.Packets[PacketSlot];
00040
00041 if (!Nodes) return FALSE;
00042
00043 #ifdef DEBUGMATCH
00044 printf("**************************************\n");
00045 printf("Before applying udp no case tests\n");
00046 for (i=0;i<Globals.NumRules;i++)
00047 if (RuleIsActive(PacketSlot,i))
00048 printf("Rule %i is active\n",i);
00049 else
00050 printf("Rule %i is inactive\n",i);
00051 printf("**************************************\n");
00052 #endif
00053
00054 MatchStrings(&UDPNoCaseTree, p->RuleBits, p->RawPacket+p->BeginData, p->PacketLen - p->BeginData);
00055
00056 #ifdef DEBUGMATCH
00057 printf("**************************************\n");
00058 for (i=0;i<Globals.NumRules;i++)
00059 if (RuleIsActive(PacketSlot,i))
00060 printf("Rule %i is active\n",i);
00061 else
00062 printf("Rule %i is inactive\n",i);
00063 printf("**************************************\n");
00064 #endif
00065
00066 return TRUE;
00067 }
00068
00069
00070
00071
00072 int UDPNoCaseAddNode(int TestID, int RuleID, char* Args){
00073 UDPNoCaseData* data;
00074
00075 #ifdef DEBUGPATH
00076 printf("In UDPNoCaseAddNode\n");
00077 #endif
00078
00079 #ifdef DEBUG
00080 printf("Addding a Node with args %s\n",Args);
00081 #endif
00082
00083 data=calloc(sizeof(UDPNoCaseData),1);
00084 snprintf(data->udp_content, MAX_CONTENT_LEN, Args);
00085
00086 if (!AddStringJTree(&UDPNoCaseTree, Args, strlen(Args), RuleID)){
00087 printf("Failed to add to tree\n");
00088 free(data);
00089 data=NULL;
00090 return FALSE;
00091 }
00092
00093 return TestAddNode(TestID, RuleID, (void*)data);
00094 }
00095
00096
00097
00098
00099 int TestUDPNoCaseFinishedSetup(){
00100 #ifdef DEBUGPATH
00101 printf("In TestUDPContentFinishedSetup\n");
00102 #endif
00103
00104 return FinalizeJTree(&UDPNoCaseTree);
00105 }
00106
00107
00108
00109
00110
00111 int InitTestUDPNoCase(){
00112 int TestID;
00113
00114 #ifdef DEBUGPATH
00115 printf("In InitTestUDPNoCase\n");
00116 #endif
00117
00118 InitJTree(&UDPNoCaseTree, TRUE);
00119
00120 TestID=CreateTest("UDPNoCase");
00121 if (TestID==TEST_NONE) return FALSE;
00122
00123 if (!BindTestToDecoder(TestID, "UDP")){
00124 printf("Failed to Bind to UDP\n");
00125 return FALSE;
00126 }
00127
00128 snprintf(Globals.Tests[TestID].ShortName, MAX_NAME_LEN, "nocase");
00129 Globals.Tests[TestID].AddNode=UDPNoCaseAddNode;
00130 Globals.Tests[TestID].TestFunc=TestUDPNoCase;
00131 Globals.Tests[TestID].FinishedSetup=TestUDPNoCaseFinishedSetup;
00132
00133 UDPDecoderID=GetDecoderByName("UDP");
00134
00135 return TRUE;
00136 }