Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

rubicon.c

Go to the documentation of this file.
00001 /****************************************************************************/
00002 /****************************************************************************/
00007 /****************************************************************************/
00008 
00009 #include "plugin.h"
00010 #include "policy.h"
00011 #include "types.h"
00012 #include "policy-xml.h"
00013 #include "policy-dump.h"
00014 #include "naming.h"
00015 #include <unistd.h>
00016 #include <signal.h>
00017 #include <string.h>
00018 #include <errno.h>
00019 #include <stdio.h>
00020 
00021 PLUGIN *inp_list=0;
00022 PLUGIN *anp_list=0;
00023 PLUGIN *protop_list=0;
00024 PLUGIN *outp_list=0;
00025 PLUGIN *all_plugins=0;
00026 
00027 int cleanup=0;
00028 int shutdown=0;
00029 
00030 
00031 #ifndef DEBUG_RUBICON
00032 #ifdef DEBUG
00033 #define DEBUG_RUBICON DEBUG
00034 #else
00035 #define DEBUG_RUBICON 0
00036 #endif
00037 #endif
00038 
00039 /****************************************************************************/
00048 /****************************************************************************/
00049 void sig_handler(int i){
00050   printf("Got signal int=%d\n",i);
00051   switch(i){
00052   case SIGHUP:
00053     printf("HUP received. Flagged to reinitialise asap.\n");
00054     cleanup=1;
00055     break;
00056   case SIGINT:
00057     if(!shutdown){
00058       printf("INT received. Flagged to cleanup and then shutdown.\n");
00059       printf("Sending a second INT signal (e.g. kill -INT or control-c)\n");
00060       printf("if you want to immediately shutdown.\n");
00061       shutdown = 1;
00062     }
00063     else {
00064       printf("Second INT received. Shutting down now!\n");
00065       exit(0);
00066     }
00067     break;
00068   default:
00069   }
00070 }
00071 
00072 /****************************************************************************/
00077 /****************************************************************************/
00078 int main(int argc, char *argv[]){
00079   POLICY_HEAD *pol;
00080   char *plug_dir;
00081   char *log_location;
00082   char *in_file;
00083   char *config_file;
00084   char c;
00085   struct sigaction sigact;
00086 
00087   /* set defaults */
00088   plug_dir = ".";
00089   log_location = "./log/";
00090   in_file = (char*)0;
00091   config_file = (char*)0;
00092 
00093   /* get arguments */
00094   while((c=getopt(argc, argv, "p:h?l:i:c:d:"))!=(char)-1){
00095     switch(c){
00096     case 'l':
00097       log_location = optarg;
00098       break;
00099     case 'i':
00100       in_file = optarg;
00101       break;
00102     case 'c': 
00103       config_file = optarg;
00104       break;
00105     case 'd':
00107       break;
00108     case 'p':
00109       plug_dir = optarg;
00110       break;
00111     case 'h':
00112     case '?':
00113     default:
00114       printf("Usage: ./rubicon [options]\n");
00115       printf("Options:-\n");
00116       printf("        -p <dir> Specifies the directory to look for plugins\n");
00117       printf("        -i <file> Input data file (pcap/tcpdump format)\n");
00118       printf("        -l <dir or file> Log directory/file. If dir, must exist.\n");
00119       printf("        -c <file> Config file\n");
00120       printf("        -d <dev>=<name>  Device name mapping. e.g. /dev/eth0=IN\n");
00121       printf("        -h or -?  Show this usage\n");
00122       exit(0);
00123     }
00124   }
00125 
00126   sigact.sa_handler = &sig_handler;
00127   sigact.sa_flags = 0;
00128   sigemptyset(&(sigact.sa_mask));
00129   if(sigaction(SIGINT, &sigact, (struct sigaction *)0)==-1){
00130     printf("WARN: sigaction SIGINT failed. errno=%d =%s\n", errno, strerror(errno));
00131   }
00132 
00133   if(sigaction(SIGHUP, &sigact, (struct sigaction *)0)==-1){
00134     printf("WARN: sigaction SIGHUP failed. errno=%d =%s\n", errno, strerror(errno));
00135   }
00136 
00137   
00138   if(!loadPlugins(plug_dir)){
00139     printf("ERR: loadPlugins failed\n");
00140     return 0;
00141   }
00142 
00143   /* start up the policy thread */
00144   pol = buildXmlPolicyFromFile(config_file);
00145   if(!pol){
00146     printf("ERR: The xml policy couldn't be loaded.\n");
00147     return 0;
00148   }
00149   
00150   dumpPolicy(stdout, pol, (char)0);
00151 
00152   /* start message loop */
00153 
00154   while(1){
00155     if(cleanup){
00156       cleanup = 0;
00157       cleanupPlugins();
00158       cleanMapping();
00159       if(DEBUG_RUBICON>=DEBUG_DO_INTERNALS) 
00160         dumpPolicy(stdout, pol, (char)1);
00161       else 
00162         dumpPolicy(0, pol, (char)1);
00163       
00164       pol = (POLICY_HEAD*)0;
00165 
00166       if(!loadPlugins(plug_dir)){
00167         printf("ERR: loadPlugins failed\n");
00168         return 0;
00169       }
00170       
00171       /* start up the policy thread */
00172       pol = buildXmlPolicyFromFile(config_file);
00173       if(!pol){
00174         printf("ERR: The xml policy couldn't be loaded.\n");
00175         return 0;
00176       }
00177     }
00178     if(shutdown){
00179       shutdown = 0;
00180       cleanup = 0;
00181       cleanupPlugins();
00182       cleanMapping();
00183       if(DEBUG_RUBICON>=DEBUG_DO_INTERNALS) 
00184         dumpPolicy(stdout, pol, (char)1);
00185       else 
00186         dumpPolicy(0, pol, (char)1);
00187       
00188       pol = (POLICY_HEAD*)0;
00189       exit(0);
00190     }
00191     /* new policy */
00192     /* -- if so, load, init */
00193 
00194     /* find source for packet */
00195     /* get packet */
00196 
00197     /* handle packet */
00198   }
00199 
00200   return 0;
00201 }

Generated at Mon Jul 8 15:16:50 2002 for RUBICON by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000