]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/capture/nfqueue/nfqueue.cpp
Merge remote-tracking branch 'github/master'
[stg.git] / projects / stargazer / plugins / capture / nfqueue / nfqueue.cpp
index 68f7270caff0aafe4256c8fb63a9f76390052504..3c79c1b1c2f0376f5c771ff3278cbf7d1e069a0d 100644 (file)
@@ -21,7 +21,6 @@
 #include "nfqueue.h"
 
 #include "stg/traffcounter.h"
 #include "nfqueue.h"
 
 #include "stg/traffcounter.h"
-#include "stg/plugin_creator.h"
 #include "stg/common.h"
 #include "stg/raw_ip_packet.h"
 
 #include "stg/common.h"
 #include "stg/raw_ip_packet.h"
 
@@ -45,8 +44,6 @@ extern "C" {
 namespace
 {
 
 namespace
 {
 
-PLUGIN_CREATOR<NFQ_CAP> ncc;
-
 int Callback(struct nfq_q_handle * queueHandle, struct nfgenmsg * /*msg*/,
              struct nfq_data * nfqData, void *data)
 {
 int Callback(struct nfq_q_handle * queueHandle, struct nfgenmsg * /*msg*/,
              struct nfq_data * nfqData, void *data)
 {
@@ -63,7 +60,7 @@ unsigned char * payload = NULL;
 if (nfq_get_payload(nfqData, &payload) < 0 || payload == NULL)
     return id;
 
 if (nfq_get_payload(nfqData, &payload) < 0 || payload == NULL)
     return id;
 
-RAW_PACKET packet;
+STG::RawPacket packet;
 
 memcpy(&packet.rawPacket, payload, sizeof(packet.rawPacket));
 
 
 memcpy(&packet.rawPacket, payload, sizeof(packet.rawPacket));
 
@@ -76,13 +73,10 @@ return nfq_set_verdict(queueHandle, id, NF_ACCEPT, 0, NULL);
 
 }
 
 
 }
 
-extern "C" PLUGIN * GetPlugin();
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-PLUGIN * GetPlugin()
+extern "C" STG::Plugin* GetPlugin()
 {
 {
-return ncc.GetPlugin();
+    static NFQ_CAP plugin;
+    return &plugin;
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -93,23 +87,21 @@ return "cap_nfqueue v.1.0";
 }
 //-----------------------------------------------------------------------------
 NFQ_CAP::NFQ_CAP()
 }
 //-----------------------------------------------------------------------------
 NFQ_CAP::NFQ_CAP()
-    : errorStr(),
-      thread(),
-      nonstop(false),
+    : nonstop(false),
       isRunning(false),
       queueNumber(0),
       nfqHandle(NULL),
       queueHandle(NULL),
       traffCnt(NULL),
       isRunning(false),
       queueNumber(0),
       nfqHandle(NULL),
       queueHandle(NULL),
       traffCnt(NULL),
-      logger(GetPluginLogger(GetStgLogger(), "cap_nfqueue"))
+      logger(STG::PluginLogger::get("cap_nfqueue"))
 {
 }
 //-----------------------------------------------------------------------------
 int NFQ_CAP::ParseSettings()
 {
 for (size_t i = 0; i < settings.moduleParams.size(); i++)
 {
 }
 //-----------------------------------------------------------------------------
 int NFQ_CAP::ParseSettings()
 {
 for (size_t i = 0; i < settings.moduleParams.size(); i++)
-    if (settings.moduleParams[i].param == "queueNumber")
-        if (str2x(settings.moduleParams[i].param, queueNumber) < 0)
+    if (settings.moduleParams[i].param == "queueNumber" && !settings.moduleParams[i].value.empty())
+        if (str2x(settings.moduleParams[i].value[0], queueNumber) < 0)
             {
             errorStr = "Queue number should be a number. Got: '" + settings.moduleParams[i].param + "'";
             logger(errorStr);
             {
             errorStr = "Queue number should be a number. Got: '" + settings.moduleParams[i].param + "'";
             logger(errorStr);
@@ -148,14 +140,14 @@ if (nfq_bind_pf(nfqHandle, AF_INET) < 0)
 queueHandle = nfq_create_queue(nfqHandle, queueNumber, &Callback, this);
 if (queueHandle == NULL)
     {
 queueHandle = nfq_create_queue(nfqHandle, queueNumber, &Callback, this);
 if (queueHandle == NULL)
     {
-    errorStr = "Failed to create queue " + x2str(queueNumber) + ".";
+    errorStr = "Failed to create queue " + std::to_string(queueNumber) + ".";
     logger(errorStr);
     return -1;
     }
 
 if (nfq_set_mode(queueHandle, NFQNL_COPY_PACKET, 0xffFF) < 0)
     {
     logger(errorStr);
     return -1;
     }
 
 if (nfq_set_mode(queueHandle, NFQNL_COPY_PACKET, 0xffFF) < 0)
     {
-    errorStr = "Failed to set queue " + x2str(queueNumber) + " mode.";
+    errorStr = "Failed to set queue " + std::to_string(queueNumber) + " mode.";
     logger(errorStr);
     return -1;
     }
     logger(errorStr);
     return -1;
     }
@@ -248,7 +240,7 @@ dc->isRunning = false;
 return NULL;
 }
 //-----------------------------------------------------------------------------
 return NULL;
 }
 //-----------------------------------------------------------------------------
-void NFQ_CAP::Process(const RAW_PACKET & packet)
+void NFQ_CAP::Process(const STG::RawPacket & packet)
 {
 {
-traffCnt->Process(packet);
+traffCnt->process(packet);
 }
 }