]> git.stg.codes - stg.git/commitdiff
Fixed build.
authorMaxim Mamontov <faust.madf@gmail.com>
Sun, 8 Jun 2014 10:57:57 +0000 (13:57 +0300)
committerMaxim Mamontov <faust.madf@gmail.com>
Sun, 8 Jun 2014 10:57:57 +0000 (13:57 +0300)
projects/stargazer/build
projects/stargazer/plugins/capture/nfqueue/nfqueue.cpp
projects/stargazer/plugins/capture/nfqueue/nfqueue.h

index a695ed0db54ac886b5e344a46bc3daec359d57fa..754f83f77ffebd9f0e2a1a7b424aaa481f0a64aa 100755 (executable)
@@ -465,7 +465,7 @@ printf "CHECK_PCAP=$CHECK_PCAP\n" >> $CONFFILE
 printf "CHECK_NFNETLINK=$CHECK_NFNETLINK\n" >> $CONFFILE
 printf "CHECK_NFQ=$CHECK_NFQ\n" >> $CONFFILE
 printf "DEFS=$DEFS\n" >> $CONFFILE
 printf "CHECK_NFNETLINK=$CHECK_NFNETLINK\n" >> $CONFFILE
 printf "CHECK_NFQ=$CHECK_NFQ\n" >> $CONFFILE
 printf "DEFS=$DEFS\n" >> $CONFFILE
-printf "NFQ_LIBS=$NFQ_LIBS" >> $CONFFILE
+printf "NFQ_LIBS=$NFQ_LIBS\n" >> $CONFFILE
 printf "STG_LIBS=" >> $CONFFILE
 for lib in $STG_LIBS
 do
 printf "STG_LIBS=" >> $CONFFILE
 for lib in $STG_LIBS
 do
index 245fc64925837f937f4e13664658fbc5027fe37f..6a339523bc381416308692d0d3f446aee9a28143 100644 (file)
@@ -32,8 +32,12 @@ extern "C" {
 
 }
 
 
 }
 
+#include <cerrno>
+#include <csignal>
+
 #include <arpa/inet.h> // ntohl
 #include <arpa/inet.h> // ntohl
-#include <signal.h>
+
+#include <unistd.h> // read
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -43,7 +47,7 @@ namespace
 
 PLUGIN_CREATOR<NFQ_CAP> ncc;
 
 
 PLUGIN_CREATOR<NFQ_CAP> ncc;
 
-int callback(struct nfq_q_handle * /*queueHandle*/, struct nfgenmsg * /*msg*/,
+int Callback(struct nfq_q_handle * queueHandle, struct nfgenmsg * /*msg*/,
              struct nfq_data * nfqData, void *data)
 {
 int id = 0;
              struct nfq_data * nfqData, void *data)
 {
 int id = 0;
@@ -56,18 +60,18 @@ id = ntohl(packetHeader->packet_id);
 
 unsigned char * payload = NULL;
 
 
 unsigned char * payload = NULL;
 
-if (nfq_get_payload(nfqData) < 0)
+if (nfq_get_payload(nfqData, &payload) < 0 || payload == NULL)
     return id;
 
 RAW_PACKET packet;
 
     return id;
 
 RAW_PACKET packet;
 
-memcpy(&packet.rawPacket, payload, sizeof(ip.rawPacket));
+memcpy(&packet.rawPacket, payload, sizeof(packet.rawPacket));
 
 NFQ_CAP * cap = static_cast<NFQ_CAP *>(data);
 
 cap->Process(packet);
 
 
 NFQ_CAP * cap = static_cast<NFQ_CAP *>(data);
 
 cap->Process(packet);
 
-return nfq_set_verdict(qh, id, NF_ACCEPT, 0, NULL);
+return nfq_set_verdict(queueHandle, id, NF_ACCEPT, 0, NULL);
 }
 
 }
 }
 
 }
@@ -93,6 +97,7 @@ NFQ_CAP::NFQ_CAP()
       thread(),
       nonstop(false),
       isRunning(false),
       thread(),
       nonstop(false),
       isRunning(false),
