00001 #include "route.h" 00002 #include "route_dip.h" 00003 #include "route_sip.h" 00004 #include "route_macfilter.h" 00005 #include "route_simple_bridge.h" 00006 #include "route_broadcast.h" 00007 #include "route_arp.h" 00008 #include "route_interface.h" 00009 #include "route_bns.h" 00010 #include <string.h> 00011 #include <stdio.h> 00012 #include <stdlib.h> 00013 #ifdef _SOLARIS_ 00014 #include <strings.h> 00015 #endif 00016 00017 //#define DEBUG 00018 00019 extern GlobalVars Globals; 00020 00021 /*********************************** 00022 * Set up all the routing code 00023 ***********************************/ 00024 int InitRoutes(){ 00025 DEBUGPATH; 00026 00027 if (!InitRouteDIP()) return FALSE; 00028 if (!InitRouteSIP()) return FALSE; 00029 if (!InitMacFilter()) return FALSE; 00030 if (!InitSBridge()) return FALSE; 00031 if (!InitRouteBroadcast()) return FALSE; 00032 if (!InitRouteARP()) return FALSE; 00033 if (!InitRouteInterface()) return FALSE; 00034 if (!InitRouteBNS()) return FALSE; 00035 00036 return TRUE; 00037 } 00038 00039 /****************************************** 00040 * Put a new entry into the routing system 00041 ******************************************/ 00042 int RouteAdd(int RouteID, char* Args){ 00043 DEBUGPATH; 00044 00045 if (RouteID>=Globals.NumRoutes) return FALSE; 00046 if (!Globals.Routes[RouteID].AddNode) return FALSE; 00047 00048 return Globals.Routes[RouteID].AddNode(RouteID, Args); 00049 } 00050 00051 /*********************************** 00052 * Given an route's name, return 00053 * its ID 00054 ***********************************/ 00055 int GetRouteByName(char* Name){ 00056 int i; 00057 00058 DEBUGPATH; 00059 00060 for (i=0;i<Globals.NumRoutes;i++){ 00061 if (strcasecmp(Name, Globals.Routes[i].Name)==0){ 00062 return i; 00063 } 00064 } 00065 00066 return ROUTE_NONE; 00067 } 00068 00069 /******************************** 00070 * Create a new route handler 00071 *********************************/ 00072 int CreateRoute(char* Name){ 00073 int RouteID; 00074 00075 DEBUGPATH; 00076 00077 /*check to see if this name is already used*/ 00078 RouteID=GetRouteByName(Name); 00079 if (RouteID!=ROUTE_NONE){ 00080 printf("Route %s already exists\n",Name); 00081 return ROUTE_NONE; 00082 } 00083 00084 RouteID=Globals.NumRoutes; 00085 Globals.NumRoutes++; 00086 00087 bzero(&Globals.Routes[RouteID], sizeof(RouteRec)); 00088 Globals.Routes[RouteID].ID=RouteID; 00089 snprintf(Globals.Routes[RouteID].Name, MAX_NAME_LEN, Name); 00090 00091 #ifdef DEBUG 00092 printf("Allocated Route \"%s\" at number %i\n",Name, RouteID); 00093 #endif 00094 00095 return RouteID; 00096 } 00097 00098 /********************************************** 00099 * Apply routing rules to this packet 00100 * Returns FALSE if you need to drop the packet 00101 **********************************************/ 00102 int Route(int PacketSlot){ 00103 int i; 00104 int result; 00105 00106 DEBUGPATH; 00107 00108 for (i=0;i<Globals.NumRoutes;i++){ 00109 if (Globals.Routes[i].Active) 00110 if (Globals.Routes[i].RouteFunc){ 00111 result=Globals.Routes[i].RouteFunc(PacketSlot); 00112 if (result==ROUTE_RESULT_DROP) return FALSE; 00113 if (result==ROUTE_RESULT_DONE) return TRUE; 00114 } 00115 } 00116 00117 return TRUE; 00118 } 00119