2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
23 #include "stg/traffcounter.h"
24 #include "stg/plugin_creator.h"
25 #include "stg/common.h"
26 #include "stg/raw_ip_packet.h"
30 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
35 PLUGIN_CREATOR<NFQ_CAP> ncc;
38 extern "C" PLUGIN * GetPlugin();
39 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
44 return ncc.GetPlugin();
46 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
49 std::string NFQ_CAP::GetVersion() const
51 return "cap_nfqueue v.1.0";
53 //-----------------------------------------------------------------------------
60 logger(GetPluginLogger(GetStgLogger(), "cap_nfqueue"))
63 //-----------------------------------------------------------------------------
64 int NFQ_CAP::ParseSettings()
68 //-----------------------------------------------------------------------------
76 if (pthread_create(&thread, NULL, Run, this))
78 errorStr = "Cannot create thread.";
79 logger("Cannot create thread.");
80 printfd(__FILE__, "Cannot create thread\n");
86 //-----------------------------------------------------------------------------
94 //5 seconds to thread stops itself
95 for (int i = 0; i < 25 && isRunning; i++)
97 struct timespec ts = {0, 200000000};
100 //after 5 seconds waiting thread still running. now killing it
103 if (pthread_kill(thread, SIGUSR1))
105 errorStr = "Cannot kill thread.";
106 logger("Cannot send signal to thread.");
109 for (int i = 0; i < 25 && isRunning; ++i)
111 struct timespec ts = {0, 200000000};
112 nanosleep(&ts, NULL);
116 errorStr = "NFQ_CAP not stopped.";
117 logger("Cannot stop thread.");
118 printfd(__FILE__, "Cannot stop thread\n");
123 pthread_join(thread, NULL);
127 //-----------------------------------------------------------------------------
128 void * NFQ_CAP::Run(void * d)
131 sigfillset(&signalSet);
132 pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
134 NFQ_CAP * dc = static_cast<NFQ_CAP *>(d);
135 dc->isRunning = true;
141 dc->isRunning = false;