tests/test_interface_name.c

Go to the documentation of this file.
00001 #include "test_interface_name.h"
00002 #include <stdio.h>
00003 #include <string.h>
00004 #include <stdlib.h>
00005 #include "../decoders/decode_interface.h"
00006 #include "../packets/packet.h"
00007 
00008 extern GlobalVars       Globals;
00009 
00010 typedef struct interface_name_data{
00011         int             InterfaceNum;
00012 } InterfaceNameData;
00013 
00014 #define DEBUG
00015 
00016 int InterfaceDecoderID;
00017 
00018 /******************************************
00019 * Apply the Test
00020 ******************************************/
00021 int TestInterfaceName(int PacketSlot, TestNode* Nodes){
00022         InterfaceData*          IData;
00023         InterfaceNameData*      INData;
00024         TestNode*                       Node;
00025         int                                     i;
00026         PacketRec*                      p;
00027         
00028 #ifdef DEBUGPATH
00029         printf("In TestInterfaceName\n");
00030 #endif
00031 
00032 #ifdef DEBUG
00033         printf("Testing Interface Name\n");
00034 #endif  
00035 
00036         p=&Globals.Packets[PacketSlot];
00037 
00038         /*TODO: Find a better way to hand this off*/
00039         for (i=0;i<p->NumDecoderData;i++){
00040                 if (p->DecoderInfo[i].DecoderID==InterfaceDecoderID){
00041                         IData=(InterfaceData*)p->DecoderInfo[i].Data;
00042                 }
00043         }
00044 
00045 #ifdef DEBUGMATCH
00046         printf("\n\n"); 
00047         printf("**************************************\n");
00048         printf("Before applying interface name tests\n");
00049         for (i=0;i<Globals.NumRules;i++)
00050         if (RuleIsActive(p,i))
00051                 printf("Rule %i is active\n",i);
00052         else
00053                 printf("Rule %i is inactive\n",i);
00054         printf("**************************************\n");
00055 #endif  
00056 
00057         Node=Nodes;
00058         while (Node){
00059                 if (RuleIsActive(PacketSlot, Node->RuleID)){
00060                         INData=(InterfaceNameData*)Node->Data;
00061                 
00062                         if (INData->InterfaceNum!=IData->r->ID){
00063 #ifdef DEBUGMATCH                       
00064                                 printf("Interface %s Doesn't Match\n",Globals.Interfaces[INData->InterfaceNum].Name);
00065 #endif                          
00066                                 SetRuleInactive(PacketSlot,Node->RuleID);
00067                         }
00068 #ifdef DEBUGMATCH                       
00069                         else{
00070                                 printf("Interface %s Matches\n",Globals.Interfaces[INData->InterfaceNum].Name);
00071                         }
00072 #endif                                          
00073                 }
00074 #ifdef DEBUGMATCH               
00075                 else{
00076                         printf("Rule %i is inactive\n", Node->RuleID);
00077                 }
00078 #endif          
00079                 Node=Node->Next;        
00080         }       
00081 
00082 #ifdef DEBUGMATCH
00083         printf("**************************************\n");
00084         printf("After applying interface name tests\n");
00085         for (i=0;i<Globals.NumRules;i++)
00086         if (RuleIsActive(p,i))
00087                 printf("Rule %i is active\n",i);
00088         else
00089                 printf("Rule %i is inactive\n",i);
00090         printf("**************************************\n");
00091 #endif  
00092         
00093         return TRUE;
00094 }
00095 
00096 /******************************************
00097 * Add a rule node to this test
00098 ******************************************/
00099 int InterfaceNameAddNode(int TestID, int RuleID, char* Args){
00100         int                             i;
00101         InterfaceNameData*      data;
00102         
00103 #ifdef DEBUGPATH
00104         printf("In InterfaceNameAddNode\n");
00105 #endif
00106 
00107 #ifdef DEBUG
00108         printf("Addding Node with args %s\n",Args);
00109 #endif
00110 
00111         /*find the interface*/
00112         for (i=0;i<Globals.NumInterfaces;i++){
00113                 if (strcasecmp(Args, Globals.Interfaces[i].Name)==0){
00114                         data=(InterfaceNameData*)calloc(sizeof(InterfaceNameData),1);
00115                         data->InterfaceNum=i;
00116                         return TestAddNode(TestID, RuleID, (void*)data);
00117                 }
00118         }
00119 
00120         printf("There is no interface defined named \"%s\"\n",Args);
00121 
00122         return FALSE;
00123 }
00124 
00125 /****************************************
00126 * Set up the test of the interface name
00127 *****************************************/
00128 int InitTestInterfaceName(){
00129         int     TestID;
00130 
00131 #ifdef DEBUGPATH
00132         printf("In InitTestInterfaceName\n");
00133 #endif
00134 
00135         TestID=CreateTest("InterfaceName");
00136         if (TestID==TEST_NONE) return FALSE;
00137         
00138         if (!BindTestToDecoder(TestID, "Interface")){
00139                 printf("Failed to Bind to Interface\n");
00140                 return FALSE;
00141         } 
00142         
00143         snprintf(Globals.Tests[TestID].ShortName, MAX_NAME_LEN, "name");
00144         Globals.Tests[TestID].AddNode=InterfaceNameAddNode;
00145         Globals.Tests[TestID].TestFunc=TestInterfaceName;
00146         
00147         InterfaceDecoderID=GetDecoderByName("Interface");
00148 
00149         return TRUE;
00150 }

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