User Manual, Developers Guide and API Documentation

DLLFlowIDTarget.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  * IPModule   Internet Protocol Implementation                                *
00003  * __________________________________________________________________________ *
00004  *                                                                            *
00005  * Copyright (C) 2005                                                         *
00006  * Lehrstuhl fuer Kommunikationsnetze (ComNets)                               *
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany                                 *
00008  * phone: ++49-241-80-27910 (phone), fax: ++49-241-80-22242                   *
00009  * email: wns@comnetsrwth-aachen.de, www: http://wns.comnets.rwth-aachen.de/  *
00010  ******************************************************************************/
00011 
00012 #include <IP/iptables/targets/DLLFlowIDTarget.hpp>
00013 #include <IP/iptables/targets/DLLFlowIDTaggerTarget.hpp>
00014 #include <IP/iptables/filters/AcceptsAllFilter.hpp>
00015 #include <IP/iptables/PostroutingChain.hpp>
00016 
00017 using namespace ip::iptables::targets;
00018 
00019 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00020                      DLLFlowIDTarget,
00021                      TargetInterface,
00022                      "dllFlowIDTarget",
00023                      wns::PyConfigViewCreator);
00024 
00025 DLLFlowIDTarget::DLLFlowIDTarget(const wns::pyconfig::View& _pyco):
00026   log(_pyco.get("logger"))
00027 {
00028 }
00029 
00030 DLLFlowIDTarget::~DLLFlowIDTarget()
00031 {
00032 }
00033 
00034 TargetResult
00035 DLLFlowIDTarget::mangle(ip::IPCommand* ipHeader)
00036 {
00037   MESSAGE_BEGIN(NORMAL, log, m, "");
00038   m << *ipHeader;
00039   MESSAGE_END();
00040 
00041   return CONT;
00042 }
00043 
00044 TargetResult
00045 DLLFlowIDTarget::mangle(ip::IPCommand* ipHeader, wns::service::tl::ITCPHeader* tcpHeader)
00046 {
00047   MESSAGE_BEGIN(NORMAL, log, m, "");
00048   m << "MANGLE Incoming Compound with DLLFlowID: " << ipHeader->local.dllFlowID;
00049   m << " for TCP-FlowID: " << tcpHeader->getFlowID();
00050   MESSAGE_END();
00051 
00052   if(!knowsFlowIDList.knows(ipHeader->local.dllFlowID))
00053     {
00054       MESSAGE_BEGIN(NORMAL, log, m, "");
00055       m << "Unknown DllFlowID : " << ipHeader->local.dllFlowID;
00056       m << " adding new Rule to PostroutingChain.";
00057       MESSAGE_END();
00058       knowsFlowIDList.insert(ipHeader->local.dllFlowID, tcpHeader->getFlowID());
00059 
00060       //add new rule to postroutingchain and add dll and tl flowids to
00061       // creating new target:
00062       ip::iptables::targets::DLLFlowIDTaggerTarget* target =
00063     new ip::iptables::targets::DLLFlowIDTaggerTarget(ipHeader->local.dllFlowID, tcpHeader->getFlowID());
00064 
00065       //creating AcceptsAllFilter:
00066       ip::iptables::filters::AcceptsAllFilter* filter = new ip::iptables::filters::AcceptsAllFilter();
00067 
00068       //creating with dllFlowID as ruleTag
00069       ip::iptables::Rule rule = ip::iptables::Rule(filter,
00070                            target,
00071                            ipHeader->local.dllFlowID);
00072       //adding Rule
00073       postroutingChain->addRule(rule);
00074 
00075       return CONT;
00076     }
00077   else
00078     {
00079       return CONT;
00080     }
00081 
00082   MESSAGE_BEGIN(NORMAL, log, m, "DLLFlowIDTarget::mangle()");
00083   m << *ipHeader;
00084   m << " TCP : " << tcpHeader->getFlowID();
00085   if (tcpHeader->getUrgentFlag())
00086     {
00087       m << " URG";
00088     }
00089 
00090   if (tcpHeader->getAckFlag())
00091     {
00092       m << " ACK";
00093     }
00094   if (tcpHeader->getPushFlag())
00095     {
00096       m << " PSH";
00097     }
00098   if (tcpHeader->getSynFlag())
00099     {
00100       m << " SYN";
00101     }
00102   if (tcpHeader->getFinFlag())
00103     {
00104       m << " FIN";
00105     }
00106 
00107   MESSAGE_END();
00108 
00109   return CONT;
00110 }
00111 
00112 TargetResult
00113 DLLFlowIDTarget::mangle(ip::IPCommand* ipHeader, wns::service::tl::IUDPHeader* udpHeader)
00114 {
00115   MESSAGE_BEGIN(NORMAL, log, m, "");
00116   m << "MANGLE Incoming Compound with DLLFlowID: " << ipHeader->local.dllFlowID;
00117   m << " for UDP-FlowID: " << udpHeader->getFlowID();
00118   MESSAGE_END();
00119 
00120   if(!knowsFlowIDList.knows(ipHeader->local.dllFlowID))
00121     {
00122       MESSAGE_BEGIN(NORMAL, log, m, "");
00123       m << "Unknown DllFlowID : " << ipHeader->local.dllFlowID;
00124       m << " adding new Rule to PostroutingChain.";
00125       MESSAGE_END();
00126       knowsFlowIDList.insert(ipHeader->local.dllFlowID, udpHeader->getFlowID());
00127 
00128       //add new rule to postroutingchain and add dll and tl flowids to
00129       // creating new target:
00130       ip::iptables::targets::DLLFlowIDTaggerTarget* target =
00131     new ip::iptables::targets::DLLFlowIDTaggerTarget(ipHeader->local.dllFlowID, udpHeader->getFlowID());
00132 
00133       //creating AcceptsAllFilter:
00134       ip::iptables::filters::AcceptsAllFilter* filter = new ip::iptables::filters::AcceptsAllFilter();
00135 
00136       //creating with dllFlowID as ruleTag
00137       ip::iptables::Rule rule = ip::iptables::Rule(filter,
00138                            target,
00139                            ipHeader->local.dllFlowID);
00140       //adding Rule
00141       postroutingChain->addRule(rule);
00142 
00143       return CONT;
00144     }
00145   else
00146     {
00147       return CONT;
00148     }
00149 
00150   MESSAGE_BEGIN(NORMAL, log, m, "DLLFlowIDTarget::mangle()");
00151   m << *ipHeader;
00152   m << " UDP : " << udpHeader->getFlowID();
00153   MESSAGE_END();
00154 }
00155 
00156 void
00157 DLLFlowIDTarget::setRuleController(ip::iptables::IRuleControl* controller)
00158 {
00159   postroutingChain = controller;
00160   assure(postroutingChain, "PostroutingChain not registered");
00161 
00162   ip::iptables::PostroutingChain* tmp = dynamic_cast<ip::iptables::PostroutingChain*>(postroutingChain);
00163   tmp->registerDLLFlowIDTarget(this);
00164 
00165   MESSAGE_BEGIN(NORMAL, log, m, "PostroutingChain set");
00166   m << postroutingChain;
00167   MESSAGE_END();
00168 }
00169 
00170 bool
00171 DLLFlowIDTarget::knowsTLFlowID(wns::service::tl::FlowID tlFlowID)
00172 {
00173   bool foundTLFlowID = false;
00174   for (dllFlowIDList::const_iterator iter = knowsFlowIDList.begin();
00175        iter != knowsFlowIDList.end();
00176        ++iter)
00177     {
00178       if(iter->second == tlFlowID)
00179     {
00180       foundTLFlowID = true;
00181     }
00182     }
00183   return foundTLFlowID;
00184 }
00185 
00186 wns::service::dll::FlowID
00187 DLLFlowIDTarget::getDLLFlowID(wns::service::tl::FlowID tlFlowID)
00188 {
00189   for (dllFlowIDList::const_iterator iter = knowsFlowIDList.begin();
00190        iter != knowsFlowIDList.end();
00191        ++iter)
00192     {
00193       if(iter->second == tlFlowID)
00194     {
00195       return iter->first;
00196     }
00197     }
00198 }
00199 
00200 void
00201 DLLFlowIDTarget::ruleErased(wns::service::dll::FlowID flowID)
00202 {
00203   knowsFlowIDList.erase(flowID);
00204   MESSAGE_BEGIN(NORMAL, log, m, "FlowID erased from KnowsFlowIDList. FlowID: ");
00205   m << flowID;
00206   MESSAGE_END();
00207 }

Generated on Tue May 22 03:32:14 2012 for openWNS by  doxygen 1.5.5