00001 #ifndef N2NCFILTER_H
00002 #define N2NCFILTER_H
00003
00004
00005
00006
00007
00008
00009 #include "nixsys.h"
00010
00011 #include "blowfish.h"
00012 #include "packetmanager.h"
00013
00014 namespace n2nc {
00015
00028 class Filter{
00029 protected:
00030
00031 std::string m_name ;
00032 std::string m_description ;
00033 bool m_isenabled ;
00034 size_t m_maxoverhead ;
00035
00036 std::string m_filename ;
00037 void *this_handle;
00038
00039 security::BlowFish::key_t *m_skey ;
00040 n2nc::PacketManager *m_pkm ;
00041
00042
00043 n2nc::net::Socket *m_com_sock ;
00044
00048 Filter(std::string name,std::string description){
00049 std::cerr << "loaded filter module: " << name << std::endl ;
00050 this->m_name = name ;
00051 this->m_description = description ;
00052 this->m_com_sock = NULL ;
00053 this->m_maxoverhead = 0 ;
00054 }
00055
00056 public:
00057
00059 enum status_t{
00061 FILTER_CONTINUE = 0,
00063 FILTER_RETURN,
00065 FILTER_DROP
00066 };
00067
00068 virtual ~Filter(){
00069 std::cerr << "UN-loaded filter module: " << this->m_name << std::endl ;
00070 }
00072 virtual status_t egress(void *inbuf, void *outbuf,size_t inlen,size_t *outlen) = 0 ;
00073
00075 virtual status_t ingress(void *inbuf, void *outbuf,size_t inlen,size_t *outlen) = 0 ;
00076
00077
00078
00080 virtual int setSessionKey(security::BlowFish::key_t *key){ this->m_skey = key ;}
00082 virtual int setPKM(n2nc::PacketManager *pkm){this->m_pkm = pkm ;}
00083 virtual size_t getMaxOverHead(){ return this->m_maxoverhead ;}
00085 std::string toString(){
00086 std::ostringstream os;
00087 std::string s;
00088 os << "Name: " << this->m_name << " Description: " << this->m_description << " Filename: " << this->m_filename ; ;
00089 s = "Name: " + this->m_name + " Description: " + this->m_description + " Filename: " + this->m_filename ;
00090
00091 return os.str();
00092 }
00094 static Filter *load_filter(const std::string filename){
00095 void *handle ;
00096 Filter *ist;
00097 typedef Filter* (*get_istance_t)();
00098 get_istance_t tmp_get_istance;
00099
00100 handle = dlopen(filename.c_str(),RTLD_NOW );
00101 if (handle==NULL){ std::cerr << "dlopen fails!:" << dlerror() << std::endl; return NULL ;}
00102 tmp_get_istance = (get_istance_t)dlsym(handle,"get_istance");
00103 if (tmp_get_istance ==NULL ) {std::cerr << "dlsym fails!:" << dlerror() << std::endl ; return NULL ;}
00104 ist = tmp_get_istance() ;
00105 ist->this_handle = handle ;
00106 ist->m_filename = filename ;
00107 return ist ;
00108 }
00112 static int free_filter(Filter *filter){
00113 void *handle;
00114 typedef int (*free_istance_t)(Filter *filter);
00115 free_istance_t tmp_free_istance;
00116 tmp_free_istance = (free_istance_t)dlsym(filter->this_handle,"free_istance");
00117 if (tmp_free_istance ==NULL ) {std::cerr << "dlsym fails!:" << dlerror(); exit(1);}
00118 handle = filter->this_handle ;
00119
00120 tmp_free_istance(filter);
00121
00122 dlclose(handle);
00123 }
00124
00125
00126
00134 };
00135
00136
00137 }
00138
00139
00140 #endif