00001
00002
00003
00004
00005
00006 #include "route_dip.h"
00007 #include <string.h>
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include "../packets/packet.h"
00011 #include "../engine/num_list.h"
00012 #include "../decoders/decode.h"
00013 #include "../decoders/decode_ip.h"
00014 #include <arpa/inet.h>
00015 #ifdef _SOLARIS_
00016 #include <strings.h>
00017 #endif
00018
00019 int IPDecoderID;
00020 NumList* DInterfaces[MAX_INTERFACES];
00021
00022
00023
00024 extern GlobalVars Globals;
00025
00026
00027
00028
00029 int RouteDIP(int PacketSlot){
00030 IPData* IData;
00031 PacketRec* p;
00032 int i;
00033
00034 #ifdef DEBUGPATH
00035 printf("In RouteDIP\n");
00036 #endif
00037
00038 p=&Globals.Packets[PacketSlot];
00039
00040 if (!GetDataByID(p->PacketSlot, IPDecoderID, (void**)&IData)){
00041 #ifdef DEBUG
00042 printf("This isn't an ip packet\n");
00043 #endif
00044 return ROUTE_RESULT_CONTINUE;
00045 }
00046
00047 #ifdef DEBUG
00048 printf("%s->",inet_ntoa(*(struct in_addr*)&IData->Header->saddr));
00049 printf("%s\n",inet_ntoa(*(struct in_addr*)&IData->Header->daddr));
00050 printf("This packet is from %i(%s)\n",p->InterfaceNum, Globals.Interfaces[p->InterfaceNum].Name);
00051 #endif
00052
00053
00054 for (i=0;i<Globals.NumInterfaces;i++){
00055 if (DInterfaces[i]){
00056 if (IsInList(DInterfaces[i], ntohl(IData->Header->daddr))){
00057 #ifdef DEBUG
00058 printf("Found a DIP route for this packet. Going out interface %i(%s)\n",i,Globals.Interfaces[i].Name);
00059 #endif
00060 p->TargetInterface=i;
00061 return ROUTE_RESULT_DONE;
00062 }
00063 }
00064 }
00065
00066 #ifdef DEBUG
00067 printf("There isn't a route set for this DIP\n");
00068 #endif
00069 return ROUTE_RESULT_CONTINUE;
00070 }
00071
00072
00073
00074
00075
00076
00077 int RouteDIPAddNode(int RouteID, char* Args){
00078 int i;
00079 char* sp;
00080 int InterfaceNum;
00081
00082 #ifdef DEBUGPATH
00083 printf("In RouteDIPAddNode\n");
00084 #endif
00085
00086 #ifdef DEBUG
00087 printf("Adding with args %s\n",Args);
00088 #endif
00089
00090
00091 sp=strchr(Args, ' ');
00092 if (!sp){
00093 printf("Expected Interface Name\nFormat: DIP(<interface> <dip>,<dip>,.....)\n");
00094 return FALSE;
00095 }
00096
00097 *sp=0x00;
00098 sp++;
00099 while (*sp==' ') sp++;
00100 if (sp==0x00){
00101 printf("Expected Destination IP\nFormat: DIP(<interface> <dip>,<dip>,.....)\n");
00102 return FALSE;
00103 }
00104
00105
00106 #ifdef DEBUG
00107 printf("Searching for interface \"%s\"\n",Args);
00108 #endif
00109 for (i=0;i<Globals.NumInterfaces;i++){
00110 if (strcasecmp(Args, Globals.Interfaces[i].Name)==0){
00111 InterfaceNum=i;
00112 break;
00113 }
00114 }
00115
00116 if (i==Globals.NumInterfaces){
00117 printf("Unknown Interface \"%s\"\n",Args);
00118 return FALSE;
00119 }
00120
00121 if (!DInterfaces[InterfaceNum]){
00122 DInterfaces[InterfaceNum]=InitNumList(LIST_TYPE_NORMAL);
00123 }
00124
00125 if (!AddIPRanges(DInterfaces[InterfaceNum], sp)){
00126 printf("Failed to parse IP list \"%s\"\n",sp);
00127 return FALSE;
00128 }
00129
00130 return TRUE;
00131 }
00132
00133
00134
00135
00136 int InitRouteDIP(){
00137 int RouteID;
00138
00139 #ifdef DEBUGPATH
00140 printf("In InitRoutDIP\n");
00141 #endif
00142
00143 bzero(DInterfaces, sizeof(NumList*) * MAX_INTERFACES);
00144
00145 if ( (RouteID=CreateRoute("DIP"))==ROUTE_NONE){
00146 printf("Couldn't create route DIP\n");
00147 return FALSE;
00148 }
00149
00150 Globals.Routes[RouteID].RouteFunc=RouteDIP;
00151 Globals.Routes[RouteID].AddNode=RouteDIPAddNode;
00152
00153 if ( (IPDecoderID=GetDecoderByName("IP"))==DECODER_NONE){
00154 printf("Couldn't find the IP Deoder\n");
00155 return FALSE;
00156 }
00157
00158 return TRUE;
00159 }
00160