+      queueNumber(0),
       traffCnt(NULL),
       logger(GetPluginLogger(GetStgLogger(), "cap_nfqueue"))
 {
       traffCnt(NULL),
       logger(GetPluginLogger(GetStgLogger(), "cap_nfqueue"))
 {
@@ -100,6 +105,14 @@ NFQ_CAP::NFQ_CAP()
 //-----------------------------------------------------------------------------
 int NFQ_CAP::ParseSettings()
 {
 //-----------------------------------------------------------------------------
 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)
+            {
+            errorStr = "Queue number should be a number. Got: '" + settings.moduleParams[i].param + "'";
+            logger(errorStr);
+            return -1;
+            }
 return 0;
 }
 //-----------------------------------------------------------------------------
 return 0;
 }
 //-----------------------------------------------------------------------------
@@ -211,7 +224,7 @@ pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
 NFQ_CAP * dc = static_cast<NFQ_CAP *>(d);
 dc->isRunning = true;
 
 NFQ_CAP * dc = static_cast<NFQ_CAP *>(d);
 dc->isRunning = true;
 
-int fd = nfq_fd(nfqHandle);
+int fd = nfq_fd(dc->nfqHandle);
 char buf[4096];
 
 while (dc->nonstop)
 char buf[4096];
 
 while (dc->nonstop)
@@ -219,16 +232,21 @@ while (dc->nonstop)
         if (!WaitPackets(fd))
             continue;
 
         if (!WaitPackets(fd))
             continue;
 
-        int rv = read(fd, buf, sizeof(buf), 0);
+        int rv = read(fd, buf, sizeof(buf));
         if (rv < 0)
             {
         if (rv < 0)
             {
-            errorStr = "Read error: " + strerror(errno);
-            logger(errorStr);
+            dc->errorStr = std::string("Read error: ") + strerror(errno);
+            dc->logger(dc->errorStr);
             break;
             }
             break;
             }
-        nfq_handle_packet(nfqHandle, buf, rv);
+        nfq_handle_packet(dc->nfqHandle, buf, rv);
     }
 
 dc->isRunning = false;
 return NULL;
 }
     }
 
 dc->isRunning = false;
 return NULL;
 }
+//-----------------------------------------------------------------------------
+void NFQ_CAP::Process(const RAW_PACKET & packet)
+{
+traffCnt->Process(packet);
+}
index 45342be012db250273f002bffe78fb3ff6ab1c12..871247848e0c1fef4c762493b925c50744f79438 100644 (file)
@@ -35,6 +35,7 @@ class TARIFFS;
 class ADMINS;
 class TRAFFCOUNTER;
 class SETTINGS;
 class ADMINS;
 class TRAFFCOUNTER;
 class SETTINGS;
+class RAW_PACKET;
 
 class TRAFFCOUNTER;
 
 
 class TRAFFCOUNTER;
 
@@ -61,7 +62,7 @@ public:
     uint16_t            GetStartPosition() const { return 40; }
     uint16_t            GetStopPosition() const { return 40; }
 
     uint16_t            GetStartPosition() const { return 40; }
     uint16_t            GetStopPosition() const { return 40; }
 
-    void                Process(const RAW_PACKET & packet) { traffCnt->Process(packet); }
+    void                Process(const RAW_PACKET & packet);
 
 private:
     NFQ_CAP(const NFQ_CAP & rvalue);
 
 private:
     NFQ_CAP(const NFQ_CAP & rvalue);
@@ -76,6 +77,8 @@ private:
     bool                isRunning;
     MODULE_SETTINGS     settings;
 
     bool                isRunning;
     MODULE_SETTINGS     settings;
 
+    size_t              queueNumber;
+
     struct nfq_handle * nfqHandle;
     struct nfq_q_handle * queueHandle;
 
     struct nfq_handle * nfqHandle;
     struct nfq_q_handle * queueHandle;